10Sstevel@tonic-gate /* 20Sstevel@tonic-gate * CDDL HEADER START 30Sstevel@tonic-gate * 40Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*2414Saguzovsk * Common Development and Distribution License (the "License"). 6*2414Saguzovsk * You may not use this file except in compliance with the License. 70Sstevel@tonic-gate * 80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 100Sstevel@tonic-gate * See the License for the specific language governing permissions 110Sstevel@tonic-gate * and limitations under the License. 120Sstevel@tonic-gate * 130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 180Sstevel@tonic-gate * 190Sstevel@tonic-gate * CDDL HEADER END 200Sstevel@tonic-gate */ 210Sstevel@tonic-gate /* 22*2414Saguzovsk * Copyright 2006 Sun Microsystems, Inc. All rights reserved. 230Sstevel@tonic-gate * Use is subject to license terms. 240Sstevel@tonic-gate */ 250Sstevel@tonic-gate 260Sstevel@tonic-gate /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ 270Sstevel@tonic-gate /* All Rights Reserved */ 280Sstevel@tonic-gate 290Sstevel@tonic-gate /* 300Sstevel@tonic-gate * University Copyright- Copyright (c) 1982, 1986, 1988 310Sstevel@tonic-gate * The Regents of the University of California 320Sstevel@tonic-gate * All Rights Reserved 330Sstevel@tonic-gate * 340Sstevel@tonic-gate * University Acknowledgment- Portions of this document are derived from 350Sstevel@tonic-gate * software developed by the University of California, Berkeley, and its 360Sstevel@tonic-gate * contributors. 370Sstevel@tonic-gate */ 380Sstevel@tonic-gate 390Sstevel@tonic-gate #ifndef _VM_ANON_H 400Sstevel@tonic-gate #define _VM_ANON_H 410Sstevel@tonic-gate 420Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 430Sstevel@tonic-gate 440Sstevel@tonic-gate #include <sys/cred.h> 450Sstevel@tonic-gate #include <vm/seg.h> 460Sstevel@tonic-gate #include <vm/vpage.h> 470Sstevel@tonic-gate 480Sstevel@tonic-gate #ifdef __cplusplus 490Sstevel@tonic-gate extern "C" { 500Sstevel@tonic-gate #endif 510Sstevel@tonic-gate 520Sstevel@tonic-gate /* 530Sstevel@tonic-gate * VM - Anonymous pages. 540Sstevel@tonic-gate */ 550Sstevel@tonic-gate 560Sstevel@tonic-gate typedef unsigned long anoff_t; /* anon offsets */ 570Sstevel@tonic-gate 580Sstevel@tonic-gate /* 590Sstevel@tonic-gate * Each anonymous page, either in memory or in swap, has an anon structure. 600Sstevel@tonic-gate * The structure (slot) provides a level of indirection between anonymous pages 610Sstevel@tonic-gate * and their backing store. 620Sstevel@tonic-gate * 630Sstevel@tonic-gate * (an_vp, an_off) names the vnode of the anonymous page for this slot. 640Sstevel@tonic-gate * 650Sstevel@tonic-gate * (an_pvp, an_poff) names the location of the physical backing store 660Sstevel@tonic-gate * for the page this slot represents. If the name is null there is no 670Sstevel@tonic-gate * associated physical store. The physical backing store location can 680Sstevel@tonic-gate * change while the slot is in use. 690Sstevel@tonic-gate * 700Sstevel@tonic-gate * an_hash is a hash list of anon slots. The list is hashed by 710Sstevel@tonic-gate * (an_vp, an_off) of the associated anonymous page and provides a 720Sstevel@tonic-gate * method of going from the name of an anonymous page to its 730Sstevel@tonic-gate * associated anon slot. 740Sstevel@tonic-gate * 750Sstevel@tonic-gate * an_refcnt holds a reference count which is the number of separate 760Sstevel@tonic-gate * copies that will need to be created in case of copy-on-write. 770Sstevel@tonic-gate * A refcnt > 0 protects the existence of the slot. The refcnt is 780Sstevel@tonic-gate * initialized to 1 when the anon slot is created in anon_alloc(). 790Sstevel@tonic-gate * If a client obtains an anon slot and allows multiple threads to 800Sstevel@tonic-gate * share it, then it is the client's responsibility to insure that 810Sstevel@tonic-gate * it does not allow one thread to try to reference the slot at the 820Sstevel@tonic-gate * same time as another is trying to decrement the last count and 830Sstevel@tonic-gate * destroy the anon slot. E.g., the seg_vn segment type protects 840Sstevel@tonic-gate * against this with higher level locks. 850Sstevel@tonic-gate */ 860Sstevel@tonic-gate 870Sstevel@tonic-gate struct anon { 880Sstevel@tonic-gate struct vnode *an_vp; /* vnode of anon page */ 890Sstevel@tonic-gate struct vnode *an_pvp; /* vnode of physical backing store */ 900Sstevel@tonic-gate anoff_t an_off; /* offset of anon page */ 910Sstevel@tonic-gate anoff_t an_poff; /* offset in vnode */ 920Sstevel@tonic-gate struct anon *an_hash; /* hash table of anon slots */ 930Sstevel@tonic-gate int an_refcnt; /* # of people sharing slot */ 940Sstevel@tonic-gate }; 950Sstevel@tonic-gate 960Sstevel@tonic-gate #ifdef _KERNEL 970Sstevel@tonic-gate /* 980Sstevel@tonic-gate * The swapinfo_lock protects: 990Sstevel@tonic-gate * swapinfo list 1000Sstevel@tonic-gate * individual swapinfo structures 1010Sstevel@tonic-gate * 1020Sstevel@tonic-gate * The anoninfo_lock protects: 1030Sstevel@tonic-gate * anoninfo counters 1040Sstevel@tonic-gate * 1050Sstevel@tonic-gate * The anonhash_lock protects: 1060Sstevel@tonic-gate * anon hash lists 1070Sstevel@tonic-gate * anon slot fields 1080Sstevel@tonic-gate * 1090Sstevel@tonic-gate * Fields in the anon slot which are read-only for the life of the slot 1100Sstevel@tonic-gate * (an_vp, an_off) do not require the anonhash_lock be held to access them. 1110Sstevel@tonic-gate * If you access a field without the anonhash_lock held you must be holding 1120Sstevel@tonic-gate * the slot with an_refcnt to make sure it isn't destroyed. 1130Sstevel@tonic-gate * To write (an_pvp, an_poff) in a given slot you must also hold the 1140Sstevel@tonic-gate * p_iolock of the anonymous page for slot. 1150Sstevel@tonic-gate */ 1160Sstevel@tonic-gate extern kmutex_t anoninfo_lock; 1170Sstevel@tonic-gate extern kmutex_t swapinfo_lock; 1180Sstevel@tonic-gate extern kmutex_t anonhash_lock[]; 1190Sstevel@tonic-gate extern pad_mutex_t anon_array_lock[]; 1200Sstevel@tonic-gate extern kcondvar_t anon_array_cv[]; 1210Sstevel@tonic-gate 1220Sstevel@tonic-gate /* 1230Sstevel@tonic-gate * Global hash table to provide a function from (vp, off) -> ap 1240Sstevel@tonic-gate */ 1250Sstevel@tonic-gate extern size_t anon_hash_size; 1260Sstevel@tonic-gate extern struct anon **anon_hash; 1270Sstevel@tonic-gate #define ANON_HASH_SIZE anon_hash_size 1280Sstevel@tonic-gate #define ANON_HASHAVELEN 4 1290Sstevel@tonic-gate #define ANON_HASH(VP, OFF) \ 1300Sstevel@tonic-gate ((((uintptr_t)(VP) >> 7) ^ ((OFF) >> PAGESHIFT)) & (ANON_HASH_SIZE - 1)) 1310Sstevel@tonic-gate 1320Sstevel@tonic-gate #define AH_LOCK_SIZE 64 1330Sstevel@tonic-gate #define AH_LOCK(vp, off) (ANON_HASH((vp), (off)) & (AH_LOCK_SIZE -1)) 1340Sstevel@tonic-gate 1350Sstevel@tonic-gate #endif /* _KERNEL */ 1360Sstevel@tonic-gate 1370Sstevel@tonic-gate /* 1380Sstevel@tonic-gate * Declaration for the Global counters to accurately 1390Sstevel@tonic-gate * track the kernel foot print in memory. 1400Sstevel@tonic-gate */ 1410Sstevel@tonic-gate extern pgcnt_t segvn_pages_locked; 1420Sstevel@tonic-gate extern pgcnt_t pages_locked; 1430Sstevel@tonic-gate extern pgcnt_t pages_claimed; 1440Sstevel@tonic-gate extern pgcnt_t pages_useclaim; 1450Sstevel@tonic-gate extern pgcnt_t obp_pages; 1460Sstevel@tonic-gate 1470Sstevel@tonic-gate /* 1480Sstevel@tonic-gate * Anonymous backing store accounting structure for swapctl. 1490Sstevel@tonic-gate * 1500Sstevel@tonic-gate * ani_max = maximum amount of swap space 1510Sstevel@tonic-gate * (including potentially available physical memory) 1520Sstevel@tonic-gate * ani_free = amount of unallocated anonymous memory 1530Sstevel@tonic-gate * (some of which might be reserved and including 1540Sstevel@tonic-gate * potentially available physical memory) 1550Sstevel@tonic-gate * ani_resv = amount of claimed (reserved) anonymous memory 1560Sstevel@tonic-gate * 1570Sstevel@tonic-gate * The swap data can be aquired more efficiently through the 1580Sstevel@tonic-gate * kstats interface. 1590Sstevel@tonic-gate * Total slots currently available for reservation = 1600Sstevel@tonic-gate * MAX(ani_max - ani_resv, 0) + (availrmem - swapfs_minfree) 1610Sstevel@tonic-gate */ 1620Sstevel@tonic-gate struct anoninfo { 1630Sstevel@tonic-gate pgcnt_t ani_max; 1640Sstevel@tonic-gate pgcnt_t ani_free; 1650Sstevel@tonic-gate pgcnt_t ani_resv; 1660Sstevel@tonic-gate }; 1670Sstevel@tonic-gate 1680Sstevel@tonic-gate #ifdef _SYSCALL32 1690Sstevel@tonic-gate struct anoninfo32 { 1700Sstevel@tonic-gate size32_t ani_max; 1710Sstevel@tonic-gate size32_t ani_free; 1720Sstevel@tonic-gate size32_t ani_resv; 1730Sstevel@tonic-gate }; 1740Sstevel@tonic-gate #endif /* _SYSCALL32 */ 1750Sstevel@tonic-gate 1760Sstevel@tonic-gate /* 1770Sstevel@tonic-gate * Define the NCPU pool of the ani_free counters. Update the counter 1780Sstevel@tonic-gate * of the cpu on which the thread is running and in every clock intr 1790Sstevel@tonic-gate * sync anoninfo.ani_free with the current total off all the NCPU entries. 1800Sstevel@tonic-gate */ 1810Sstevel@tonic-gate 1820Sstevel@tonic-gate typedef struct ani_free { 1830Sstevel@tonic-gate kmutex_t ani_lock; 1840Sstevel@tonic-gate pgcnt_t ani_count; 1850Sstevel@tonic-gate uchar_t pad[64 - sizeof (kmutex_t) - sizeof (pgcnt_t)]; 1860Sstevel@tonic-gate /* XXX 64 = cacheline size */ 1870Sstevel@tonic-gate } ani_free_t; 1880Sstevel@tonic-gate 1890Sstevel@tonic-gate #define ANI_MAX_POOL 128 1900Sstevel@tonic-gate extern ani_free_t ani_free_pool[]; 1910Sstevel@tonic-gate 1920Sstevel@tonic-gate #define ANI_ADD(inc) { \ 1930Sstevel@tonic-gate ani_free_t *anifp; \ 1940Sstevel@tonic-gate int index; \ 1950Sstevel@tonic-gate index = (CPU->cpu_id & (ANI_MAX_POOL - 1)); \ 1960Sstevel@tonic-gate anifp = &ani_free_pool[index]; \ 1970Sstevel@tonic-gate mutex_enter(&anifp->ani_lock); \ 1980Sstevel@tonic-gate anifp->ani_count += inc; \ 1990Sstevel@tonic-gate mutex_exit(&anifp->ani_lock); \ 2000Sstevel@tonic-gate } 2010Sstevel@tonic-gate 2020Sstevel@tonic-gate /* 2030Sstevel@tonic-gate * Anon array pointers are allocated in chunks. Each chunk 2040Sstevel@tonic-gate * has PAGESIZE/sizeof(u_long *) of anon pointers. 2050Sstevel@tonic-gate * There are two levels of arrays for anon array pointers larger 2060Sstevel@tonic-gate * than a chunk. The first level points to anon array chunks. 2070Sstevel@tonic-gate * The second level consists of chunks of anon pointers. 2080Sstevel@tonic-gate * 2090Sstevel@tonic-gate * If anon array is smaller than a chunk then the whole anon array 2100Sstevel@tonic-gate * is created (memory is allocated for whole anon array). 2110Sstevel@tonic-gate * If anon array is larger than a chunk only first level array is 2120Sstevel@tonic-gate * allocated. Then other arrays (chunks) are allocated only when 2130Sstevel@tonic-gate * they are initialized with anon pointers. 2140Sstevel@tonic-gate */ 2150Sstevel@tonic-gate struct anon_hdr { 2160Sstevel@tonic-gate kmutex_t serial_lock; /* serialize array chunk allocation */ 2170Sstevel@tonic-gate pgcnt_t size; /* number of pointers to (anon) pages */ 2180Sstevel@tonic-gate void **array_chunk; /* pointers to anon pointers or chunks of */ 2190Sstevel@tonic-gate /* anon pointers */ 2200Sstevel@tonic-gate int flags; /* ANON_ALLOC_FORCE force preallocation of */ 2210Sstevel@tonic-gate /* whole anon array */ 2220Sstevel@tonic-gate }; 2230Sstevel@tonic-gate 2240Sstevel@tonic-gate #ifdef _LP64 2250Sstevel@tonic-gate #define ANON_PTRSHIFT 3 2260Sstevel@tonic-gate #define ANON_PTRMASK ~7 2270Sstevel@tonic-gate #else 2280Sstevel@tonic-gate #define ANON_PTRSHIFT 2 2290Sstevel@tonic-gate #define ANON_PTRMASK ~3 2300Sstevel@tonic-gate #endif 2310Sstevel@tonic-gate 2320Sstevel@tonic-gate #define ANON_CHUNK_SIZE (PAGESIZE >> ANON_PTRSHIFT) 2330Sstevel@tonic-gate #define ANON_CHUNK_SHIFT (PAGESHIFT - ANON_PTRSHIFT) 2340Sstevel@tonic-gate #define ANON_CHUNK_OFF (ANON_CHUNK_SIZE - 1) 2350Sstevel@tonic-gate 2360Sstevel@tonic-gate /* 2370Sstevel@tonic-gate * Anon flags. 2380Sstevel@tonic-gate */ 2390Sstevel@tonic-gate #define ANON_SLEEP 0x0 /* ok to block */ 2400Sstevel@tonic-gate #define ANON_NOSLEEP 0x1 /* non-blocking call */ 2410Sstevel@tonic-gate #define ANON_ALLOC_FORCE 0x2 /* force single level anon array */ 2420Sstevel@tonic-gate #define ANON_GROWDOWN 0x4 /* anon array should grow downward */ 2430Sstevel@tonic-gate 2440Sstevel@tonic-gate /* 2450Sstevel@tonic-gate * The anon_map structure is used by various clients of the anon layer to 2460Sstevel@tonic-gate * manage anonymous memory. When anonymous memory is shared, 2470Sstevel@tonic-gate * then the different clients sharing it will point to the 2480Sstevel@tonic-gate * same anon_map structure. Also, if a segment is unmapped 2490Sstevel@tonic-gate * in the middle where an anon_map structure exists, the 2500Sstevel@tonic-gate * newly created segment will also share the anon_map structure, 2510Sstevel@tonic-gate * although the two segments will use different ranges of the 2520Sstevel@tonic-gate * anon array. When mappings are private (or shared with 2530Sstevel@tonic-gate * a reference count of 1), an unmap operation will free up 2540Sstevel@tonic-gate * a range of anon slots in the array given by the anon_map 2550Sstevel@tonic-gate * structure. Because of fragmentation due to this unmapping, 2560Sstevel@tonic-gate * we have to store the size of the anon array in the anon_map 2570Sstevel@tonic-gate * structure so that we can free everything when the referernce 2580Sstevel@tonic-gate * count goes to zero. 2590Sstevel@tonic-gate * 2600Sstevel@tonic-gate * A new rangelock scheme is introduced to make the anon layer scale. 2610Sstevel@tonic-gate * A reader/writer lock per anon_amp and an array of system-wide hash 2620Sstevel@tonic-gate * locks, anon_array_lock[] are introduced to replace serial_lock and 2630Sstevel@tonic-gate * anonmap lock. The writer lock is held when we want to singlethreaD 2640Sstevel@tonic-gate * the reference to the anon array pointers or when references to 2650Sstevel@tonic-gate * anon_map's members, whereas reader lock and anon_array_lock are 2660Sstevel@tonic-gate * held to allows multiple threads to reference different part of 2670Sstevel@tonic-gate * anon array. A global set of condition variables, anon_array_cv, 2680Sstevel@tonic-gate * are used with anon_array_lock[] to make the hold time of the locks 2690Sstevel@tonic-gate * short. 2700Sstevel@tonic-gate * 2710Sstevel@tonic-gate * szc is used to calculate the index of hash locks and cv's. We 2720Sstevel@tonic-gate * could've just used seg->s_szc if not for the possible sharing of 2730Sstevel@tonic-gate * anon_amp between SYSV shared memory and ISM, so now we introduce 2740Sstevel@tonic-gate * szc in the anon_map structure. For MAP_SHARED, the amp->szc is either 2750Sstevel@tonic-gate * 0 (base page size) or page_num_pagesizes() - 1, while MAP_PRIVATE 2760Sstevel@tonic-gate * the amp->szc could be anything in [0, page_num_pagesizes() - 1]. 2770Sstevel@tonic-gate */ 2780Sstevel@tonic-gate struct anon_map { 2790Sstevel@tonic-gate krwlock_t a_rwlock; /* protect anon_map and anon array */ 2800Sstevel@tonic-gate size_t size; /* size in bytes mapped by the anon array */ 2810Sstevel@tonic-gate struct anon_hdr *ahp; /* anon array header pointer, containing */ 2820Sstevel@tonic-gate /* anon pointer array(s) */ 2830Sstevel@tonic-gate size_t swresv; /* swap space reserved for this anon_map */ 284*2414Saguzovsk ulong_t refcnt; /* reference count on this structure */ 2850Sstevel@tonic-gate ushort_t a_szc; /* max szc among shared processes */ 2860Sstevel@tonic-gate void *locality; /* lgroup locality info */ 2870Sstevel@tonic-gate }; 2880Sstevel@tonic-gate 2890Sstevel@tonic-gate #ifdef _KERNEL 2900Sstevel@tonic-gate 2910Sstevel@tonic-gate #define ANON_BUSY 0x1 2920Sstevel@tonic-gate #define ANON_ISBUSY(slot) (*(slot) & ANON_BUSY) 2930Sstevel@tonic-gate #define ANON_SETBUSY(slot) (*(slot) |= ANON_BUSY) 2940Sstevel@tonic-gate #define ANON_CLRBUSY(slot) (*(slot) &= ~ANON_BUSY) 2950Sstevel@tonic-gate 2960Sstevel@tonic-gate #define ANON_MAP_SHIFT 6 /* log2(sizeof (struct anon_map)) */ 2970Sstevel@tonic-gate #define ANON_ARRAY_SHIFT 7 /* log2(ANON_LOCKSIZE) */ 2980Sstevel@tonic-gate #define ANON_LOCKSIZE 128 2990Sstevel@tonic-gate 3000Sstevel@tonic-gate #define ANON_LOCK_ENTER(lock, type) rw_enter((lock), (type)) 3010Sstevel@tonic-gate #define ANON_LOCK_EXIT(lock) rw_exit((lock)) 3020Sstevel@tonic-gate 3030Sstevel@tonic-gate #define ANON_ARRAY_HASH(amp, idx)\ 3040Sstevel@tonic-gate ((((idx) + ((idx) >> ANON_ARRAY_SHIFT) +\ 3050Sstevel@tonic-gate ((idx) >> (ANON_ARRAY_SHIFT << 1)) +\ 3060Sstevel@tonic-gate ((idx) >> (ANON_ARRAY_SHIFT + (ANON_ARRAY_SHIFT << 1)))) ^\ 3070Sstevel@tonic-gate ((uintptr_t)(amp) >> ANON_MAP_SHIFT)) & (ANON_LOCKSIZE - 1)) 3080Sstevel@tonic-gate 3090Sstevel@tonic-gate typedef struct anon_sync_obj { 3100Sstevel@tonic-gate kmutex_t *sync_mutex; 3110Sstevel@tonic-gate kcondvar_t *sync_cv; 3120Sstevel@tonic-gate ulong_t *sync_data; 3130Sstevel@tonic-gate } anon_sync_obj_t; 3140Sstevel@tonic-gate 3150Sstevel@tonic-gate /* 3160Sstevel@tonic-gate * Anonymous backing store accounting structure for kernel. 3170Sstevel@tonic-gate * ani_max = total reservable slots on physical (disk-backed) swap 3180Sstevel@tonic-gate * ani_phys_resv = total phys slots reserved for use by clients 3190Sstevel@tonic-gate * ani_mem_resv = total mem slots reserved for use by clients 3200Sstevel@tonic-gate * ani_free = # unallocated physical slots + # of reserved unallocated 3210Sstevel@tonic-gate * memory slots 3220Sstevel@tonic-gate */ 3230Sstevel@tonic-gate 3240Sstevel@tonic-gate /* 3250Sstevel@tonic-gate * Initial total swap slots available for reservation 3260Sstevel@tonic-gate */ 3270Sstevel@tonic-gate #define TOTAL_AVAILABLE_SWAP \ 3280Sstevel@tonic-gate (k_anoninfo.ani_max + MAX((spgcnt_t)(availrmem - swapfs_minfree), 0)) 3290Sstevel@tonic-gate 3300Sstevel@tonic-gate /* 3310Sstevel@tonic-gate * Swap slots currently available for reservation 3320Sstevel@tonic-gate */ 3330Sstevel@tonic-gate #define CURRENT_TOTAL_AVAILABLE_SWAP \ 3340Sstevel@tonic-gate ((k_anoninfo.ani_max - k_anoninfo.ani_phys_resv) + \ 3350Sstevel@tonic-gate MAX((spgcnt_t)(availrmem - swapfs_minfree), 0)) 3360Sstevel@tonic-gate 3370Sstevel@tonic-gate struct k_anoninfo { 3380Sstevel@tonic-gate pgcnt_t ani_max; /* total reservable slots on phys */ 3390Sstevel@tonic-gate /* (disk) swap */ 3400Sstevel@tonic-gate pgcnt_t ani_free; /* # of unallocated phys and mem slots */ 3410Sstevel@tonic-gate pgcnt_t ani_phys_resv; /* # of reserved phys (disk) slots */ 3420Sstevel@tonic-gate pgcnt_t ani_mem_resv; /* # of reserved mem slots */ 3430Sstevel@tonic-gate pgcnt_t ani_locked_swap; /* # of swap slots locked in reserved */ 3440Sstevel@tonic-gate /* mem swap */ 3450Sstevel@tonic-gate }; 3460Sstevel@tonic-gate 3470Sstevel@tonic-gate extern struct k_anoninfo k_anoninfo; 3480Sstevel@tonic-gate 3490Sstevel@tonic-gate extern void anon_init(void); 3500Sstevel@tonic-gate extern struct anon *anon_alloc(struct vnode *, anoff_t); 3510Sstevel@tonic-gate extern void anon_dup(struct anon_hdr *, ulong_t, 3520Sstevel@tonic-gate struct anon_hdr *, ulong_t, size_t); 3530Sstevel@tonic-gate extern void anon_dup_fill_holes(struct anon_hdr *, ulong_t, 3540Sstevel@tonic-gate struct anon_hdr *, ulong_t, size_t, uint_t, int); 3550Sstevel@tonic-gate extern int anon_fill_cow_holes(struct seg *, caddr_t, struct anon_hdr *, 3560Sstevel@tonic-gate ulong_t, struct vnode *, u_offset_t, size_t, uint_t, 3570Sstevel@tonic-gate uint_t, struct vpage [], struct cred *); 3580Sstevel@tonic-gate extern void anon_free(struct anon_hdr *, ulong_t, size_t); 3590Sstevel@tonic-gate extern void anon_free_pages(struct anon_hdr *, ulong_t, size_t, uint_t); 3600Sstevel@tonic-gate extern void anon_disclaim(struct anon_map *, ulong_t, size_t, int); 3610Sstevel@tonic-gate extern int anon_getpage(struct anon **, uint_t *, struct page **, 3620Sstevel@tonic-gate size_t, struct seg *, caddr_t, enum seg_rw, struct cred *); 3630Sstevel@tonic-gate extern int swap_getconpage(struct vnode *, u_offset_t, size_t, 364*2414Saguzovsk uint_t *, page_t *[], size_t, page_t *, uint_t *, 3650Sstevel@tonic-gate spgcnt_t *, struct seg *, caddr_t, 3660Sstevel@tonic-gate enum seg_rw, struct cred *); 3670Sstevel@tonic-gate extern int anon_map_getpages(struct anon_map *, ulong_t, 3680Sstevel@tonic-gate uint_t, struct seg *, caddr_t, uint_t, 3690Sstevel@tonic-gate uint_t *, page_t *[], uint_t *, 3700Sstevel@tonic-gate struct vpage [], enum seg_rw, int, int, struct cred *); 3710Sstevel@tonic-gate extern int anon_map_privatepages(struct anon_map *, ulong_t, 3720Sstevel@tonic-gate uint_t, struct seg *, caddr_t, uint_t, 3730Sstevel@tonic-gate page_t *[], struct vpage [], int, struct cred *); 3740Sstevel@tonic-gate extern struct page *anon_private(struct anon **, struct seg *, 3750Sstevel@tonic-gate caddr_t, uint_t, struct page *, 3760Sstevel@tonic-gate int, struct cred *); 3770Sstevel@tonic-gate extern struct page *anon_zero(struct seg *, caddr_t, 3780Sstevel@tonic-gate struct anon **, struct cred *); 3790Sstevel@tonic-gate extern int anon_map_createpages(struct anon_map *, ulong_t, 3800Sstevel@tonic-gate size_t, struct page **, 3810Sstevel@tonic-gate struct seg *, caddr_t, 3820Sstevel@tonic-gate enum seg_rw, struct cred *); 3830Sstevel@tonic-gate extern int anon_map_demotepages(struct anon_map *, ulong_t, 3840Sstevel@tonic-gate struct seg *, caddr_t, uint_t, 3850Sstevel@tonic-gate struct vpage [], struct cred *); 386*2414Saguzovsk extern void anon_shmap_free_pages(struct anon_map *, ulong_t, size_t); 3870Sstevel@tonic-gate extern int anon_resvmem(size_t, uint_t); 3880Sstevel@tonic-gate extern void anon_unresv(size_t); 3890Sstevel@tonic-gate extern struct anon_map *anonmap_alloc(size_t, size_t); 3900Sstevel@tonic-gate extern void anonmap_free(struct anon_map *); 3910Sstevel@tonic-gate extern void anon_decref(struct anon *); 3920Sstevel@tonic-gate extern int non_anon(struct anon_hdr *, ulong_t, u_offset_t *, size_t *); 3930Sstevel@tonic-gate extern pgcnt_t anon_pages(struct anon_hdr *, ulong_t, pgcnt_t); 3940Sstevel@tonic-gate extern int anon_swap_adjust(pgcnt_t); 3950Sstevel@tonic-gate extern void anon_swap_restore(pgcnt_t); 3960Sstevel@tonic-gate extern struct anon_hdr *anon_create(pgcnt_t, int); 3970Sstevel@tonic-gate extern void anon_release(struct anon_hdr *, pgcnt_t); 3980Sstevel@tonic-gate extern struct anon *anon_get_ptr(struct anon_hdr *, ulong_t); 3990Sstevel@tonic-gate extern ulong_t *anon_get_slot(struct anon_hdr *, ulong_t); 4000Sstevel@tonic-gate extern struct anon *anon_get_next_ptr(struct anon_hdr *, ulong_t *); 4010Sstevel@tonic-gate extern int anon_set_ptr(struct anon_hdr *, ulong_t, struct anon *, int); 4020Sstevel@tonic-gate extern int anon_copy_ptr(struct anon_hdr *, ulong_t, 4030Sstevel@tonic-gate struct anon_hdr *, ulong_t, pgcnt_t, int); 4040Sstevel@tonic-gate extern pgcnt_t anon_grow(struct anon_hdr *, ulong_t *, pgcnt_t, pgcnt_t, int); 4050Sstevel@tonic-gate extern void anon_array_enter(struct anon_map *, ulong_t, 4060Sstevel@tonic-gate anon_sync_obj_t *); 407888Scwb extern int anon_array_try_enter(struct anon_map *, ulong_t, 408888Scwb anon_sync_obj_t *); 4090Sstevel@tonic-gate extern void anon_array_exit(anon_sync_obj_t *); 4100Sstevel@tonic-gate 4110Sstevel@tonic-gate /* 4120Sstevel@tonic-gate * anon_resv checks to see if there is enough swap space to fulfill a 4130Sstevel@tonic-gate * request and if so, reserves the appropriate anonymous memory resources. 4140Sstevel@tonic-gate * anon_checkspace just checks to see if there is space to fulfill the request, 4150Sstevel@tonic-gate * without taking any resources. Both return 1 if successful and 0 if not. 4160Sstevel@tonic-gate */ 4170Sstevel@tonic-gate #define anon_resv(size) anon_resvmem((size), 1) 4180Sstevel@tonic-gate #define anon_checkspace(size) anon_resvmem((size), 0) 4190Sstevel@tonic-gate 4200Sstevel@tonic-gate /* 4210Sstevel@tonic-gate * Flags to anon_private 4220Sstevel@tonic-gate */ 4230Sstevel@tonic-gate #define STEAL_PAGE 0x1 /* page can be stolen */ 4240Sstevel@tonic-gate #define LOCK_PAGE 0x2 /* page must be ``logically'' locked */ 4250Sstevel@tonic-gate 4260Sstevel@tonic-gate /* 4270Sstevel@tonic-gate * Flags to anon_disclaim 4280Sstevel@tonic-gate */ 4290Sstevel@tonic-gate #define ANON_PGLOOKUP_BLK 0x1 /* block on locked pages */ 4300Sstevel@tonic-gate 4310Sstevel@tonic-gate /* 4320Sstevel@tonic-gate * SEGKP ANON pages that are locked are assumed to be LWP stack pages 4330Sstevel@tonic-gate * and thus count towards the user pages locked count. 4340Sstevel@tonic-gate * This value is protected by the same lock as availrmem. 4350Sstevel@tonic-gate */ 4360Sstevel@tonic-gate extern pgcnt_t anon_segkp_pages_locked; 4370Sstevel@tonic-gate 4380Sstevel@tonic-gate extern int anon_debug; 4390Sstevel@tonic-gate 4400Sstevel@tonic-gate #ifdef ANON_DEBUG 4410Sstevel@tonic-gate 4420Sstevel@tonic-gate #define A_ANON 0x01 4430Sstevel@tonic-gate #define A_RESV 0x02 4440Sstevel@tonic-gate #define A_MRESV 0x04 4450Sstevel@tonic-gate 4460Sstevel@tonic-gate /* vararg-like debugging macro. */ 4470Sstevel@tonic-gate #define ANON_PRINT(f, printf_args) \ 4480Sstevel@tonic-gate if (anon_debug & f) \ 4490Sstevel@tonic-gate printf printf_args 4500Sstevel@tonic-gate 4510Sstevel@tonic-gate #else /* ANON_DEBUG */ 4520Sstevel@tonic-gate 4530Sstevel@tonic-gate #define ANON_PRINT(f, printf_args) 4540Sstevel@tonic-gate 4550Sstevel@tonic-gate #endif /* ANON_DEBUG */ 4560Sstevel@tonic-gate 4570Sstevel@tonic-gate #endif /* _KERNEL */ 4580Sstevel@tonic-gate 4590Sstevel@tonic-gate #ifdef __cplusplus 4600Sstevel@tonic-gate } 4610Sstevel@tonic-gate #endif 4620Sstevel@tonic-gate 4630Sstevel@tonic-gate #endif /* _VM_ANON_H */ 464