Annotation of Gnu-Mach/vm/vm_page.h, revision 1.1.1.3

1.1       root        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  [email protected]
                     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:  *     File:   vm/vm_page.h
                     28:  *     Author: Avadis Tevanian, Jr., Michael Wayne Young
                     29:  *     Date:   1985
                     30:  *
                     31:  *     Resident memory system definitions.
                     32:  */
                     33: 
                     34: #ifndef        _VM_VM_PAGE_H_
                     35: #define _VM_VM_PAGE_H_
                     36: 
                     37: #include <mach/boolean.h>
                     38: #include <mach/vm_prot.h>
                     39: #include <mach/vm_param.h>
                     40: #include <vm/vm_object.h>
1.1.1.3 ! root       41: #include <vm/vm_types.h>
1.1       root       42: #include <kern/queue.h>
                     43: #include <kern/lock.h>
                     44: 
                     45: #include <kern/macro_help.h>
                     46: #include <kern/sched_prim.h>   /* definitions of wait/wakeup */
                     47: 
                     48: #if    MACH_VM_DEBUG
                     49: #include <mach_debug/hash_info.h>
                     50: #endif
                     51: 
                     52: /*
                     53:  *     Management of resident (logical) pages.
                     54:  *
                     55:  *     A small structure is kept for each resident
                     56:  *     page, indexed by page number.  Each structure
                     57:  *     is an element of several lists:
                     58:  *
                     59:  *             A hash table bucket used to quickly
                     60:  *             perform object/offset lookups
                     61:  *
                     62:  *             A list of all pages for a given object,
                     63:  *             so they can be quickly deactivated at
                     64:  *             time of deallocation.
                     65:  *
                     66:  *             An ordered list of pages due for pageout.
                     67:  *
                     68:  *     In addition, the structure contains the object
                     69:  *     and offset to which this page belongs (for pageout),
                     70:  *     and sundry status bits.
                     71:  *
                     72:  *     Fields in this structure are locked either by the lock on the
                     73:  *     object that the page belongs to (O) or by the lock on the page
                     74:  *     queues (P).  [Some fields require that both locks be held to
                     75:  *     change that field; holding either lock is sufficient to read.]
                     76:  */
                     77: 
                     78: struct vm_page {
                     79:        queue_chain_t   pageq;          /* queue info for FIFO
                     80:                                         * queue or free list (P) */
                     81:        queue_chain_t   listq;          /* all pages in same object (O) */
                     82:        struct vm_page  *next;          /* VP bucket link (O) */
                     83: 
                     84:        vm_object_t     object;         /* which object am I in (O,P) */
                     85:        vm_offset_t     offset;         /* offset into that object (O,P) */
                     86: 
                     87:        unsigned int    wire_count:16,  /* how many wired down maps use me?
                     88:                                           (O&P) */
                     89:        /* boolean_t */ inactive:1,     /* page is in inactive list (P) */
                     90:                        active:1,       /* page is in active list (P) */
                     91:                        laundry:1,      /* page is being cleaned now (P)*/
                     92:                        free:1,         /* page is on free list (P) */
                     93:                        reference:1,    /* page has been used (P) */
1.1.1.2   root       94:                        external:1,     /* page considered external (P) */
                     95:                        extcounted:1,   /* page counted in ext counts (P) */
1.1       root       96:                        :0;             /* (force to 'long' boundary) */
                     97: #ifdef ns32000
                     98:        int             pad;            /* extra space for ns32000 bit ops */
                     99: #endif /* ns32000 */
                    100: 
                    101:        unsigned int
                    102:        /* boolean_t */ busy:1,         /* page is in transit (O) */
                    103:                        wanted:1,       /* someone is waiting for page (O) */
                    104:                        tabled:1,       /* page is in VP table (O) */
                    105:                        fictitious:1,   /* Physical page doesn't exist (O) */
                    106:                        private:1,      /* Page should not be returned to
                    107:                                         *  the free list (O) */
                    108:                        absent:1,       /* Data has been requested, but is
                    109:                                         *  not yet available (O) */
                    110:                        error:1,        /* Data manager was unable to provide
                    111:                                         *  data due to error (O) */
                    112:                        dirty:1,        /* Page must be cleaned (O) */
                    113:                        precious:1,     /* Page is precious; data must be
                    114:                                         *  returned even if clean (O) */
                    115:                        overwriting:1,  /* Request to unlock has been made
                    116:                                         * without having data. (O)
                    117:                                         * [See vm_object_overwrite] */
                    118:                        :0;
                    119: 
                    120:        vm_offset_t     phys_addr;      /* Physical address of page, passed
                    121:                                         *  to pmap_enter (read-only) */
                    122:        vm_prot_t       page_lock;      /* Uses prohibited by data manager (O) */
                    123:        vm_prot_t       unlock_request; /* Outstanding unlock request (O) */
                    124: };
                    125: 
                    126: /*
                    127:  *     For debugging, this macro can be defined to perform
                    128:  *     some useful check on a page structure.
                    129:  */
                    130: 
                    131: #define VM_PAGE_CHECK(mem)
                    132: 
                    133: /*
                    134:  *     Each pageable resident page falls into one of three lists:
                    135:  *
                    136:  *     free    
                    137:  *             Available for allocation now.
                    138:  *     inactive
                    139:  *             Not referenced in any map, but still has an
                    140:  *             object/offset-page mapping, and may be dirty.
                    141:  *             This is the list of pages that should be
                    142:  *             paged out next.
                    143:  *     active
                    144:  *             A list of pages which have been placed in
                    145:  *             at least one physical map.  This list is
                    146:  *             ordered, in LRU-like fashion.
                    147:  */
                    148: 
                    149: extern
                    150: vm_page_t      vm_page_queue_free;     /* memory free queue */
                    151: extern
                    152: vm_page_t      vm_page_queue_fictitious;       /* fictitious free queue */
                    153: extern
                    154: queue_head_t   vm_page_queue_active;   /* active memory queue */
                    155: extern
                    156: queue_head_t   vm_page_queue_inactive; /* inactive memory queue */
                    157: 
                    158: extern
                    159: vm_offset_t    first_phys_addr;        /* physical address for first_page */
                    160: extern
                    161: vm_offset_t    last_phys_addr;         /* physical address for last_page */
                    162: 
                    163: extern
                    164: int    vm_page_free_count;     /* How many pages are free? */
                    165: extern
                    166: int    vm_page_fictitious_count;/* How many fictitious pages are free? */
                    167: extern
                    168: int    vm_page_active_count;   /* How many pages are active? */
                    169: extern
                    170: int    vm_page_inactive_count; /* How many pages are inactive? */
                    171: extern
                    172: int    vm_page_wire_count;     /* How many pages are wired? */
                    173: extern
                    174: int    vm_page_free_target;    /* How many do we want free? */
                    175: extern
                    176: int    vm_page_free_min;       /* When to wakeup pageout */
                    177: extern
                    178: int    vm_page_inactive_target;/* How many do we want inactive? */
                    179: extern
                    180: int    vm_page_free_reserved;  /* How many pages reserved to do pageout */
                    181: extern
                    182: int    vm_page_laundry_count;  /* How many pages being laundered? */
