[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <218ccf06e7104eb580023fb69c395d3e@AcuMS.aculab.com>
Date: Wed, 19 Jun 2024 10:36:47 +0000
From: David Laight <David.Laight@...LAB.COM>
To: 'Yu Ma' <yu.ma@...el.com>, "viro@...iv.linux.org.uk"
<viro@...iv.linux.org.uk>, "brauner@...nel.org" <brauner@...nel.org>,
"jack@...e.cz" <jack@...e.cz>
CC: "linux-fsdevel@...r.kernel.org" <linux-fsdevel@...r.kernel.org>,
"linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>,
"tim.c.chen@...ux.intel.com" <tim.c.chen@...ux.intel.com>,
"tim.c.chen@...el.com" <tim.c.chen@...el.com>, "pan.deng@...el.com"
<pan.deng@...el.com>, "tianyou.li@...el.com" <tianyou.li@...el.com>
Subject: RE: [PATCH 1/3] fs/file.c: add fast path in alloc_fd()
From: Yu Ma <yu.ma@...el.com>
> Sent: 14 June 2024 17:34
>
> There is available fd in the lower 64 bits of open_fds bitmap for most cases
> when we look for an available fd slot. Skip 2-levels searching via
> find_next_zero_bit() for this common fast path.
>
> Look directly for an open bit in the lower 64 bits of open_fds bitmap when a
> free slot is available there, as:
> (1) The fd allocation algorithm would always allocate fd from small to large.
> Lower bits in open_fds bitmap would be used much more frequently than higher
> bits.
> (2) After fdt is expanded (the bitmap size doubled for each time of expansion),
> it would never be shrunk. The search size increases but there are few open fds
> available here.
> (3) There is fast path inside of find_next_zero_bit() when size<=64 to speed up
> searching.
>
> With the fast path added in alloc_fd() through one-time bitmap searching,
> pts/blogbench-1.1.0 read is improved by 20% and write by 10% on Intel ICX 160
> cores configuration with v6.8-rc6.
>
> Reviewed-by: Tim Chen <tim.c.chen@...ux.intel.com>
> Signed-off-by: Yu Ma <yu.ma@...el.com>
> ---
> fs/file.c | 9 +++++++--
> 1 file changed, 7 insertions(+), 2 deletions(-)
>
> diff --git a/fs/file.c b/fs/file.c
> index 3b683b9101d8..e8d2f9ef7fd1 100644
> --- a/fs/file.c
> +++ b/fs/file.c
> @@ -510,8 +510,13 @@ static int alloc_fd(unsigned start, unsigned end, unsigned flags)
> if (fd < files->next_fd)
> fd = files->next_fd;
>
> - if (fd < fdt->max_fds)
> + if (fd < fdt->max_fds) {
> + if (~fdt->open_fds[0]) {
> + fd = find_next_zero_bit(fdt->open_fds, BITS_PER_LONG, fd);
> + goto success;
> + }
> fd = find_next_fd(fdt, fd);
> + }
Hmm...
How well does that work when the initial fd is > 64?
Since there is exactly one call to find_next_fd() and it is static and should
be inlined doesn't this optimisation belong inside find_next_fd().
Plausibly find_next_fd() just needs rewriting.
Or, possibly. even inside an inlinable copy of find_next_zero-bit()
(although a lot of callers won't be 'hot' enough for the inlined bloat
being worth while).
David
-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)
Powered by blists - more mailing lists