From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 267263864C15; Fri, 17 May 2024 21:14:01 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 267263864C15 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1715980442; bh=pJfUs2xHceOHJE+oNoqtX+41mvaoDlrJEn4YnDiDctY=; h=From:To:Subject:Date:In-Reply-To:References:From; b=s/rc+WvA96dcEGVKQlNViXKB6w3FUT1jB2pQ8O19GKw1UrKVZQXu7aMemYsxCfJzv xeRVgMnkFaMzMNRNZkUSeed6kasc+5h2C2/gGM+L/czxjto6Ixtw1surCQRuKl7DBS D+V9h57K3D3rhLthXDTllvpEttli+ZDpzGkuOuBI= From: "cvs-commit at gcc dot gnu.org" To: glibc-bugs@sourceware.org Subject: [Bug stdio/27777] fclose does a linear search, takes ages when many FILE* are opened Date: Fri, 17 May 2024 21:14:01 +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: cvs-commit at gcc dot gnu.org 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: 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 --- Comment #6 from Sourceware Commits --- The master branch has been updated by H.J. Lu : https://sourceware.org/git/gitweb.cgi?p=3Dglibc.git;h=3D2a99e2398d9d717c034= e915f7846a49e623f5450 commit 2a99e2398d9d717c034e915f7846a49e623f5450 Author: Alexandre Ferrieux Date: Thu May 16 05:54:30 2024 -0700 Use a doubly-linked list for _IO_list_all (bug 27777) 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) =3D=3D 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. After opening 2 million (FILE*), the fclose() of 100 of them takes quite a few seconds without the patch, and under 2 seconds with it on a loaded machine. No test is added since there are no functional changes. Co-Authored-By: H.J. Lu Signed-off-by: Alexandre Ferrieux Signed-off-by: H.J. Lu Reviewed-by: Carlos O'Donell --=20 You are receiving this mail because: You are on the CC list for the bug.=