From: Al Viro <viro@zeniv.linux.org.uk>
To: Abd-Alrhman Masalkhi <abd.masalkhi@gmail.com>
Cc: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org
Subject: Re: A field in files_struct has been used without initialization
Date: Sun, 9 Oct 2022 19:21:27 +0100 [thread overview]
Message-ID: <Y0MRJ8scLUZyeC4V@ZenIV> (raw)
In-Reply-To: <Y0B6+0MLZI/nv1aC@ZenIV>
On Fri, Oct 07, 2022 at 08:16:11PM +0100, Al Viro wrote:
> array of pointers (from first kvmalloc() in alloc_fdtable()): contains file pointers
> array of unsigned long (from the second kmvalloc() there): hosts the bitmaps
> fdtable (allocated in alloc_fdtable()):
> open_fds points to the beginning of bitmap-hosting array
> close_on_exec points to the middle third of the same array
> full_fd_bits points to the last third of the same array
Rereading that... a bit of clarification: the wording would seem to imply
that these 3 bitmaps are of equal size; they are not - the third one is
smaller.
If fdt->max_fds (table capacity) is equal to N, we have
* N struct file pointers in fdt->fd[]
* N bits in fdt->open_fds[] (i.e. N/BITS_PER_LONG unsigned long)
* N bits in fdt->close_on_exec[] (ditto)
* N/BITS_PER_LONG bits in fdt->full_fd_bits[]
The meaning of bitmaps:
bit k set in open_fds[] - descriptor k is in use
bit k set in close_on_exec[] - descriptor k is to be closed on exec()
bit k set in full_fd_bits[] - all descriptors covered by open_fds[k]
(i.e. BITS_PER_LONG of them,, starting from k * BITS_PER_LONG) are in use.
In other words, "don't even bother looking for clear bits in open_fds[k];
there won't be any".
->full_fd_bits[] is there purely as a way to speed finding unused descriptors,
along with ->next_fd. Some processes have an obscene amount of opened
descriptors and linear search through the mostly full bitmap can get painful.
E.g. 4 millions of descriptors would mean half megabyte worth of bitmap
(in ->open_fds[]). Cheaper to search through 8Kb of ->full_fd_bits, then
check one 64bit word in ->open_fds[]; kinder on the cache as well...
prev parent reply other threads:[~2022-10-09 18:21 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-10-06 10:44 A field in files_struct has been used without initialization Abd-Alrhman Masalkhi
2022-10-06 10:57 ` Abd-Alrhman Masalkhi
2022-10-07 19:16 ` Al Viro
2022-10-09 9:33 ` Abd-Alrhman Masalkhi
2022-10-09 18:21 ` Al Viro [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=Y0MRJ8scLUZyeC4V@ZenIV \
--to=viro@zeniv.linux.org.uk \
--cc=abd.masalkhi@gmail.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
/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;
as well as URLs for NNTP newsgroup(s).