From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 666B73955437; Sat, 24 Apr 2021 21:50:58 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 666B73955437 From: "alexandre.ferrieux at orange dot com" To: glibc-bugs@sourceware.org Subject: [Bug stdio/27777] New: fclose does a linear search, takes ages when FILE* are opened Date: Sat, 24 Apr 2021 21:50:58 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: glibc X-Bugzilla-Component: stdio X-Bugzilla-Version: 2.34 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: alexandre.ferrieux at orange dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P2 X-Bugzilla-Assigned-To: unassigned at sourceware dot org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://sourceware.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: glibc-bugs@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Glibc-bugs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 24 Apr 2021 21:50:58 -0000 https://sourceware.org/bugzilla/show_bug.cgi?id=3D27777 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 op= ened file descriptors per process has been tuned beyond the typical 1024), fclos= e() starts being *very* slow. The root cause is the following linear search in genops.c/_IO_un_link: d18ea0c5 68 for (f =3D &_IO_list_all->file._chain; *f; = f =3D &(*f)->_chain) 9964a145 69 if (*f =3D=3D (FILE *) fp) 40a55d20 70 { cedb4109 71 *f =3D 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. --=20 You are receiving this mail because: You are on the CC list for the bug.=