17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 507b65a64Saguzovsk * Common Development and Distribution License (the "License"). 607b65a64Saguzovsk * You may not use this file except in compliance with the License. 77c478bd9Sstevel@tonic-gate * 87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 117c478bd9Sstevel@tonic-gate * and limitations under the License. 127c478bd9Sstevel@tonic-gate * 137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 187c478bd9Sstevel@tonic-gate * 197c478bd9Sstevel@tonic-gate * CDDL HEADER END 207c478bd9Sstevel@tonic-gate */ 217c478bd9Sstevel@tonic-gate /* 2240688216SSudheer A * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 237c478bd9Sstevel@tonic-gate * Use is subject to license terms. 24*9d12795fSRobert Mustacchi * Copyright (c) 2015, Joyent, Inc. All rights reserved. 257c478bd9Sstevel@tonic-gate */ 267c478bd9Sstevel@tonic-gate 277c478bd9Sstevel@tonic-gate /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ 287c478bd9Sstevel@tonic-gate /* All Rights Reserved */ 297c478bd9Sstevel@tonic-gate 307c478bd9Sstevel@tonic-gate /* 317c478bd9Sstevel@tonic-gate * University Copyright- Copyright (c) 1982, 1986, 1988 327c478bd9Sstevel@tonic-gate * The Regents of the University of California 337c478bd9Sstevel@tonic-gate * All Rights Reserved 347c478bd9Sstevel@tonic-gate * 357c478bd9Sstevel@tonic-gate * University Acknowledgment- Portions of this document are derived from 367c478bd9Sstevel@tonic-gate * software developed by the University of California, Berkeley, and its 377c478bd9Sstevel@tonic-gate * contributors. 387c478bd9Sstevel@tonic-gate */ 397c478bd9Sstevel@tonic-gate 407c478bd9Sstevel@tonic-gate #ifndef _VM_SEG_VN_H 417c478bd9Sstevel@tonic-gate #define _VM_SEG_VN_H 427c478bd9Sstevel@tonic-gate 437c478bd9Sstevel@tonic-gate #include <sys/lgrp.h> 447c478bd9Sstevel@tonic-gate #include <vm/anon.h> 457c478bd9Sstevel@tonic-gate 467c478bd9Sstevel@tonic-gate #ifdef __cplusplus 477c478bd9Sstevel@tonic-gate extern "C" { 487c478bd9Sstevel@tonic-gate #endif 497c478bd9Sstevel@tonic-gate 507c478bd9Sstevel@tonic-gate /* 517c478bd9Sstevel@tonic-gate * A pointer to this structure is passed to segvn_create(). 527c478bd9Sstevel@tonic-gate */ 537c478bd9Sstevel@tonic-gate typedef struct segvn_crargs { 547c478bd9Sstevel@tonic-gate struct vnode *vp; /* vnode mapped from */ 557c478bd9Sstevel@tonic-gate struct cred *cred; /* credentials */ 567c478bd9Sstevel@tonic-gate u_offset_t offset; /* starting offset of vnode for mapping */ 577c478bd9Sstevel@tonic-gate uchar_t type; /* type of sharing done */ 587c478bd9Sstevel@tonic-gate uchar_t prot; /* protections */ 597c478bd9Sstevel@tonic-gate uchar_t maxprot; /* maximum protections */ 607c478bd9Sstevel@tonic-gate uint_t flags; /* flags */ 617c478bd9Sstevel@tonic-gate struct anon_map *amp; /* anon mapping to map to */ 627c478bd9Sstevel@tonic-gate uint_t szc; /* max preferred page size code */ 637c478bd9Sstevel@tonic-gate uint_t lgrp_mem_policy_flags; 647c478bd9Sstevel@tonic-gate } segvn_crargs_t; 657c478bd9Sstevel@tonic-gate 667c478bd9Sstevel@tonic-gate /* 677c478bd9Sstevel@tonic-gate * (Semi) private data maintained by the seg_vn driver per segment mapping. 687c478bd9Sstevel@tonic-gate * 697c478bd9Sstevel@tonic-gate * The read/write segment lock protects all of segvn_data including the 707c478bd9Sstevel@tonic-gate * vpage array. All fields in segvn_data are treated as read-only when 717c478bd9Sstevel@tonic-gate * the "read" version of the address space and the segment locks are held. 727c478bd9Sstevel@tonic-gate * The "write" version of the segment lock, however, is required in order to 737c478bd9Sstevel@tonic-gate * update the following fields: 747c478bd9Sstevel@tonic-gate * 757c478bd9Sstevel@tonic-gate * pageprot 767c478bd9Sstevel@tonic-gate * prot 777c478bd9Sstevel@tonic-gate * amp 787c478bd9Sstevel@tonic-gate * vpage 797c478bd9Sstevel@tonic-gate * 807c478bd9Sstevel@tonic-gate * softlockcnt 817c478bd9Sstevel@tonic-gate * is written by acquiring either the readers lock on the segment and 827c478bd9Sstevel@tonic-gate * freemem lock, or any lock combination which guarantees exclusive use 837c478bd9Sstevel@tonic-gate * of this segment (e.g., adress space writers lock, 847c478bd9Sstevel@tonic-gate * address space readers lock + segment writers lock). 857c478bd9Sstevel@tonic-gate */ 867c478bd9Sstevel@tonic-gate typedef struct segvn_data { 877c478bd9Sstevel@tonic-gate krwlock_t lock; /* protect segvn_data and vpage array */ 88a98e9dbfSaguzovsk kmutex_t segfree_syncmtx; /* barrier lock for segvn_free() */ 897c478bd9Sstevel@tonic-gate uchar_t pageprot; /* true if per page protections present */ 907c478bd9Sstevel@tonic-gate uchar_t prot; /* current segment prot if pageprot == 0 */ 917c478bd9Sstevel@tonic-gate uchar_t maxprot; /* maximum segment protections */ 927c478bd9Sstevel@tonic-gate uchar_t type; /* type of sharing done */ 937c478bd9Sstevel@tonic-gate u_offset_t offset; /* starting offset of vnode for mapping */ 947c478bd9Sstevel@tonic-gate struct vnode *vp; /* vnode that segment mapping is to */ 957c478bd9Sstevel@tonic-gate ulong_t anon_index; /* starting index into anon_map anon array */ 967c478bd9Sstevel@tonic-gate struct anon_map *amp; /* pointer to anon share structure, if needed */ 977c478bd9Sstevel@tonic-gate struct vpage *vpage; /* per-page information, if needed */ 987c478bd9Sstevel@tonic-gate struct cred *cred; /* mapping credentials */ 997c478bd9Sstevel@tonic-gate size_t swresv; /* swap space reserved for this segment */ 1007c478bd9Sstevel@tonic-gate uchar_t advice; /* madvise flags for segment */ 1017c478bd9Sstevel@tonic-gate uchar_t pageadvice; /* true if per page advice set */ 102*9d12795fSRobert Mustacchi uchar_t svn_inz; /* true if pages marked as inherit zero */ 1037c478bd9Sstevel@tonic-gate ushort_t flags; /* flags - from sys/mman.h */ 104a98e9dbfSaguzovsk spgcnt_t softlockcnt; /* # of pages SOFTLOCKED in seg */ 1057c478bd9Sstevel@tonic-gate lgrp_mem_policy_info_t policy_info; /* memory allocation policy */ 10605d3dc4bSpaulsan hat_region_cookie_t rcookie; /* region for hat calls */ 1072cb27123Saguzovsk lgrp_mem_policy_info_t tr_policy_info; /* memory allocation for TR */ 1082cb27123Saguzovsk struct seg *seg; /* pointer back to seg */ 1092cb27123Saguzovsk struct segvn_data *svn_trnext; /* textrepl list next link */ 1102cb27123Saguzovsk struct segvn_data *svn_trprev; /* textrepl list prev link */ 1112cb27123Saguzovsk int tr_state; /* TR (text replication) state */ 11267256803Srh87107 uchar_t pageswap; /* true if per page swap accounting is set */ 113a98e9dbfSaguzovsk spgcnt_t softlockcnt_sbase; /* # of softlocks for seg start addr */ 114a98e9dbfSaguzovsk spgcnt_t softlockcnt_send; /* # of softlocks for seg end addr */ 1157c478bd9Sstevel@tonic-gate } segvn_data_t; 1167c478bd9Sstevel@tonic-gate 1177c478bd9Sstevel@tonic-gate #ifdef _KERNEL 1187c478bd9Sstevel@tonic-gate 1197c478bd9Sstevel@tonic-gate /* 1202cb27123Saguzovsk * segment text replication states. 1212cb27123Saguzovsk */ 1222cb27123Saguzovsk #define SEGVN_TR_INIT (0) /* Check if text replication can be enabled */ 1232cb27123Saguzovsk #define SEGVN_TR_ON (1) /* Text replication is enabled */ 1242cb27123Saguzovsk #define SEGVN_TR_OFF (2) /* Text replication is disabled */ 1252cb27123Saguzovsk 1262cb27123Saguzovsk /* 127*9d12795fSRobert Mustacchi * Inherit zero states 128*9d12795fSRobert Mustacchi */ 129*9d12795fSRobert Mustacchi #define SEGVN_INZ_NONE (0) /* Nothing in the segment is inherit zero */ 130*9d12795fSRobert Mustacchi #define SEGVN_INZ_ALL (1) /* Everything in the segment is inherit zero */ 131*9d12795fSRobert Mustacchi #define SEGVN_INZ_VPP (2) /* Check struct vpages for inherit zero */ 132*9d12795fSRobert Mustacchi 133*9d12795fSRobert Mustacchi /* 1347c478bd9Sstevel@tonic-gate * Macros for segvn segment driver locking. 1357c478bd9Sstevel@tonic-gate */ 1367c478bd9Sstevel@tonic-gate #define SEGVN_LOCK_ENTER(as, lock, type) rw_enter((lock), (type)) 1377c478bd9Sstevel@tonic-gate #define SEGVN_LOCK_EXIT(as, lock) rw_exit((lock)) 1387c478bd9Sstevel@tonic-gate #define SEGVN_LOCK_DOWNGRADE(as, lock) rw_downgrade((lock)) 1392cb27123Saguzovsk #define SEGVN_LOCK_TRYENTER(as, lock, type) rw_tryenter((lock), (type)) 1407c478bd9Sstevel@tonic-gate 1417c478bd9Sstevel@tonic-gate /* 1427c478bd9Sstevel@tonic-gate * Macros to test lock states. 1437c478bd9Sstevel@tonic-gate */ 1447c478bd9Sstevel@tonic-gate #define SEGVN_LOCK_HELD(as, lock) RW_LOCK_HELD((lock)) 1457c478bd9Sstevel@tonic-gate #define SEGVN_READ_HELD(as, lock) RW_READ_HELD((lock)) 1467c478bd9Sstevel@tonic-gate #define SEGVN_WRITE_HELD(as, lock) RW_WRITE_HELD((lock)) 1477c478bd9Sstevel@tonic-gate 1487c478bd9Sstevel@tonic-gate /* 1497c478bd9Sstevel@tonic-gate * Macro used to detect the need to Break the sharing of COW pages 1507c478bd9Sstevel@tonic-gate * 1517c478bd9Sstevel@tonic-gate * The rw == S_WRITE is for the COW case 1527c478bd9Sstevel@tonic-gate * rw == S_READ and type == SOFTLOCK is for the physio case 1537c478bd9Sstevel@tonic-gate * We don't want to share a softlocked page because it can cause problems 1547c478bd9Sstevel@tonic-gate * with multithreaded apps but if rw == S_READ_NOCOW it's ok to not break 1557c478bd9Sstevel@tonic-gate * sharing of COW pages even in SOFTLOCK case. 1567c478bd9Sstevel@tonic-gate */ 1577c478bd9Sstevel@tonic-gate #define BREAK_COW_SHARE(rw, type, seg_type) ((rw == S_WRITE || \ 1587c478bd9Sstevel@tonic-gate (type == F_SOFTLOCK && rw != S_READ_NOCOW)) && \ 1597c478bd9Sstevel@tonic-gate seg_type == MAP_PRIVATE) 1607c478bd9Sstevel@tonic-gate 1617c478bd9Sstevel@tonic-gate #define SEGVN_ZFOD_ARGS(prot, max) \ 1627c478bd9Sstevel@tonic-gate { NULL, NULL, 0, MAP_PRIVATE, prot, max, 0, NULL, 0, 0 } 1637c478bd9Sstevel@tonic-gate 164ec25b48fSsusans #define AS_MAP_CHECK_VNODE_LPOOB(crfp, argsp) \ 1657c478bd9Sstevel@tonic-gate ((crfp) == (int (*)())segvn_create && \ 1667c478bd9Sstevel@tonic-gate (((struct segvn_crargs *)(argsp))->flags & \ 1677c478bd9Sstevel@tonic-gate (MAP_TEXT | MAP_INITDATA)) && \ 168ec25b48fSsusans ((struct segvn_crargs *)(argsp))->szc == 0 && \ 169ec25b48fSsusans ((struct segvn_crargs *)(argsp))->vp != NULL) 1707c478bd9Sstevel@tonic-gate 171ec25b48fSsusans #define AS_MAP_CHECK_ANON_LPOOB(crfp, argsp) \ 17207b65a64Saguzovsk ((crfp) == (int (*)())segvn_create && \ 173ec25b48fSsusans (((struct segvn_crargs *)(argsp))->szc == 0 || \ 174ec25b48fSsusans ((struct segvn_crargs *)(argsp))->szc == AS_MAP_HEAP || \ 175ec25b48fSsusans ((struct segvn_crargs *)(argsp))->szc == AS_MAP_STACK) && \ 17607b65a64Saguzovsk ((struct segvn_crargs *)(argsp))->vp == NULL) 1777c478bd9Sstevel@tonic-gate 1782cb27123Saguzovsk #define SVNTR_HASH_FUNC(vp) (((((uintptr_t)(vp)) >> 4) ^ \ 1792cb27123Saguzovsk (((uintptr_t)(vp)) >> 11)) & \ 1802cb27123Saguzovsk (svntr_hashtab_sz - 1)) 1812cb27123Saguzovsk 1822cb27123Saguzovsk #define SEGVN_TR_ADDSTAT(stat) \ 1832cb27123Saguzovsk segvn_textrepl_stats[CPU->cpu_id].tr_stat_##stat++ 1842cb27123Saguzovsk 18540688216SSudheer A #define SEGVN_DATA(seg) ((struct segvn_data *)(seg)->s_data) 18640688216SSudheer A #define SEG_IS_PARTIAL_RESV(seg) \ 18740688216SSudheer A ((seg)->s_ops == &segvn_ops && SEGVN_DATA(seg) != NULL && \ 18840688216SSudheer A (SEGVN_DATA(seg)->vp == NULL || \ 18940688216SSudheer A SEGVN_DATA(seg)->vp->v_type != VREG) && \ 19040688216SSudheer A (SEGVN_DATA(seg)->flags & MAP_NORESERVE)) 19140688216SSudheer A 1922cb27123Saguzovsk /* 1932cb27123Saguzovsk * A hash table entry looked up by vnode, off/eoff and szc to find anon map to 1942cb27123Saguzovsk * use for text replication based on main thread's (t_tid = 1) lgrp. 1952cb27123Saguzovsk */ 1962cb27123Saguzovsk typedef struct svntr { 1972cb27123Saguzovsk struct vnode *tr_vp; /* text file vnode */ 1982cb27123Saguzovsk u_offset_t tr_off; /* tr_vp mapping start offset */ 1992cb27123Saguzovsk size_t tr_eoff; /* tr_vp mapping end offset */ 2002cb27123Saguzovsk uint_t tr_szc; /* tr_vp mapping pagesize */ 2012cb27123Saguzovsk int tr_valid; /* entry validity state */ 2022cb27123Saguzovsk struct svntr *tr_next; /* next svntr in this hash bucket */ 2032cb27123Saguzovsk timestruc_t tr_mtime; /* tr_vp modification time */ 204f747815bSpaulsan timestruc_t tr_ctime; /* time of last change to attributes */ 2052cb27123Saguzovsk ulong_t tr_refcnt; /* number of segs sharing this entry */ 2062cb27123Saguzovsk segvn_data_t *tr_svnhead; /* list of segs sharing this entry */ 2072cb27123Saguzovsk struct anon_map *tr_amp[NLGRPS_MAX]; /* per lgrp anon maps */ 2082cb27123Saguzovsk } svntr_t; 2092cb27123Saguzovsk 2102cb27123Saguzovsk typedef struct svntr_bucket { 2112cb27123Saguzovsk svntr_t *tr_head; /* first svntr in this hash bucket */ 2122cb27123Saguzovsk kmutex_t tr_lock; /* per bucket lock */ 2132cb27123Saguzovsk } svntr_bucket_t; 2142cb27123Saguzovsk 2152cb27123Saguzovsk typedef struct svntr_stats { 2162cb27123Saguzovsk ulong_t tr_stat_gaerr; /* VOP_GETATTR() failures */ 2172cb27123Saguzovsk ulong_t tr_stat_overmap; /* no TR due to beyond EOF mappings */ 2182cb27123Saguzovsk ulong_t tr_stat_wrcnt; /* no TR due to writtable mappings */ 2192cb27123Saguzovsk ulong_t tr_stat_stale; /* TR entry is stale */ 2202cb27123Saguzovsk ulong_t tr_stat_overlap; /* overlap with other mappings */ 2212cb27123Saguzovsk ulong_t tr_stat_nokmem; /* no TR due to kmem alloc failures */ 2222cb27123Saguzovsk ulong_t tr_stat_noanon; /* no TR due to no swap space */ 2232cb27123Saguzovsk ulong_t tr_stat_normem; /* no TR due to no repl memory */ 2242cb27123Saguzovsk ulong_t tr_stat_nolock; /* async TR failure due to locks */ 2252cb27123Saguzovsk ulong_t tr_stat_asyncrepl; /* number of async TRs */ 2262cb27123Saguzovsk ulong_t tr_stat_repl; /* number of sync TRs */ 2272cb27123Saguzovsk ulong_t tr_stat_newamp; /* number of new amp allocs for TR */ 2282cb27123Saguzovsk } svntr_stats_t; 2292cb27123Saguzovsk 2307c478bd9Sstevel@tonic-gate extern void segvn_init(void); 2317c478bd9Sstevel@tonic-gate extern int segvn_create(struct seg *, void *); 2327c478bd9Sstevel@tonic-gate 2337c478bd9Sstevel@tonic-gate extern struct seg_ops segvn_ops; 2347c478bd9Sstevel@tonic-gate 2357c478bd9Sstevel@tonic-gate /* 2367c478bd9Sstevel@tonic-gate * Provided as shorthand for creating user zfod segments. 2377c478bd9Sstevel@tonic-gate */ 2387c478bd9Sstevel@tonic-gate extern caddr_t zfod_argsp; 2397c478bd9Sstevel@tonic-gate extern caddr_t kzfod_argsp; 2407c478bd9Sstevel@tonic-gate extern caddr_t stack_exec_argsp; 2417c478bd9Sstevel@tonic-gate extern caddr_t stack_noexec_argsp; 2427c478bd9Sstevel@tonic-gate 2437c478bd9Sstevel@tonic-gate #endif /* _KERNEL */ 2447c478bd9Sstevel@tonic-gate 2457c478bd9Sstevel@tonic-gate #ifdef __cplusplus 2467c478bd9Sstevel@tonic-gate } 2477c478bd9Sstevel@tonic-gate #endif 2487c478bd9Sstevel@tonic-gate 2497c478bd9Sstevel@tonic-gate #endif /* _VM_SEG_VN_H */ 250