seg_vn.h revision 05d3dc4b6755c54754109ffbe7e792f4e5b7c7c9
1cc553493b17fa6a6770261bbfeb258f354ebf48rmesta/*
1cc553493b17fa6a6770261bbfeb258f354ebf48rmesta * CDDL HEADER START
1cc553493b17fa6a6770261bbfeb258f354ebf48rmesta *
1cc553493b17fa6a6770261bbfeb258f354ebf48rmesta * The contents of this file are subject to the terms of the
1cc553493b17fa6a6770261bbfeb258f354ebf48rmesta * Common Development and Distribution License (the "License").
1cc553493b17fa6a6770261bbfeb258f354ebf48rmesta * You may not use this file except in compliance with the License.
1cc553493b17fa6a6770261bbfeb258f354ebf48rmesta *
1cc553493b17fa6a6770261bbfeb258f354ebf48rmesta * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
1cc553493b17fa6a6770261bbfeb258f354ebf48rmesta * or http://www.opensolaris.org/os/licensing.
1cc553493b17fa6a6770261bbfeb258f354ebf48rmesta * See the License for the specific language governing permissions
1cc553493b17fa6a6770261bbfeb258f354ebf48rmesta * and limitations under the License.
1cc553493b17fa6a6770261bbfeb258f354ebf48rmesta *
1cc553493b17fa6a6770261bbfeb258f354ebf48rmesta * When distributing Covered Code, include this CDDL HEADER in each
1cc553493b17fa6a6770261bbfeb258f354ebf48rmesta * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
1cc553493b17fa6a6770261bbfeb258f354ebf48rmesta * If applicable, add the following below this CDDL HEADER, with the
1cc553493b17fa6a6770261bbfeb258f354ebf48rmesta * fields enclosed by brackets "[]" replaced with your own identifying
1cc553493b17fa6a6770261bbfeb258f354ebf48rmesta * information: Portions Copyright [yyyy] [name of copyright owner]
1cc553493b17fa6a6770261bbfeb258f354ebf48rmesta *
1cc553493b17fa6a6770261bbfeb258f354ebf48rmesta * CDDL HEADER END
1cc553493b17fa6a6770261bbfeb258f354ebf48rmesta */
1cc553493b17fa6a6770261bbfeb258f354ebf48rmesta/*
1cc553493b17fa6a6770261bbfeb258f354ebf48rmesta * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
1cc553493b17fa6a6770261bbfeb258f354ebf48rmesta * Use is subject to license terms.
1cc553493b17fa6a6770261bbfeb258f354ebf48rmesta */
5cb0d67909d9970a3e7adbea9422ca3fc88000bfMarcel Telka
5cb0d67909d9970a3e7adbea9422ca3fc88000bfMarcel Telka/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
5cb0d67909d9970a3e7adbea9422ca3fc88000bfMarcel Telka/* All Rights Reserved */
1cc553493b17fa6a6770261bbfeb258f354ebf48rmesta
1cc553493b17fa6a6770261bbfeb258f354ebf48rmesta/*
1cc553493b17fa6a6770261bbfeb258f354ebf48rmesta * University Copyright- Copyright (c) 1982, 1986, 1988
1cc553493b17fa6a6770261bbfeb258f354ebf48rmesta * The Regents of the University of California
1cc553493b17fa6a6770261bbfeb258f354ebf48rmesta * All Rights Reserved
1cc553493b17fa6a6770261bbfeb258f354ebf48rmesta *
1cc553493b17fa6a6770261bbfeb258f354ebf48rmesta * University Acknowledgment- Portions of this document are derived from
1cc553493b17fa6a6770261bbfeb258f354ebf48rmesta * software developed by the University of California, Berkeley, and its
1cc553493b17fa6a6770261bbfeb258f354ebf48rmesta * contributors.
1cc553493b17fa6a6770261bbfeb258f354ebf48rmesta */
1cc553493b17fa6a6770261bbfeb258f354ebf48rmesta
1cc553493b17fa6a6770261bbfeb258f354ebf48rmesta#ifndef _VM_SEG_VN_H
1cc553493b17fa6a6770261bbfeb258f354ebf48rmesta#define _VM_SEG_VN_H
1cc553493b17fa6a6770261bbfeb258f354ebf48rmesta
5cb0d67909d9970a3e7adbea9422ca3fc88000bfMarcel Telka#pragma ident "%Z%%M% %I% %E% SMI"
1cc553493b17fa6a6770261bbfeb258f354ebf48rmesta
1cc553493b17fa6a6770261bbfeb258f354ebf48rmesta#include <sys/lgrp.h>
1cc553493b17fa6a6770261bbfeb258f354ebf48rmesta#include <vm/anon.h>
1cc553493b17fa6a6770261bbfeb258f354ebf48rmesta
1cc553493b17fa6a6770261bbfeb258f354ebf48rmesta#ifdef __cplusplus
1cc553493b17fa6a6770261bbfeb258f354ebf48rmestaextern "C" {
1cc553493b17fa6a6770261bbfeb258f354ebf48rmesta#endif
1cc553493b17fa6a6770261bbfeb258f354ebf48rmesta
5cb0d67909d9970a3e7adbea9422ca3fc88000bfMarcel Telka/*
5cb0d67909d9970a3e7adbea9422ca3fc88000bfMarcel Telka * A pointer to this structure is passed to segvn_create().
1cc553493b17fa6a6770261bbfeb258f354ebf48rmesta */
1cc553493b17fa6a6770261bbfeb258f354ebf48rmestatypedef struct segvn_crargs {
1cc553493b17fa6a6770261bbfeb258f354ebf48rmesta struct vnode *vp; /* vnode mapped from */
1cc553493b17fa6a6770261bbfeb258f354ebf48rmesta struct cred *cred; /* credentials */
1cc553493b17fa6a6770261bbfeb258f354ebf48rmesta u_offset_t offset; /* starting offset of vnode for mapping */
1cc553493b17fa6a6770261bbfeb258f354ebf48rmesta uchar_t type; /* type of sharing done */
1cc553493b17fa6a6770261bbfeb258f354ebf48rmesta uchar_t prot; /* protections */
1cc553493b17fa6a6770261bbfeb258f354ebf48rmesta uchar_t maxprot; /* maximum protections */
5cb0d67909d9970a3e7adbea9422ca3fc88000bfMarcel Telka uint_t flags; /* flags */
5cb0d67909d9970a3e7adbea9422ca3fc88000bfMarcel Telka struct anon_map *amp; /* anon mapping to map to */
1cc553493b17fa6a6770261bbfeb258f354ebf48rmesta uint_t szc; /* max preferred page size code */
1cc553493b17fa6a6770261bbfeb258f354ebf48rmesta uint_t lgrp_mem_policy_flags;
1cc553493b17fa6a6770261bbfeb258f354ebf48rmesta} segvn_crargs_t;
1cc553493b17fa6a6770261bbfeb258f354ebf48rmesta
1cc553493b17fa6a6770261bbfeb258f354ebf48rmesta/*
1cc553493b17fa6a6770261bbfeb258f354ebf48rmesta * (Semi) private data maintained by the seg_vn driver per segment mapping.
1cc553493b17fa6a6770261bbfeb258f354ebf48rmesta *
1cc553493b17fa6a6770261bbfeb258f354ebf48rmesta * The read/write segment lock protects all of segvn_data including the
1cc553493b17fa6a6770261bbfeb258f354ebf48rmesta * vpage array. All fields in segvn_data are treated as read-only when
5cb0d67909d9970a3e7adbea9422ca3fc88000bfMarcel Telka * the "read" version of the address space and the segment locks are held.
5cb0d67909d9970a3e7adbea9422ca3fc88000bfMarcel Telka * The "write" version of the segment lock, however, is required in order to
1cc553493b17fa6a6770261bbfeb258f354ebf48rmesta * update the following fields:
1cc553493b17fa6a6770261bbfeb258f354ebf48rmesta *
1cc553493b17fa6a6770261bbfeb258f354ebf48rmesta * pageprot
1cc553493b17fa6a6770261bbfeb258f354ebf48rmesta * prot
1cc553493b17fa6a6770261bbfeb258f354ebf48rmesta * amp
1cc553493b17fa6a6770261bbfeb258f354ebf48rmesta * vpage
1cc553493b17fa6a6770261bbfeb258f354ebf48rmesta *
1cc553493b17fa6a6770261bbfeb258f354ebf48rmesta * softlockcnt
1cc553493b17fa6a6770261bbfeb258f354ebf48rmesta * is written by acquiring either the readers lock on the segment and
1cc553493b17fa6a6770261bbfeb258f354ebf48rmesta * freemem lock, or any lock combination which guarantees exclusive use
1cc553493b17fa6a6770261bbfeb258f354ebf48rmesta * of this segment (e.g., adress space writers lock,
1cc553493b17fa6a6770261bbfeb258f354ebf48rmesta * address space readers lock + segment writers lock).
1cc553493b17fa6a6770261bbfeb258f354ebf48rmesta */
1cc553493b17fa6a6770261bbfeb258f354ebf48rmestatypedef struct segvn_data {
1cc553493b17fa6a6770261bbfeb258f354ebf48rmesta krwlock_t lock; /* protect segvn_data and vpage array */
1cc553493b17fa6a6770261bbfeb258f354ebf48rmesta kmutex_t segp_slock; /* serialize insertions into seg_pcache */
1cc553493b17fa6a6770261bbfeb258f354ebf48rmesta uchar_t pageprot; /* true if per page protections present */
1cc553493b17fa6a6770261bbfeb258f354ebf48rmesta uchar_t prot; /* current segment prot if pageprot == 0 */
1cc553493b17fa6a6770261bbfeb258f354ebf48rmesta uchar_t maxprot; /* maximum segment protections */
1cc553493b17fa6a6770261bbfeb258f354ebf48rmesta uchar_t type; /* type of sharing done */
1cc553493b17fa6a6770261bbfeb258f354ebf48rmesta u_offset_t offset; /* starting offset of vnode for mapping */
1cc553493b17fa6a6770261bbfeb258f354ebf48rmesta struct vnode *vp; /* vnode that segment mapping is to */
1cc553493b17fa6a6770261bbfeb258f354ebf48rmesta ulong_t anon_index; /* starting index into anon_map anon array */
1cc553493b17fa6a6770261bbfeb258f354ebf48rmesta struct anon_map *amp; /* pointer to anon share structure, if needed */
1cc553493b17fa6a6770261bbfeb258f354ebf48rmesta struct vpage *vpage; /* per-page information, if needed */
1cc553493b17fa6a6770261bbfeb258f354ebf48rmesta struct cred *cred; /* mapping credentials */
1cc553493b17fa6a6770261bbfeb258f354ebf48rmesta size_t swresv; /* swap space reserved for this segment */
1cc553493b17fa6a6770261bbfeb258f354ebf48rmesta uchar_t advice; /* madvise flags for segment */
1cc553493b17fa6a6770261bbfeb258f354ebf48rmesta uchar_t pageadvice; /* true if per page advice set */
1cc553493b17fa6a6770261bbfeb258f354ebf48rmesta ushort_t flags; /* flags - from sys/mman.h */
1cc553493b17fa6a6770261bbfeb258f354ebf48rmesta ssize_t softlockcnt; /* # of pages SOFTLOCKED in seg */
1cc553493b17fa6a6770261bbfeb258f354ebf48rmesta lgrp_mem_policy_info_t policy_info; /* memory allocation policy */
1cc553493b17fa6a6770261bbfeb258f354ebf48rmesta hat_region_cookie_t rcookie; /* region for hat calls */
1cc553493b17fa6a6770261bbfeb258f354ebf48rmesta lgrp_mem_policy_info_t tr_policy_info; /* memory allocation for TR */
1cc553493b17fa6a6770261bbfeb258f354ebf48rmesta struct seg *seg; /* pointer back to seg */
1cc553493b17fa6a6770261bbfeb258f354ebf48rmesta struct segvn_data *svn_trnext; /* textrepl list next link */
1cc553493b17fa6a6770261bbfeb258f354ebf48rmesta struct segvn_data *svn_trprev; /* textrepl list prev link */
1cc553493b17fa6a6770261bbfeb258f354ebf48rmesta int tr_state; /* TR (text replication) state */
1cc553493b17fa6a6770261bbfeb258f354ebf48rmesta} segvn_data_t;
1cc553493b17fa6a6770261bbfeb258f354ebf48rmesta
5cb0d67909d9970a3e7adbea9422ca3fc88000bfMarcel Telka#ifdef _KERNEL
5cb0d67909d9970a3e7adbea9422ca3fc88000bfMarcel Telka
1cc553493b17fa6a6770261bbfeb258f354ebf48rmesta/*
1cc553493b17fa6a6770261bbfeb258f354ebf48rmesta * segment text replication states.
1cc553493b17fa6a6770261bbfeb258f354ebf48rmesta */
1cc553493b17fa6a6770261bbfeb258f354ebf48rmesta#define SEGVN_TR_INIT (0) /* Check if text replication can be enabled */
1cc553493b17fa6a6770261bbfeb258f354ebf48rmesta#define SEGVN_TR_ON (1) /* Text replication is enabled */
1cc553493b17fa6a6770261bbfeb258f354ebf48rmesta#define SEGVN_TR_OFF (2) /* Text replication is disabled */
5cb0d67909d9970a3e7adbea9422ca3fc88000bfMarcel Telka
5cb0d67909d9970a3e7adbea9422ca3fc88000bfMarcel Telka/*
1cc553493b17fa6a6770261bbfeb258f354ebf48rmesta * Macros for segvn segment driver locking.
1cc553493b17fa6a6770261bbfeb258f354ebf48rmesta */
1cc553493b17fa6a6770261bbfeb258f354ebf48rmesta#define SEGVN_LOCK_ENTER(as, lock, type) rw_enter((lock), (type))
1cc553493b17fa6a6770261bbfeb258f354ebf48rmesta#define SEGVN_LOCK_EXIT(as, lock) rw_exit((lock))
1cc553493b17fa6a6770261bbfeb258f354ebf48rmesta#define SEGVN_LOCK_DOWNGRADE(as, lock) rw_downgrade((lock))
5cb0d67909d9970a3e7adbea9422ca3fc88000bfMarcel Telka#define SEGVN_LOCK_TRYENTER(as, lock, type) rw_tryenter((lock), (type))
5cb0d67909d9970a3e7adbea9422ca3fc88000bfMarcel Telka
1cc553493b17fa6a6770261bbfeb258f354ebf48rmesta/*
1cc553493b17fa6a6770261bbfeb258f354ebf48rmesta * Macros to test lock states.
1cc553493b17fa6a6770261bbfeb258f354ebf48rmesta */
1cc553493b17fa6a6770261bbfeb258f354ebf48rmesta#define SEGVN_LOCK_HELD(as, lock) RW_LOCK_HELD((lock))
1cc553493b17fa6a6770261bbfeb258f354ebf48rmesta#define SEGVN_READ_HELD(as, lock) RW_READ_HELD((lock))
1cc553493b17fa6a6770261bbfeb258f354ebf48rmesta#define SEGVN_WRITE_HELD(as, lock) RW_WRITE_HELD((lock))
1cc553493b17fa6a6770261bbfeb258f354ebf48rmesta
1cc553493b17fa6a6770261bbfeb258f354ebf48rmesta/*
1cc553493b17fa6a6770261bbfeb258f354ebf48rmesta * Macro used to detect the need to Break the sharing of COW pages
1cc553493b17fa6a6770261bbfeb258f354ebf48rmesta *
1cc553493b17fa6a6770261bbfeb258f354ebf48rmesta * The rw == S_WRITE is for the COW case
1cc553493b17fa6a6770261bbfeb258f354ebf48rmesta * rw == S_READ and type == SOFTLOCK is for the physio case
1cc553493b17fa6a6770261bbfeb258f354ebf48rmesta * We don't want to share a softlocked page because it can cause problems
1cc553493b17fa6a6770261bbfeb258f354ebf48rmesta * with multithreaded apps but if rw == S_READ_NOCOW it's ok to not break
1cc553493b17fa6a6770261bbfeb258f354ebf48rmesta * sharing of COW pages even in SOFTLOCK case.
1cc553493b17fa6a6770261bbfeb258f354ebf48rmesta */
1cc553493b17fa6a6770261bbfeb258f354ebf48rmesta#define BREAK_COW_SHARE(rw, type, seg_type) ((rw == S_WRITE || \
1cc553493b17fa6a6770261bbfeb258f354ebf48rmesta (type == F_SOFTLOCK && rw != S_READ_NOCOW)) && \
1cc553493b17fa6a6770261bbfeb258f354ebf48rmesta seg_type == MAP_PRIVATE)
1cc553493b17fa6a6770261bbfeb258f354ebf48rmesta
1cc553493b17fa6a6770261bbfeb258f354ebf48rmesta#define SEGVN_ZFOD_ARGS(prot, max) \
1cc553493b17fa6a6770261bbfeb258f354ebf48rmesta { NULL, NULL, 0, MAP_PRIVATE, prot, max, 0, NULL, 0, 0 }
1cc553493b17fa6a6770261bbfeb258f354ebf48rmesta
1cc553493b17fa6a6770261bbfeb258f354ebf48rmesta#define AS_MAP_CHECK_VNODE_LPOOB(crfp, argsp) \
1cc553493b17fa6a6770261bbfeb258f354ebf48rmesta ((crfp) == (int (*)())segvn_create && \
1cc553493b17fa6a6770261bbfeb258f354ebf48rmesta (((struct segvn_crargs *)(argsp))->flags & \
1cc553493b17fa6a6770261bbfeb258f354ebf48rmesta (MAP_TEXT | MAP_INITDATA)) && \
1cc553493b17fa6a6770261bbfeb258f354ebf48rmesta ((struct segvn_crargs *)(argsp))->szc == 0 && \
1cc553493b17fa6a6770261bbfeb258f354ebf48rmesta ((struct segvn_crargs *)(argsp))->vp != NULL)
1cc553493b17fa6a6770261bbfeb258f354ebf48rmesta
1cc553493b17fa6a6770261bbfeb258f354ebf48rmesta#define AS_MAP_CHECK_ANON_LPOOB(crfp, argsp) \
1cc553493b17fa6a6770261bbfeb258f354ebf48rmesta ((crfp) == (int (*)())segvn_create && \
1cc553493b17fa6a6770261bbfeb258f354ebf48rmesta (((struct segvn_crargs *)(argsp))->szc == 0 || \
1cc553493b17fa6a6770261bbfeb258f354ebf48rmesta ((struct segvn_crargs *)(argsp))->szc == AS_MAP_HEAP || \
1cc553493b17fa6a6770261bbfeb258f354ebf48rmesta ((struct segvn_crargs *)(argsp))->szc == AS_MAP_STACK) && \
1cc553493b17fa6a6770261bbfeb258f354ebf48rmesta ((struct segvn_crargs *)(argsp))->vp == NULL)
1cc553493b17fa6a6770261bbfeb258f354ebf48rmesta
1cc553493b17fa6a6770261bbfeb258f354ebf48rmesta#define SVNTR_HASH_FUNC(vp) (((((uintptr_t)(vp)) >> 4) ^ \
1cc553493b17fa6a6770261bbfeb258f354ebf48rmesta (((uintptr_t)(vp)) >> 11)) & \
1cc553493b17fa6a6770261bbfeb258f354ebf48rmesta (svntr_hashtab_sz - 1))
1cc553493b17fa6a6770261bbfeb258f354ebf48rmesta
1cc553493b17fa6a6770261bbfeb258f354ebf48rmesta#define SEGVN_TR_ADDSTAT(stat) \
1cc553493b17fa6a6770261bbfeb258f354ebf48rmesta segvn_textrepl_stats[CPU->cpu_id].tr_stat_##stat++
1cc553493b17fa6a6770261bbfeb258f354ebf48rmesta
1cc553493b17fa6a6770261bbfeb258f354ebf48rmesta/*
1cc553493b17fa6a6770261bbfeb258f354ebf48rmesta * A hash table entry looked up by vnode, off/eoff and szc to find anon map to
1cc553493b17fa6a6770261bbfeb258f354ebf48rmesta * use for text replication based on main thread's (t_tid = 1) lgrp.
1cc553493b17fa6a6770261bbfeb258f354ebf48rmesta */
1cc553493b17fa6a6770261bbfeb258f354ebf48rmestatypedef struct svntr {
1cc553493b17fa6a6770261bbfeb258f354ebf48rmesta struct vnode *tr_vp; /* text file vnode */
1cc553493b17fa6a6770261bbfeb258f354ebf48rmesta u_offset_t tr_off; /* tr_vp mapping start offset */
1cc553493b17fa6a6770261bbfeb258f354ebf48rmesta size_t tr_eoff; /* tr_vp mapping end offset */
1cc553493b17fa6a6770261bbfeb258f354ebf48rmesta uint_t tr_szc; /* tr_vp mapping pagesize */
1cc553493b17fa6a6770261bbfeb258f354ebf48rmesta int tr_valid; /* entry validity state */
1cc553493b17fa6a6770261bbfeb258f354ebf48rmesta struct svntr *tr_next; /* next svntr in this hash bucket */
1cc553493b17fa6a6770261bbfeb258f354ebf48rmesta timestruc_t tr_mtime; /* tr_vp modification time */
1cc553493b17fa6a6770261bbfeb258f354ebf48rmesta ulong_t tr_refcnt; /* number of segs sharing this entry */
1cc553493b17fa6a6770261bbfeb258f354ebf48rmesta segvn_data_t *tr_svnhead; /* list of segs sharing this entry */
1cc553493b17fa6a6770261bbfeb258f354ebf48rmesta struct anon_map *tr_amp[NLGRPS_MAX]; /* per lgrp anon maps */
1cc553493b17fa6a6770261bbfeb258f354ebf48rmesta} svntr_t;
1cc553493b17fa6a6770261bbfeb258f354ebf48rmesta
typedef struct svntr_bucket {
svntr_t *tr_head; /* first svntr in this hash bucket */
kmutex_t tr_lock; /* per bucket lock */
} svntr_bucket_t;
typedef struct svntr_stats {
ulong_t tr_stat_gaerr; /* VOP_GETATTR() failures */
ulong_t tr_stat_overmap; /* no TR due to beyond EOF mappings */
ulong_t tr_stat_wrcnt; /* no TR due to writtable mappings */
ulong_t tr_stat_stale; /* TR entry is stale */
ulong_t tr_stat_overlap; /* overlap with other mappings */
ulong_t tr_stat_nokmem; /* no TR due to kmem alloc failures */
ulong_t tr_stat_noanon; /* no TR due to no swap space */
ulong_t tr_stat_normem; /* no TR due to no repl memory */
ulong_t tr_stat_nolock; /* async TR failure due to locks */
ulong_t tr_stat_asyncrepl; /* number of async TRs */
ulong_t tr_stat_repl; /* number of sync TRs */
ulong_t tr_stat_newamp; /* number of new amp allocs for TR */
} svntr_stats_t;
extern void segvn_init(void);
extern int segvn_create(struct seg *, void *);
extern struct seg_ops segvn_ops;
/*
* Provided as shorthand for creating user zfod segments.
*/
extern caddr_t zfod_argsp;
extern caddr_t kzfod_argsp;
extern caddr_t stack_exec_argsp;
extern caddr_t stack_noexec_argsp;
#endif /* _KERNEL */
#ifdef __cplusplus
}
#endif
#endif /* _VM_SEG_VN_H */