Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

sunrpc: introduce the concept of a minimum number of threads per pool

Add a new pool->sp_nrthrmin field to track the minimum number of threads
in a pool. Add min_threads parameters to both svc_set_num_threads() and
svc_set_pool_threads(). If min_threads is non-zero and less than the
max, svc_set_num_threads() will ensure that the number of running
threads is between the min and the max.

If the min is 0 or greater than the max, then it is ignored, and the
maximum number of threads will be started, and never spun down.

For now, the min_threads is always 0, but a later patch will pass the
proper value through from nfsd.

Signed-off-by: Jeff Layton <jlayton@kernel.org>
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>

authored by

Jeff Layton and committed by
Chuck Lever
7ffc7ade 6cd60f42

+52 -21
+2 -2
fs/lockd/svc.c
··· 340 340 return -ENOMEM; 341 341 } 342 342 343 - error = svc_set_num_threads(serv, 1); 343 + error = svc_set_num_threads(serv, 0, 1); 344 344 if (error < 0) { 345 345 svc_destroy(&serv); 346 346 return error; ··· 368 368 unregister_inet6addr_notifier(&lockd_inet6addr_notifier); 369 369 #endif 370 370 371 - svc_set_num_threads(nlmsvc_serv, 0); 371 + svc_set_num_threads(nlmsvc_serv, 0, 0); 372 372 timer_delete_sync(&nlmsvc_retry); 373 373 svc_destroy(&nlmsvc_serv); 374 374 dprintk("lockd_down: service destroyed\n");
+4 -4
fs/nfs/callback.c
··· 119 119 if (serv->sv_nrthreads == nrservs) 120 120 return 0; 121 121 122 - ret = svc_set_num_threads(serv, nrservs); 122 + ret = svc_set_num_threads(serv, 0, nrservs); 123 123 if (ret) { 124 - svc_set_num_threads(serv, 0); 124 + svc_set_num_threads(serv, 0, 0); 125 125 return ret; 126 126 } 127 127 dprintk("nfs_callback_up: service started\n"); ··· 242 242 cb_info->users++; 243 243 err_net: 244 244 if (!cb_info->users) { 245 - svc_set_num_threads(cb_info->serv, 0); 245 + svc_set_num_threads(cb_info->serv, 0, 0); 246 246 svc_destroy(&cb_info->serv); 247 247 } 248 248 err_create: ··· 268 268 nfs_callback_down_net(minorversion, serv, net); 269 269 cb_info->users--; 270 270 if (cb_info->users == 0) { 271 - svc_set_num_threads(serv, 0); 271 + svc_set_num_threads(serv, 0, 0); 272 272 dprintk("nfs_callback_down: service destroyed\n"); 273 273 xprt_svc_destroy_nullify_bc(xprt, &cb_info->serv); 274 274 }
+4 -4
fs/nfsd/nfssvc.c
··· 580 580 } 581 581 582 582 /* Kill outstanding nfsd threads */ 583 - svc_set_num_threads(serv, 0); 583 + svc_set_num_threads(serv, 0, 0); 584 584 nfsd_destroy_serv(net); 585 585 mutex_unlock(&nfsd_mutex); 586 586 } ··· 690 690 691 691 /* Special case: When n == 1, distribute threads equally among pools. */ 692 692 if (n == 1) 693 - return svc_set_num_threads(nn->nfsd_serv, nthreads[0]); 693 + return svc_set_num_threads(nn->nfsd_serv, 0, nthreads[0]); 694 694 695 695 if (n > nn->nfsd_serv->sv_nrpools) 696 696 n = nn->nfsd_serv->sv_nrpools; ··· 718 718 for (i = 0; i < n; i++) { 719 719 err = svc_set_pool_threads(nn->nfsd_serv, 720 720 &nn->nfsd_serv->sv_pools[i], 721 - nthreads[i]); 721 + 0, nthreads[i]); 722 722 if (err) 723 723 goto out; 724 724 } ··· 727 727 for (i = n; i < nn->nfsd_serv->sv_nrpools; ++i) { 728 728 err = svc_set_pool_threads(nn->nfsd_serv, 729 729 &nn->nfsd_serv->sv_pools[i], 730 - 0); 730 + 0, 0); 731 731 if (err) 732 732 goto out; 733 733 }
+5 -3
include/linux/sunrpc/svc.h
··· 36 36 struct svc_pool { 37 37 unsigned int sp_id; /* pool id; also node id on NUMA */ 38 38 unsigned int sp_nrthreads; /* # of threads currently running in pool */ 39 + unsigned int sp_nrthrmin; /* Min number of threads to run per pool */ 39 40 unsigned int sp_nrthrmax; /* Max requested number of threads in pool */ 40 41 struct lwq sp_xprts; /* pending transports */ 41 42 struct list_head sp_all_threads; /* all server threads */ ··· 73 72 struct svc_stat * sv_stats; /* RPC statistics */ 74 73 spinlock_t sv_lock; 75 74 unsigned int sv_nprogs; /* Number of sv_programs */ 76 - unsigned int sv_nrthreads; /* # of server threads */ 75 + unsigned int sv_nrthreads; /* # of running server threads */ 77 76 unsigned int sv_max_payload; /* datagram payload size */ 78 77 unsigned int sv_max_mesg; /* max_payload + 1 page for overheads */ 79 78 unsigned int sv_xdrsize; /* XDR buffer size */ ··· 449 448 unsigned int bufsize, 450 449 int (*threadfn)(void *data)); 451 450 int svc_set_pool_threads(struct svc_serv *serv, struct svc_pool *pool, 452 - unsigned int nrservs); 453 - int svc_set_num_threads(struct svc_serv *serv, unsigned int nrservs); 451 + unsigned int min_threads, unsigned int max_threads); 452 + int svc_set_num_threads(struct svc_serv *serv, unsigned int min_threads, 453 + unsigned int nrservs); 454 454 int svc_pool_stats_open(struct svc_info *si, struct file *file); 455 455 void svc_process(struct svc_rqst *rqstp); 456 456 void svc_process_bc(struct rpc_rqst *req, struct svc_rqst *rqstp);
+37 -8
net/sunrpc/svc.c
··· 820 820 * svc_set_pool_threads - adjust number of threads per pool 821 821 * @serv: RPC service to adjust 822 822 * @pool: Specific pool from which to choose threads 823 - * @nrservs: New number of threads for @serv (0 means kill all threads) 823 + * @min_threads: min number of threads to run in @pool 824 + * @max_threads: max number of threads in @pool (0 means kill all threads) 824 825 * 825 - * Create or destroy threads in @pool to bring it to @nrservs. 826 + * Create or destroy threads in @pool to bring it into an acceptable range 827 + * between @min_threads and @max_threads. 828 + * 829 + * If @min_threads is 0 or larger than @max_threads, then it is ignored and 830 + * the pool will be set to run a static @max_threads number of threads. 826 831 * 827 832 * Caller must ensure mutual exclusion between this and server startup or 828 833 * shutdown. ··· 837 832 */ 838 833 int 839 834 svc_set_pool_threads(struct svc_serv *serv, struct svc_pool *pool, 840 - unsigned int nrservs) 835 + unsigned int min_threads, unsigned int max_threads) 841 836 { 842 - int delta = nrservs; 837 + int delta; 843 838 844 839 if (!pool) 845 840 return -EINVAL; 846 841 847 - pool->sp_nrthrmax = nrservs; 848 - delta -= pool->sp_nrthreads; 842 + /* clamp min threads to the max */ 843 + if (min_threads > max_threads) 844 + min_threads = max_threads; 849 845 846 + pool->sp_nrthrmin = min_threads; 847 + pool->sp_nrthrmax = max_threads; 848 + 849 + /* 850 + * When min_threads is set, then only change the number of 851 + * threads to bring it within an acceptable range. 852 + */ 853 + if (min_threads) { 854 + if (pool->sp_nrthreads > max_threads) 855 + delta = max_threads; 856 + else if (pool->sp_nrthreads < min_threads) 857 + delta = min_threads; 858 + else 859 + return 0; 860 + } else { 861 + delta = max_threads; 862 + } 863 + 864 + delta -= pool->sp_nrthreads; 850 865 if (delta > 0) 851 866 return svc_start_kthreads(serv, pool, delta); 852 867 if (delta < 0) ··· 878 853 /** 879 854 * svc_set_num_threads - adjust number of threads in serv 880 855 * @serv: RPC service to adjust 856 + * @min_threads: min number of threads to run per pool 881 857 * @nrservs: New number of threads for @serv (0 means kill all threads) 882 858 * 883 859 * Create or destroy threads in @serv to bring it to @nrservs. If there ··· 893 867 * adjusted; the caller is responsible for recovery. 894 868 */ 895 869 int 896 - svc_set_num_threads(struct svc_serv *serv, unsigned int nrservs) 870 + svc_set_num_threads(struct svc_serv *serv, unsigned int min_threads, 871 + unsigned int nrservs) 897 872 { 898 873 unsigned int base = nrservs / serv->sv_nrpools; 899 874 unsigned int remain = nrservs % serv->sv_nrpools; 900 875 int i, err = 0; 901 876 902 877 for (i = 0; i < serv->sv_nrpools; ++i) { 878 + struct svc_pool *pool = &serv->sv_pools[i]; 903 879 int threads = base; 904 880 905 881 if (remain) { 906 882 ++threads; 907 883 --remain; 908 884 } 909 - err = svc_set_pool_threads(serv, &serv->sv_pools[i], threads); 885 + 886 + err = svc_set_pool_threads(serv, pool, min_threads, threads); 910 887 if (err) 911 888 break; 912 889 }