Print this page
6154 const-ify segment ops structures
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/uts/common/vm/seg_vn.h
+++ new/usr/src/uts/common/vm/seg_vn.h
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
12 12 *
13 13 * When distributing Covered Code, include this CDDL HEADER in each
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 15 * If applicable, add the following below this CDDL HEADER, with the
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
19 19 * CDDL HEADER END
20 20 */
21 21 /*
22 22 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
23 23 * Use is subject to license terms.
24 24 * Copyright (c) 2015, Joyent, Inc. All rights reserved.
25 25 */
26 26
27 27 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
28 28 /* All Rights Reserved */
29 29
30 30 /*
31 31 * University Copyright- Copyright (c) 1982, 1986, 1988
32 32 * The Regents of the University of California
33 33 * All Rights Reserved
34 34 *
35 35 * University Acknowledgment- Portions of this document are derived from
36 36 * software developed by the University of California, Berkeley, and its
37 37 * contributors.
38 38 */
39 39
40 40 #ifndef _VM_SEG_VN_H
41 41 #define _VM_SEG_VN_H
42 42
43 43 #include <sys/lgrp.h>
44 44 #include <vm/anon.h>
45 45
46 46 #ifdef __cplusplus
47 47 extern "C" {
48 48 #endif
49 49
50 50 /*
51 51 * A pointer to this structure is passed to segvn_create().
52 52 */
53 53 typedef struct segvn_crargs {
54 54 struct vnode *vp; /* vnode mapped from */
55 55 struct cred *cred; /* credentials */
56 56 u_offset_t offset; /* starting offset of vnode for mapping */
57 57 uchar_t type; /* type of sharing done */
58 58 uchar_t prot; /* protections */
59 59 uchar_t maxprot; /* maximum protections */
60 60 uint_t flags; /* flags */
61 61 struct anon_map *amp; /* anon mapping to map to */
62 62 uint_t szc; /* max preferred page size code */
63 63 uint_t lgrp_mem_policy_flags;
64 64 } segvn_crargs_t;
65 65
66 66 /*
67 67 * (Semi) private data maintained by the seg_vn driver per segment mapping.
68 68 *
69 69 * The read/write segment lock protects all of segvn_data including the
70 70 * vpage array. All fields in segvn_data are treated as read-only when
71 71 * the "read" version of the address space and the segment locks are held.
72 72 * The "write" version of the segment lock, however, is required in order to
73 73 * update the following fields:
74 74 *
75 75 * pageprot
76 76 * prot
77 77 * amp
78 78 * vpage
79 79 *
80 80 * softlockcnt
81 81 * is written by acquiring either the readers lock on the segment and
82 82 * freemem lock, or any lock combination which guarantees exclusive use
83 83 * of this segment (e.g., adress space writers lock,
84 84 * address space readers lock + segment writers lock).
85 85 */
86 86 typedef struct segvn_data {
87 87 krwlock_t lock; /* protect segvn_data and vpage array */
88 88 kmutex_t segfree_syncmtx; /* barrier lock for segvn_free() */
89 89 uchar_t pageprot; /* true if per page protections present */
90 90 uchar_t prot; /* current segment prot if pageprot == 0 */
91 91 uchar_t maxprot; /* maximum segment protections */
92 92 uchar_t type; /* type of sharing done */
93 93 u_offset_t offset; /* starting offset of vnode for mapping */
94 94 struct vnode *vp; /* vnode that segment mapping is to */
95 95 ulong_t anon_index; /* starting index into anon_map anon array */
96 96 struct anon_map *amp; /* pointer to anon share structure, if needed */
97 97 struct vpage *vpage; /* per-page information, if needed */
98 98 struct cred *cred; /* mapping credentials */
99 99 size_t swresv; /* swap space reserved for this segment */
100 100 uchar_t advice; /* madvise flags for segment */
101 101 uchar_t pageadvice; /* true if per page advice set */
102 102 uchar_t svn_inz; /* true if pages marked as inherit zero */
103 103 ushort_t flags; /* flags - from sys/mman.h */
104 104 spgcnt_t softlockcnt; /* # of pages SOFTLOCKED in seg */
105 105 lgrp_mem_policy_info_t policy_info; /* memory allocation policy */
106 106 hat_region_cookie_t rcookie; /* region for hat calls */
107 107 lgrp_mem_policy_info_t tr_policy_info; /* memory allocation for TR */
108 108 struct seg *seg; /* pointer back to seg */
109 109 struct segvn_data *svn_trnext; /* textrepl list next link */
110 110 struct segvn_data *svn_trprev; /* textrepl list prev link */
111 111 int tr_state; /* TR (text replication) state */
112 112 uchar_t pageswap; /* true if per page swap accounting is set */
113 113 spgcnt_t softlockcnt_sbase; /* # of softlocks for seg start addr */
114 114 spgcnt_t softlockcnt_send; /* # of softlocks for seg end addr */
115 115 } segvn_data_t;
116 116
117 117 #ifdef _KERNEL
118 118
119 119 /*
120 120 * segment text replication states.
121 121 */
122 122 #define SEGVN_TR_INIT (0) /* Check if text replication can be enabled */
123 123 #define SEGVN_TR_ON (1) /* Text replication is enabled */
124 124 #define SEGVN_TR_OFF (2) /* Text replication is disabled */
125 125
126 126 /*
127 127 * Inherit zero states
128 128 */
129 129 #define SEGVN_INZ_NONE (0) /* Nothing in the segment is inherit zero */
130 130 #define SEGVN_INZ_ALL (1) /* Everything in the segment is inherit zero */
131 131 #define SEGVN_INZ_VPP (2) /* Check struct vpages for inherit zero */
132 132
133 133 /*
134 134 * Macros for segvn segment driver locking.
135 135 */
136 136 #define SEGVN_LOCK_ENTER(as, lock, type) rw_enter((lock), (type))
137 137 #define SEGVN_LOCK_EXIT(as, lock) rw_exit((lock))
138 138 #define SEGVN_LOCK_DOWNGRADE(as, lock) rw_downgrade((lock))
139 139 #define SEGVN_LOCK_TRYENTER(as, lock, type) rw_tryenter((lock), (type))
140 140
141 141 /*
142 142 * Macros to test lock states.
143 143 */
144 144 #define SEGVN_LOCK_HELD(as, lock) RW_LOCK_HELD((lock))
145 145 #define SEGVN_READ_HELD(as, lock) RW_READ_HELD((lock))
146 146 #define SEGVN_WRITE_HELD(as, lock) RW_WRITE_HELD((lock))
147 147
148 148 /*
149 149 * Macro used to detect the need to Break the sharing of COW pages
150 150 *
151 151 * The rw == S_WRITE is for the COW case
152 152 * rw == S_READ and type == SOFTLOCK is for the physio case
153 153 * We don't want to share a softlocked page because it can cause problems
154 154 * with multithreaded apps but if rw == S_READ_NOCOW it's ok to not break
155 155 * sharing of COW pages even in SOFTLOCK case.
156 156 */
157 157 #define BREAK_COW_SHARE(rw, type, seg_type) ((rw == S_WRITE || \
158 158 (type == F_SOFTLOCK && rw != S_READ_NOCOW)) && \
159 159 seg_type == MAP_PRIVATE)
160 160
161 161 #define SEGVN_ZFOD_ARGS(prot, max) \
162 162 { NULL, NULL, 0, MAP_PRIVATE, prot, max, 0, NULL, 0, 0 }
163 163
164 164 #define AS_MAP_CHECK_VNODE_LPOOB(crfp, argsp) \
165 165 ((crfp) == (int (*)())segvn_create && \
166 166 (((struct segvn_crargs *)(argsp))->flags & \
167 167 (MAP_TEXT | MAP_INITDATA)) && \
168 168 ((struct segvn_crargs *)(argsp))->szc == 0 && \
169 169 ((struct segvn_crargs *)(argsp))->vp != NULL)
170 170
171 171 #define AS_MAP_CHECK_ANON_LPOOB(crfp, argsp) \
172 172 ((crfp) == (int (*)())segvn_create && \
173 173 (((struct segvn_crargs *)(argsp))->szc == 0 || \
174 174 ((struct segvn_crargs *)(argsp))->szc == AS_MAP_HEAP || \
175 175 ((struct segvn_crargs *)(argsp))->szc == AS_MAP_STACK) && \
176 176 ((struct segvn_crargs *)(argsp))->vp == NULL)
177 177
178 178 #define SVNTR_HASH_FUNC(vp) (((((uintptr_t)(vp)) >> 4) ^ \
179 179 (((uintptr_t)(vp)) >> 11)) & \
180 180 (svntr_hashtab_sz - 1))
181 181
182 182 #define SEGVN_TR_ADDSTAT(stat) \
183 183 segvn_textrepl_stats[CPU->cpu_id].tr_stat_##stat++
184 184
185 185 #define SEGVN_DATA(seg) ((struct segvn_data *)(seg)->s_data)
186 186 #define SEG_IS_PARTIAL_RESV(seg) \
187 187 ((seg)->s_ops == &segvn_ops && SEGVN_DATA(seg) != NULL && \
188 188 (SEGVN_DATA(seg)->vp == NULL || \
189 189 SEGVN_DATA(seg)->vp->v_type != VREG) && \
190 190 (SEGVN_DATA(seg)->flags & MAP_NORESERVE))
191 191
192 192 /*
193 193 * A hash table entry looked up by vnode, off/eoff and szc to find anon map to
194 194 * use for text replication based on main thread's (t_tid = 1) lgrp.
195 195 */
196 196 typedef struct svntr {
197 197 struct vnode *tr_vp; /* text file vnode */
198 198 u_offset_t tr_off; /* tr_vp mapping start offset */
199 199 size_t tr_eoff; /* tr_vp mapping end offset */
200 200 uint_t tr_szc; /* tr_vp mapping pagesize */
201 201 int tr_valid; /* entry validity state */
202 202 struct svntr *tr_next; /* next svntr in this hash bucket */
203 203 timestruc_t tr_mtime; /* tr_vp modification time */
204 204 timestruc_t tr_ctime; /* time of last change to attributes */
205 205 ulong_t tr_refcnt; /* number of segs sharing this entry */
206 206 segvn_data_t *tr_svnhead; /* list of segs sharing this entry */
207 207 struct anon_map *tr_amp[NLGRPS_MAX]; /* per lgrp anon maps */
208 208 } svntr_t;
209 209
210 210 typedef struct svntr_bucket {
211 211 svntr_t *tr_head; /* first svntr in this hash bucket */
212 212 kmutex_t tr_lock; /* per bucket lock */
213 213 } svntr_bucket_t;
214 214
215 215 typedef struct svntr_stats {
216 216 ulong_t tr_stat_gaerr; /* VOP_GETATTR() failures */
217 217 ulong_t tr_stat_overmap; /* no TR due to beyond EOF mappings */
218 218 ulong_t tr_stat_wrcnt; /* no TR due to writtable mappings */
219 219 ulong_t tr_stat_stale; /* TR entry is stale */
220 220 ulong_t tr_stat_overlap; /* overlap with other mappings */
221 221 ulong_t tr_stat_nokmem; /* no TR due to kmem alloc failures */
222 222 ulong_t tr_stat_noanon; /* no TR due to no swap space */
↓ open down ↓ |
222 lines elided |
↑ open up ↑ |
223 223 ulong_t tr_stat_normem; /* no TR due to no repl memory */
224 224 ulong_t tr_stat_nolock; /* async TR failure due to locks */
225 225 ulong_t tr_stat_asyncrepl; /* number of async TRs */
226 226 ulong_t tr_stat_repl; /* number of sync TRs */
227 227 ulong_t tr_stat_newamp; /* number of new amp allocs for TR */
228 228 } svntr_stats_t;
229 229
230 230 extern void segvn_init(void);
231 231 extern int segvn_create(struct seg *, void *);
232 232
233 -extern struct seg_ops segvn_ops;
233 +extern const struct seg_ops segvn_ops;
234 234
235 235 /*
236 236 * Provided as shorthand for creating user zfod segments.
237 237 */
238 238 extern caddr_t zfod_argsp;
239 239 extern caddr_t kzfod_argsp;
240 240 extern caddr_t stack_exec_argsp;
241 241 extern caddr_t stack_noexec_argsp;
242 242
243 243 #endif /* _KERNEL */
244 244
245 245 #ifdef __cplusplus
246 246 }
247 247 #endif
248 248
249 249 #endif /* _VM_SEG_VN_H */
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX