The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/vm/vm_page.h

Version: -  FREEBSD  -  FREEBSD-13-STABLE  -  FREEBSD-13-0  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  l41  -  OPENBSD  -  linux-2.6  -  MK84  -  PLAN9  -  xnu-8792 
SearchContext: -  none  -  3  -  10 

    1 /* 
    2  * Mach Operating System
    3  * Copyright (c) 1993-1988 Carnegie Mellon University
    4  * All Rights Reserved.
    5  * 
    6  * Permission to use, copy, modify and distribute this software and its
    7  * documentation is hereby granted, provided that both the copyright
    8  * notice and this permission notice appear in all copies of the
    9  * software, derivative works or modified versions, and any portions
   10  * thereof, and that both notices appear in supporting documentation.
   11  * 
   12  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
   13  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
   14  * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
   15  * 
   16  * Carnegie Mellon requests users of this software to return to
   17  * 
   18  *  Software Distribution Coordinator  or  Software.Distribution@CS.CMU.EDU
   19  *  School of Computer Science
   20  *  Carnegie Mellon University
   21  *  Pittsburgh PA 15213-3890
   22  * 
   23  * any improvements or extensions that they make and grant Carnegie Mellon
   24  * the rights to redistribute these changes.
   25  */
   26 /*
   27  * HISTORY
   28  * $Log:        vm_page.h,v $
   29  * Revision 2.14  93/11/17  18:57:01  dbg
   30  *      Fixed declaration of vm_page_wait to use continuation_t.
   31  *      [93/06/16            dbg]
   32  * 
   33  * Revision 2.13  93/01/14  18:02:02  danner
   34  *      Added ANSI prototypes.
   35  *      [92/12/30            dbg]
   36  *      64bit cleanup.
   37  *      [92/12/01            af]
   38  * 
   39  * Revision 2.12  92/01/14  16:48:28  rpd
   40  *      Added vm_page_info declaration.
   41  *      [92/01/14            rpd]
   42  * 
   43  * Revision 2.11  91/07/01  08:28:05  jsb
   44  *      Change unused was_absent field to precious field.
   45  * 
   46  *      Remove extraneous include of kern/thread.h.
   47  *      [91/06/21            dlb]
   48  * 
   49  * Revision 2.10  91/05/18  14:41:37  rpd
   50  *      Removed vm_page_fictitious_zone.
   51  *      [91/05/16            rpd]
   52  * 
   53  *      Added vm_page_fictitious_addr.
   54  *      Removed VM_PAGE_TO_PHYS.
   55  *      [91/04/10            rpd]
   56  * 
   57  *      Changed vm_page_free_wanted to unsigned int.
   58  *      [91/04/05            rpd]
   59  *      Added vm_page_grab_fictitious, etc.
   60  *      [91/03/29            rpd]
   61  *      Removed VM_PAGE_DEBUG and associated variables,
   62  *      leaving a dummy VM_PAGE_CHECK definition.
   63  *      Added vm_page_attach.
   64  *      [91/03/22            rpd]
   65  * 
   66  * Revision 2.9  91/05/14  17:50:46  mrt
   67  *      Correcting copyright
   68  * 
   69  * Revision 2.8  91/03/16  15:06:38  rpd
   70  *      Added continuation argument to VM_PAGE_WAIT, vm_page_wait.
   71  *      [91/02/05            rpd]
   72  * 
   73  * Revision 2.7  91/02/05  17:59:48  mrt
   74  *      Changed to new Mach copyright
   75  *      [91/02/01  16:34:06  mrt]
   76  * 
   77  * Revision 2.6  91/01/08  16:45:48  rpd
   78  *      Changed to singly-linked VP bucket chains.
   79  *      [91/01/03            rpd]
   80  *      Changed vm_wait/VM_WAIT to vm_page_wait/VM_PAGE_WAIT.
   81  *      [90/11/13            rpd]
   82  * 
   83  * Revision 2.5  90/10/25  14:50:43  rwd
   84  *      Removed the max_mapping field of pages.
   85  *      [90/10/22            rpd]
   86  * 
   87  * Revision 2.4  90/10/12  13:06:41  rpd
   88  *      Added software reference bit to the page structure.
   89  *      [90/10/08            rpd]
   90  * 
   91  * Revision 2.3  90/02/22  20:06:43  dbg
   92  *              Rename PAGE_WAKEUP to PAGE_WAKEUP_DONE to reflect the fact that
   93  *              it clears the busy flag.  Add new PAGE_WAKEUP that only does the
   94  *              wakeup, and leaves the busy flag alone.
   95  *              [89/12/13            dlb]
   96  * 
   97  * Revision 2.2  90/01/11  11:48:21  dbg
   98  *      Add changes from mainline:
   99  * 
  100  *              Add vm_page_module_init() declaration.
  101  *              Change vm_page_zero_fill() to return void.
  102  *              [89/08/07            mwyoung]
  103  *              Added was_absent, overwriting fields.
  104  *              [89/05/15            mwyoung]
  105  *              Separate "private" from "fictitious" page attributes.
  106  *              [89/04/22            mwyoung]
  107  *              Move dirty bit under the object lock (from the page
  108  *              queues lock).
  109  *              [89/04/22            mwyoung]
  110  *      Changes for MACH_KERNEL:
  111  *      . Removed non-XP declarations.
  112  *      [89/04/28            dbg]
  113  * 
  114  * Revision 2.1  89/08/03  16:45:49  rwd
  115  * Created.
  116  * 
  117  * Revision 2.10  89/04/18  21:26:59  mwyoung
  118  *      Recent history:
  119  *              Add vm_page_fictitious_zone; remove clean, owner fields.
  120  *      History condensation: no relevant history.
  121  *      [89/04/18            mwyoung]
  122  * 
  123  * Revision 2.4  88/12/19  03:00:55  mwyoung
  124  */
  125 /*
  126  *      File:   vm/vm_page.h
  127  *      Author: Avadis Tevanian, Jr., Michael Wayne Young
  128  *      Date:   1985
  129  *
  130  *      Resident memory system definitions.
  131  */
  132 
  133 #ifndef _VM_VM_PAGE_H_
  134 #define _VM_VM_PAGE_H_
  135 
  136 #include <mach_vm_debug.h>
  137 
  138 #include <mach/boolean.h>
  139 #include <mach/vm_prot.h>
  140 #include <mach/vm_param.h>
  141 #include <vm/vm_object.h>
  142 #include <kern/queue.h>
  143 #include <kern/lock.h>
  144 #include <kern/zalloc.h>
  145 
  146 #include <kern/macro_help.h>
  147 #include <kern/sched_prim.h>    /* definitions of wait/wakeup */
  148 
  149 #if     MACH_VM_DEBUG
  150 #include <mach_debug/hash_info.h>
  151 #endif
  152 
  153 /*
  154  *      Management of resident (logical) pages.
  155  *
  156  *      A small structure is kept for each resident
  157  *      page, indexed by page number.  Each structure
  158  *      is an element of several lists:
  159  *
  160  *              A hash table bucket used to quickly
  161  *              perform object/offset lookups
  162  *
  163  *              A list of all pages for a given object,
  164  *              so they can be quickly deactivated at
  165  *              time of deallocation.
  166  *
  167  *              An ordered list of pages due for pageout.
  168  *
  169  *      In addition, the structure contains the object
  170  *      and offset to which this page belongs (for pageout),
  171  *      and sundry status bits.
  172  *
  173  *      Fields in this structure are locked either by the lock on the
  174  *      object that the page belongs to (O) or by the lock on the page
  175  *      queues (P).  [Some fields require that both locks be held to
  176  *      change that field; holding either lock is sufficient to read.]
  177  */
  178 
  179 struct vm_page {
  180         queue_chain_t   pageq;          /* queue info for FIFO
  181                                          * queue or free list (P) */
  182         queue_chain_t   listq;          /* all pages in same object (O) */
  183         struct vm_page  *next;          /* VP bucket link (O) */
  184 
  185         vm_object_t     object;         /* which object am I in (O,P) */
  186         vm_offset_t     offset;         /* offset into that object (O,P) */
  187 
  188         unsigned int    wire_count:16,  /* how many wired down maps use me?
  189                                            (O&P) */
  190         /* boolean_t */ inactive:1,     /* page is in inactive list (P) */
  191                         active:1,       /* page is in active list (P) */
  192                         laundry:1,      /* page is being cleaned now (P)*/
  193                         free:1,         /* page is on free list (P) */
  194                         reference:1,    /* page has been used (P) */
  195                         :0;             /* (force to 'long' boundary) */
  196 #ifdef  ns32000
  197         int             pad;            /* extra space for ns32000 bit ops */
  198 #endif  /* ns32000 */
  199 
  200         unsigned int
  201         /* boolean_t */ busy:1,         /* page is in transit (O) */
  202                         wanted:1,       /* someone is waiting for page (O) */
  203                         tabled:1,       /* page is in VP table (O) */
  204                         fictitious:1,   /* Physical page doesn't exist (O) */
  205                         private:1,      /* Page should not be returned to
  206                                          *  the free list (O) */
  207                         absent:1,       /* Data has been requested, but is
  208                                          *  not yet available (O) */
  209                         error:1,        /* Data manager was unable to provide
  210                                          *  data due to error (O) */
  211                         dirty:1,        /* Page must be cleaned (O) */
  212                         precious:1,     /* Page is precious; data must be
  213                                          *  returned even if clean (O) */
  214                         overwriting:1,  /* Request to unlock has been made
  215                                          * without having data. (O)
  216                                          * [See vm_object_overwrite] */
  217                         :0;
  218 
  219         vm_offset_t     phys_addr;      /* Physical address of page, passed
  220                                          *  to pmap_enter (read-only) */
  221         vm_prot_t       page_lock;      /* Uses prohibited by data manager (O) */
  222         vm_prot_t       unlock_request; /* Outstanding unlock request (O) */
  223 };
  224 
  225 typedef struct vm_page  *vm_page_t;
  226 
  227 #define VM_PAGE_NULL            ((vm_page_t) 0)
  228 
  229 /*
  230  *      For debugging, this macro can be defined to perform
  231  *      some useful check on a page structure.
  232  */
  233 
  234 #define VM_PAGE_CHECK(mem)
  235 
  236 /*
  237  *      Each pageable resident page falls into one of three lists:
  238  *
  239  *      free    
  240  *              Available for allocation now.
  241  *      inactive
  242  *              Not referenced in any map, but still has an
  243  *              object/offset-page mapping, and may be dirty.
  244  *              This is the list of pages that should be
  245  *              paged out next.
  246  *      active
  247  *              A list of pages which have been placed in
  248  *              at least one physical map.  This list is
  249  *              ordered, in LRU-like fashion.
  250  */
  251 
  252 extern
  253 vm_page_t       vm_page_queue_free;     /* memory free queue */
  254 extern
  255 vm_page_t       vm_page_queue_fictitious;       /* fictitious free queue */
  256 extern
  257 queue_head_t    vm_page_queue_active;   /* active memory queue */
  258 extern
  259 queue_head_t    vm_page_queue_inactive; /* inactive memory queue */
  260 
  261 extern
  262 vm_offset_t     first_phys_addr;        /* physical address for first_page */
  263 extern
  264 vm_offset_t     last_phys_addr;         /* physical address for last_page */
  265 
  266 extern
  267 int     vm_page_free_count;     /* How many pages are free? */
  268 extern
  269 int     vm_page_fictitious_count;/* How many fictitious pages are free? */
  270 extern
  271 int     vm_page_active_count;   /* How many pages are active? */
  272 extern
  273 int     vm_page_inactive_count; /* How many pages are inactive? */
  274 extern
  275 int     vm_page_wire_count;     /* How many pages are wired? */
  276 extern
  277 int     vm_page_free_target;    /* How many do we want free? */
  278 extern
  279 int     vm_page_free_min;       /* When to wakeup pageout */
  280 extern
  281 int     vm_page_inactive_target;/* How many do we want inactive? */
  282 extern
  283 int     vm_page_free_reserved;  /* How many pages reserved to do pageout */
  284 extern
  285 int     vm_page_laundry_count;  /* How many pages being laundered? */
  286 
  287 decl_simple_lock_data(extern,vm_page_queue_lock)/* lock on active and inactive
  288                                                    page queues */
  289 decl_simple_lock_data(extern,vm_page_queue_free_lock)
  290                                                 /* lock on free page queue */
  291 
  292 extern unsigned int     vm_page_free_wanted;
  293                                 /* how many threads are waiting for memory */
  294 
  295 extern vm_offset_t      vm_page_fictitious_addr;
  296                                 /* (fake) phys_addr of fictitious pages */
  297 
  298 extern void             vm_page_bootstrap(
  299                 vm_offset_t     *startp,
  300                 vm_offset_t     *endp);
  301 extern void             vm_page_module_init(void);
  302 
  303 extern void             vm_page_create(
  304                 vm_offset_t     start,
  305                 vm_offset_t     end);
  306 extern vm_page_t        vm_page_lookup(
  307                 vm_object_t     object,
  308                 vm_offset_t     offset);
  309 extern vm_page_t        vm_page_grab_fictitious(void);
  310 extern void             vm_page_release_fictitious(vm_page_t);
  311 extern boolean_t        vm_page_convert(vm_page_t);
  312 extern void             vm_page_more_fictitious(void);
  313 extern vm_page_t        vm_page_grab(void);
  314 extern void             vm_page_release(vm_page_t);
  315 extern void             vm_page_wait(continuation_t);
  316 extern vm_page_t        vm_page_alloc(
  317                 vm_object_t     object,
  318                 vm_offset_t     offset);
  319 extern void             vm_page_init(
  320                 vm_page_t       mem,
  321                 vm_offset_t     phys_addr);
  322 extern void             vm_page_free(vm_page_t);
  323 extern void             vm_page_activate(vm_page_t);
  324 extern void             vm_page_deactivate(vm_page_t);
  325 extern void             vm_page_rename(
  326                 vm_page_t       mem,
  327                 vm_object_t     new_object,
  328                 vm_offset_t     new_offset);
  329 extern void             vm_page_insert(
  330                 vm_page_t       mem,
  331                 vm_object_t     object,
  332                 vm_offset_t     offset);
  333 extern void             vm_page_replace(
  334                 vm_page_t       mem,
  335                 vm_object_t     object,
  336                 vm_offset_t     offset);
  337 extern void             vm_page_remove(
  338                 vm_page_t       mem);
  339 
  340 extern void             vm_page_zero_fill(vm_page_t);
  341 extern void             vm_page_copy(vm_page_t src_m, vm_page_t dest_m);
  342 
  343 extern void             vm_page_wire(vm_page_t);
  344 extern void             vm_page_unwire(vm_page_t);
  345 
  346 extern void             vm_set_page_size(void);
  347 
  348 #if     MACH_VM_DEBUG
  349 extern unsigned int     vm_page_info(
  350         hash_info_bucket_t      *info,
  351         unsigned int            count);
  352 #endif
  353 
  354 /*
  355  *      Functions implemented as macros
  356  */
  357 
  358 #define PAGE_ASSERT_WAIT(m, interruptible)                      \
  359                 MACRO_BEGIN                                     \
  360                 (m)->wanted = TRUE;                             \
  361                 assert_wait((event_t) (m), (interruptible));    \
  362                 MACRO_END
  363 
  364 #define PAGE_WAKEUP_DONE(m)                                     \
  365                 MACRO_BEGIN                                     \
  366                 (m)->busy = FALSE;                              \
  367                 if ((m)->wanted) {                              \
  368                         (m)->wanted = FALSE;                    \
  369                         thread_wakeup(((event_t) m));           \
  370                 }                                               \
  371                 MACRO_END
  372 
  373 #define PAGE_WAKEUP(m)                                          \
  374                 MACRO_BEGIN                                     \
  375                 if ((m)->wanted) {                              \
  376                         (m)->wanted = FALSE;                    \
  377                         thread_wakeup((event_t) (m));           \
  378                 }                                               \
  379                 MACRO_END
  380 
  381 #define VM_PAGE_FREE(p)                         \
  382                 MACRO_BEGIN                     \
  383                 vm_page_lock_queues();          \
  384                 vm_page_free(p);                \
  385                 vm_page_unlock_queues();        \
  386                 MACRO_END
  387 
  388 /*
  389  *      Macro to be used in place of pmap_enter()
  390  */
  391 
  392 #define PMAP_ENTER(pmap, virtual_address, page, protection, wired) \
  393                 MACRO_BEGIN                                     \
  394                 pmap_enter(                                     \
  395                         (pmap),                                 \
  396                         (virtual_address),                      \
  397                         (page)->phys_addr,                      \
  398                         (protection) & ~(page)->page_lock,      \
  399                         (wired)                                 \
  400                  );                                             \
  401                 MACRO_END
  402 
  403 #define VM_PAGE_WAIT(continuation)      vm_page_wait(continuation)
  404 
  405 #define vm_page_lock_queues()   simple_lock(&vm_page_queue_lock)
  406 #define vm_page_unlock_queues() simple_unlock(&vm_page_queue_lock)
  407 
  408 #define VM_PAGE_QUEUES_REMOVE(mem)                              \
  409         MACRO_BEGIN                                             \
  410         if (mem->active) {                                      \
  411                 queue_remove(&vm_page_queue_active,             \
  412                         mem, vm_page_t, pageq);                 \
  413                 mem->active = FALSE;                            \
  414                 vm_page_active_count--;                         \
  415         }                                                       \
  416                                                                 \
  417         if (mem->inactive) {                                    \
  418                 queue_remove(&vm_page_queue_inactive,           \
  419                         mem, vm_page_t, pageq);                 \
  420                 mem->inactive = FALSE;                          \
  421                 vm_page_inactive_count--;                       \
  422         }                                                       \
  423         MACRO_END
  424 
  425 #endif  /* _VM_VM_PAGE_H_ */

Cache object: c25a4d8ebc8f8133d49162b6fb788684


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.