From: Waiman Long <longman@redhat.com>
To: Paul Moore <paul@paul-moore.com>
Cc: Eric Paris <eparis@redhat.com>,
Christian Brauner <brauner@kernel.org>,
Al Viro <viro@zeniv.linux.org.uk>, Jan Kara <jack@suse.cz>,
linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org,
audit@vger.kernel.org, Richard Guy Briggs <rgb@redhat.com>,
Ricardo Robaina <rrobaina@redhat.com>
Subject: Re: [RESEND PATCH v3 1/2] fs: Add a pool of extra fs->pwd references to fs_struct
Date: Sat, 28 Feb 2026 13:42:14 -0500 [thread overview]
Message-ID: <e4b0a196-ec20-48ec-adc1-2d995e27a0ff@redhat.com> (raw)
In-Reply-To: <CAHC9VhTA+b1sdg88o1wXgMUcPDpxd_nQYc-aPEcBuzUuNVz+ag@mail.gmail.com>
On 2/19/26 5:20 PM, Paul Moore wrote:
> On Thu, Feb 12, 2026 at 1:09 PM Waiman Long <longman@redhat.com> wrote:
>> When the audit subsystem is enabled, it can do a lot of get_fs_pwd()
>> calls to get references to fs->pwd and then releasing those references
>> back with path_put() later. That may cause a lot of spinlock contention
>> on a single pwd's dentry lock because of the constant changes to the
>> reference count when there are many processes on the same working
>> directory actively doing open/close system calls. This can cause
>> noticeable performance regresssion when compared with the case where
>> the audit subsystem is turned off especially on systems with a lot of
>> CPUs which is becoming more common these days.
>>
>> A simple and elegant solution to avoid this kind of performance
>> regression is to add a common pool of extra fs->pwd references inside
>> the fs_struct. When a caller needs a pwd reference, it can borrow one
>> from pool, if available, to avoid an explicit path_get(). When it is
>> time to release the reference, it can put it back into the common pool
>> if fs->pwd isn't changed before without doing a path_put(). We still
>> need to acquire the fs's spinlock, but fs_struct is more distributed
>> and it is less common to have many tasks sharing a single fs_struct.
>>
>> A new set of get_fs_pwd_pool/put_fs_pwd_pool() APIs are introduced
>> with this patch to enable other subsystems to acquire and release
>> a pwd reference from the common pool without doing unnecessary
>> path_get/path_put().
>>
>> Besides fs/fs_struct.c, the copy_mnt_ns() function of fs/namespace.c is
>> also modified to properly handle the extra pwd references, if available.
>>
>> Signed-off-by: Waiman Long <longman@redhat.com>
>> ---
>> fs/fs_struct.c | 26 +++++++++++++++++++++-----
>> fs/namespace.c | 8 ++++++++
>> include/linux/fs_struct.h | 30 +++++++++++++++++++++++++++++-
>> 3 files changed, 58 insertions(+), 6 deletions(-)
> ...
>
>> diff --git a/fs/namespace.c b/fs/namespace.c
>> index c58674a20cad..a2323ba84d76 100644
>> --- a/fs/namespace.c
>> +++ b/fs/namespace.c
>> @@ -40,6 +41,33 @@ static inline void get_fs_pwd(struct fs_struct *fs, struct path *pwd)
>> read_sequnlock_excl(&fs->seq);
>> }
>>
>> +/* Acquire a pwd reference from the pwd_refs pool, if available */
>> +static inline void get_fs_pwd_pool(struct fs_struct *fs, struct path *pwd)
>> +{
>> + read_seqlock_excl(&fs->seq);
>> + *pwd = fs->pwd;
>> + if (fs->pwd_refs)
>> + fs->pwd_refs--;
>> + else
>> + path_get(pwd);
>> + read_sequnlock_excl(&fs->seq);
>> +}
>> +
>> +/* Release a pwd reference back to the pwd_refs pool, if appropriate */
>> +static inline void put_fs_pwd_pool(struct fs_struct *fs, struct path *pwd)
>> +{
>> + bool put = false;
>> +
>> + read_seqlock_excl(&fs->seq);
>> + if ((fs->pwd.dentry == pwd->dentry) && (fs->pwd.mnt == pwd->mnt))
>> + fs->pwd_refs++;
>> + else
>> + put = true;
>> + read_sequnlock_excl(&fs->seq);
>> + if (put)
>> + path_put(pwd);
>> +}
> This is a nitpick, and perhaps I'm missing something, but I think you
> could skip the local 'put' boolean by setting 'pwd' to NULL in the
> pool case, e.g.
>
> static inline void put_fs_pwd_pool(fs, pwd)
> {
> read_seqlock_excl(&fs)
> if (fs == pwd) {
> fs->pwd_refs++
> pwd = NULL
> }
> read_sequnlock_excl(&fs)
> if (pwd)
> path_put(pwd)
> }
Thanks for the suggestion. It does make the function simpler. I have
included that change in my v4 patch.
Al & Christian, are you OK with taking these patches for the next v7.1
release or do you have other suggested changes you would like to see?
Thanks,
Longman
next prev parent reply other threads:[~2026-02-28 18:42 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-02-06 20:19 [PATCH v3 0/2] fs, audit: Avoid excessive dput/dget in audit_context setup and reset paths Waiman Long
2026-02-06 20:19 ` [PATCH v3 1/2] fs: Add a pool of extra fs->pwd references to fs_struct Waiman Long
2026-02-27 16:37 ` Richard Guy Briggs
2026-02-06 20:19 ` [PATCH v3 2/2] audit: Use the new {get,put}_fs_pwd_pool() APIs to get/put pwd references Waiman Long
2026-02-27 16:37 ` Richard Guy Briggs
2026-02-12 16:36 ` [PATCH v3 0/2] fs, audit: Avoid excessive dput/dget in audit_context setup and reset paths Ricardo Robaina
2026-02-12 18:08 ` [RESEND PATCH " Waiman Long
2026-02-12 18:08 ` [RESEND PATCH v3 1/2] fs: Add a pool of extra fs->pwd references to fs_struct Waiman Long
2026-02-19 22:20 ` Paul Moore
2026-02-28 18:42 ` Waiman Long [this message]
2026-02-12 18:08 ` [RESEND PATCH v3 2/2] audit: Use the new {get,put}_fs_pwd_pool() APIs to get/put pwd references Waiman Long
2026-02-19 22:14 ` Paul Moore
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=e4b0a196-ec20-48ec-adc1-2d995e27a0ff@redhat.com \
--to=longman@redhat.com \
--cc=audit@vger.kernel.org \
--cc=brauner@kernel.org \
--cc=eparis@redhat.com \
--cc=jack@suse.cz \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=paul@paul-moore.com \
--cc=rgb@redhat.com \
--cc=rrobaina@redhat.com \
--cc=viro@zeniv.linux.org.uk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox