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 23:19:40 -0500 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="21432"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) Cc: fweimer@redhat.com, carlos@redhat.com, hi-angel@yandex.ru, 45200@debbugs.gnu.org To: DJ Delorie Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Thu Feb 04 05:20:18 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 1l7W7u-0005UO-4q for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 04 Feb 2021 05:20:18 +0100 Original-Received: from localhost ([::1]:55808 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l7W7t-0003Hp-8C for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 03 Feb 2021 23:20:17 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:42528) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l7W7e-0003GR-F9 for bug-gnu-emacs@gnu.org; Wed, 03 Feb 2021 23:20:02 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]:56098) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1l7W7e-0007Xz-7D for bug-gnu-emacs@gnu.org; Wed, 03 Feb 2021 23:20:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1l7W7e-000116-0P for bug-gnu-emacs@gnu.org; Wed, 03 Feb 2021 23:20: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: Thu, 04 Feb 2021 04:20:01 +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.16124123903884 (code B ref 45200); Thu, 04 Feb 2021 04:20:01 +0000 Original-Received: (at 45200) by debbugs.gnu.org; 4 Feb 2021 04:19:50 +0000 Original-Received: from localhost ([127.0.0.1]:39411 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1l7W7R-00010S-PH for submit@debbugs.gnu.org; Wed, 03 Feb 2021 23:19:50 -0500 Original-Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:56960) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1l7W7Q-00010B-Kj for 45200@debbugs.gnu.org; Wed, 03 Feb 2021 23:19:48 -0500 Original-Received: from pmg3.iro.umontreal.ca (localhost [127.0.0.1]) by pmg3.iro.umontreal.ca (Proxmox) with ESMTP id 1AAE84409AE; Wed, 3 Feb 2021 23:19:43 -0500 (EST) Original-Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg3.iro.umontreal.ca (Proxmox) with ESMTP id B1F56440996; Wed, 3 Feb 2021 23:19:41 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1612412381; bh=iuMj4I8c9DPAjiv8u/wJVLgb5fTDByuF7DrGwU1WSvI=; h=From:To:Cc:Subject:References:Date:In-Reply-To:From; b=OFFoFmj/CQB/zPP4S+RD/FdMJxqbbUKuTTtrsKuzFkFAnRQqHwZZzv0utiop+6N2I EAKFU2XQv8/5RCm5+jMB3tXmg9K6RkUH0DJQCJZXcUhVySDZ4KWO21jcb2tTO+ynuC QVr9GiZs7FiHErGFIjWR35kktiI07EZ3azkXuMgHeBnFMcn3eIa/K/C9X2u81EFPG2 +LoYKE7NUXEWVQZuEmJGnTiEwFG/DNjfLXNOOZ18RAMO0z6FjMpqTkATE1/M5G+zxL ErOrqwS7HD9jxTSYrj3V2GGv7zU2zpGxIYhwYvkLah9EX+FsKnRH2zd/vf0AJsWUYx bI3OuCRfcpWhw== Original-Received: from alfajor (76-10-182-85.dsl.teksavvy.com [76.10.182.85]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id 59E191204AE; Wed, 3 Feb 2021 23:19:41 -0500 (EST) In-Reply-To: (DJ Delorie's message of "Wed, 03 Feb 2021 23:02:05 -0500") 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:199265 Archived-At: >> But wouldn't glibc release that memory even without calling >> `malloc_trim` simply because it's at the top and is larger than >> `M_TRIM_THRESHOLD`? > Probably, if you disabled fastbins. Like I said earler, I think > fastbins bypasses the top-of-heap consolidation, so the chunks might be > free'd but in the fastbin cache. malloc_trim() flushes the fastbin > cache. > There are other ways to flush the fastbins but they're harder to > programmatically invoke (i.e. "magic rules"). > Also, fastbins bypass the chunk consolidation, so even if all the memory > is free()'d it might still be in small-chunk form in the fastbins, ready > for fast re-use. [ I have no idea what "fastbins" are, but I'll nod along approvingly. ] OK, so `malloc_trim` can do a more thorough job and discover that there's indeed 200MB free at the top which malloc/free wouldn't have noticed? I guess that makes sense. Since our GC doesn't move objects, there will often be some left over live object near the top that will prevent most of those mythical 200MB from being released. Anyway, thanks for bearing with us and hand-holding me until I start to feel like I understand the situation. I have a much better understanding of what Emacs might be able to do. Stefan PS: One last thing: I must say I'm surprised to see the amount of effort that seems to be spent on trying to release that "top" free memory. >From where I stand, it seems that it will only very rarely allow you to release any non-trivial amount of memory. Why bother?