Skip to content

Commit d8316b8

Browse files
jtlaytonchucklever
authored andcommitted
nfsd: add controls to set the minimum number of threads per pool
Add a new "min_threads" variable to the nfsd_net, along with the corresponding netlink interface, to set that value from userland. Pass that value to svc_set_pool_threads() and svc_set_num_threads(). Signed-off-by: Jeff Layton <jlayton@kernel.org> Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
1 parent 1c87a0c commit d8316b8

7 files changed

Lines changed: 42 additions & 4 deletions

File tree

Documentation/netlink/specs/nfsd.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@ attribute-sets:
7878
-
7979
name: scope
8080
type: string
81+
-
82+
name: min-threads
83+
type: u32
8184
-
8285
name: version
8386
attributes:
@@ -159,6 +162,7 @@ operations:
159162
- gracetime
160163
- leasetime
161164
- scope
165+
- min-threads
162166
-
163167
name: threads-get
164168
doc: get the number of running threads
@@ -170,6 +174,7 @@ operations:
170174
- gracetime
171175
- leasetime
172176
- scope
177+
- min-threads
173178
-
174179
name: version-set
175180
doc: set nfs enabled versions

fs/nfsd/netlink.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,12 @@ const struct nla_policy nfsd_version_nl_policy[NFSD_A_VERSION_ENABLED + 1] = {
2424
};
2525

2626
/* NFSD_CMD_THREADS_SET - do */
27-
static const struct nla_policy nfsd_threads_set_nl_policy[NFSD_A_SERVER_SCOPE + 1] = {
27+
static const struct nla_policy nfsd_threads_set_nl_policy[NFSD_A_SERVER_MIN_THREADS + 1] = {
2828
[NFSD_A_SERVER_THREADS] = { .type = NLA_U32, },
2929
[NFSD_A_SERVER_GRACETIME] = { .type = NLA_U32, },
3030
[NFSD_A_SERVER_LEASETIME] = { .type = NLA_U32, },
3131
[NFSD_A_SERVER_SCOPE] = { .type = NLA_NUL_STRING, },
32+
[NFSD_A_SERVER_MIN_THREADS] = { .type = NLA_U32, },
3233
};
3334

3435
/* NFSD_CMD_VERSION_SET - do */
@@ -57,7 +58,7 @@ static const struct genl_split_ops nfsd_nl_ops[] = {
5758
.cmd = NFSD_CMD_THREADS_SET,
5859
.doit = nfsd_nl_threads_set_doit,
5960
.policy = nfsd_threads_set_nl_policy,
60-
.maxattr = NFSD_A_SERVER_SCOPE,
61+
.maxattr = NFSD_A_SERVER_MIN_THREADS,
6162
.flags = GENL_ADMIN_PERM | GENL_CMD_CAP_DO,
6263
},
6364
{

fs/nfsd/netns.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,12 @@ struct nfsd_net {
129129
seqlock_t writeverf_lock;
130130
unsigned char writeverf[8];
131131

132+
/*
133+
* Minimum number of threads to run per pool. If 0 then the
134+
* min == max requested number of threads.
135+
*/
136+
unsigned int min_threads;
137+
132138
u32 clientid_base;
133139
u32 clientid_counter;
134140
u32 clverifier_counter;

fs/nfsd/nfsctl.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1642,6 +1642,10 @@ int nfsd_nl_threads_set_doit(struct sk_buff *skb, struct genl_info *info)
16421642
scope = nla_data(attr);
16431643
}
16441644

1645+
attr = info->attrs[NFSD_A_SERVER_MIN_THREADS];
1646+
if (attr)
1647+
nn->min_threads = nla_get_u32(attr);
1648+
16451649
ret = nfsd_svc(nrpools, nthreads, net, get_current_cred(), scope);
16461650
if (ret > 0)
16471651
ret = 0;
@@ -1681,6 +1685,8 @@ int nfsd_nl_threads_get_doit(struct sk_buff *skb, struct genl_info *info)
16811685
nn->nfsd4_grace) ||
16821686
nla_put_u32(skb, NFSD_A_SERVER_LEASETIME,
16831687
nn->nfsd4_lease) ||
1688+
nla_put_u32(skb, NFSD_A_SERVER_MIN_THREADS,
1689+
nn->min_threads) ||
16841690
nla_put_string(skb, NFSD_A_SERVER_SCOPE,
16851691
nn->nfsd_name);
16861692
if (err)

fs/nfsd/nfssvc.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -690,7 +690,7 @@ int nfsd_set_nrthreads(int n, int *nthreads, struct net *net)
690690

691691
/* Special case: When n == 1, distribute threads equally among pools. */
692692
if (n == 1)
693-
return svc_set_num_threads(nn->nfsd_serv, 0, nthreads[0]);
693+
return svc_set_num_threads(nn->nfsd_serv, nn->min_threads, nthreads[0]);
694694

695695
if (n > nn->nfsd_serv->sv_nrpools)
696696
n = nn->nfsd_serv->sv_nrpools;
@@ -718,7 +718,7 @@ int nfsd_set_nrthreads(int n, int *nthreads, struct net *net)
718718
for (i = 0; i < n; i++) {
719719
err = svc_set_pool_threads(nn->nfsd_serv,
720720
&nn->nfsd_serv->sv_pools[i],
721-
0, nthreads[i]);
721+
nn->min_threads, nthreads[i]);
722722
if (err)
723723
goto out;
724724
}

fs/nfsd/trace.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2164,6 +2164,25 @@ TRACE_EVENT(nfsd_ctl_maxblksize,
21642164
)
21652165
);
21662166

2167+
TRACE_EVENT(nfsd_ctl_minthreads,
2168+
TP_PROTO(
2169+
const struct net *net,
2170+
int minthreads
2171+
),
2172+
TP_ARGS(net, minthreads),
2173+
TP_STRUCT__entry(
2174+
__field(unsigned int, netns_ino)
2175+
__field(int, minthreads)
2176+
),
2177+
TP_fast_assign(
2178+
__entry->netns_ino = net->ns.inum;
2179+
__entry->minthreads = minthreads
2180+
),
2181+
TP_printk("minthreads=%d",
2182+
__entry->minthreads
2183+
)
2184+
);
2185+
21672186
TRACE_EVENT(nfsd_ctl_time,
21682187
TP_PROTO(
21692188
const struct net *net,

include/uapi/linux/nfsd_netlink.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ enum {
3535
NFSD_A_SERVER_GRACETIME,
3636
NFSD_A_SERVER_LEASETIME,
3737
NFSD_A_SERVER_SCOPE,
38+
NFSD_A_SERVER_MIN_THREADS,
3839

3940
__NFSD_A_SERVER_MAX,
4041
NFSD_A_SERVER_MAX = (__NFSD_A_SERVER_MAX - 1)

0 commit comments

Comments
 (0)