vm_pager.h revision 118384
11541Srgrimes/* 21541Srgrimes * Copyright (c) 1990 University of Utah. 31541Srgrimes * Copyright (c) 1991, 1993 41541Srgrimes * The Regents of the University of California. All rights reserved. 51541Srgrimes * 61541Srgrimes * This code is derived from software contributed to Berkeley by 71541Srgrimes * the Systems Programming Group of the University of Utah Computer 81541Srgrimes * Science Department. 91541Srgrimes * 101541Srgrimes * Redistribution and use in source and binary forms, with or without 111541Srgrimes * modification, are permitted provided that the following conditions 121541Srgrimes * are met: 131541Srgrimes * 1. Redistributions of source code must retain the above copyright 141541Srgrimes * notice, this list of conditions and the following disclaimer. 151541Srgrimes * 2. Redistributions in binary form must reproduce the above copyright 161541Srgrimes * notice, this list of conditions and the following disclaimer in the 171541Srgrimes * documentation and/or other materials provided with the distribution. 181541Srgrimes * 3. All advertising materials mentioning features or use of this software 191541Srgrimes * must display the following acknowledgement: 201541Srgrimes * This product includes software developed by the University of 211541Srgrimes * California, Berkeley and its contributors. 221541Srgrimes * 4. Neither the name of the University nor the names of its contributors 231541Srgrimes * may be used to endorse or promote products derived from this software 241541Srgrimes * without specific prior written permission. 251541Srgrimes * 261541Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 271541Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 281541Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 291541Srgrimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 301541Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 311541Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 321541Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 331541Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 341541Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 351541Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 361541Srgrimes * SUCH DAMAGE. 371541Srgrimes * 381541Srgrimes * @(#)vm_pager.h 8.4 (Berkeley) 1/12/94 3950477Speter * $FreeBSD: head/sys/vm/vm_pager.h 118384 2003-08-03 09:27:39Z phk $ 401541Srgrimes */ 411541Srgrimes 421541Srgrimes/* 431541Srgrimes * Pager routine interface definition. 441541Srgrimes */ 451541Srgrimes 461541Srgrimes#ifndef _VM_PAGER_ 471541Srgrimes#define _VM_PAGER_ 481541Srgrimes 4933058Sbde#include <sys/queue.h> 5033058Sbde 5160938SjakeTAILQ_HEAD(pagerlst, vm_object); 521541Srgrimes 5359915Sphkstruct bio; 5444739Sjulian 555455Sdgstruct pagerops { 5692727Salfred void (*pgo_init)(void); /* Initialize pager. */ 5792727Salfred vm_object_t (*pgo_alloc)(void *, vm_ooffset_t, vm_prot_t, vm_ooffset_t); /* Allocate pager. */ 5892727Salfred void (*pgo_dealloc)(vm_object_t); /* Disassociate. */ 5992727Salfred int (*pgo_getpages)(vm_object_t, vm_page_t *, int, int); /* Get (read) page. */ 6092727Salfred void (*pgo_putpages)(vm_object_t, vm_page_t *, int, int, int *); /* Put (write) page. */ 6192727Salfred boolean_t (*pgo_haspage)(vm_object_t, vm_pindex_t, int *, int *); /* Does pager have page? */ 6292727Salfred void (*pgo_pageunswapped)(vm_page_t); 6392727Salfred void (*pgo_strategy)(vm_object_t, struct bio *); 641541Srgrimes}; 651541Srgrimes 66118384Sphkextern struct pagerops defaultpagerops; 67118384Sphkextern struct pagerops swappagerops; 68118384Sphkextern struct pagerops vnodepagerops; 69118384Sphkextern struct pagerops devicepagerops; 70118384Sphkextern struct pagerops physpagerops; 71118384Sphk 721541Srgrimes/* 731541Srgrimes * get/put return values 741541Srgrimes * OK operation was successful 751541Srgrimes * BAD specified data was out of the accepted range 761541Srgrimes * FAIL specified data was in range, but doesn't exist 771541Srgrimes * PEND operations was initiated but not completed 781541Srgrimes * ERROR error while accessing data that is in range and exists 791541Srgrimes * AGAIN temporary resource shortage prevented operation from happening 801541Srgrimes */ 811541Srgrimes#define VM_PAGER_OK 0 821541Srgrimes#define VM_PAGER_BAD 1 831541Srgrimes#define VM_PAGER_FAIL 2 841541Srgrimes#define VM_PAGER_PEND 3 851541Srgrimes#define VM_PAGER_ERROR 4 861541Srgrimes#define VM_PAGER_AGAIN 5 871541Srgrimes 88108358Sdillon#define VM_PAGER_PUT_SYNC 0x0001 89108358Sdillon#define VM_PAGER_PUT_INVAL 0x0002 90108358Sdillon#define VM_PAGER_IGNORE_CLEANCHK 0x0004 91108358Sdillon#define VM_PAGER_CLUSTER_OK 0x0008 9234206Sdyson 9355206Speter#ifdef _KERNEL 9430354Sphk#ifdef MALLOC_DECLARE 9530354SphkMALLOC_DECLARE(M_VMPGDATA); 9630354Sphk#endif 9730354Sphk 989759Sbdeextern vm_map_t pager_map; 999759Sbdeextern int pager_map_size; 10042957Sdillonextern struct pagerops *pagertab[]; 10175474Salfredextern struct mtx pbuf_mtx; 1029759Sbde 10392727Salfredvm_object_t vm_pager_allocate(objtype_t, void *, vm_ooffset_t, vm_prot_t, vm_ooffset_t); 10492727Salfredvoid vm_pager_bufferinit(void); 10592727Salfredvoid vm_pager_deallocate(vm_object_t); 10692727Salfredstatic __inline int vm_pager_get_pages(vm_object_t, vm_page_t *, int, int); 10792727Salfredstatic __inline boolean_t vm_pager_has_page(vm_object_t, vm_pindex_t, int *, int *); 10892727Salfredvoid vm_pager_init(void); 10992727Salfredvm_object_t vm_pager_object_lookup(struct pagerlst *, void *); 11092727Salfredvm_offset_t vm_pager_map_page(vm_page_t); 11192727Salfredvoid vm_pager_unmap_page(vm_offset_t); 11292727Salfredvoid vm_pager_strategy(vm_object_t object, struct bio *bp); 11342957Sdillon 11446349Salc/* 11546349Salc * vm_page_get_pages: 11646349Salc * 11746349Salc * Retrieve pages from the VM system in order to map them into an object 11846349Salc * ( or into VM space somewhere ). If the pagein was successful, we 11946349Salc * must fully validate it. 12046349Salc */ 12142957Sdillonstatic __inline int 12242957Sdillonvm_pager_get_pages( 12342957Sdillon vm_object_t object, 12442957Sdillon vm_page_t *m, 12542957Sdillon int count, 12642957Sdillon int reqpage 12742957Sdillon) { 12846349Salc int r; 12946349Salc 130116710Salc VM_OBJECT_LOCK_ASSERT(object, MA_OWNED); 13146349Salc r = (*pagertab[object->type]->pgo_getpages)(object, m, count, reqpage); 13246349Salc if (r == VM_PAGER_OK && m[reqpage]->valid != VM_PAGE_BITS_ALL) { 13346349Salc vm_page_zero_invalid(m[reqpage], TRUE); 13446349Salc } 13592029Seivind return (r); 13642957Sdillon} 13742957Sdillon 13843129Sdillonstatic __inline void 13942957Sdillonvm_pager_put_pages( 14042957Sdillon vm_object_t object, 14142957Sdillon vm_page_t *m, 14242957Sdillon int count, 14342957Sdillon int flags, 14442957Sdillon int *rtvals 14542957Sdillon) { 14679224Sdillon GIANT_REQUIRED; 14743129Sdillon (*pagertab[object->type]->pgo_putpages) 14843129Sdillon (object, m, count, flags, rtvals); 14942957Sdillon} 15042957Sdillon 15158708Sdillon/* 15258708Sdillon * vm_pager_haspage 15358708Sdillon * 15458708Sdillon * Check to see if an object's pager has the requested page. The 15558708Sdillon * object's pager will also set before and after to give the caller 15658708Sdillon * some idea of the number of pages before and after the requested 15758708Sdillon * page can be I/O'd efficiently. 15858708Sdillon * 15958708Sdillon * This routine does not have to be called at any particular spl. 16058708Sdillon */ 16142957Sdillonstatic __inline boolean_t 16242957Sdillonvm_pager_has_page( 16342957Sdillon vm_object_t object, 16442957Sdillon vm_pindex_t offset, 16542957Sdillon int *before, 16642957Sdillon int *after 16742957Sdillon) { 16876827Salfred boolean_t ret; 16976827Salfred 170116695Salc VM_OBJECT_LOCK_ASSERT(object, MA_OWNED); 17176827Salfred ret = (*pagertab[object->type]->pgo_haspage) 17276827Salfred (object, offset, before, after); 17376827Salfred return (ret); 17442957Sdillon} 17542957Sdillon 17642957Sdillon/* 17742957Sdillon * vm_pager_page_unswapped 17842957Sdillon * 17942957Sdillon * called at splvm() to destroy swap associated with the page. 18042957Sdillon * 18142957Sdillon * This function may not block. 18242957Sdillon */ 18342957Sdillonstatic __inline void 18442957Sdillonvm_pager_page_unswapped(vm_page_t m) 18542957Sdillon{ 18679224Sdillon GIANT_REQUIRED; 18742957Sdillon if (pagertab[m->object->type]->pgo_pageunswapped) 18842957Sdillon (*pagertab[m->object->type]->pgo_pageunswapped)(m); 18942957Sdillon} 19042957Sdillon 19192029Seivind#endif /* _KERNEL */ 1925455Sdg#endif /* _VM_PAGER_ */ 193