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