[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <6115bfac-658c-4e8c-859f-d4a1a5820dae@kernel.dk>
Date: Wed, 12 Mar 2025 10:07:21 -0600
From: Jens Axboe <axboe@...nel.dk>
To: Mateusz Guzik <mjguzik@...il.com>, brauner@...nel.org,
viro@...iv.linux.org.uk
Cc: jack@...e.cz, linux-kernel@...r.kernel.org,
linux-fsdevel@...r.kernel.org, io-uring@...r.kernel.org,
audit@...r.kernel.org
Subject: Re: [PATCH] fs: dodge an atomic in putname if ref == 1
On 3/11/25 12:18 PM, Mateusz Guzik wrote:
> diff --git a/fs/namei.c b/fs/namei.c
> index 06765d320e7e..add90981cfcd 100644
> --- a/fs/namei.c
> +++ b/fs/namei.c
> @@ -275,14 +275,19 @@ EXPORT_SYMBOL(getname_kernel);
>
> void putname(struct filename *name)
> {
> + int refcnt;
> +
> if (IS_ERR_OR_NULL(name))
> return;
>
> - if (WARN_ON_ONCE(!atomic_read(&name->refcnt)))
> - return;
> + refcnt = atomic_read(&name->refcnt);
> + if (refcnt != 1) {
> + if (WARN_ON_ONCE(!refcnt))
> + return;
>
> - if (!atomic_dec_and_test(&name->refcnt))
> - return;
> + if (!atomic_dec_and_test(&name->refcnt))
> + return;
> + }
Looks good to me, I use this trick with bitops too all the time, to
avoid a RMW when possible.
Reviewed-by: Jens Axboe <axboe@...nel.dk>
--
Jens Axboe
Powered by blists - more mailing lists