From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 5F33B3849AEE; Wed, 24 Apr 2024 17:05:35 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5F33B3849AEE DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1713978335; bh=d7qC7LyoVrkAGfX+DPpBVe25u4dHV2ghdto1TypvaL0=; h=From:To:Subject:Date:In-Reply-To:References:From; b=uNo6UvBRVE/5qvka5NJ2nO3XcGLDwcMJPzbYJqPZ/W1/ZzueG84FRx7naJmxlU3+w gLoCAbmHr5VVxXTvBu/uBKt6EA2mjj6HU9cIzM0LwG5MVWShDz2MNLXZdCRWhyGKD9 kel11nH3EV4Gby0gHBGcRB0hQKQuQMkQV9KDtPs4= From: "carlos at redhat dot com" 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 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed 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: carlos at redhat dot com X-Bugzilla-Status: NEW 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: cc bug_status cf_reconfirmed_on everconfirmed Message-ID: In-Reply-To: References: 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 List-Id: https://sourceware.org/bugzilla/show_bug.cgi?id=3D27777 Carlos O'Donell 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 --- (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 102= 4), > fclose() starts being *very* slow. >=20 > The root cause is the following linear search in genops.c/_IO_un_link: >=20 > d18ea0c5 68 for (f =3D &_IO_list_all->file._chain; *f; f =3D &(*f)->_cha= in) > 9964a145 69 if (*f =3D=3D (FILE *) fp) > 40a55d20 70 { > cedb4109 71 *f =3D fp->file._chain; > 40a55d20 72 break; > UD 73 } >=20 > 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 b= ugs. 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. --=20 You are receiving this mail because: You are on the CC list for the bug.=