anon.h revision 870154656b6ec47dea8a31e79fa48256dc521bf4
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2005 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
/* All Rights Reserved */
/*
* University Copyright- Copyright (c) 1982, 1986, 1988
* The Regents of the University of California
* All Rights Reserved
*
* University Acknowledgment- Portions of this document are derived from
* software developed by the University of California, Berkeley, and its
* contributors.
*/
#ifndef _VM_ANON_H
#define _VM_ANON_H
#pragma ident "%Z%%M% %I% %E% SMI"
#ifdef __cplusplus
extern "C" {
#endif
/*
* VM - Anonymous pages.
*/
typedef unsigned long anoff_t; /* anon offsets */
/*
* Each anonymous page, either in memory or in swap, has an anon structure.
* The structure (slot) provides a level of indirection between anonymous pages
* and their backing store.
*
* (an_vp, an_off) names the vnode of the anonymous page for this slot.
*
* (an_pvp, an_poff) names the location of the physical backing store
* for the page this slot represents. If the name is null there is no
* associated physical store. The physical backing store location can
* change while the slot is in use.
*
* an_hash is a hash list of anon slots. The list is hashed by
* (an_vp, an_off) of the associated anonymous page and provides a
* method of going from the name of an anonymous page to its
* associated anon slot.
*
* an_refcnt holds a reference count which is the number of separate
* copies that will need to be created in case of copy-on-write.
* A refcnt > 0 protects the existence of the slot. The refcnt is
* initialized to 1 when the anon slot is created in anon_alloc().
* If a client obtains an anon slot and allows multiple threads to
* share it, then it is the client's responsibility to insure that
* it does not allow one thread to try to reference the slot at the
* same time as another is trying to decrement the last count and
* destroy the anon slot. E.g., the seg_vn segment type protects
* against this with higher level locks.
*/
struct anon {
int an_refcnt; /* # of people sharing slot */
};
#ifdef _KERNEL
/*
* The swapinfo_lock protects:
* swapinfo list
* individual swapinfo structures
*
* The anoninfo_lock protects:
* anoninfo counters
*
* The anonhash_lock protects:
* anon hash lists
* anon slot fields
*
* Fields in the anon slot which are read-only for the life of the slot
* (an_vp, an_off) do not require the anonhash_lock be held to access them.
* If you access a field without the anonhash_lock held you must be holding
* the slot with an_refcnt to make sure it isn't destroyed.
* To write (an_pvp, an_poff) in a given slot you must also hold the
* p_iolock of the anonymous page for slot.
*/
extern kmutex_t anoninfo_lock;
extern kmutex_t swapinfo_lock;
extern kmutex_t anonhash_lock[];
extern pad_mutex_t anon_array_lock[];
extern kcondvar_t anon_array_cv[];
/*
* Global hash table to provide a function from (vp, off) -> ap
*/
extern size_t anon_hash_size;
#define ANON_HASH_SIZE anon_hash_size
#define ANON_HASHAVELEN 4
#define AH_LOCK_SIZE 64
#endif /* _KERNEL */
/*
* Declaration for the Global counters to accurately
* track the kernel foot print in memory.
*/
extern pgcnt_t segvn_pages_locked;
extern pgcnt_t pages_locked;
extern pgcnt_t pages_claimed;
extern pgcnt_t pages_useclaim;
/*
* Anonymous backing store accounting structure for swapctl.
*
* ani_max = maximum amount of swap space
* (including potentially available physical memory)
* ani_free = amount of unallocated anonymous memory
* (some of which might be reserved and including
* potentially available physical memory)
* ani_resv = amount of claimed (reserved) anonymous memory
*
* The swap data can be aquired more efficiently through the
* kstats interface.
* Total slots currently available for reservation =
* MAX(ani_max - ani_resv, 0) + (availrmem - swapfs_minfree)
*/
struct anoninfo {
};
#ifdef _SYSCALL32
struct anoninfo32 {
};
#endif /* _SYSCALL32 */
/*
* Define the NCPU pool of the ani_free counters. Update the counter
* of the cpu on which the thread is running and in every clock intr
* sync anoninfo.ani_free with the current total off all the NCPU entries.
*/
typedef struct ani_free {
/* XXX 64 = cacheline size */
} ani_free_t;
#define ANI_MAX_POOL 128
extern ani_free_t ani_free_pool[];
ani_free_t *anifp; \
int index; \
}
/*
* Anon array pointers are allocated in chunks. Each chunk
* There are two levels of arrays for anon array pointers larger
* than a chunk. The first level points to anon array chunks.
* The second level consists of chunks of anon pointers.
*
* If anon array is smaller than a chunk then the whole anon array
* is created (memory is allocated for whole anon array).
* If anon array is larger than a chunk only first level array is
* allocated. Then other arrays (chunks) are allocated only when
* they are initialized with anon pointers.
*/
struct anon_hdr {
void **array_chunk; /* pointers to anon pointers or chunks of */
/* anon pointers */
int flags; /* ANON_ALLOC_FORCE force preallocation of */
/* whole anon array */
};
#ifdef _LP64
#define ANON_PTRSHIFT 3
#define ANON_PTRMASK ~7
#else
#define ANON_PTRSHIFT 2
#define ANON_PTRMASK ~3
#endif
/*
* Anon flags.
*/
/*
* The anon_map structure is used by various clients of the anon layer to
* manage anonymous memory. When anonymous memory is shared,
* then the different clients sharing it will point to the
* same anon_map structure. Also, if a segment is unmapped
* in the middle where an anon_map structure exists, the
* newly created segment will also share the anon_map structure,
* although the two segments will use different ranges of the
* anon array. When mappings are private (or shared with
* a reference count of 1), an unmap operation will free up
* a range of anon slots in the array given by the anon_map
* structure. Because of fragmentation due to this unmapping,
* we have to store the size of the anon array in the anon_map
* structure so that we can free everything when the referernce
* count goes to zero.
*
* A new rangelock scheme is introduced to make the anon layer scale.
* locks, anon_array_lock[] are introduced to replace serial_lock and
* anonmap lock. The writer lock is held when we want to singlethreaD
* the reference to the anon array pointers or when references to
* anon_map's members, whereas reader lock and anon_array_lock are
* held to allows multiple threads to reference different part of
* anon array. A global set of condition variables, anon_array_cv,
* are used with anon_array_lock[] to make the hold time of the locks
* short.
*
* szc is used to calculate the index of hash locks and cv's. We
* could've just used seg->s_szc if not for the possible sharing of
* anon_amp between SYSV shared memory and ISM, so now we introduce
* szc in the anon_map structure. For MAP_SHARED, the amp->szc is either
* 0 (base page size) or page_num_pagesizes() - 1, while MAP_PRIVATE
* the amp->szc could be anything in [0, page_num_pagesizes() - 1].
*/
struct anon_map {
/* anon pointer array(s) */
void *locality; /* lgroup locality info */
};
#ifdef _KERNEL
#define ANON_BUSY 0x1
#define ANON_LOCKSIZE 128
typedef struct anon_sync_obj {
/*
* Anonymous backing store accounting structure for kernel.
* ani_max = total reservable slots on physical (disk-backed) swap
* ani_phys_resv = total phys slots reserved for use by clients
* ani_mem_resv = total mem slots reserved for use by clients
* ani_free = # unallocated physical slots + # of reserved unallocated
* memory slots
*/
/*
* Initial total swap slots available for reservation
*/
#define TOTAL_AVAILABLE_SWAP \
/*
* Swap slots currently available for reservation
*/
#define CURRENT_TOTAL_AVAILABLE_SWAP \
struct k_anoninfo {
/* (disk) swap */
/* mem swap */
};
extern struct k_anoninfo k_anoninfo;
extern void anon_init(void);
int, struct cred *);
extern void anon_unresv(size_t);
extern void anonmap_free(struct anon_map *);
extern void anon_decref(struct anon *);
extern int anon_swap_adjust(pgcnt_t);
extern void anon_swap_restore(pgcnt_t);
anon_sync_obj_t *);
anon_sync_obj_t *);
extern void anon_array_exit(anon_sync_obj_t *);
/*
* anon_resv checks to see if there is enough swap space to fulfill a
* request and if so, reserves the appropriate anonymous memory resources.
* anon_checkspace just checks to see if there is space to fulfill the request,
* without taking any resources. Both return 1 if successful and 0 if not.
*/
/*
* Flags to anon_private
*/
/*
* Flags to anon_disclaim
*/
/*
* SEGKP ANON pages that are locked are assumed to be LWP stack pages
* and thus count towards the user pages locked count.
* This value is protected by the same lock as availrmem.
*/
extern pgcnt_t anon_segkp_pages_locked;
extern int anon_debug;
#ifdef ANON_DEBUG
#define A_ANON 0x01
#define A_RESV 0x02
#define A_MRESV 0x04
/* vararg-like debugging macro. */
#define ANON_PRINT(f, printf_args) \
if (anon_debug & f) \
#else /* ANON_DEBUG */
#define ANON_PRINT(f, printf_args)
#endif /* ANON_DEBUG */
#endif /* _KERNEL */
#ifdef __cplusplus
}
#endif
#endif /* _VM_ANON_H */