Skip to content

Commit 7d12cce

Browse files
Kefeng Wangchucklever
authored andcommitted
fs: nfsd: use group allocation/free of per-cpu counters API
Use group allocation/free of per-cpu counters api to accelerate nfsd percpu_counters init/destroy(), and also squash the nfsd_percpu_counters_init/reset/destroy() and nfsd_counters_init/destroy() into callers to simplify code. Signed-off-by: Kefeng Wang <[email protected]> Reviewed-by: Jeff Layton <[email protected]> Signed-off-by: Chuck Lever <[email protected]>
1 parent 33a1e6e commit 7d12cce

File tree

4 files changed

+13
-55
lines changed

4 files changed

+13
-55
lines changed

fs/nfsd/export.c

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -334,21 +334,25 @@ static void nfsd4_fslocs_free(struct nfsd4_fs_locations *fsloc)
334334
static int export_stats_init(struct export_stats *stats)
335335
{
336336
stats->start_time = ktime_get_seconds();
337-
return nfsd_percpu_counters_init(stats->counter, EXP_STATS_COUNTERS_NUM);
337+
return percpu_counter_init_many(stats->counter, 0, GFP_KERNEL,
338+
EXP_STATS_COUNTERS_NUM);
338339
}
339340

340341
static void export_stats_reset(struct export_stats *stats)
341342
{
342-
if (stats)
343-
nfsd_percpu_counters_reset(stats->counter,
344-
EXP_STATS_COUNTERS_NUM);
343+
if (stats) {
344+
int i;
345+
346+
for (i = 0; i < EXP_STATS_COUNTERS_NUM; i++)
347+
percpu_counter_set(&stats->counter[i], 0);
348+
}
345349
}
346350

347351
static void export_stats_destroy(struct export_stats *stats)
348352
{
349353
if (stats)
350-
nfsd_percpu_counters_destroy(stats->counter,
351-
EXP_STATS_COUNTERS_NUM);
354+
percpu_counter_destroy_many(stats->counter,
355+
EXP_STATS_COUNTERS_NUM);
352356
}
353357

354358
static void svc_export_put(struct kref *ref)

fs/nfsd/nfsctl.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1672,7 +1672,8 @@ static __net_init int nfsd_net_init(struct net *net)
16721672
retval = nfsd_idmap_init(net);
16731673
if (retval)
16741674
goto out_idmap_error;
1675-
retval = nfsd_stat_counters_init(nn);
1675+
retval = percpu_counter_init_many(nn->counter, 0, GFP_KERNEL,
1676+
NFSD_STATS_COUNTERS_NUM);
16761677
if (retval)
16771678
goto out_repcache_error;
16781679
memset(&nn->nfsd_svcstats, 0, sizeof(nn->nfsd_svcstats));
@@ -1704,7 +1705,7 @@ static __net_exit void nfsd_net_exit(struct net *net)
17041705
struct nfsd_net *nn = net_generic(net, nfsd_net_id);
17051706

17061707
nfsd_proc_stat_shutdown(net);
1707-
nfsd_stat_counters_destroy(nn);
1708+
percpu_counter_destroy_many(nn->counter, NFSD_STATS_COUNTERS_NUM);
17081709
nfsd_idmap_shutdown(net);
17091710
nfsd_export_shutdown(net);
17101711
nfsd_netns_free_versions(nn);

fs/nfsd/stats.c

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -73,48 +73,6 @@ static int nfsd_show(struct seq_file *seq, void *v)
7373

7474
DEFINE_PROC_SHOW_ATTRIBUTE(nfsd);
7575

76-
int nfsd_percpu_counters_init(struct percpu_counter *counters, int num)
77-
{
78-
int i, err = 0;
79-
80-
for (i = 0; !err && i < num; i++)
81-
err = percpu_counter_init(&counters[i], 0, GFP_KERNEL);
82-
83-
if (!err)
84-
return 0;
85-
86-
for (; i > 0; i--)
87-
percpu_counter_destroy(&counters[i-1]);
88-
89-
return err;
90-
}
91-
92-
void nfsd_percpu_counters_reset(struct percpu_counter counters[], int num)
93-
{
94-
int i;
95-
96-
for (i = 0; i < num; i++)
97-
percpu_counter_set(&counters[i], 0);
98-
}
99-
100-
void nfsd_percpu_counters_destroy(struct percpu_counter counters[], int num)
101-
{
102-
int i;
103-
104-
for (i = 0; i < num; i++)
105-
percpu_counter_destroy(&counters[i]);
106-
}
107-
108-
int nfsd_stat_counters_init(struct nfsd_net *nn)
109-
{
110-
return nfsd_percpu_counters_init(nn->counter, NFSD_STATS_COUNTERS_NUM);
111-
}
112-
113-
void nfsd_stat_counters_destroy(struct nfsd_net *nn)
114-
{
115-
nfsd_percpu_counters_destroy(nn->counter, NFSD_STATS_COUNTERS_NUM);
116-
}
117-
11876
void nfsd_proc_stat_init(struct net *net)
11977
{
12078
struct nfsd_net *nn = net_generic(net, nfsd_net_id);

fs/nfsd/stats.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,6 @@
1010
#include <uapi/linux/nfsd/stats.h>
1111
#include <linux/percpu_counter.h>
1212

13-
int nfsd_percpu_counters_init(struct percpu_counter *counters, int num);
14-
void nfsd_percpu_counters_reset(struct percpu_counter *counters, int num);
15-
void nfsd_percpu_counters_destroy(struct percpu_counter *counters, int num);
16-
int nfsd_stat_counters_init(struct nfsd_net *nn);
17-
void nfsd_stat_counters_destroy(struct nfsd_net *nn);
1813
void nfsd_proc_stat_init(struct net *net);
1914
void nfsd_proc_stat_shutdown(struct net *net);
2015

0 commit comments

Comments
 (0)