public inbox for glibc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug stdio/27777] New: fclose does a linear search, takes ages when FILE* are opened
@ 2021-04-24 21:50 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
                   ` (8 more replies)
  0 siblings, 9 replies; 10+ messages in thread
From: alexandre.ferrieux at orange dot com @ 2021-04-24 21:50 UTC (permalink / raw)
  To: glibc-bugs

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

            Bug ID: 27777
           Summary: fclose does a linear search, takes ages when FILE* are
                    opened
           Product: glibc
           Version: 2.34
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: stdio
          Assignee: unassigned at sourceware dot org
          Reporter: alexandre.ferrieux at orange dot com
  Target Milestone: ---

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.

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

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2024-05-17 21:15 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-24 21:50 [Bug stdio/27777] New: fclose does a linear search, takes ages when FILE* are opened 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
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

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).