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 01:44:13 +0300 Message-ID: <9f49e5542f303736d2e53ce3dc53c1374969e6b4.camel@yandex.ru> References: <83k0tmeq6f.fsf@gnu.org> 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="13955"; 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 Sat Dec 12 23:45:34 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 1koDdt-0003Vd-Ah for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 12 Dec 2020 23:45:33 +0100 Original-Received: from localhost ([::1]:44710 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1koDds-0008Sr-By for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 12 Dec 2020 17:45:32 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:49736) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1koDdO-0008Sa-C8 for bug-gnu-emacs@gnu.org; Sat, 12 Dec 2020 17:45:02 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]:35536) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1koDdO-0008SW-44 for bug-gnu-emacs@gnu.org; Sat, 12 Dec 2020 17:45:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1koDdN-0001CC-Vs for bug-gnu-emacs@gnu.org; Sat, 12 Dec 2020 17:45: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: Sat, 12 Dec 2020 22:45: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.16078130634518 (code B ref 45200); Sat, 12 Dec 2020 22:45:01 +0000 Original-Received: (at 45200) by debbugs.gnu.org; 12 Dec 2020 22:44:23 +0000 Original-Received: from localhost ([127.0.0.1]:47081 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1koDcl-0001Ao-Jb for submit@debbugs.gnu.org; Sat, 12 Dec 2020 17:44:23 -0500 Original-Received: from forward100j.mail.yandex.net ([5.45.198.240]:48976) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1koDcj-0001AX-V7 for 45200@debbugs.gnu.org; Sat, 12 Dec 2020 17:44:22 -0500 Original-Received: from mxback30g.mail.yandex.net (mxback30g.mail.yandex.net [IPv6:2a02:6b8:c03:7b3:0:640:11da:816c]) by forward100j.mail.yandex.net (Yandex) with ESMTP id 7115050E05EA; Sun, 13 Dec 2020 01:44:15 +0300 (MSK) Original-Received: from sas1-f4dc5f2fc86f.qloud-c.yandex.net (sas1-f4dc5f2fc86f.qloud-c.yandex.net [2a02:6b8:c08:cb28:0:640:f4dc:5f2f]) by mxback30g.mail.yandex.net (mxback/Yandex) with ESMTP id lJ20sGCHhX-iF68mw13; Sun, 13 Dec 2020 01:44:15 +0300 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex.ru; s=mail; t=1607813055; bh=CsczHDEKLHpHQTtgc48u6y+nG1g/IH3PtkJUT8dU74k=; h=In-Reply-To:Cc:To:From:Subject:Message-ID:References:Date; b=j8O+CCChqjnDxzp8DcAh1XHwHEH9wg9KYOmmv/raicWSXyf9urLD9INgcvdbPCmT7 j9ZmM1GxmR2gEY88hrlEXeVLk3ykiORHmedr6w8UuI/gdDgZ6OSX/wPUzH1ul17aBJ T36N+O5qrC5pS/FtTXcOLZCZbpBF8FADI18LC+S8= Authentication-Results: mxback30g.mail.yandex.net; dkim=pass header.i=@yandex.ru Original-Received: by sas1-f4dc5f2fc86f.qloud-c.yandex.net (smtp/Yandex) with ESMTPSA id xeQDxoCdlM-iEI4txB7; Sun, 13 Dec 2020 01:44:14 +0300 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (Client certificate not present) In-Reply-To: <83k0tmeq6f.fsf@gnu.org> 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:195919 Archived-At: On Sat, 2020-12-12 at 22:15 +0200, Eli Zaretskii wrote: > > From: Konstantin Kharlamov > > Date: Sat, 12 Dec 2020 21:43:10 +0300 > > > > # 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. > > > > ## Actual > > > > Size without calling explicit garbage-collect, from 3 runs, varied around > > 41.2..41.7 MB. > > > > Size afterwards, also 3 runs, varied around 45.4..45.5 MB. > > Could be simply the effect of different stack size, since Emacs's GC > is conservative, and when there's doubt whether something is a live > object, it won't GC it. > > I think more specific and detailed evidence is needed to prove your > case: which objects were not GC'ed and why. 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. Regarding, whether it is stack size: λ grep VmStk /proc/283047/status VmStk: 132 kB Apparently, it is not stack size.