From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.bugs Subject: bug#45200: [PATCH] Force Glibc to free the memory freed Date: Wed, 03 Feb 2021 11:51:55 -0500 Message-ID: References: <83k0rz21dw.fsf@gnu.org> <331805c74fc5d3d412dd2065030b11fa3343710d.camel@yandex.ru> <8a91fc16f93298bca1281b43d6821ae3621376dc.camel@yandex.ru> <7ffacc5f-fc0e-a5f8-104d-2c0ae8e06953@gmx.at> <3f4f8b3034e9f52f48ec520f2732b1687bb24dbc.camel@yandex.ru> <31608795-6155-c7c9-7d94-6024adb0a3b9@gmx.at> <09cc70f14e90f6b13b51b0536fae76e87dfe3f42.camel@yandex.ru> <55be0318-c907-bf9b-d644-d88abb816871@gmx.at> <35163027-a5b7-4a6c-6700-69d34fecf451@gmx.at> <824625557ce288b0cbc3edd66ff730afd479b511.camel@yandex.ru> <6b1ddaa05952c3d942ca74f187427c2319605621.camel@yandex.ru> Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="12860"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) Cc: carlos@redhat.com, fweimer@redhat.com, dj@redhat.com, 45200@debbugs.gnu.org To: Konstantin Kharlamov Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Wed Feb 03 17:53:44 2021 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1l7LPS-0003Ce-6q for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 03 Feb 2021 17:53:42 +0100 Original-Received: from localhost ([::1]:33012 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l7LPR-0001vM-6i for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 03 Feb 2021 11:53:41 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:59614) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l7LOo-0001aW-Qf for bug-gnu-emacs@gnu.org; Wed, 03 Feb 2021 11:53:02 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]:55427) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1l7LOo-0007Zj-J4 for bug-gnu-emacs@gnu.org; Wed, 03 Feb 2021 11:53:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1l7LOo-0006TB-HC for bug-gnu-emacs@gnu.org; Wed, 03 Feb 2021 11:53:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Stefan Monnier Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 03 Feb 2021 16:53:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 45200 X-GNU-PR-Package: emacs Original-Received: via spool by 45200-submit@debbugs.gnu.org id=B45200.161237112624767 (code B ref 45200); Wed, 03 Feb 2021 16:53:02 +0000 Original-Received: (at 45200) by debbugs.gnu.org; 3 Feb 2021 16:52:06 +0000 Original-Received: from localhost ([127.0.0.1]:38740 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1l7LNu-0006RP-8y for submit@debbugs.gnu.org; Wed, 03 Feb 2021 11:52:06 -0500 Original-Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:48311) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1l7LNr-0006Qe-Vc for 45200@debbugs.gnu.org; Wed, 03 Feb 2021 11:52:05 -0500 Original-Received: from pmg3.iro.umontreal.ca (localhost [127.0.0.1]) by pmg3.iro.umontreal.ca (Proxmox) with ESMTP id 5A267440977; Wed, 3 Feb 2021 11:51:58 -0500 (EST) Original-Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg3.iro.umontreal.ca (Proxmox) with ESMTP id A82F3440958; Wed, 3 Feb 2021 11:51:56 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1612371116; bh=0Fl18BMF21QG7/Eb6X+sKYKdfD/7d9h6MD3fJtST7eI=; h=From:To:Cc:Subject:References:Date:In-Reply-To:From; b=U9melYBQM0gWy/Szv/Bai2kQim2mui0sF6R6JEepCmrqVI24iHkqEvJkBJvige+6S xUb4yqYD4QzOZWNVu6vlwHYP3uVSvbnHd4GJIckTnV7x0DnYjce7fZavmU7XtRimfA /+I7GNsOXJNMK8M0iRT+HXxMpILdki6EnENw7N+o2lE75/mILhBYx8gLdtsQF0DhuA pfEQqqJZA1dKYxNQd4UNi5AU9UicwiJVRHNeJCQfZMCLRrsc4EVQvv81qY56eeNMPM mk+cQqfWu4hWusL/bBzCr5y/r/gPjMu8VLMZsJSfayVlDCYbp32ZBrEGj7hgn1UG3G 41jpKJlUxftoQ== Original-Received: from alfajor (76-10-182-85.dsl.teksavvy.com [76.10.182.85]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id 35F3212005C; Wed, 3 Feb 2021 11:51:56 -0500 (EST) In-Reply-To: <6b1ddaa05952c3d942ca74f187427c2319605621.camel@yandex.ru> (Konstantin Kharlamov's message of "Wed, 03 Feb 2021 19:35:08 +0300") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:199213 Archived-At: >> So I think we need more info: do the glibc maintainers consider it >> normal for glibc to behave this way?=A0 Why does it behave this way? > Very good question! I hope Glibc mainainers that are on CC list will be a= ble to > answer. Even though I created a report on Glibc just some months ago, th= e problem per > se existed for a long time. And I've seen Carlos O'Donell leaving a small= comment on a > similar issue with Ruby 2 years ago, which implies they're aware of this = situation. I mean, I understand why glibc doesn't always immediately release memory to the OS, but I'd like to better understand whether we can expect that there is a mechanism in glibc to avoid it keeping 500MB of free memory around eternally when the subsequent actual use remains below 100MB. >> Would the equivalent of `malloc_trim` happen anyway "at some point in >> the future"?=A0 E.g. If you create a test case where you disable GC, let >> the memory use grow to 1GB, then reset the GC vars to their default and >> keep using Emacs modestly, will the memory ever be returned to the OS or >> is an explicit call to `malloc_trim` really indispensable? > > No, the memory will never be returned to OS. I can tell that right > away, because the only difference would be `free()` getting called > more often. I'm not sure I follow: if I were to implement a malloc library, calls to `free` would be exactly the place where I'd decide that some memory should be returned to the OS, so even if a given call to `free` might not return the now-unused 400MB, I'd expect that this memory might be finally returned after some number of other/unrelated calls to `free`. > I think it is worth mentioning here that Glibc usually does return > memory to the OS without any need in malloc_trim(0). What happens in > affected applications (such as here) is that an application stumbles > upon a very special allocation pattern, which kinda breaks Glibc > algorithms of returning memory. Indeed. The question is whether it's a bug in glibc or whether it's something that the upper layer should deal with. Knowing a bit better why/when this happens would also help the upper layer decide when to call `malloc_trim` if indeed that's needed (another useful info would be a function that returns the mount of memory there is to trim, assuming that info can be obtained much more cheaply than a call to `malloc_trim`). Stefan