From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 8DF013858D39; Mon, 18 Mar 2024 05:13:16 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8DF013858D39 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1710738796; bh=gp2ue/iEkBfEngbn6EwK0JPW5O/mQikTY75fK+gtPWo=; h=From:To:Subject:Date:In-Reply-To:References:From; b=iwERY6No1WKKcseENWnvo9O0+2OvSAdaAXBgf+kMP4oAYzqHqn1m41l+sk9qUqZEY hooN007NXrA6I6EKCIayVR3qCVfVzKKRW3H885PMIBaYO02JdpBumGN+prO6b8pSFl EwBkZqkIf8+6YEnZnOgbgRlJ8/WtD+7KPFaAvTJg= From: "shubhankargambhir013 at gmail dot com" To: glibc-bugs@sourceware.org Subject: [Bug malloc/30769] malloc_trim is not working correctly for arenas other than arena 0 Date: Mon, 18 Mar 2024 05:13:15 +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.35 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: shubhankargambhir013 at gmail 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: cc 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=3D30769 Shubhankar Gambhir changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |shubhankargambhir013@gmail. | |com --- Comment #2 from Shubhankar Gambhir --- In the original example (mem.cpp) given, the MMAP_THRESHOLD is 128KB (by default) in starting and can increase upto 64MB. In first iteration the blo= cks are mmaped because they are above threshold, now When you free the first 18= MB block the MMAP_THRESHOLD is adjusted, so now from 2nd iteration the blocks = will be allocated in arenas, and when they are freed they will be added to malloc cache and not given back to os.=20 When you set M_TOP_PAD (or M_TRIM_THRESHOLD, M_MMAP_THRESHOLD, M_MMAP_MAX) MMAP_THRESHOLD is disabled, so the blocks from 2nd iterations also get mmap= ed and memory is given back to os when they are freed. Further malloc_trim calls madvise(DONT_NEED) on free pages in arenas, this causes pages to be on demand loaded on next access, and the way your program calculates rss is through proc/self/stat. I can see following description in man documentation. ``` number of pages the process has in real memory. This is just the pages which count toward text, data, or stack space. This does not include pag= es which have not been demand-loaded in, or which are swapped out. Th= is=20 value is inaccurate; ``` --=20 You are receiving this mail because: You are on the CC list for the bug.=