From: "H.J. Lu" <hjl.tools@gmail.com>
To: alexandre.ferrieux@orange.com
Cc: libc-alpha@sourceware.org
Subject: Re: [PATCH] Fix #27777 - now use a doubly-linked list for _IO_list_all
Date: Tue, 30 Apr 2024 11:11:59 -0700 [thread overview]
Message-ID: <CAMe9rOo1JzrjCD7tD6RuU+wGmby_ZBMrUu1zmE9hKko=ymxUsw@mail.gmail.com> (raw)
In-Reply-To: <1086de0c-9e97-44aa-9822-a457973d0793@orange.com>
On Tue, Apr 30, 2024 at 11:00 AM <alexandre.ferrieux@orange.com> wrote:
>
>
>
> On 30/04/2024 19:20, H.J. Lu wrote:
> >
> > From: Alexandre Ferrieux <alexandre.ferrieux@orange.com>
> >
> > This patch fixes BZ #27777 "fclose does a linear search, takes ages when
> > many FILE* are opened". Simply put, the master list of opened (FILE*),
> > namely _IO_list_all, is a singly-linked list. As a consequence, the
> > removal of a single element is in O(N), which cripples the performance
> > of fclose(). The patch switches to a doubly-linked list, yielding O(1)
> > removal. The one padding field in struct _IO_FILE, __pad5, is renamed
> > to _prevchain for a doubly-linked list. Since fields in struct _IO_FILE
> > after the _lock field are internal to glibc and opaque to applications.
> > We can change them as long as the size of struct _IO_FILE is unchanged,
> > which is checked as the part of glibc ABI with sizes of _IO_2_1_stdin_,
> > _IO_2_1_stdout_ and _IO_2_1_stderr_.
> >
> > NB: When _IO_vtable_offset (fp) == 0, copy relocation will cover the
> > whole struct _IO_FILE. Otherwise, only fields up to the _lock field
> > will be copied to applications at run-time. It is used to check if
> > the _prevchain field can be safely accessed.
> >
> >
> > Co-Authored-By: H.J. Lu <hjl.tools@gmail.com>
>
> Thanks a lot, H.J., for finishing the job !
> And thanks also for providing the explanation about the semantics of the
> vtable_offset nullity check, that was not obvious for an outside observer like me :)
I submitted a test:
https://patchwork.sourceware.org/project/glibc/list/?series=33313
to verify that the old binary linked against glibc 2.0 works.
> (If I missed a README explaining all this, thanks for giving me the link)
>
> > As tst-fclose.c shows, after opening 2 million (FILE*), the fclose() of
> > 100 of them takes more than a few seconds without the patch, and under
> > 2 seconds with it.
>
> Don't you mean "under 2 milliseconds" ? That's closer to what I see here.
The timeout value in tst-fclose.c is in seconds. I verified that if
the doubly-linked
list wasn't used, tst-fclose failed with timeout.
--
H.J.
next prev parent reply other threads:[~2024-04-30 18:13 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-04-30 17:20 [PATCH] Fix #27777 - now use a doubly-linked list for _IO_list_all H.J. Lu
2024-04-30 18:00 ` alexandre.ferrieux
2024-04-30 18:11 ` H.J. Lu [this message]
2024-04-30 19:37 ` H.J. Lu
2024-04-30 19:52 ` alexandre.ferrieux
2024-04-30 20:02 ` H.J. Lu
-- strict thread matches above, loose matches on Subject: below --
2024-04-26 14:18 alexandre.ferrieux
2024-04-26 14:45 ` H.J. Lu
[not found] ` <ffa6e29b-3a7b-4be6-a0d2-327510a7094d@orange.com>
2024-04-26 15:05 ` H.J. Lu
2024-04-26 15:12 ` H.J. Lu
[not found] ` <84cbc4a9-2ddf-45f3-94be-132441db5c8a@orange.com>
2024-04-26 15:16 ` H.J. Lu
[not found] ` <7fa02e06-42b1-463b-a7c4-66600d524186@orange.com>
2024-04-26 16:08 ` H.J. Lu
[not found] ` <5fad7b2e-43a4-4e57-bd10-a9ce1ce38006@orange.com>
2024-04-26 16:24 ` H.J. Lu
2024-04-26 17:51 ` Florian Weimer
2024-04-26 18:20 ` alexandre.ferrieux
2024-04-26 18:44 ` alexandre.ferrieux
2024-04-26 19:08 ` Florian Weimer
2024-04-26 19:08 ` Florian Weimer
2024-04-26 18:50 ` H.J. Lu
2024-04-26 19:04 ` alexandre.ferrieux
2024-04-26 19:16 ` Florian Weimer
2024-04-26 20:15 ` alexandre.ferrieux
2024-04-29 13:20 ` Florian Weimer
2024-04-29 19:05 ` alexandre.ferrieux
2024-04-30 2:47 ` H.J. Lu
2024-04-30 17:22 ` H.J. Lu
2024-04-26 19:09 ` Florian Weimer
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
List information: https://www.gnu.org/software/libc/involved.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CAMe9rOo1JzrjCD7tD6RuU+wGmby_ZBMrUu1zmE9hKko=ymxUsw@mail.gmail.com' \
--to=hjl.tools@gmail.com \
--cc=alexandre.ferrieux@orange.com \
--cc=libc-alpha@sourceware.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 read-only IMAP folder(s) and NNTP newsgroup(s).