large pause when opening file descriptor which is power of 2

"Kernel.org Bugbot" <[email protected]> Wed, 26 Apr 2023 17:58:06 +0000 (UTC)
Newsgroups dev.linux.lists.bugs,org.kernel.vger.linux-fsdevel
Message-ID <[email protected]>
phemmer+kernel added an attachment on Kernel.org Bugzilla:

Created attachment 304186
issue demonstration code

When running a threaded program, and opening a file descriptor that is a power of 2 (starting at 64), the call takes a very long time to complete. Normally such a call takes less than 2us. However with this issue, I've seen the call take up to around 50ms. Additionally this only happens the first time, and not subsequent times that file descriptor is used. I'm guessing there might be some expansion of some internal data structures going on. But I cannot see why this process would take so long.

Attached is a simple program that can reproduce the issue. The following is example output:

...
FD=62 duration=2695
FD=63 duration=2726
FD=64 duration=12565293
FD=64 duration=3837 (second attempt)
FD=65 duration=1523
FD=66 duration=1533
...
FD=126 duration=1463
FD=127 duration=1402
FD=128 duration=24755063
FD=128 duration=3186 (second attempt)
FD=129 duration=1433
FD=130 duration=1413
...
FD=254 duration=1363
FD=255 duration=1493
FD=256 duration=7602777
FD=256 duration=1573 (second attempt)
FD=257 duration=1392
FD=258 duration=1363
...

I've reproduced the issue on systems running multiple different 4.19 kernels, and on a system running 6.2.8

File: fd_pause.c (text/x-csrc)
Size: 970.00 B
Link: https://bugzilla.kernel.org/attachment.cgi?id=304186
---
issue demonstration code

You can reply to this message to join the discussion.
-- 
Deet-doot-dot, I am a bot.
Kernel.org Bugzilla (peebz 0.1)