From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 2C6453858D3C; Thu, 22 Jun 2023 15:10:41 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2C6453858D3C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1687446641; bh=uPpJRyIueu19/Krmo13+G8u+BwYNDeJWLEsEenGf1no=; h=From:To:Subject:Date:In-Reply-To:References:From; b=ldafgUjZYfTimMDxAYX2X764ju6GWXAxidMHJ8gzuOeD0OXnBC4XrlBYPKlUkQMcx 8qzvhez5TDYthNzoOhn4swNVibv6YvlS+fkQYTE2V3wMFuUktzTWxvXN3IgACuUbIk 9PhUOU9TaWnumchcShOM+sypS2CKH7uhogXM/BBs= From: "nicolas at freedelity dot be" To: glibc-bugs@sourceware.org Subject: [Bug malloc/30579] trim_threshold in realloc lead to high memory usage Date: Thu, 22 Jun 2023 15:10:40 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: glibc X-Bugzilla-Component: malloc X-Bugzilla-Version: 2.37 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: nicolas at freedelity dot be 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: 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=3D30579 --- Comment #2 from Nicolas Dusart --- I apologize for any previous misunderstanding regarding the use of trim_threshold in relation to heap fragmentation. I incorrectly assumed tha= t it was primarily relevant to the mmap use case, based on the message of the commit. I still have concerns about the recent change to the realloc function and I would argue that it doesn't significantly mitigate fragmentation. There are two primary reasons for my concern: - Memory "freed" by realloc is not immediately accessible, even to the proc= ess itself. - The memory that is reallocated isn't necessarily positioned at the top of= the heap. Consequently, we tend to accumulate more and more memory blocks that become stagnant (in use cases where we initially allocate more memory than needed = and then realloc to the precise size). These blocks can't even be released back= to the system if their combined size exceeds the trim_threshold, since they do= n't constitute a contiguous space at the top of the heap. I maintain that the use of trim_threshold in this context is not ideal. We might still want to retain the default threshold of 128K to prevent fragmen= ting memory returned to the system, while also preventing the accumulation of stagnant blocks up to 128K in our memory space. --=20 You are receiving this mail because: You are on the CC list for the bug.=