* [PATCH] nfsd: Simplify the allocation of slab caches in nfsd_drc_slab_create
@ 2024-02-01 8:19 Kunwu Chan
2024-02-02 14:13 ` Benjamin Coddington
0 siblings, 1 reply; 5+ messages in thread
From: Kunwu Chan @ 2024-02-01 8:19 UTC (permalink / raw)
To: chuck.lever, jlayton, neilb, kolga, Dai.Ngo, tom
Cc: linux-nfs, linux-kernel, Kunwu Chan
Use the new KMEM_CACHE() macro instead of direct kmem_cache_create
to simplify the creation of SLAB caches.
Make the code cleaner and more readable.
Signed-off-by: Kunwu Chan <chentao@kylinos.cn>
---
fs/nfsd/nfscache.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/fs/nfsd/nfscache.c b/fs/nfsd/nfscache.c
index 5c1a4a0aa605..64ce0cc22197 100644
--- a/fs/nfsd/nfscache.c
+++ b/fs/nfsd/nfscache.c
@@ -166,8 +166,7 @@ nfsd_reply_cache_free(struct nfsd_drc_bucket *b, struct nfsd_cacherep *rp,
int nfsd_drc_slab_create(void)
{
- drc_slab = kmem_cache_create("nfsd_drc",
- sizeof(struct nfsd_cacherep), 0, 0, NULL);
+ drc_slab = KMEM_CACHE(nfsd_cacherep, 0);
return drc_slab ? 0: -ENOMEM;
}
--
2.39.2
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] nfsd: Simplify the allocation of slab caches in nfsd_drc_slab_create
2024-02-01 8:19 [PATCH] nfsd: Simplify the allocation of slab caches in nfsd_drc_slab_create Kunwu Chan
@ 2024-02-02 14:13 ` Benjamin Coddington
2024-02-02 14:24 ` Jeff Layton
2024-02-03 0:35 ` NeilBrown
0 siblings, 2 replies; 5+ messages in thread
From: Benjamin Coddington @ 2024-02-02 14:13 UTC (permalink / raw)
To: Kunwu Chan
Cc: chuck.lever, jlayton, neilb, kolga, Dai.Ngo, tom, linux-nfs,
linux-kernel
On 1 Feb 2024, at 3:19, Kunwu Chan wrote:
> Use the new KMEM_CACHE() macro instead of direct kmem_cache_create
> to simplify the creation of SLAB caches.
> Make the code cleaner and more readable.
>
> Signed-off-by: Kunwu Chan <chentao@kylinos.cn>
> ---
> fs/nfsd/nfscache.c | 3 +--
> 1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/fs/nfsd/nfscache.c b/fs/nfsd/nfscache.c
> index 5c1a4a0aa605..64ce0cc22197 100644
> --- a/fs/nfsd/nfscache.c
> +++ b/fs/nfsd/nfscache.c
> @@ -166,8 +166,7 @@ nfsd_reply_cache_free(struct nfsd_drc_bucket *b, struct nfsd_cacherep *rp,
>
> int nfsd_drc_slab_create(void)
> {
> - drc_slab = kmem_cache_create("nfsd_drc",
> - sizeof(struct nfsd_cacherep), 0, 0, NULL);
> + drc_slab = KMEM_CACHE(nfsd_cacherep, 0);
> return drc_slab ? 0: -ENOMEM;
> }
>
> --
> 2.39.2
I don't agree that the code is cleaner or more readable like this. I really
dislike having to parse through the extra "simplification" to see what's
actually being called and sent.
Just my .02 worth.
Ben
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] nfsd: Simplify the allocation of slab caches in nfsd_drc_slab_create
2024-02-02 14:13 ` Benjamin Coddington
@ 2024-02-02 14:24 ` Jeff Layton
2024-02-04 3:19 ` Kunwu Chan
2024-02-03 0:35 ` NeilBrown
1 sibling, 1 reply; 5+ messages in thread
From: Jeff Layton @ 2024-02-02 14:24 UTC (permalink / raw)
To: Benjamin Coddington, Kunwu Chan
Cc: chuck.lever, neilb, kolga, Dai.Ngo, tom, linux-nfs, linux-kernel
On Fri, 2024-02-02 at 09:13 -0500, Benjamin Coddington wrote:
> On 1 Feb 2024, at 3:19, Kunwu Chan wrote:
>
> > Use the new KMEM_CACHE() macro instead of direct kmem_cache_create
> > to simplify the creation of SLAB caches.
> > Make the code cleaner and more readable.
> >
> > Signed-off-by: Kunwu Chan <chentao@kylinos.cn>
> > ---
> > fs/nfsd/nfscache.c | 3 +--
> > 1 file changed, 1 insertion(+), 2 deletions(-)
> >
> > diff --git a/fs/nfsd/nfscache.c b/fs/nfsd/nfscache.c
> > index 5c1a4a0aa605..64ce0cc22197 100644
> > --- a/fs/nfsd/nfscache.c
> > +++ b/fs/nfsd/nfscache.c
> > @@ -166,8 +166,7 @@ nfsd_reply_cache_free(struct nfsd_drc_bucket *b, struct nfsd_cacherep *rp,
> >
> > int nfsd_drc_slab_create(void)
> > {
> > - drc_slab = kmem_cache_create("nfsd_drc",
> > - sizeof(struct nfsd_cacherep), 0, 0, NULL);
> > + drc_slab = KMEM_CACHE(nfsd_cacherep, 0);
> > return drc_slab ? 0: -ENOMEM;
> > }
> >
> > --
> > 2.39.2
>
> I don't agree that the code is cleaner or more readable like this. I really
> dislike having to parse through the extra "simplification" to see what's
> actually being called and sent.
>
> Just my .02 worth.
>
> Ben
>
This will also result in a behavioral change. The "nfsd_drc" string is
lost with the above macro and (I think) the new name will be
"nfsd_cacherep". I'm not necessarily opposed to that, as I don't think
anything depends on the old name, but it should at least be noted in the
changelog.
--
Jeff Layton <jlayton@kernel.org>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] nfsd: Simplify the allocation of slab caches in nfsd_drc_slab_create
2024-02-02 14:13 ` Benjamin Coddington
2024-02-02 14:24 ` Jeff Layton
@ 2024-02-03 0:35 ` NeilBrown
1 sibling, 0 replies; 5+ messages in thread
From: NeilBrown @ 2024-02-03 0:35 UTC (permalink / raw)
To: Benjamin Coddington
Cc: Kunwu Chan, chuck.lever, jlayton, kolga, Dai.Ngo, tom, linux-nfs,
linux-kernel
On Sat, 03 Feb 2024, Benjamin Coddington wrote:
> On 1 Feb 2024, at 3:19, Kunwu Chan wrote:
>
> > Use the new KMEM_CACHE() macro instead of direct kmem_cache_create
> > to simplify the creation of SLAB caches.
> > Make the code cleaner and more readable.
> >
> > Signed-off-by: Kunwu Chan <chentao@kylinos.cn>
> > ---
> > fs/nfsd/nfscache.c | 3 +--
> > 1 file changed, 1 insertion(+), 2 deletions(-)
> >
> > diff --git a/fs/nfsd/nfscache.c b/fs/nfsd/nfscache.c
> > index 5c1a4a0aa605..64ce0cc22197 100644
> > --- a/fs/nfsd/nfscache.c
> > +++ b/fs/nfsd/nfscache.c
> > @@ -166,8 +166,7 @@ nfsd_reply_cache_free(struct nfsd_drc_bucket *b, struct nfsd_cacherep *rp,
> >
> > int nfsd_drc_slab_create(void)
> > {
> > - drc_slab = kmem_cache_create("nfsd_drc",
> > - sizeof(struct nfsd_cacherep), 0, 0, NULL);
> > + drc_slab = KMEM_CACHE(nfsd_cacherep, 0);
> > return drc_slab ? 0: -ENOMEM;
> > }
> >
> > --
> > 2.39.2
>
> I don't agree that the code is cleaner or more readable like this. I really
> dislike having to parse through the extra "simplification" to see what's
> actually being called and sent.
>
> Just my .02 worth.
>
In general I agree that wrappers like this can hinder as much as they
help - if not more.
In this particular case it doesn't seem to bother me. This is probably
because it is only used in initialisation code and I don't look at that
nearly as much as code that uses the initialised things.
Initialisation/cleanup code often has a lot of boilerplate which can
make it look messy. Reducing that, which I think this patch helps with,
can be a good thing.
So I agree that we should be cautious about using (or creating) new
wrapper macros, but in this case I am mildly in favour.
Thanks,
NeilBrown
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] nfsd: Simplify the allocation of slab caches in nfsd_drc_slab_create
2024-02-02 14:24 ` Jeff Layton
@ 2024-02-04 3:19 ` Kunwu Chan
0 siblings, 0 replies; 5+ messages in thread
From: Kunwu Chan @ 2024-02-04 3:19 UTC (permalink / raw)
To: Jeff Layton, Benjamin Coddington
Cc: chuck.lever, neilb, kolga, Dai.Ngo, tom, linux-nfs, linux-kernel
Thank you to all the guys who responded to my emails.
On 2024/2/2 22:24, Jeff Layton wrote:
> On Fri, 2024-02-02 at 09:13 -0500, Benjamin Coddington wrote:
>> On 1 Feb 2024, at 3:19, Kunwu Chan wrote:
>>
>>> Use the new KMEM_CACHE() macro instead of direct kmem_cache_create
>>> to simplify the creation of SLAB caches.
>>> Make the code cleaner and more readable.
>>>
>>> Signed-off-by: Kunwu Chan <chentao@kylinos.cn>
>>> ---
>>> fs/nfsd/nfscache.c | 3 +--
>>> 1 file changed, 1 insertion(+), 2 deletions(-)
>>>
>>> diff --git a/fs/nfsd/nfscache.c b/fs/nfsd/nfscache.c
>>> index 5c1a4a0aa605..64ce0cc22197 100644
>>> --- a/fs/nfsd/nfscache.c
>>> +++ b/fs/nfsd/nfscache.c
>>> @@ -166,8 +166,7 @@ nfsd_reply_cache_free(struct nfsd_drc_bucket *b, struct nfsd_cacherep *rp,
>>>
>>> int nfsd_drc_slab_create(void)
>>> {
>>> - drc_slab = kmem_cache_create("nfsd_drc",
>>> - sizeof(struct nfsd_cacherep), 0, 0, NULL);
>>> + drc_slab = KMEM_CACHE(nfsd_cacherep, 0);
>>> return drc_slab ? 0: -ENOMEM;
>>> }
>>>
>>> --
>>> 2.39.2
>>
>> I don't agree that the code is cleaner or more readable like this. I really
>> dislike having to parse through the extra "simplification" to see what's
>> actually being called and sent.
>>
>> Just my .02 worth.
>>
>> Ben
>>
>
Everyone has a different opinion. From newcomers like me, a simple code
is more important than checking all the args of a call function to
understand what it does.
Too many default arguments can cost us a lot of time that could be spent
understanding the main logic of the module code, rather than wasting it
on a single line of calls.
> This will also result in a behavioral change. The "nfsd_drc" string is
> lost with the above macro and (I think) the new name will be
> "nfsd_cacherep". I'm not necessarily opposed to that, as I don't think
> anything depends on the old name, but it should at least be noted in the
> changelog.
Thanks i'll update my v2 patch with a new commit msg to show the name
change.
>
--
Thanks,
Kunwu
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2024-02-04 3:19 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-02-01 8:19 [PATCH] nfsd: Simplify the allocation of slab caches in nfsd_drc_slab_create Kunwu Chan
2024-02-02 14:13 ` Benjamin Coddington
2024-02-02 14:24 ` Jeff Layton
2024-02-04 3:19 ` Kunwu Chan
2024-02-03 0:35 ` NeilBrown
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox