public inbox for glibc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "carlos at redhat dot com" <sourceware-bugzilla@sourceware.org>
To: glibc-bugs@sourceware.org
Subject: [Bug stdio/27777] fclose does a linear search, takes ages when many FILE* are opened
Date: Wed, 24 Apr 2024 17:05:34 +0000	[thread overview]
Message-ID: <bug-27777-131-7RqgT1oQZV@http.sourceware.org/bugzilla/> (raw)
In-Reply-To: <bug-27777-131@http.sourceware.org/bugzilla/>

https://sourceware.org/bugzilla/show_bug.cgi?id=27777

Carlos O'Donell <carlos at redhat dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |carlos at redhat dot com
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2024-04-24
     Ever confirmed|0                           |1

--- Comment #1 from Carlos O'Donell <carlos at redhat dot com> ---
(In reply to Alexandre Ferrieux from comment #0)
> If one has *many* opened streams (which is possible if the max number of
> opened file descriptors per process has been tuned beyond the typical 1024),
> fclose() starts being *very* slow.
> 
> The root cause is the following linear search in genops.c/_IO_un_link:
> 
> d18ea0c5	68		for (f = &_IO_list_all->file._chain; *f; f = &(*f)->_chain)
> 9964a145	69		  if (*f == (FILE *) fp)
> 40a55d20	70		    {
> cedb4109	71		      *f = fp->file._chain;
> 40a55d20        72		      break;
> UD	        73		    }
> 
> Clearly a singly-linked list does not allow for O(1) removal.
> Given what I understand of the design constraints of this list, the most
> natural fix would be to switch to a doubly-linked list.

Just wanted to mention that I saw this recently while walking the list of bugs.
I can confirm that this is the case. Please feel free to work with the
community to improve the performance. Likewise you might also want to look at
fcloseall() performance too.

-- 
You are receiving this mail because:
You are on the CC list for the bug.

  parent reply	other threads:[~2024-04-24 17:05 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-24 21:50 [Bug stdio/27777] New: fclose does a linear search, takes ages when " alexandre.ferrieux at orange dot com
2021-04-24 21:51 ` [Bug stdio/27777] fclose does a linear search, takes ages when many " alexandre.ferrieux at orange dot com
2024-04-24 17:05 ` carlos at redhat dot com [this message]
2024-04-24 21:12 ` alexandre.ferrieux at orange dot com
2024-04-25 10:52 ` carlos at redhat dot com
2024-04-25 14:17 ` sam at gentoo dot org
2024-04-25 16:20 ` alexandre.ferrieux at orange dot com
2024-04-26 14:23 ` alexandre.ferrieux at orange dot com
2024-05-17 21:14 ` cvs-commit at gcc dot gnu.org
2024-05-17 21:15 ` hjl.tools at gmail dot com

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=bug-27777-131-7RqgT1oQZV@http.sourceware.org/bugzilla/ \
    --to=sourceware-bugzilla@sourceware.org \
    --cc=glibc-bugs@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).