home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Source Code / C / Applications / Portable Patmos / usr / include / vm / vm_page.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-11-08  |  9.3 KB  |  287 lines  |  [TEXT/R*ch]

  1. /* 
  2.  * Copyright (c) 1991 Regents of the University of California.
  3.  * All rights reserved.
  4.  *
  5.  * This code is derived from software contributed to Berkeley by
  6.  * The Mach Operating System project at Carnegie-Mellon University.
  7.  *
  8.  * Redistribution and use in source and binary forms, with or without
  9.  * modification, are permitted provided that the following conditions
  10.  * are met:
  11.  * 1. Redistributions of source code must retain the above copyright
  12.  *    notice, this list of conditions and the following disclaimer.
  13.  * 2. Redistributions in binary form must reproduce the above copyright
  14.  *    notice, this list of conditions and the following disclaimer in the
  15.  *    documentation and/or other materials provided with the distribution.
  16.  * 3. All advertising materials mentioning features or use of this software
  17.  *    must display the following acknowledgement:
  18.  *    This product includes software developed by the University of
  19.  *    California, Berkeley and its contributors.
  20.  * 4. Neither the name of the University nor the names of its contributors
  21.  *    may be used to endorse or promote products derived from this software
  22.  *    without specific prior written permission.
  23.  *
  24.  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  25.  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  26.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  27.  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  28.  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  29.  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  30.  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  31.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  32.  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  33.  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  34.  * SUCH DAMAGE.
  35.  *
  36.  *    from: @(#)vm_page.h    7.3 (Berkeley) 4/21/91
  37.  *    $Id: vm_page.h,v 1.6 1993/11/10 08:22:18 cgd Exp $
  38.  *
  39.  *
  40.  * Copyright (c) 1987, 1990 Carnegie-Mellon University.
  41.  * All rights reserved.
  42.  *
  43.  * Authors: Avadis Tevanian, Jr., Michael Wayne Young
  44.  * 
  45.  * Permission to use, copy, modify and distribute this software and
  46.  * its documentation is hereby granted, provided that both the copyright
  47.  * notice and this permission notice appear in all copies of the
  48.  * software, derivative works or modified versions, and any portions
  49.  * thereof, and that both notices appear in supporting documentation.
  50.  * 
  51.  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" 
  52.  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND 
  53.  * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
  54.  * 
  55.  * Carnegie Mellon requests users of this software to return to
  56.  *
  57.  *  Software Distribution Coordinator  or  Software.Distribution@CS.CMU.EDU
  58.  *  School of Computer Science
  59.  *  Carnegie Mellon University
  60.  *  Pittsburgh PA 15213-3890
  61.  *
  62.  * any improvements or extensions that they make and grant Carnegie the
  63.  * rights to redistribute these changes.
  64.  */
  65.  
  66. #ifndef _VM_VM_PAGE_H_
  67. #define _VM_VM_PAGE_H_
  68.  
  69. /*
  70.  *    Resident memory system definitions.
  71.  */
  72.  
  73. /*
  74.  *    Management of resident (logical) pages.
  75.  *
  76.  *    A small structure is kept for each resident
  77.  *    page, indexed by page number.  Each structure
  78.  *    is an element of several lists:
  79.  *
  80.  *        A hash table bucket used to quickly
  81.  *        perform object/offset lookups
  82.  *
  83.  *        A list of all pages for a given object,
  84.  *        so they can be quickly deactivated at
  85.  *        time of deallocation.
  86.  *
  87.  *        An ordered list of pages due for pageout.
  88.  *
  89.  *    In addition, the structure contains the object
  90.  *    and offset to which this page belongs (for pageout),
  91.  *    and sundry status bits.
  92.  *
  93.  *    Fields in this structure are locked either by the lock on the
  94.  *    object that the page belongs to (O) or by the lock on the page
  95.  *    queues (P).
  96.  */
  97.  
  98. struct vm_page {
  99.     queue_chain_t    pageq;        /* queue info for FIFO
  100.                      * queue or free list (P) */
  101.     queue_chain_t    hashq;        /* hash table links (O)*/
  102.     queue_chain_t    listq;        /* all pages in same object (O)*/
  103.  
  104.     vm_object_t    object;        /* which object am I in (O,P)*/
  105.     vm_offset_t    offset;        /* offset into that object (O,P) */
  106.  
  107.     unsigned int    wire_count:16,    /* how many wired down maps use me?
  108.                        (P) */
  109.     /* boolean_t */    inactive:1,    /* page is in inactive list (P) */
  110.             active:1,    /* page is in active list (P) */
  111.             laundry:1,    /* page is being cleaned now (P)*/
  112. #ifdef DEBUG
  113.             pagerowned:1,    /* async paging op in progress */
  114.             ptpage:1,    /* is a user page table page */
  115. #endif
  116.             :0;        /* (force to 'long' boundary) */
  117. #ifdef    ns32000
  118.     int        pad;        /* extra space for ns32000 bit ops */
  119. #endif    /* ns32000 */
  120.     boolean_t    clean;        /* page has not been modified */
  121.     unsigned int
  122.     /* boolean_t */    busy:1,        /* page is in transit (O) */
  123.             wanted:1,    /* someone is waiting for page (O) */
  124.             tabled:1,    /* page is in VP table (O) */
  125.             copy_on_write:1,/* page must be copied before being
  126.                        changed (O) */
  127.             fictitious:1,    /* physical page doesn't exist (O) */
  128.             fake:1,        /* page is a placeholder for page-in
  129.                        (O) */
  130.             :0;
  131.  
  132.     vm_offset_t    phys_addr;    /* physical address of page */
  133.     vm_prot_t    page_lock;    /* Uses prohibited by data manager */
  134.     vm_prot_t    unlock_request;    /* Outstanding unlock request */
  135. };
  136.  
  137. typedef struct vm_page    *vm_page_t;
  138.  
  139. #if    VM_PAGE_DEBUG
  140. #ifdef    MACHINE_NONCONTIG
  141. #define    VM_PAGE_CHECK(mem) { \
  142.         if ( (((unsigned int) mem) < ((unsigned int) &vm_page_array[0])) || \
  143.              (((unsigned int) mem) > ((unsigned int) &vm_page_array[vm_page_count])) || \
  144.              (mem->active && mem->inactive) \
  145.             ) panic("vm_page_check: not valid!"); \
  146.         }
  147. #else    /* MACHINE_NONCONTIG */
  148. #define    VM_PAGE_CHECK(mem) { \
  149.         if ( (((unsigned int) mem) < ((unsigned int) &vm_page_array[0])) || \
  150.              (((unsigned int) mem) > ((unsigned int) &vm_page_array[last_page-first_page])) || \
  151.              (mem->active && mem->inactive) \
  152.             ) panic("vm_page_check: not valid!"); \
  153.         }
  154. #endif    /* MACHINE_NONCONTIG */
  155. #else    /* VM_PAGE_DEBUG */
  156. #define    VM_PAGE_CHECK(mem)
  157. #endif    /* VM_PAGE_DEBUG */
  158.  
  159. #ifdef    KERNEL
  160. /*
  161.  *    Each pageable resident page falls into one of three lists:
  162.  *
  163.  *    free    
  164.  *        Available for allocation now.
  165.  *    inactive
  166.  *        Not referenced in any map, but still has an
  167.  *        object/offset-page mapping, and may be dirty.
  168.  *        This is the list of pages that should be
  169.  *        paged out next.
  170.  *    active
  171.  *        A list of pages which have been placed in
  172.  *        at least one physical map.  This list is
  173.  *        ordered, in LRU-like fashion.
  174.  */
  175.  
  176. extern
  177. queue_head_t    vm_page_queue_free;    /* memory free queue */
  178. extern
  179. queue_head_t    vm_page_queue_active;    /* active memory queue */
  180. extern
  181. queue_head_t    vm_page_queue_inactive;    /* inactive memory queue */
  182.  
  183. extern
  184. vm_page_t    vm_page_array;        /* First resident page in table */
  185.  
  186. #ifndef MACHINE_NONCONTIG
  187. extern
  188. long        first_page;        /* first physical page number */
  189.                     /* ... represented in vm_page_array */
  190. extern
  191. long        last_page;        /* last physical page number */
  192.  
  193. extern
  194. vm_offset_t    first_phys_addr;    /* physical address for first_page */
  195. extern
  196. vm_offset_t    last_phys_addr;        /* physical address for last_page */
  197. #else    /* MACHINE_NONCONTIG */
  198. extern
  199. u_long        first_page;        /* first physical page number */
  200. extern
  201. int        vm_page_count;        /* How many pages do we manage? */
  202. #endif    /* MACHINE_NONCONTIG */
  203.                     /* ... represented in vm_page_array */
  204.  
  205. extern
  206. int    vm_page_free_count;    /* How many pages are free? */
  207. extern
  208. int    vm_page_active_count;    /* How many pages are active? */
  209. extern
  210. int    vm_page_inactive_count;    /* How many pages are inactive? */
  211. extern
  212. int    vm_page_wire_count;    /* How many pages are wired? */
  213. extern
  214. int    vm_page_free_target;    /* How many do we want free? */
  215. extern
  216. int    vm_page_free_min;    /* When to wakeup pageout */
  217. extern
  218. int    vm_page_inactive_target;/* How many do we want inactive? */
  219. extern
  220. int    vm_page_free_reserved;    /* How many pages reserved to do pageout */
  221. extern
  222. int    vm_page_laundry_count;    /* How many pages being laundered? */
  223.  
  224. #define VM_PAGE_TO_PHYS(entry)    ((entry)->phys_addr)
  225.  
  226. #ifndef MACHINE_NONCONTIG
  227. #define IS_VM_PHYSADDR(pa) \
  228.         ((pa) >= first_phys_addr && (pa) <= last_phys_addr)
  229.  
  230. #define PHYS_TO_VM_PAGE(pa) \
  231.         (&vm_page_array[atop(pa) - first_page ])
  232. #else
  233. #define    IS_VM_PHYSADDR(pa) \
  234.         (pmap_page_index(pa) >= 0)
  235. #define    PHYS_TO_VM_PAGE(pa) \
  236.         (&vm_page_array[pmap_page_index(pa) - first_page])
  237. #endif /* MACHINE_NONCONTIG */
  238.  
  239. extern
  240. simple_lock_data_t    vm_page_queue_lock;    /* lock on active and inactive
  241.                            page queues */
  242. extern
  243. simple_lock_data_t    vm_page_queue_free_lock;
  244.                         /* lock on free page queue */
  245. vm_offset_t    vm_page_startup();
  246. vm_page_t    vm_page_lookup();
  247. vm_page_t    vm_page_alloc();
  248. void        vm_page_init();
  249. void        vm_page_free();
  250. void        vm_page_activate();
  251. void        vm_page_deactivate();
  252. void        vm_page_rename();
  253. void        vm_page_replace();
  254.  
  255. boolean_t    vm_page_zero_fill();
  256. void        vm_page_copy();
  257.  
  258. void        vm_page_wire();
  259. void        vm_page_unwire();
  260.  
  261. void        vm_set_page_size();
  262.  
  263. /*
  264.  *    Functions implemented as macros
  265.  */
  266.  
  267. #define PAGE_ASSERT_WAIT(m, interruptible)    { \
  268.                 (m)->wanted = TRUE; \
  269.                 assert_wait((int) (m), (interruptible)); \
  270.             }
  271.  
  272. #define PAGE_WAKEUP(m)    { \
  273.                 (m)->busy = FALSE; \
  274.                 if ((m)->wanted) { \
  275.                     (m)->wanted = FALSE; \
  276.                     thread_wakeup((int) (m)); \
  277.                 } \
  278.             }
  279.  
  280. #define    vm_page_lock_queues()    simple_lock(&vm_page_queue_lock)
  281. #define    vm_page_unlock_queues()    simple_unlock(&vm_page_queue_lock)
  282.  
  283. #define vm_page_set_modified(m)    { (m)->clean = FALSE; }
  284. #endif    /* KERNEL */
  285.  
  286. #endif    /* !_VM_VM_PAGE_H_ */
  287.