vm_pager.h revision 75474
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 75474 2001-04-13 10:23:32Z alfred $ 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 { 565455Sdg void (*pgo_init) __P((void)); /* Initialize pager. */ 5740286Sdg vm_object_t (*pgo_alloc) __P((void *, vm_ooffset_t, vm_prot_t, vm_ooffset_t)); /* Allocate pager. */ 589507Sdg void (*pgo_dealloc) __P((vm_object_t)); /* Disassociate. */ 599507Sdg int (*pgo_getpages) __P((vm_object_t, vm_page_t *, int, int)); /* Get (read) page. */ 6043129Sdillon void (*pgo_putpages) __P((vm_object_t, vm_page_t *, int, int, int *)); /* Put (write) page. */ 6112767Sdyson boolean_t (*pgo_haspage) __P((vm_object_t, vm_pindex_t, int *, int *)); /* Does pager have page? */ 6242957Sdillon void (*pgo_pageunswapped) __P((vm_page_t)); 6359915Sphk void (*pgo_strategy) __P((vm_object_t, struct bio *)); 641541Srgrimes}; 651541Srgrimes 661541Srgrimes/* 671541Srgrimes * get/put return values 681541Srgrimes * OK operation was successful 691541Srgrimes * BAD specified data was out of the accepted range 701541Srgrimes * FAIL specified data was in range, but doesn't exist 711541Srgrimes * PEND operations was initiated but not completed 721541Srgrimes * ERROR error while accessing data that is in range and exists 731541Srgrimes * AGAIN temporary resource shortage prevented operation from happening 741541Srgrimes */ 751541Srgrimes#define VM_PAGER_OK 0 761541Srgrimes#define VM_PAGER_BAD 1 771541Srgrimes#define VM_PAGER_FAIL 2 781541Srgrimes#define VM_PAGER_PEND 3 791541Srgrimes#define VM_PAGER_ERROR 4 801541Srgrimes#define VM_PAGER_AGAIN 5 811541Srgrimes 8234206Sdyson#define VM_PAGER_PUT_SYNC 0x1 8334206Sdyson#define VM_PAGER_PUT_INVAL 0x2 8434206Sdyson 8555206Speter#ifdef _KERNEL 8630354Sphk 8730354Sphk#ifdef MALLOC_DECLARE 8830354SphkMALLOC_DECLARE(M_VMPGDATA); 8930354Sphk#endif 9030354Sphk 919759Sbdeextern vm_map_t pager_map; 929759Sbdeextern int pager_map_size; 9342957Sdillonextern struct pagerops *pagertab[]; 9475474Salfredextern struct mtx pbuf_mtx; 959759Sbde 9640286Sdgvm_object_t vm_pager_allocate __P((objtype_t, void *, vm_ooffset_t, vm_prot_t, vm_ooffset_t)); 977090Sbdevoid vm_pager_bufferinit __P((void)); 989507Sdgvoid vm_pager_deallocate __P((vm_object_t)); 9942957Sdillonstatic __inline int vm_pager_get_pages __P((vm_object_t, vm_page_t *, int, int)); 10042957Sdillonstatic __inline boolean_t vm_pager_has_page __P((vm_object_t, vm_pindex_t, int *, int *)); 1015455Sdgvoid vm_pager_init __P((void)); 1029507Sdgvm_object_t vm_pager_object_lookup __P((struct pagerlst *, void *)); 1035455Sdgvm_offset_t vm_pager_map_pages __P((vm_page_t *, int, boolean_t)); 1045455Sdgvm_offset_t vm_pager_map_page __P((vm_page_t)); 1055455Sdgvoid vm_pager_sync __P((void)); 1065455Sdgvoid vm_pager_unmap_pages __P((vm_offset_t, int)); 1075455Sdgvoid vm_pager_unmap_page __P((vm_offset_t)); 10859915Sphkvoid vm_pager_strategy __P((vm_object_t object, struct bio *bp)); 10942957Sdillon 11046349Salc/* 11146349Salc * vm_page_get_pages: 11246349Salc * 11346349Salc * Retrieve pages from the VM system in order to map them into an object 11446349Salc * ( or into VM space somewhere ). If the pagein was successful, we 11546349Salc * must fully validate it. 11646349Salc */ 11746349Salc 11842957Sdillonstatic __inline int 11942957Sdillonvm_pager_get_pages( 12042957Sdillon vm_object_t object, 12142957Sdillon vm_page_t *m, 12242957Sdillon int count, 12342957Sdillon int reqpage 12442957Sdillon) { 12546349Salc int r; 12646349Salc 12746349Salc r = (*pagertab[object->type]->pgo_getpages)(object, m, count, reqpage); 12846349Salc if (r == VM_PAGER_OK && m[reqpage]->valid != VM_PAGE_BITS_ALL) { 12946349Salc vm_page_zero_invalid(m[reqpage], TRUE); 13046349Salc } 13146349Salc return(r); 13242957Sdillon} 13342957Sdillon 13443129Sdillonstatic __inline void 13542957Sdillonvm_pager_put_pages( 13642957Sdillon vm_object_t object, 13742957Sdillon vm_page_t *m, 13842957Sdillon int count, 13942957Sdillon int flags, 14042957Sdillon int *rtvals 14142957Sdillon) { 14243129Sdillon (*pagertab[object->type]->pgo_putpages) 14343129Sdillon (object, m, count, flags, rtvals); 14442957Sdillon} 14542957Sdillon 14658708Sdillon/* 14758708Sdillon * vm_pager_haspage 14858708Sdillon * 14958708Sdillon * Check to see if an object's pager has the requested page. The 15058708Sdillon * object's pager will also set before and after to give the caller 15158708Sdillon * some idea of the number of pages before and after the requested 15258708Sdillon * page can be I/O'd efficiently. 15358708Sdillon * 15458708Sdillon * This routine does not have to be called at any particular spl. 15558708Sdillon */ 15658708Sdillon 15742957Sdillonstatic __inline boolean_t 15842957Sdillonvm_pager_has_page( 15942957Sdillon vm_object_t object, 16042957Sdillon vm_pindex_t offset, 16142957Sdillon int *before, 16242957Sdillon int *after 16342957Sdillon) { 16442957Sdillon return ((*pagertab[object->type]->pgo_haspage) (object, offset, before, after)); 16542957Sdillon} 16642957Sdillon 16742957Sdillon/* 16842957Sdillon * vm_pager_page_unswapped 16942957Sdillon * 17042957Sdillon * called at splvm() to destroy swap associated with the page. 17142957Sdillon * 17242957Sdillon * This function may not block. 17342957Sdillon */ 17442957Sdillon 17542957Sdillonstatic __inline void 17642957Sdillonvm_pager_page_unswapped(vm_page_t m) 17742957Sdillon{ 17842957Sdillon if (pagertab[m->object->type]->pgo_pageunswapped) 17942957Sdillon (*pagertab[m->object->type]->pgo_pageunswapped)(m); 18042957Sdillon} 18142957Sdillon 1821541Srgrimes#endif 1831541Srgrimes 1845455Sdg#endif /* _VM_PAGER_ */ 185