nfs_clnfsiod.c (210455) | nfs_clnfsiod.c (220683) |
---|---|
1/*- 2 * Copyright (c) 1989, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * This code is derived from software contributed to Berkeley by 6 * Rick Macklem at The University of Guelph. 7 * 8 * Redistribution and use in source and binary forms, with or without --- 19 unchanged lines hidden (view full) --- 28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30 * SUCH DAMAGE. 31 * 32 * from nfs_syscalls.c 8.5 (Berkeley) 3/30/95 33 */ 34 35#include <sys/cdefs.h> | 1/*- 2 * Copyright (c) 1989, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * This code is derived from software contributed to Berkeley by 6 * Rick Macklem at The University of Guelph. 7 * 8 * Redistribution and use in source and binary forms, with or without --- 19 unchanged lines hidden (view full) --- 28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30 * SUCH DAMAGE. 31 * 32 * from nfs_syscalls.c 8.5 (Berkeley) 3/30/95 33 */ 34 35#include <sys/cdefs.h> |
36__FBSDID("$FreeBSD: head/sys/fs/nfsclient/nfs_clnfsiod.c 210455 2010-07-24 22:11:11Z rmacklem $"); | 36__FBSDID("$FreeBSD: head/sys/fs/nfsclient/nfs_clnfsiod.c 220683 2011-04-15 23:07:48Z rmacklem $"); |
37 38#include <sys/param.h> 39#include <sys/systm.h> 40#include <sys/sysproto.h> 41#include <sys/kernel.h> 42#include <sys/sysctl.h> 43#include <sys/file.h> 44#include <sys/filedesc.h> --- 9 unchanged lines hidden (view full) --- 54#include <sys/domain.h> 55#include <sys/protosw.h> 56#include <sys/namei.h> 57#include <sys/unistd.h> 58#include <sys/kthread.h> 59#include <sys/fcntl.h> 60#include <sys/lockf.h> 61#include <sys/mutex.h> | 37 38#include <sys/param.h> 39#include <sys/systm.h> 40#include <sys/sysproto.h> 41#include <sys/kernel.h> 42#include <sys/sysctl.h> 43#include <sys/file.h> 44#include <sys/filedesc.h> --- 9 unchanged lines hidden (view full) --- 54#include <sys/domain.h> 55#include <sys/protosw.h> 56#include <sys/namei.h> 57#include <sys/unistd.h> 58#include <sys/kthread.h> 59#include <sys/fcntl.h> 60#include <sys/lockf.h> 61#include <sys/mutex.h> |
62#include <sys/taskqueue.h> |
|
62 63#include <netinet/in.h> 64#include <netinet/tcp.h> 65 66#include <fs/nfs/nfsport.h> 67#include <fs/nfsclient/nfsmount.h> 68#include <fs/nfsclient/nfs.h> 69#include <fs/nfsclient/nfsnode.h> 70 | 63 64#include <netinet/in.h> 65#include <netinet/tcp.h> 66 67#include <fs/nfs/nfsport.h> 68#include <fs/nfsclient/nfsmount.h> 69#include <fs/nfsclient/nfs.h> 70#include <fs/nfsclient/nfsnode.h> 71 |
71extern struct mtx ncl_iod_mutex; | 72extern struct mtx ncl_iod_mutex; 73extern struct task ncl_nfsiodnew_task; |
72 73int ncl_numasync; | 74 75int ncl_numasync; |
74enum nfsiod_state ncl_iodwant[NFS_MAXRAHEAD]; 75struct nfsmount *ncl_iodmount[NFS_MAXRAHEAD]; | 76enum nfsiod_state ncl_iodwant[NFS_MAXASYNCDAEMON]; 77struct nfsmount *ncl_iodmount[NFS_MAXASYNCDAEMON]; |
76 77static void nfssvc_iod(void *); 78 | 78 79static void nfssvc_iod(void *); 80 |
79static int nfs_asyncdaemon[NFS_MAXRAHEAD]; | 81static int nfs_asyncdaemon[NFS_MAXASYNCDAEMON]; |
80 81SYSCTL_DECL(_vfs_newnfs); 82 83/* Maximum number of seconds a nfsiod kthread will sleep before exiting */ | 82 83SYSCTL_DECL(_vfs_newnfs); 84 85/* Maximum number of seconds a nfsiod kthread will sleep before exiting */ |
84static unsigned int ncl_iodmaxidle = 120; 85SYSCTL_UINT(_vfs_newnfs, OID_AUTO, iodmaxidle, CTLFLAG_RW, &ncl_iodmaxidle, 0, ""); | 86static unsigned int nfs_iodmaxidle = 120; 87SYSCTL_UINT(_vfs_newnfs, OID_AUTO, iodmaxidle, CTLFLAG_RW, &nfs_iodmaxidle, 0, 88 "Max number of seconds an nfsiod kthread will sleep before exiting"); |
86 87/* Maximum number of nfsiod kthreads */ | 89 90/* Maximum number of nfsiod kthreads */ |
88unsigned int ncl_iodmax = NFS_MAXRAHEAD; | 91unsigned int ncl_iodmax = 20; |
89 90/* Minimum number of nfsiod kthreads to keep as spares */ 91static unsigned int nfs_iodmin = 0; 92 | 92 93/* Minimum number of nfsiod kthreads to keep as spares */ 94static unsigned int nfs_iodmin = 0; 95 |
96static int nfs_nfsiodnew_sync(void); 97 |
|
93static int 94sysctl_iodmin(SYSCTL_HANDLER_ARGS) 95{ 96 int error, i; 97 int newmin; 98 99 newmin = nfs_iodmin; 100 error = sysctl_handle_int(oidp, &newmin, 0, req); --- 7 unchanged lines hidden (view full) --- 108 nfs_iodmin = newmin; 109 if (ncl_numasync >= nfs_iodmin) 110 goto out; 111 /* 112 * If the current number of nfsiod is lower 113 * than the new minimum, create some more. 114 */ 115 for (i = nfs_iodmin - ncl_numasync; i > 0; i--) | 98static int 99sysctl_iodmin(SYSCTL_HANDLER_ARGS) 100{ 101 int error, i; 102 int newmin; 103 104 newmin = nfs_iodmin; 105 error = sysctl_handle_int(oidp, &newmin, 0, req); --- 7 unchanged lines hidden (view full) --- 113 nfs_iodmin = newmin; 114 if (ncl_numasync >= nfs_iodmin) 115 goto out; 116 /* 117 * If the current number of nfsiod is lower 118 * than the new minimum, create some more. 119 */ 120 for (i = nfs_iodmin - ncl_numasync; i > 0; i--) |
116 ncl_nfsiodnew(0); | 121 nfs_nfsiodnew_sync(); |
117out: 118 mtx_unlock(&ncl_iod_mutex); 119 return (0); 120} 121SYSCTL_PROC(_vfs_newnfs, OID_AUTO, iodmin, CTLTYPE_UINT | CTLFLAG_RW, 0, | 122out: 123 mtx_unlock(&ncl_iod_mutex); 124 return (0); 125} 126SYSCTL_PROC(_vfs_newnfs, OID_AUTO, iodmin, CTLTYPE_UINT | CTLFLAG_RW, 0, |
122 sizeof (nfs_iodmin), sysctl_iodmin, "IU", ""); | 127 sizeof (nfs_iodmin), sysctl_iodmin, "IU", 128 "Min number of nfsiod kthreads to keep as spares"); |
123 | 129 |
124 | |
125static int 126sysctl_iodmax(SYSCTL_HANDLER_ARGS) 127{ 128 int error, i; 129 int iod, newmax; 130 131 newmax = ncl_iodmax; 132 error = sysctl_handle_int(oidp, &newmax, 0, req); 133 if (error || (req->newptr == NULL)) 134 return (error); | 130static int 131sysctl_iodmax(SYSCTL_HANDLER_ARGS) 132{ 133 int error, i; 134 int iod, newmax; 135 136 newmax = ncl_iodmax; 137 error = sysctl_handle_int(oidp, &newmax, 0, req); 138 if (error || (req->newptr == NULL)) 139 return (error); |
135 if (newmax > NFS_MAXRAHEAD) | 140 if (newmax > NFS_MAXASYNCDAEMON) |
136 return (EINVAL); 137 mtx_lock(&ncl_iod_mutex); 138 ncl_iodmax = newmax; 139 if (ncl_numasync <= ncl_iodmax) 140 goto out; 141 /* 142 * If there are some asleep nfsiods that should 143 * exit, wakeup() them so that they check ncl_iodmax --- 6 unchanged lines hidden (view full) --- 150 wakeup(&ncl_iodwant[iod]); 151 iod--; 152 } 153out: 154 mtx_unlock(&ncl_iod_mutex); 155 return (0); 156} 157SYSCTL_PROC(_vfs_newnfs, OID_AUTO, iodmax, CTLTYPE_UINT | CTLFLAG_RW, 0, | 141 return (EINVAL); 142 mtx_lock(&ncl_iod_mutex); 143 ncl_iodmax = newmax; 144 if (ncl_numasync <= ncl_iodmax) 145 goto out; 146 /* 147 * If there are some asleep nfsiods that should 148 * exit, wakeup() them so that they check ncl_iodmax --- 6 unchanged lines hidden (view full) --- 155 wakeup(&ncl_iodwant[iod]); 156 iod--; 157 } 158out: 159 mtx_unlock(&ncl_iod_mutex); 160 return (0); 161} 162SYSCTL_PROC(_vfs_newnfs, OID_AUTO, iodmax, CTLTYPE_UINT | CTLFLAG_RW, 0, |
158 sizeof (ncl_iodmax), sysctl_iodmax, "IU", ""); | 163 sizeof (ncl_iodmax), sysctl_iodmax, "IU", 164 "Max number of nfsiod kthreads"); |
159 | 165 |
160int 161ncl_nfsiodnew(int set_iodwant) | 166static int 167nfs_nfsiodnew_sync(void) |
162{ 163 int error, i; | 168{ 169 int error, i; |
164 int newiod; | |
165 | 170 |
166 if (ncl_numasync >= ncl_iodmax) 167 return (-1); 168 newiod = -1; 169 for (i = 0; i < ncl_iodmax; i++) | 171 mtx_assert(&ncl_iod_mutex, MA_OWNED); 172 for (i = 0; i < ncl_iodmax; i++) { |
170 if (nfs_asyncdaemon[i] == 0) { | 173 if (nfs_asyncdaemon[i] == 0) { |
171 nfs_asyncdaemon[i]++; 172 newiod = i; | 174 nfs_asyncdaemon[i] = 1; |
173 break; 174 } | 175 break; 176 } |
175 if (newiod == -1) 176 return (-1); 177 if (set_iodwant > 0) 178 ncl_iodwant[i] = NFSIOD_CREATED_FOR_NFS_ASYNCIO; | 177 } 178 if (i == ncl_iodmax) 179 return (0); |
179 mtx_unlock(&ncl_iod_mutex); | 180 mtx_unlock(&ncl_iod_mutex); |
180 error = kproc_create(nfssvc_iod, nfs_asyncdaemon + i, NULL, RFHIGHPID, 181 0, "nfsiod %d", newiod); | 181 error = kproc_create(nfssvc_iod, nfs_asyncdaemon + i, NULL, 182 RFHIGHPID, 0, "newnfs %d", i); |
182 mtx_lock(&ncl_iod_mutex); | 183 mtx_lock(&ncl_iod_mutex); |
183 if (error) { 184 if (set_iodwant > 0) 185 ncl_iodwant[i] = NFSIOD_NOT_AVAILABLE; 186 return (-1); | 184 if (error == 0) { 185 ncl_numasync++; 186 ncl_iodwant[i] = NFSIOD_AVAILABLE; 187 } else 188 nfs_asyncdaemon[i] = 0; 189 return (error); 190} 191 192void 193ncl_nfsiodnew_tq(__unused void *arg, int pending) 194{ 195 196 mtx_lock(&ncl_iod_mutex); 197 while (pending > 0) { 198 pending--; 199 nfs_nfsiodnew_sync(); |
187 } | 200 } |
188 ncl_numasync++; 189 return (newiod); | 201 mtx_unlock(&ncl_iod_mutex); |
190} 191 | 202} 203 |
204void 205ncl_nfsiodnew(void) 206{ 207 208 mtx_assert(&ncl_iod_mutex, MA_OWNED); 209 taskqueue_enqueue(taskqueue_thread, &ncl_nfsiodnew_task); 210} 211 |
|
192static void 193nfsiod_setup(void *dummy) 194{ | 212static void 213nfsiod_setup(void *dummy) 214{ |
195 int i; | |
196 int error; 197 198 TUNABLE_INT_FETCH("vfs.newnfs.iodmin", &nfs_iodmin); 199 nfscl_init(); 200 mtx_lock(&ncl_iod_mutex); 201 /* Silently limit the start number of nfsiod's */ | 215 int error; 216 217 TUNABLE_INT_FETCH("vfs.newnfs.iodmin", &nfs_iodmin); 218 nfscl_init(); 219 mtx_lock(&ncl_iod_mutex); 220 /* Silently limit the start number of nfsiod's */ |
202 if (nfs_iodmin > NFS_MAXRAHEAD) 203 nfs_iodmin = NFS_MAXRAHEAD; | 221 if (nfs_iodmin > NFS_MAXASYNCDAEMON) 222 nfs_iodmin = NFS_MAXASYNCDAEMON; |
204 | 223 |
205 for (i = 0; i < nfs_iodmin; i++) { 206 error = ncl_nfsiodnew(0); | 224 while (ncl_numasync < nfs_iodmin) { 225 error = nfs_nfsiodnew_sync(); |
207 if (error == -1) | 226 if (error == -1) |
208 panic("newnfsiod_setup: ncl_nfsiodnew failed"); | 227 panic("nfsiod_setup: nfs_nfsiodnew failed"); |
209 } 210 mtx_unlock(&ncl_iod_mutex); 211} 212SYSINIT(newnfsiod, SI_SUB_KTHREAD_IDLE, SI_ORDER_ANY, nfsiod_setup, NULL); 213 214static int nfs_defect = 0; | 228 } 229 mtx_unlock(&ncl_iod_mutex); 230} 231SYSINIT(newnfsiod, SI_SUB_KTHREAD_IDLE, SI_ORDER_ANY, nfsiod_setup, NULL); 232 233static int nfs_defect = 0; |
215SYSCTL_INT(_vfs_newnfs, OID_AUTO, defect, CTLFLAG_RW, &nfs_defect, 0, ""); | 234SYSCTL_INT(_vfs_newnfs, OID_AUTO, defect, CTLFLAG_RW, &nfs_defect, 0, 235 "Allow nfsiods to migrate serving different mounts"); |
216 217/* 218 * Asynchronous I/O daemons for client nfs. 219 * They do read-ahead and write-behind operations on the block I/O cache. 220 * Returns if we hit the timeout defined by the iodmaxidle sysctl. 221 */ 222static void 223nfssvc_iod(void *instance) --- 16 unchanged lines hidden (view full) --- 240 if (nmp) 241 nmp->nm_bufqiods--; 242 if (ncl_iodwant[myiod] == NFSIOD_NOT_AVAILABLE) 243 ncl_iodwant[myiod] = NFSIOD_AVAILABLE; 244 ncl_iodmount[myiod] = NULL; 245 /* 246 * Always keep at least nfs_iodmin kthreads. 247 */ | 236 237/* 238 * Asynchronous I/O daemons for client nfs. 239 * They do read-ahead and write-behind operations on the block I/O cache. 240 * Returns if we hit the timeout defined by the iodmaxidle sysctl. 241 */ 242static void 243nfssvc_iod(void *instance) --- 16 unchanged lines hidden (view full) --- 260 if (nmp) 261 nmp->nm_bufqiods--; 262 if (ncl_iodwant[myiod] == NFSIOD_NOT_AVAILABLE) 263 ncl_iodwant[myiod] = NFSIOD_AVAILABLE; 264 ncl_iodmount[myiod] = NULL; 265 /* 266 * Always keep at least nfs_iodmin kthreads. 267 */ |
248 timo = (myiod < nfs_iodmin) ? 0 : ncl_iodmaxidle * hz; | 268 timo = (myiod < nfs_iodmin) ? 0 : nfs_iodmaxidle * hz; |
249 error = msleep(&ncl_iodwant[myiod], &ncl_iod_mutex, PWAIT | PCATCH, 250 "-", timo); 251 if (error) { 252 nmp = ncl_iodmount[myiod]; 253 /* 254 * Rechecking the nm_bufq closes a rare race where the 255 * nfsiod is woken up at the exact time the idle timeout 256 * fires 257 */ 258 if (nmp && TAILQ_FIRST(&nmp->nm_bufq)) 259 error = 0; 260 break; 261 } 262 } 263 if (error) 264 break; 265 while ((bp = TAILQ_FIRST(&nmp->nm_bufq)) != NULL) { | 269 error = msleep(&ncl_iodwant[myiod], &ncl_iod_mutex, PWAIT | PCATCH, 270 "-", timo); 271 if (error) { 272 nmp = ncl_iodmount[myiod]; 273 /* 274 * Rechecking the nm_bufq closes a rare race where the 275 * nfsiod is woken up at the exact time the idle timeout 276 * fires 277 */ 278 if (nmp && TAILQ_FIRST(&nmp->nm_bufq)) 279 error = 0; 280 break; 281 } 282 } 283 if (error) 284 break; 285 while ((bp = TAILQ_FIRST(&nmp->nm_bufq)) != NULL) { |
266 | |
267 /* Take one off the front of the list */ 268 TAILQ_REMOVE(&nmp->nm_bufq, bp, b_freelist); 269 nmp->nm_bufqlen--; 270 if (nmp->nm_bufqwant && nmp->nm_bufqlen <= ncl_numasync) { 271 nmp->nm_bufqwant = 0; 272 wakeup(&nmp->nm_bufq); 273 } 274 mtx_unlock(&ncl_iod_mutex); --- 41 unchanged lines hidden --- | 286 /* Take one off the front of the list */ 287 TAILQ_REMOVE(&nmp->nm_bufq, bp, b_freelist); 288 nmp->nm_bufqlen--; 289 if (nmp->nm_bufqwant && nmp->nm_bufqlen <= ncl_numasync) { 290 nmp->nm_bufqwant = 0; 291 wakeup(&nmp->nm_bufq); 292 } 293 mtx_unlock(&ncl_iod_mutex); --- 41 unchanged lines hidden --- |