From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Konstantin Kharlamov Newsgroups: gmane.emacs.bugs Subject: bug#45200: Memory leaks: (garbage-collect) fails to reclaim memory Date: Sun, 13 Dec 2020 15:07:46 +0300 Message-ID: <72e40cc93232dd0054977bb7037a5ac38e2165ba.camel@yandex.ru> References: <83k0tmeq6f.fsf@gnu.org> <9f49e5542f303736d2e53ce3dc53c1374969e6b4.camel@yandex.ru> Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="7356"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Evolution 3.38.2 Cc: 45200@debbugs.gnu.org To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sun Dec 13 13:08:46 2020 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 1koQBB-0001po-VO for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 13 Dec 2020 13:08:45 +0100 Original-Received: from localhost ([::1]:54072 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1koQBA-0002Ja-Tp for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 13 Dec 2020 07:08:44 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:35090) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1koQAV-00023y-7B for bug-gnu-emacs@gnu.org; Sun, 13 Dec 2020 07:08:03 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]:36039) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1koQAU-0008Q0-F9 for bug-gnu-emacs@gnu.org; Sun, 13 Dec 2020 07:08:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1koQAU-0008Si-9z for bug-gnu-emacs@gnu.org; Sun, 13 Dec 2020 07:08:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Konstantin Kharlamov Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 13 Dec 2020 12:08: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.160786127632504 (code B ref 45200); Sun, 13 Dec 2020 12:08:02 +0000 Original-Received: (at 45200) by debbugs.gnu.org; 13 Dec 2020 12:07:56 +0000 Original-Received: from localhost ([127.0.0.1]:47585 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1koQAO-0008SB-Ip for submit@debbugs.gnu.org; Sun, 13 Dec 2020 07:07:56 -0500 Original-Received: from forward104p.mail.yandex.net ([77.88.28.107]:55659) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1koQAL-0008Rc-S3 for 45200@debbugs.gnu.org; Sun, 13 Dec 2020 07:07:55 -0500 Original-Received: from mxback14o.mail.yandex.net (mxback14o.mail.yandex.net [IPv6:2a02:6b8:0:1a2d::65]) by forward104p.mail.yandex.net (Yandex) with ESMTP id 7E8244B00D54; Sun, 13 Dec 2020 15:07:47 +0300 (MSK) Original-Received: from myt5-95c1fb78270f.qloud-c.yandex.net (myt5-95c1fb78270f.qloud-c.yandex.net [2a02:6b8:c12:1725:0:640:95c1:fb78]) by mxback14o.mail.yandex.net (mxback/Yandex) with ESMTP id E1pNK9OF5a-7lVq638b; Sun, 13 Dec 2020 15:07:47 +0300 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex.ru; s=mail; t=1607861267; bh=izcAo6NbdFJ4KXQv4oPCQvEna4EUceJEw9aT8DRatFA=; h=In-Reply-To:Cc:To:From:Subject:Message-ID:References:Date; b=aXjqOMH/g5MdYjPTxajlU5Cd8nI6w58lXd83bMJE33i93QDtxD4hRoJWnM6mpGmhl 18h+eqUN/WazlPlRWl2NgJWAEfcn5OryiRdkwAbRmcCVFkW8CJ2nhuwAoLCnOGKanH cwNEYldz8RXR8HNzLZG2XL7kIBtnGXm0WW1BElig= Authentication-Results: mxback14o.mail.yandex.net; dkim=pass header.i=@yandex.ru Original-Received: by myt5-95c1fb78270f.qloud-c.yandex.net (smtp/Yandex) with ESMTPSA id Rpbu72hy8I-7kn0dX9E; Sun, 13 Dec 2020 15:07:46 +0300 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (Client certificate not present) In-Reply-To: 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:195946 Archived-At: On Sun, 2020-12-13 at 00:53 -0500, Eli Zaretskii wrote: > > From: Konstantin Kharlamov > > Cc: 45200@debbugs.gnu.org > > Date: Sun, 13 Dec 2020 01:44:13 +0300 > > > > Alright, fair enough. I crafted up another testcase, it may be better. The > > following code first temporarily disables GC, then it prints "hello" 1000000 > > times, and finally it calls GC manually. > > > > I call `emacs -Q`, then measure PSS, then evaluate the code below, then > > again measure PSS. > > > >     (let ((i 1000000)) > >       (setq gc-cons-threshold most-positive-fixnum) > >       (while (> i 0) > >         (print "hello") > >         (setq i (- i 1))) > >       (garbage-collect)) > > > > The loop takes 20-30 seconds for me, I think. PSS before is ≈41M, and PSS > > after is 266.3M. That is ≈200M of memory just vanished. > > That memory hasn't vanished, it is in your libc's malloc arena, > available for future allocations.  When and if it will be given back > to the OS is up to the specifics of the malloc implementation.  E.g., > when I do the above on MS-Windows, where malloc is more eager to return > memory to the OS, I end up with just 40 MB footprint, and if I then > invoke GC manually, the memory goes down almost to the original value: > 14 MB vs 12 MB after startup. Your explanation seems likely, because such memory is reused by glibc on later mallocs, and if I repeat the testcase, I can see that memory does not increase further, meaning it got reused.