xref: /minix3/sys/uvm/uvm.h (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1*0a6a1f1dSLionel Sambuc /*	$NetBSD: uvm.h,v 1.66 2015/04/13 22:04:44 riastradh Exp $	*/
26c8f7fc3SBen Gras 
36c8f7fc3SBen Gras /*
46c8f7fc3SBen Gras  * Copyright (c) 1997 Charles D. Cranor and Washington University.
56c8f7fc3SBen Gras  * All rights reserved.
66c8f7fc3SBen Gras  *
76c8f7fc3SBen Gras  * Redistribution and use in source and binary forms, with or without
86c8f7fc3SBen Gras  * modification, are permitted provided that the following conditions
96c8f7fc3SBen Gras  * are met:
106c8f7fc3SBen Gras  * 1. Redistributions of source code must retain the above copyright
116c8f7fc3SBen Gras  *    notice, this list of conditions and the following disclaimer.
126c8f7fc3SBen Gras  * 2. Redistributions in binary form must reproduce the above copyright
136c8f7fc3SBen Gras  *    notice, this list of conditions and the following disclaimer in the
146c8f7fc3SBen Gras  *    documentation and/or other materials provided with the distribution.
156c8f7fc3SBen Gras  *
166c8f7fc3SBen Gras  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
176c8f7fc3SBen Gras  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
186c8f7fc3SBen Gras  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
196c8f7fc3SBen Gras  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
206c8f7fc3SBen Gras  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
216c8f7fc3SBen Gras  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
226c8f7fc3SBen Gras  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
236c8f7fc3SBen Gras  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
246c8f7fc3SBen Gras  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
256c8f7fc3SBen Gras  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
266c8f7fc3SBen Gras  *
276c8f7fc3SBen Gras  * from: Id: uvm.h,v 1.1.2.14 1998/02/02 20:07:19 chuck Exp
286c8f7fc3SBen Gras  */
296c8f7fc3SBen Gras 
306c8f7fc3SBen Gras #ifndef _UVM_UVM_H_
316c8f7fc3SBen Gras #define _UVM_UVM_H_
326c8f7fc3SBen Gras 
336c8f7fc3SBen Gras #if defined(_KERNEL_OPT)
346c8f7fc3SBen Gras #include "opt_lockdebug.h"
356c8f7fc3SBen Gras #include "opt_multiprocessor.h"
366c8f7fc3SBen Gras #include "opt_uvmhist.h"
376c8f7fc3SBen Gras #include "opt_uvm_page_trkown.h"
386c8f7fc3SBen Gras #endif
396c8f7fc3SBen Gras 
406c8f7fc3SBen Gras #include <uvm/uvm_extern.h>
416c8f7fc3SBen Gras 
426c8f7fc3SBen Gras #ifdef _KERNEL
436c8f7fc3SBen Gras #include <uvm/uvm_stat.h>
446c8f7fc3SBen Gras #endif
456c8f7fc3SBen Gras 
466c8f7fc3SBen Gras /*
476c8f7fc3SBen Gras  * pull in prototypes
486c8f7fc3SBen Gras  */
496c8f7fc3SBen Gras 
506c8f7fc3SBen Gras #include <uvm/uvm_amap.h>
516c8f7fc3SBen Gras #include <uvm/uvm_aobj.h>
526c8f7fc3SBen Gras #include <uvm/uvm_fault.h>
536c8f7fc3SBen Gras #include <uvm/uvm_glue.h>
546c8f7fc3SBen Gras #include <uvm/uvm_km.h>
556c8f7fc3SBen Gras #include <uvm/uvm_loan.h>
566c8f7fc3SBen Gras #include <uvm/uvm_map.h>
576c8f7fc3SBen Gras #include <uvm/uvm_object.h>
586c8f7fc3SBen Gras #include <uvm/uvm_page.h>
596c8f7fc3SBen Gras #include <uvm/uvm_pager.h>
606c8f7fc3SBen Gras #include <uvm/uvm_pdaemon.h>
616c8f7fc3SBen Gras #include <uvm/uvm_swap.h>
626c8f7fc3SBen Gras 
636c8f7fc3SBen Gras #ifdef _KERNEL
646c8f7fc3SBen Gras 
65*0a6a1f1dSLionel Sambuc #include <sys/rndsource.h>
66*0a6a1f1dSLionel Sambuc 
676c8f7fc3SBen Gras /*
686c8f7fc3SBen Gras  * pull in VM_NFREELIST
696c8f7fc3SBen Gras  */
706c8f7fc3SBen Gras #include <machine/vmparam.h>
716c8f7fc3SBen Gras 
726c8f7fc3SBen Gras struct workqueue;
736c8f7fc3SBen Gras 
746c8f7fc3SBen Gras /*
756c8f7fc3SBen Gras  * per-cpu data
766c8f7fc3SBen Gras  */
776c8f7fc3SBen Gras 
786c8f7fc3SBen Gras struct uvm_cpu {
796c8f7fc3SBen Gras 	struct pgfreelist page_free[VM_NFREELIST]; /* unallocated pages */
806c8f7fc3SBen Gras 	int page_free_nextcolor;	/* next color to allocate from */
816c8f7fc3SBen Gras 	int page_idlezero_next;		/* which color to zero next */
826c8f7fc3SBen Gras 	bool page_idle_zero;		/* TRUE if we should try to zero
836c8f7fc3SBen Gras 					   pages in the idle loop */
846c8f7fc3SBen Gras 	int pages[PGFL_NQUEUES];	/* total of pages in page_free */
856c8f7fc3SBen Gras 	u_int emap_gen;			/* emap generation number */
866c8f7fc3SBen Gras 
876c8f7fc3SBen Gras 	krndsource_t rs;		/* entropy source */
886c8f7fc3SBen Gras };
896c8f7fc3SBen Gras 
906c8f7fc3SBen Gras /*
916c8f7fc3SBen Gras  * uvm structure (vm global state: collected in one structure for ease
926c8f7fc3SBen Gras  * of reference...)
936c8f7fc3SBen Gras  */
946c8f7fc3SBen Gras 
956c8f7fc3SBen Gras struct uvm {
966c8f7fc3SBen Gras 	/* vm_page related parameters */
976c8f7fc3SBen Gras 
986c8f7fc3SBen Gras 		/* vm_page queues */
996c8f7fc3SBen Gras 	struct pgfreelist page_free[VM_NFREELIST]; /* unallocated pages */
1006c8f7fc3SBen Gras 	bool page_init_done;		/* TRUE if uvm_page_init() finished */
1016c8f7fc3SBen Gras 
1026c8f7fc3SBen Gras 		/* page daemon trigger */
1036c8f7fc3SBen Gras 	int pagedaemon;			/* daemon sleeps on this */
1046c8f7fc3SBen Gras 	struct lwp *pagedaemon_lwp;	/* daemon's lid */
1056c8f7fc3SBen Gras 
1066c8f7fc3SBen Gras 		/* aiodone daemon */
1076c8f7fc3SBen Gras 	struct workqueue *aiodone_queue;
1086c8f7fc3SBen Gras 
1096c8f7fc3SBen Gras 	/* aio_done is locked by uvm.pagedaemon_lock and splbio! */
1106c8f7fc3SBen Gras 	TAILQ_HEAD(, buf) aio_done;		/* done async i/o reqs */
1116c8f7fc3SBen Gras 
1126c8f7fc3SBen Gras 	/* per-cpu data */
1136c8f7fc3SBen Gras 	struct uvm_cpu *cpus[MAXCPUS];
1146c8f7fc3SBen Gras };
1156c8f7fc3SBen Gras 
1166c8f7fc3SBen Gras /*
1176c8f7fc3SBen Gras  * kernel object: to support anonymous pageable kernel memory
1186c8f7fc3SBen Gras  */
1196c8f7fc3SBen Gras extern struct uvm_object *uvm_kernel_object;
1206c8f7fc3SBen Gras 
1216c8f7fc3SBen Gras /*
1226c8f7fc3SBen Gras  * locks (made globals for lockstat).
1236c8f7fc3SBen Gras  */
1246c8f7fc3SBen Gras 
1256c8f7fc3SBen Gras extern kmutex_t uvm_pageqlock;		/* lock for active/inactive page q */
1266c8f7fc3SBen Gras extern kmutex_t uvm_fpageqlock;		/* lock for free page q */
1276c8f7fc3SBen Gras extern kmutex_t uvm_kentry_lock;
1286c8f7fc3SBen Gras extern kmutex_t uvm_swap_data_lock;
1296c8f7fc3SBen Gras 
1306c8f7fc3SBen Gras #endif /* _KERNEL */
1316c8f7fc3SBen Gras 
1326c8f7fc3SBen Gras /*
1336c8f7fc3SBen Gras  * vm_map_entry etype bits:
1346c8f7fc3SBen Gras  */
1356c8f7fc3SBen Gras 
1366c8f7fc3SBen Gras #define UVM_ET_OBJ		0x01	/* it is a uvm_object */
1376c8f7fc3SBen Gras #define UVM_ET_SUBMAP		0x02	/* it is a vm_map submap */
1386c8f7fc3SBen Gras #define UVM_ET_COPYONWRITE 	0x04	/* copy_on_write */
1396c8f7fc3SBen Gras #define UVM_ET_NEEDSCOPY	0x08	/* needs_copy */
1406c8f7fc3SBen Gras 
1416c8f7fc3SBen Gras #define UVM_ET_ISOBJ(E)		(((E)->etype & UVM_ET_OBJ) != 0)
1426c8f7fc3SBen Gras #define UVM_ET_ISSUBMAP(E)	(((E)->etype & UVM_ET_SUBMAP) != 0)
1436c8f7fc3SBen Gras #define UVM_ET_ISCOPYONWRITE(E)	(((E)->etype & UVM_ET_COPYONWRITE) != 0)
1446c8f7fc3SBen Gras #define UVM_ET_ISNEEDSCOPY(E)	(((E)->etype & UVM_ET_NEEDSCOPY) != 0)
1456c8f7fc3SBen Gras 
1466c8f7fc3SBen Gras #ifdef _KERNEL
1476c8f7fc3SBen Gras 
1486c8f7fc3SBen Gras /*
1496c8f7fc3SBen Gras  * holds all the internal UVM data
1506c8f7fc3SBen Gras  */
1516c8f7fc3SBen Gras extern struct uvm uvm;
1526c8f7fc3SBen Gras 
1536c8f7fc3SBen Gras /*
1546c8f7fc3SBen Gras  * historys
1556c8f7fc3SBen Gras  */
1566c8f7fc3SBen Gras 
1576c8f7fc3SBen Gras #ifdef UVMHIST
1586c8f7fc3SBen Gras UVMHIST_DECL(maphist);
1596c8f7fc3SBen Gras UVMHIST_DECL(pdhist);
1606c8f7fc3SBen Gras UVMHIST_DECL(ubchist);
1616c8f7fc3SBen Gras UVMHIST_DECL(loanhist);
1626c8f7fc3SBen Gras #endif
1636c8f7fc3SBen Gras 
1646c8f7fc3SBen Gras extern struct evcnt uvm_ra_total;
1656c8f7fc3SBen Gras extern struct evcnt uvm_ra_hit;
1666c8f7fc3SBen Gras extern struct evcnt uvm_ra_miss;
1676c8f7fc3SBen Gras 
1686c8f7fc3SBen Gras /*
1696c8f7fc3SBen Gras  * UVM_UNLOCK_AND_WAIT: atomic unlock+wait... wrapper around the
1706c8f7fc3SBen Gras  * interlocked tsleep() function.
1716c8f7fc3SBen Gras  */
1726c8f7fc3SBen Gras 
1736c8f7fc3SBen Gras #define	UVM_UNLOCK_AND_WAIT(event, slock, intr, msg, timo)		\
1746c8f7fc3SBen Gras do {									\
1756c8f7fc3SBen Gras 	(void) mtsleep(event, PVM | PNORELOCK | (intr ? PCATCH : 0),	\
1766c8f7fc3SBen Gras 	    msg, timo, slock);						\
1776c8f7fc3SBen Gras } while (/*CONSTCOND*/ 0)
1786c8f7fc3SBen Gras 
1796c8f7fc3SBen Gras void uvm_kick_pdaemon(void);
1806c8f7fc3SBen Gras 
1816c8f7fc3SBen Gras /*
1826c8f7fc3SBen Gras  * UVM_PAGE_OWN: track page ownership (only if UVM_PAGE_TRKOWN)
1836c8f7fc3SBen Gras  */
1846c8f7fc3SBen Gras 
1856c8f7fc3SBen Gras #if defined(UVM_PAGE_TRKOWN)
1866c8f7fc3SBen Gras #define UVM_PAGE_OWN(PG, TAG) uvm_page_own(PG, TAG)
1876c8f7fc3SBen Gras #else
1886c8f7fc3SBen Gras #define UVM_PAGE_OWN(PG, TAG) /* nothing */
1896c8f7fc3SBen Gras #endif /* UVM_PAGE_TRKOWN */
1906c8f7fc3SBen Gras 
1916c8f7fc3SBen Gras #include <uvm/uvm_fault_i.h>
1926c8f7fc3SBen Gras 
1936c8f7fc3SBen Gras #endif /* _KERNEL */
1946c8f7fc3SBen Gras 
1956c8f7fc3SBen Gras #endif /* _UVM_UVM_H_ */
196