2024-03-25 13:16:50

by Kefeng Wang

[permalink] [raw]
Subject: [PATCH] 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 simplify code.

Signed-off-by: Kefeng Wang <[email protected]>
---
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)
--
2.41.0



2024-03-25 14:44:14

by Jeffrey Layton

[permalink] [raw]
Subject: Re: [PATCH] fs: nfsd: use group allocation/free of per-cpu counters API

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 <[email protected]>
> ---
> 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?

--
Jeff Layton <[email protected]>

2024-03-25 14:58:43

by Kefeng Wang

[permalink] [raw]
Subject: Re: [PATCH] fs: nfsd: use group allocation/free of per-cpu counters API



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 <[email protected]>
>> ---
>> 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.
>