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 /* 22*10169SSudheer.Abdul-Salam@Sun.COM * Copyright 2009 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_SEG_VN_H 400Sstevel@tonic-gate #define _VM_SEG_VN_H 410Sstevel@tonic-gate 420Sstevel@tonic-gate #include <sys/lgrp.h> 430Sstevel@tonic-gate #include <vm/anon.h> 440Sstevel@tonic-gate 450Sstevel@tonic-gate #ifdef __cplusplus 460Sstevel@tonic-gate extern "C" { 470Sstevel@tonic-gate #endif 480Sstevel@tonic-gate 490Sstevel@tonic-gate /* 500Sstevel@tonic-gate * A pointer to this structure is passed to segvn_create(). 510Sstevel@tonic-gate */ 520Sstevel@tonic-gate typedef struct segvn_crargs { 530Sstevel@tonic-gate struct vnode *vp; /* vnode mapped from */ 540Sstevel@tonic-gate struct cred *cred; /* credentials */ 550Sstevel@tonic-gate u_offset_t offset; /* starting offset of vnode for mapping */ 560Sstevel@tonic-gate uchar_t type; /* type of sharing done */ 570Sstevel@tonic-gate uchar_t prot; /* protections */ 580Sstevel@tonic-gate uchar_t maxprot; /* maximum protections */ 590Sstevel@tonic-gate uint_t flags; /* flags */ 600Sstevel@tonic-gate struct anon_map *amp; /* anon mapping to map to */ 610Sstevel@tonic-gate uint_t szc; /* max preferred page size code */ 620Sstevel@tonic-gate uint_t lgrp_mem_policy_flags; 630Sstevel@tonic-gate } segvn_crargs_t; 640Sstevel@tonic-gate 650Sstevel@tonic-gate /* 660Sstevel@tonic-gate * (Semi) private data maintained by the seg_vn driver per segment mapping. 670Sstevel@tonic-gate * 680Sstevel@tonic-gate * The read/write segment lock protects all of segvn_data including the 690Sstevel@tonic-gate * vpage array. All fields in segvn_data are treated as read-only when 700Sstevel@tonic-gate * the "read" version of the address space and the segment locks are held. 710Sstevel@tonic-gate * The "write" version of the segment lock, however, is required in order to 720Sstevel@tonic-gate * update the following fields: 730Sstevel@tonic-gate * 740Sstevel@tonic-gate * pageprot 750Sstevel@tonic-gate * prot 760Sstevel@tonic-gate * amp 770Sstevel@tonic-gate * vpage 780Sstevel@tonic-gate * 790Sstevel@tonic-gate * softlockcnt 800Sstevel@tonic-gate * is written by acquiring either the readers lock on the segment and 810Sstevel@tonic-gate * freemem lock, or any lock combination which guarantees exclusive use 820Sstevel@tonic-gate * of this segment (e.g., adress space writers lock, 830Sstevel@tonic-gate * address space readers lock + segment writers lock). 840Sstevel@tonic-gate */ 850Sstevel@tonic-gate typedef struct segvn_data { 860Sstevel@tonic-gate krwlock_t lock; /* protect segvn_data and vpage array */ 876695Saguzovsk kmutex_t segfree_syncmtx; /* barrier lock for segvn_free() */ 880Sstevel@tonic-gate uchar_t pageprot; /* true if per page protections present */ 890Sstevel@tonic-gate uchar_t prot; /* current segment prot if pageprot == 0 */ 900Sstevel@tonic-gate uchar_t maxprot; /* maximum segment protections */ 910Sstevel@tonic-gate uchar_t type; /* type of sharing done */ 920Sstevel@tonic-gate u_offset_t offset; /* starting offset of vnode for mapping */ 930Sstevel@tonic-gate struct vnode *vp; /* vnode that segment mapping is to */ 940Sstevel@tonic-gate ulong_t anon_index; /* starting index into anon_map anon array */ 950Sstevel@tonic-gate struct anon_map *amp; /* pointer to anon share structure, if needed */ 960Sstevel@tonic-gate struct vpage *vpage; /* per-page information, if needed */ 970Sstevel@tonic-gate struct cred *cred; /* mapping credentials */ 980Sstevel@tonic-gate size_t swresv; /* swap space reserved for this segment */ 990Sstevel@tonic-gate uchar_t advice; /* madvise flags for segment */ 1000Sstevel@tonic-gate uchar_t pageadvice; /* true if per page advice set */ 1010Sstevel@tonic-gate ushort_t flags; /* flags - from sys/mman.h */ 1026695Saguzovsk spgcnt_t softlockcnt; /* # of pages SOFTLOCKED in seg */ 1030Sstevel@tonic-gate lgrp_mem_policy_info_t policy_info; /* memory allocation policy */ 1044528Spaulsan hat_region_cookie_t rcookie; /* region for hat calls */ 1054426Saguzovsk lgrp_mem_policy_info_t tr_policy_info; /* memory allocation for TR */ 1064426Saguzovsk struct seg *seg; /* pointer back to seg */ 1074426Saguzovsk struct segvn_data *svn_trnext; /* textrepl list next link */ 1084426Saguzovsk struct segvn_data *svn_trprev; /* textrepl list prev link */ 1094426Saguzovsk int tr_state; /* TR (text replication) state */ 1106517Srh87107 uchar_t pageswap; /* true if per page swap accounting is set */ 1116695Saguzovsk spgcnt_t softlockcnt_sbase; /* # of softlocks for seg start addr */ 1126695Saguzovsk spgcnt_t softlockcnt_send; /* # of softlocks for seg end addr */ 1130Sstevel@tonic-gate } segvn_data_t; 1140Sstevel@tonic-gate 1150Sstevel@tonic-gate #ifdef _KERNEL 1160Sstevel@tonic-gate 1170Sstevel@tonic-gate /* 1184426Saguzovsk * segment text replication states. 1194426Saguzovsk */ 1204426Saguzovsk #define SEGVN_TR_INIT (0) /* Check if text replication can be enabled */ 1214426Saguzovsk #define SEGVN_TR_ON (1) /* Text replication is enabled */ 1224426Saguzovsk #define SEGVN_TR_OFF (2) /* Text replication is disabled */ 1234426Saguzovsk 1244426Saguzovsk /* 1250Sstevel@tonic-gate * Macros for segvn segment driver locking. 1260Sstevel@tonic-gate */ 1270Sstevel@tonic-gate #define SEGVN_LOCK_ENTER(as, lock, type) rw_enter((lock), (type)) 1280Sstevel@tonic-gate #define SEGVN_LOCK_EXIT(as, lock) rw_exit((lock)) 1290Sstevel@tonic-gate #define SEGVN_LOCK_DOWNGRADE(as, lock) rw_downgrade((lock)) 1304426Saguzovsk #define SEGVN_LOCK_TRYENTER(as, lock, type) rw_tryenter((lock), (type)) 1310Sstevel@tonic-gate 1320Sstevel@tonic-gate /* 1330Sstevel@tonic-gate * Macros to test lock states. 1340Sstevel@tonic-gate */ 1350Sstevel@tonic-gate #define SEGVN_LOCK_HELD(as, lock) RW_LOCK_HELD((lock)) 1360Sstevel@tonic-gate #define SEGVN_READ_HELD(as, lock) RW_READ_HELD((lock)) 1370Sstevel@tonic-gate #define SEGVN_WRITE_HELD(as, lock) RW_WRITE_HELD((lock)) 1380Sstevel@tonic-gate 1390Sstevel@tonic-gate /* 1400Sstevel@tonic-gate * Macro used to detect the need to Break the sharing of COW pages 1410Sstevel@tonic-gate * 1420Sstevel@tonic-gate * The rw == S_WRITE is for the COW case 1430Sstevel@tonic-gate * rw == S_READ and type == SOFTLOCK is for the physio case 1440Sstevel@tonic-gate * We don't want to share a softlocked page because it can cause problems 1450Sstevel@tonic-gate * with multithreaded apps but if rw == S_READ_NOCOW it's ok to not break 1460Sstevel@tonic-gate * sharing of COW pages even in SOFTLOCK case. 1470Sstevel@tonic-gate */ 1480Sstevel@tonic-gate #define BREAK_COW_SHARE(rw, type, seg_type) ((rw == S_WRITE || \ 1490Sstevel@tonic-gate (type == F_SOFTLOCK && rw != S_READ_NOCOW)) && \ 1500Sstevel@tonic-gate seg_type == MAP_PRIVATE) 1510Sstevel@tonic-gate 1520Sstevel@tonic-gate #define SEGVN_ZFOD_ARGS(prot, max) \ 1530Sstevel@tonic-gate { NULL, NULL, 0, MAP_PRIVATE, prot, max, 0, NULL, 0, 0 } 1540Sstevel@tonic-gate 1552991Ssusans #define AS_MAP_CHECK_VNODE_LPOOB(crfp, argsp) \ 1560Sstevel@tonic-gate ((crfp) == (int (*)())segvn_create && \ 1570Sstevel@tonic-gate (((struct segvn_crargs *)(argsp))->flags & \ 1580Sstevel@tonic-gate (MAP_TEXT | MAP_INITDATA)) && \ 1592991Ssusans ((struct segvn_crargs *)(argsp))->szc == 0 && \ 1602991Ssusans ((struct segvn_crargs *)(argsp))->vp != NULL) 1610Sstevel@tonic-gate 1622991Ssusans #define AS_MAP_CHECK_ANON_LPOOB(crfp, argsp) \ 1632414Saguzovsk ((crfp) == (int (*)())segvn_create && \ 1642991Ssusans (((struct segvn_crargs *)(argsp))->szc == 0 || \ 1652991Ssusans ((struct segvn_crargs *)(argsp))->szc == AS_MAP_HEAP || \ 1662991Ssusans ((struct segvn_crargs *)(argsp))->szc == AS_MAP_STACK) && \ 1672414Saguzovsk ((struct segvn_crargs *)(argsp))->vp == NULL) 1680Sstevel@tonic-gate 1694426Saguzovsk #define SVNTR_HASH_FUNC(vp) (((((uintptr_t)(vp)) >> 4) ^ \ 1704426Saguzovsk (((uintptr_t)(vp)) >> 11)) & \ 1714426Saguzovsk (svntr_hashtab_sz - 1)) 1724426Saguzovsk 1734426Saguzovsk #define SEGVN_TR_ADDSTAT(stat) \ 1744426Saguzovsk segvn_textrepl_stats[CPU->cpu_id].tr_stat_##stat++ 1754426Saguzovsk 176*10169SSudheer.Abdul-Salam@Sun.COM #define SEGVN_DATA(seg) ((struct segvn_data *)(seg)->s_data) 177*10169SSudheer.Abdul-Salam@Sun.COM #define SEG_IS_PARTIAL_RESV(seg) \ 178*10169SSudheer.Abdul-Salam@Sun.COM ((seg)->s_ops == &segvn_ops && SEGVN_DATA(seg) != NULL && \ 179*10169SSudheer.Abdul-Salam@Sun.COM (SEGVN_DATA(seg)->vp == NULL || \ 180*10169SSudheer.Abdul-Salam@Sun.COM SEGVN_DATA(seg)->vp->v_type != VREG) && \ 181*10169SSudheer.Abdul-Salam@Sun.COM (SEGVN_DATA(seg)->flags & MAP_NORESERVE)) 182*10169SSudheer.Abdul-Salam@Sun.COM 1834426Saguzovsk /* 1844426Saguzovsk * A hash table entry looked up by vnode, off/eoff and szc to find anon map to 1854426Saguzovsk * use for text replication based on main thread's (t_tid = 1) lgrp. 1864426Saguzovsk */ 1874426Saguzovsk typedef struct svntr { 1884426Saguzovsk struct vnode *tr_vp; /* text file vnode */ 1894426Saguzovsk u_offset_t tr_off; /* tr_vp mapping start offset */ 1904426Saguzovsk size_t tr_eoff; /* tr_vp mapping end offset */ 1914426Saguzovsk uint_t tr_szc; /* tr_vp mapping pagesize */ 1924426Saguzovsk int tr_valid; /* entry validity state */ 1934426Saguzovsk struct svntr *tr_next; /* next svntr in this hash bucket */ 1944426Saguzovsk timestruc_t tr_mtime; /* tr_vp modification time */ 1954902Spaulsan timestruc_t tr_ctime; /* time of last change to attributes */ 1964426Saguzovsk ulong_t tr_refcnt; /* number of segs sharing this entry */ 1974426Saguzovsk segvn_data_t *tr_svnhead; /* list of segs sharing this entry */ 1984426Saguzovsk struct anon_map *tr_amp[NLGRPS_MAX]; /* per lgrp anon maps */ 1994426Saguzovsk } svntr_t; 2004426Saguzovsk 2014426Saguzovsk typedef struct svntr_bucket { 2024426Saguzovsk svntr_t *tr_head; /* first svntr in this hash bucket */ 2034426Saguzovsk kmutex_t tr_lock; /* per bucket lock */ 2044426Saguzovsk } svntr_bucket_t; 2054426Saguzovsk 2064426Saguzovsk typedef struct svntr_stats { 2074426Saguzovsk ulong_t tr_stat_gaerr; /* VOP_GETATTR() failures */ 2084426Saguzovsk ulong_t tr_stat_overmap; /* no TR due to beyond EOF mappings */ 2094426Saguzovsk ulong_t tr_stat_wrcnt; /* no TR due to writtable mappings */ 2104426Saguzovsk ulong_t tr_stat_stale; /* TR entry is stale */ 2114426Saguzovsk ulong_t tr_stat_overlap; /* overlap with other mappings */ 2124426Saguzovsk ulong_t tr_stat_nokmem; /* no TR due to kmem alloc failures */ 2134426Saguzovsk ulong_t tr_stat_noanon; /* no TR due to no swap space */ 2144426Saguzovsk ulong_t tr_stat_normem; /* no TR due to no repl memory */ 2154426Saguzovsk ulong_t tr_stat_nolock; /* async TR failure due to locks */ 2164426Saguzovsk ulong_t tr_stat_asyncrepl; /* number of async TRs */ 2174426Saguzovsk ulong_t tr_stat_repl; /* number of sync TRs */ 2184426Saguzovsk ulong_t tr_stat_newamp; /* number of new amp allocs for TR */ 2194426Saguzovsk } svntr_stats_t; 2204426Saguzovsk 2210Sstevel@tonic-gate extern void segvn_init(void); 2220Sstevel@tonic-gate extern int segvn_create(struct seg *, void *); 2230Sstevel@tonic-gate 2240Sstevel@tonic-gate extern struct seg_ops segvn_ops; 2250Sstevel@tonic-gate 2260Sstevel@tonic-gate /* 2270Sstevel@tonic-gate * Provided as shorthand for creating user zfod segments. 2280Sstevel@tonic-gate */ 2290Sstevel@tonic-gate extern caddr_t zfod_argsp; 2300Sstevel@tonic-gate extern caddr_t kzfod_argsp; 2310Sstevel@tonic-gate extern caddr_t stack_exec_argsp; 2320Sstevel@tonic-gate extern caddr_t stack_noexec_argsp; 2330Sstevel@tonic-gate 2340Sstevel@tonic-gate #endif /* _KERNEL */ 2350Sstevel@tonic-gate 2360Sstevel@tonic-gate #ifdef __cplusplus 2370Sstevel@tonic-gate } 2380Sstevel@tonic-gate #endif 2390Sstevel@tonic-gate 2400Sstevel@tonic-gate #endif /* _VM_SEG_VN_H */ 241