Message ID | 20240325041019.52998-1-wangkefeng.wang@huawei.com (mailing list archive) |
---|---|
State | New |
Headers | show |
Series | fs: nfsd: use group allocation/free of per-cpu counters API | expand |
On Mon, 2024-03-25 at 12:10 +0800, Kefeng Wang wrote: > Use group allocation/free of per-cpu counters api to accelerate > nfsd_percpu_counters_init/destroy() and simplify code. > > Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com> > --- > fs/nfsd/stats.c | 18 ++---------------- > 1 file changed, 2 insertions(+), 16 deletions(-) > > diff --git a/fs/nfsd/stats.c b/fs/nfsd/stats.c > index be52fb1e928e..c7f481d180f8 100644 > --- a/fs/nfsd/stats.c > +++ b/fs/nfsd/stats.c > @@ -75,18 +75,7 @@ DEFINE_PROC_SHOW_ATTRIBUTE(nfsd); > > int nfsd_percpu_counters_init(struct percpu_counter *counters, int num) > { > - int i, err = 0; > - > - for (i = 0; !err && i < num; i++) > - err = percpu_counter_init(&counters[i], 0, GFP_KERNEL); > - > - if (!err) > - return 0; > - > - for (; i > 0; i--) > - percpu_counter_destroy(&counters[i-1]); > - > - return err; > + return percpu_counter_init_many(counters, 0, GFP_KERNEL, num); > } > > void nfsd_percpu_counters_reset(struct percpu_counter counters[], int num) > @@ -99,10 +88,7 @@ void nfsd_percpu_counters_reset(struct percpu_counter counters[], int num) > > void nfsd_percpu_counters_destroy(struct percpu_counter counters[], int num) > { > - int i; > - > - for (i = 0; i < num; i++) > - percpu_counter_destroy(&counters[i]); > + percpu_counter_destroy_many(counters, num); > } > > int nfsd_stat_counters_init(struct nfsd_net *nn) I think it would be simpler to eliminate nfsd_percpu_counters_init/_destroy altogether and just replace them with percpu_counter_*_many calls. Is there any reason not to do that?
On 2024/3/25 18:52, Jeff Layton wrote: > On Mon, 2024-03-25 at 12:10 +0800, Kefeng Wang wrote: >> Use group allocation/free of per-cpu counters api to accelerate >> nfsd_percpu_counters_init/destroy() and simplify code. >> >> Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com> >> --- >> fs/nfsd/stats.c | 18 ++---------------- >> 1 file changed, 2 insertions(+), 16 deletions(-) >> >> diff --git a/fs/nfsd/stats.c b/fs/nfsd/stats.c >> index be52fb1e928e..c7f481d180f8 100644 >> --- a/fs/nfsd/stats.c >> +++ b/fs/nfsd/stats.c >> @@ -75,18 +75,7 @@ DEFINE_PROC_SHOW_ATTRIBUTE(nfsd); >> >> int nfsd_percpu_counters_init(struct percpu_counter *counters, int num) >> { >> - int i, err = 0; >> - >> - for (i = 0; !err && i < num; i++) >> - err = percpu_counter_init(&counters[i], 0, GFP_KERNEL); >> - >> - if (!err) >> - return 0; >> - >> - for (; i > 0; i--) >> - percpu_counter_destroy(&counters[i-1]); >> - >> - return err; >> + return percpu_counter_init_many(counters, 0, GFP_KERNEL, num); >> } >> >> void nfsd_percpu_counters_reset(struct percpu_counter counters[], int num) >> @@ -99,10 +88,7 @@ void nfsd_percpu_counters_reset(struct percpu_counter counters[], int num) >> >> void nfsd_percpu_counters_destroy(struct percpu_counter counters[], int num) >> { >> - int i; >> - >> - for (i = 0; i < num; i++) >> - percpu_counter_destroy(&counters[i]); >> + percpu_counter_destroy_many(counters, num); >> } >> >> int nfsd_stat_counters_init(struct nfsd_net *nn) > > I think it would be simpler to eliminate > nfsd_percpu_counters_init/_destroy altogether and just replace them with > percpu_counter_*_many calls. Is there any reason not to do that? OK, will squash init/destroy and reset into the callers. >
diff --git a/fs/nfsd/stats.c b/fs/nfsd/stats.c index be52fb1e928e..c7f481d180f8 100644 --- a/fs/nfsd/stats.c +++ b/fs/nfsd/stats.c @@ -75,18 +75,7 @@ DEFINE_PROC_SHOW_ATTRIBUTE(nfsd); int nfsd_percpu_counters_init(struct percpu_counter *counters, int num) { - int i, err = 0; - - for (i = 0; !err && i < num; i++) - err = percpu_counter_init(&counters[i], 0, GFP_KERNEL); - - if (!err) - return 0; - - for (; i > 0; i--) - percpu_counter_destroy(&counters[i-1]); - - return err; + return percpu_counter_init_many(counters, 0, GFP_KERNEL, num); } void nfsd_percpu_counters_reset(struct percpu_counter counters[], int num) @@ -99,10 +88,7 @@ void nfsd_percpu_counters_reset(struct percpu_counter counters[], int num) void nfsd_percpu_counters_destroy(struct percpu_counter counters[], int num) { - int i; - - for (i = 0; i < num; i++) - percpu_counter_destroy(&counters[i]); + percpu_counter_destroy_many(counters, num); } int nfsd_stat_counters_init(struct nfsd_net *nn)
Use group allocation/free of per-cpu counters api to accelerate nfsd_percpu_counters_init/destroy() and simplify code. Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com> --- fs/nfsd/stats.c | 18 ++---------------- 1 file changed, 2 insertions(+), 16 deletions(-)