linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Jeff Layton <jlayton@kernel.org>
To: Mateusz Guzik <mjguzik@gmail.com>, brauner@kernel.org
Cc: viro@zeniv.linux.org.uk, jack@suse.cz,
	linux-kernel@vger.kernel.org,  linux-fsdevel@vger.kernel.org,
	hughd@google.com, linux-ext4@vger.kernel.org,  tytso@mit.edu,
	linux-mm@kvack.org
Subject: Re: [PATCH v3 0/3] symlink length caching
Date: Thu, 21 Nov 2024 09:16:19 -0500	[thread overview]
Message-ID: <bdc38296b22456be4dabde2efbf9bf144c544aa4.camel@kernel.org> (raw)
In-Reply-To: <20241120112037.822078-1-mjguzik@gmail.com>

On Wed, 2024-11-20 at 12:20 +0100, Mateusz Guzik wrote:
> quote:
>     When utilized it dodges strlen() in vfs_readlink(), giving about 1.5%
>     speed up when issuing readlink on /initrd.img on ext4.
> 
> The size is stored in a union with i_devices, which is never looked at
> unless the inode is for a device.
> 
> Benchmark code at the bottom.
> 
> ext4 and tmpfs are patched, other filesystems can also get there with
> some more work.
> 
> Arguably the current get_link API should be patched to let the fs return
> the size, but that's not a churn I'm interested into diving in.
> 
> On my v1 Jan remarked 1.5% is not a particularly high win questioning
> whether doing this makes sense. I noted the value is only this small
> because of other slowdowns.
> 
> To elaborate here are highlights while benching on Sapphire Rapids:
> 1. putname using atomics (over 3.5% on my profile)
> 
> sounds like Al has plans to do something here(?), I'm not touching it if
> it can be helped. the atomic definitely does not have to be there in the
> common case.
> 
> 2. kmem_cache_alloc_noprof/kmem_cache_free (over 7% combined) 
> 
> They are both dog slow due to cmpxchg16b. A patchset was posted which
> adds a different allocation/free fast path which should whack majority
> of the problem, see: https://lore.kernel.org/linux-mm/20241112-slub-percpu-caches-v1-0-ddc0bdc27e05@suse.cz/
> 
> If this lands I'll definitely try to make the pathname allocs use it,
> should drop about 5-6 percentage points on this sucker.
> 
> 3. __legitimize_mnt issues a full fence (again over 3%)
> 
> As far as avoiding the fence is concerned waiting on rcu grace period on
> unmount should do the trick. However, I found there is a bunch
> complexity there to sort out before doing this will be feasible (notably
> there are multiple mounts freed in one go, this needs to be batched).
> There may be other issues which I missed and which make this not worth
> it, but the fence is definitely avoidable in principle and I would be
> surprised if there was no way to sensibly get there. No ETA, for now I'm
> just pointing this out.
> 
> There is also the idea to speculatively elide lockref, but when I tried
> that last time I ran into significant LSM-related trouble.
> 
> All that aside there is also quite a bit of branching and func calling
> which does not need to be there (example: make vfsuid/vfsgid, could be
> combined into one routine etc.).
> 
> Ultimately there is single-threaded perf left on the table in various
> spots.
> 
> v3:
> - use a union instead of a dedicated field, used up with i_devices
> 
> v2:
> - add a dedicated field, flag and a helper instead of using i_size
> https://lore.kernel.org/linux-fsdevel/20241119094555.660666-1-mjguzik@gmail.com/
> 
> v1 can be found here:
> https://lore.kernel.org/linux-fsdevel/20241118085357.494178-1-mjguzik@gmail.com/
> 
> benchmark:
> plug into will-it-scale into tests/readlink1.c:
> 
> #include <stdlib.h>
> #include <unistd.h>
> #include <sys/types.h>
> #include <sys/stat.h>
> #include <fcntl.h>
> #include <assert.h>
> #include <string.h>
> 
> char *testcase_description = "readlink /initrd.img";
> 
> void testcase(unsigned long long *iterations, unsigned long nr)
> {
>         char *tmplink = "/initrd.img";
>         char buf[1024];
> 
>         while (1) {
>                 int error = readlink(tmplink, buf, sizeof(buf));
>                 assert(error > 0);
> 
>                 (*iterations)++;
>         }
> }
> 
> Mateusz Guzik (3):
>   vfs: support caching symlink lengths in inodes
>   ext4: use inode_set_cached_link()
>   tmpfs: use inode_set_cached_link()
> 
>  fs/ext4/inode.c                |  3 ++-
>  fs/ext4/namei.c                |  4 +++-
>  fs/namei.c                     | 34 +++++++++++++++++++---------------
>  fs/proc/namespaces.c           |  2 +-
>  include/linux/fs.h             | 15 +++++++++++++--
>  mm/shmem.c                     |  6 ++++--
>  security/apparmor/apparmorfs.c |  2 +-
>  7 files changed, 43 insertions(+), 23 deletions(-)
> 

Nice work, Mateusz!

Reviewed-by: Jeff Layton <jlayton@kernel.org>


      parent reply	other threads:[~2024-11-21 14:16 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-11-20 11:20 Mateusz Guzik
2024-11-20 11:20 ` [PATCH v3 1/3] vfs: support caching symlink lengths in inodes Mateusz Guzik
2024-11-21 10:12   ` Christian Brauner
2024-11-21 13:56     ` Mateusz Guzik
2024-11-22  1:56     ` Dave Chinner
2024-11-20 11:20 ` [PATCH v3 2/3] ext4: use inode_set_cached_link() Mateusz Guzik
2024-11-21 11:58   ` Jan Kara
2024-11-20 11:20 ` [PATCH v3 3/3] tmpfs: " Mateusz Guzik
2024-11-21 11:59   ` Jan Kara
2024-11-21 12:34 ` [PATCH v3 0/3] symlink length caching Christian Brauner
2024-11-21 14:16 ` Jeff Layton [this message]

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=bdc38296b22456be4dabde2efbf9bf144c544aa4.camel@kernel.org \
    --to=jlayton@kernel.org \
    --cc=brauner@kernel.org \
    --cc=hughd@google.com \
    --cc=jack@suse.cz \
    --cc=linux-ext4@vger.kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mjguzik@gmail.com \
    --cc=tytso@mit.edu \
    --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