1.1.1.2   root      183: extern
                    184: int    vm_page_external_limit; /* Max number of pages for external objects  */
                    185: 
                    186: /* Only objects marked with the extcounted bit are included in this total.
                    187:    Pages which we scan for possible pageout, but which are not actually
                    188:    dirty, don't get considered against the external page limits any more
                    189:    in this way.  */
                    190: extern
                    191: int    vm_page_external_count; /* How many pages for external objects? */
                    192: 
                    193: 
1.1       root      194: 
                    195: decl_simple_lock_data(extern,vm_page_queue_lock)/* lock on active and inactive
                    196:                                                   page queues */
                    197: decl_simple_lock_data(extern,vm_page_queue_free_lock)
                    198:                                                /* lock on free page queue */
                    199: 
                    200: extern unsigned int    vm_page_free_wanted;
                    201:                                /* how many threads are waiting for memory */
                    202: 
                    203: extern vm_offset_t     vm_page_fictitious_addr;
                    204:                                /* (fake) phys_addr of fictitious pages */
                    205: 
                    206: extern void            vm_page_bootstrap(
                    207:        vm_offset_t     *startp,
                    208:        vm_offset_t     *endp);
                    209: extern void            vm_page_module_init(void);
                    210: 
                    211: extern void            vm_page_create(
                    212:        vm_offset_t     start,
                    213:        vm_offset_t     end);
                    214: extern vm_page_t       vm_page_lookup(
                    215:        vm_object_t     object,
                    216:        vm_offset_t     offset);
                    217: extern vm_page_t       vm_page_grab_fictitious(void);
                    218: extern void            vm_page_release_fictitious(vm_page_t);
1.1.1.2   root      219: extern boolean_t       vm_page_convert(vm_page_t, boolean_t);
1.1       root      220: extern void            vm_page_more_fictitious(void);
1.1.1.2   root      221: extern vm_page_t       vm_page_grab(boolean_t);
                    222: extern void            vm_page_release(vm_page_t, boolean_t);
1.1       root      223: extern void            vm_page_wait(void (*)(void));
                    224: extern vm_page_t       vm_page_alloc(
                    225:        vm_object_t     object,
                    226:        vm_offset_t     offset);
                    227: extern void            vm_page_init(
                    228:        vm_page_t       mem,
                    229:        vm_offset_t     phys_addr);
                    230: extern void            vm_page_free(vm_page_t);
                    231: extern void            vm_page_activate(vm_page_t);
                    232: extern void            vm_page_deactivate(vm_page_t);
                    233: extern void            vm_page_rename(
                    234:        vm_page_t       mem,
                    235:        vm_object_t     new_object,
                    236:        vm_offset_t     new_offset);
                    237: extern void            vm_page_insert(
                    238:        vm_page_t       mem,
                    239:        vm_object_t     object,
                    240:        vm_offset_t     offset);
                    241: extern void            vm_page_remove(
                    242:        vm_page_t       mem);
                    243: 
                    244: extern void            vm_page_zero_fill(vm_page_t);
                    245: extern void            vm_page_copy(vm_page_t src_m, vm_page_t dest_m);
                    246: 
                    247: extern void            vm_page_wire(vm_page_t);
                    248: extern void            vm_page_unwire(vm_page_t);
                    249: 
                    250: extern void            vm_set_page_size(void);
                    251: 
                    252: #if    MACH_VM_DEBUG
                    253: extern unsigned int    vm_page_info(
                    254:        hash_info_bucket_t      *info,
                    255:        unsigned int            count);
                    256: #endif
                    257: 
                    258: /*
                    259:  *     Functions implemented as macros
                    260:  */
                    261: 
                    262: #define PAGE_ASSERT_WAIT(m, interruptible)                     \
                    263:                MACRO_BEGIN                                     \
                    264:                (m)->wanted = TRUE;                             \
                    265:                assert_wait((event_t) (m), (interruptible));    \
                    266:                MACRO_END
                    267: 
                    268: #define PAGE_WAKEUP_DONE(m)                                    \
                    269:                MACRO_BEGIN                                     \
                    270:                (m)->busy = FALSE;                              \
                    271:                if ((m)->wanted) {                              \
                    272:                        (m)->wanted = FALSE;                    \
                    273:                        thread_wakeup(((event_t) m));           \
                    274:                }                                               \
                    275:                MACRO_END
                    276: 
                    277: #define PAGE_WAKEUP(m)                                         \
                    278:                MACRO_BEGIN                                     \
                    279:                if ((m)->wanted) {                              \
                    280:                        (m)->wanted = FALSE;                    \
                    281:                        thread_wakeup((event_t) (m));           \
                    282:                }                                               \
                    283:                MACRO_END
                    284: 
                    285: #define VM_PAGE_FREE(p)                        \
                    286:                MACRO_BEGIN                     \
                    287:                vm_page_lock_queues();          \
                    288:                vm_page_free(p);                \
                    289:                vm_page_unlock_queues();        \
                    290:                MACRO_END
                    291: 
                    292: /*
                    293:  *     Macro to be used in place of pmap_enter()
                    294:  */
                    295: 
                    296: #define PMAP_ENTER(pmap, virtual_address, page, protection, wired) \
                    297:                MACRO_BEGIN                                     \
                    298:                pmap_enter(                                     \
                    299:                        (pmap),                                 \
                    300:                        (virtual_address),                      \
                    301:                        (page)->phys_addr,                      \
                    302:                        (protection) & ~(page)->page_lock,      \
                    303:                        (wired)                                 \
                    304:                 );                                             \
                    305:                MACRO_END
                    306: 
                    307: #define        VM_PAGE_WAIT(continuation)      vm_page_wait(continuation)
                    308: 
                    309: #define vm_page_lock_queues()  simple_lock(&vm_page_queue_lock)
                    310: #define vm_page_unlock_queues()        simple_unlock(&vm_page_queue_lock)
                    311: 
                    312: #define VM_PAGE_QUEUES_REMOVE(mem)                             \
                    313:        MACRO_BEGIN                                             \
                    314:        if (mem->active) {                                      \
                    315:                queue_remove(&vm_page_queue_active,             \
                    316:                        mem, vm_page_t, pageq);                 \
                    317:                mem->active = FALSE;                            \
                    318:                vm_page_active_count--;                         \
                    319:        }                                                       \
                    320:                                                                \
                    321:        if (mem->inactive) {                                    \
                    322:                queue_remove(&vm_page_queue_inactive,           \
                    323:                        mem, vm_page_t, pageq);                 \
                    324:                mem->inactive = FALSE;                          \
                    325:                vm_page_inactive_count--;                       \
                    326:        }                                                       \
                    327:        MACRO_END
                    328: 
                    329: #endif /* _VM_VM_PAGE_H_ */

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.