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, 24 Jan 2021 22:06:21 +0300 Message-ID: <0457437ff45b535a61f7c35011de1d133cdd3496.camel@yandex.ru> References: <2a4f3f31f30db28387055821a8edf44fd1d66ea5.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="21615"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Evolution 3.38.3 Cc: 45200@debbugs.gnu.org To: Stefan Monnier Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sun Jan 24 20:07:19 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 1l3kjH-0005Vt-A1 for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 24 Jan 2021 20:07:19 +0100 Original-Received: from localhost ([::1]:59996 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l3kjG-0002iK-CB for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 24 Jan 2021 14:07:18 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:56682) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l3kj0-0002hx-Ik for bug-gnu-emacs@gnu.org; Sun, 24 Jan 2021 14:07:02 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]:53974) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1l3kiz-0003bN-V8 for bug-gnu-emacs@gnu.org; Sun, 24 Jan 2021 14:07:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1l3kiz-000296-QI for bug-gnu-emacs@gnu.org; Sun, 24 Jan 2021 14:07:01 -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, 24 Jan 2021 19:07: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.16115151928204 (code B ref 45200); Sun, 24 Jan 2021 19:07:01 +0000 Original-Received: (at 45200) by debbugs.gnu.org; 24 Jan 2021 19:06:32 +0000 Original-Received: from localhost ([127.0.0.1]:37287 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1l3kiW-00028G-G9 for submit@debbugs.gnu.org; Sun, 24 Jan 2021 14:06:32 -0500 Original-Received: from forward103o.mail.yandex.net ([37.140.190.177]:53439) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1l3kiT-00027y-G3 for 45200@debbugs.gnu.org; Sun, 24 Jan 2021 14:06:30 -0500 Original-Received: from sas1-37a648709e20.qloud-c.yandex.net (sas1-37a648709e20.qloud-c.yandex.net [IPv6:2a02:6b8:c08:fe03:0:640:37a6:4870]) by forward103o.mail.yandex.net (Yandex) with ESMTP id B88AC5F80D98; Sun, 24 Jan 2021 22:06:22 +0300 (MSK) Original-Received: from sas1-e20a8b944cac.qloud-c.yandex.net (sas1-e20a8b944cac.qloud-c.yandex.net [2a02:6b8:c14:6696:0:640:e20a:8b94]) by sas1-37a648709e20.qloud-c.yandex.net (mxback/Yandex) with ESMTP id 1Z1ZMHGEDe-6MGO7SHw; Sun, 24 Jan 2021 22:06:22 +0300 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex.ru; s=mail; t=1611515182; bh=uMD8zf8vnMHzN04u2mb17Tq3FpEpsyUiU1ecPRJhjsE=; h=In-Reply-To:Cc:To:From:Subject:Message-ID:References:Date; b=kB6Iv0QnGDJwAJKIhWCIv0Gxf6ICzSTnkR0lS14EB4VfBymMg8LXCBIQIqgnB244g crDMNckmKXOSErArpdJhPOoHPuwvhbuTucujFVBX/KAnbsg86Exj/T6GiQ6hEnF2UX z2GU3x6ODA+mQVRMB0E4grJrUh+qumPPUklhHqFg= Authentication-Results: sas1-37a648709e20.qloud-c.yandex.net; dkim=pass header.i=@yandex.ru Original-Received: by sas1-e20a8b944cac.qloud-c.yandex.net (smtp/Yandex) with ESMTPSA id nl5csKbbqS-6MIaVelL; Sun, 24 Jan 2021 22:06:22 +0300 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (Client certificate not present) In-Reply-To: <2a4f3f31f30db28387055821a8edf44fd1d66ea5.camel@yandex.ru> 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:198516 Archived-At: On Sun, 2021-01-24 at 22:00 +0300, Konstantin Kharlamov wrote: > On Sun, 2021-01-24 at 13:51 -0500, Stefan Monnier wrote: > > > # Steps to reproduce: > > > > > > 1. Run `mkdir /tmp/.emacs.d` > > > 2. Run emacs as `HOME=/tmp/ emacs`, and measure its PSS > > > 3. Create a file /tmp/.emacs.d/early-init.el with content: > > > > > >     ;; only run garbage collection on idle > > >     (setq gc-cons-threshold most-positive-fixnum) > > >     (run-with-idle-timer 2 t (lambda () (garbage-collect))) > > > > > > 4. Run emacs as `HOME=/tmp/ emacs`, evaluate (garbage-collect), then > > > measure > > > its PSS > > > > > > ## Expected > > > > > > Size has no statistically-significant difference, because in both > > > cases we garbage-collected memory. > > > > I disagree with this expectation: it is perfectly normal for the amount > > of memory allocated to the Emacs process to be left higher if you delay > > the GC.  There are various reasons for that: > > - fragmentation, of course.  Not much we can do about it short of using > >   a moving collector. > > - the desire to keep memory around rather than return it to the OS, > >   under the assumption that we'll need it again soon. > > > > And it's not considered as a memory leak as long as that memory has > > indeed been needed in the past and that future allocations can still > > make use of it. > > I'm fine with Emacs possibly keeping a dozen of megabytes for personal use. > The problem though is that the issue easily manifests itself in hundreds of > megabytes, as can be seen with the testcase marked as "Message #11" in web-ui. Case in point btw: after the previous weekend I found my Emacs instance that I did not touch during the weekend to bloat to as much as 6xxMB. I think that happened because the on-idle hook that I hooked garbage collector onto was not run for 2 days, whilst Emacs might have been doing something like communication to LSP server from time to time, so this is why it ended up taking so much memory. I think it's needless to say that I had to restart Emacs for the half-gigabyte of memory to get returned to my system.