From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Paul Eggert Newsgroups: gmane.emacs.bugs Subject: bug#31852: Make memory-limit obsolete Date: Fri, 15 Jun 2018 18:33:47 -0700 Organization: UCLA Computer Science Department Message-ID: <510fa6e2-38e5-f5cf-e1c8-4a1a553a162d@cs.ucla.edu> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------200693BE6EBF92F49695F538" X-Trace: blaine.gmane.org 1529112786 10691 195.159.176.226 (16 Jun 2018 01:33:06 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sat, 16 Jun 2018 01:33:06 +0000 (UTC) User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.8.0 To: 31852@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sat Jun 16 03:33:01 2018 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1fU05N-0002ZO-EO for geb-bug-gnu-emacs@m.gmane.org; Sat, 16 Jun 2018 03:33:01 +0200 Original-Received: from localhost ([::1]:49915 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fU07U-00039B-JF for geb-bug-gnu-emacs@m.gmane.org; Fri, 15 Jun 2018 21:35:12 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:51090) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fU07N-000395-Gk for bug-gnu-emacs@gnu.org; Fri, 15 Jun 2018 21:35:07 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fU07K-0005YS-B0 for bug-gnu-emacs@gnu.org; Fri, 15 Jun 2018 21:35:05 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:42851) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fU07K-0005YA-5E for bug-gnu-emacs@gnu.org; Fri, 15 Jun 2018 21:35:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1fU07J-0000NV-Sm for bug-gnu-emacs@gnu.org; Fri, 15 Jun 2018 21:35:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Paul Eggert Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 16 Jun 2018 01:35:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 31852 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch X-Debbugs-Original-To: Emacs bug reports Original-Received: via spool by submit@debbugs.gnu.org id=B.15291128501387 (code B ref -1); Sat, 16 Jun 2018 01:35:01 +0000 Original-Received: (at submit) by debbugs.gnu.org; 16 Jun 2018 01:34:10 +0000 Original-Received: from localhost ([127.0.0.1]:50748 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1fU06S-0000MH-Ej for submit@debbugs.gnu.org; Fri, 15 Jun 2018 21:34:10 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:60037) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1fU06Q-0000Ll-9A for submit@debbugs.gnu.org; Fri, 15 Jun 2018 21:34:06 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fU06J-0003BJ-Ec for submit@debbugs.gnu.org; Fri, 15 Jun 2018 21:34:01 -0400 Original-Received: from lists.gnu.org ([2001:4830:134:3::11]:48192) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fU06J-0003B2-9L for submit@debbugs.gnu.org; Fri, 15 Jun 2018 21:33:59 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:51007) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fU06F-00030z-NH for bug-gnu-emacs@gnu.org; Fri, 15 Jun 2018 21:33:59 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fU06C-00030a-IQ for bug-gnu-emacs@gnu.org; Fri, 15 Jun 2018 21:33:55 -0400 Original-Received: from zimbra.cs.ucla.edu ([131.179.128.68]:50158) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fU06C-0002wl-6S for bug-gnu-emacs@gnu.org; Fri, 15 Jun 2018 21:33:52 -0400 Original-Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id 0383616087B for ; Fri, 15 Jun 2018 18:33:49 -0700 (PDT) Original-Received: from zimbra.cs.ucla.edu ([127.0.0.1]) by localhost (zimbra.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id dhOiKG05qMdT for ; Fri, 15 Jun 2018 18:33:47 -0700 (PDT) Original-Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id D02CB16099B for ; Fri, 15 Jun 2018 18:33:47 -0700 (PDT) X-Virus-Scanned: amavisd-new at zimbra.cs.ucla.edu Original-Received: from zimbra.cs.ucla.edu ([127.0.0.1]) by localhost (zimbra.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id szDvIe_5LXtS for ; Fri, 15 Jun 2018 18:33:47 -0700 (PDT) Original-Received: from Penguin.CS.UCLA.EDU (Penguin.CS.UCLA.EDU [131.179.64.200]) by zimbra.cs.ucla.edu (Postfix) with ESMTPSA id B019A16087B for ; Fri, 15 Jun 2018 18:33:47 -0700 (PDT) Openpgp: preference=signencrypt Autocrypt: addr=eggert@cs.ucla.edu; prefer-encrypt=mutual; keydata= xsFNBEyAcmQBEADAAyH2xoTu7ppG5D3a8FMZEon74dCvc4+q1XA2J2tBy2pwaTqfhpxxdGA9 Jj50UJ3PD4bSUEgN8tLZ0san47l5XTAFLi2456ciSl5m8sKaHlGdt9XmAAtmXqeZVIYX/UFS 96fDzf4xhEmm/y7LbYEPQdUdxu47xA5KhTYp5bltF3WYDz1Ygd7gx07Auwp7iw7eNvnoDTAl KAl8KYDZzbDNCQGEbpY3efZIvPdeI+FWQN4W+kghy+P6au6PrIIhYraeua7XDdb2LS1en3Ss mE3QjqfRqI/A2ue8JMwsvXe/WK38Ezs6x74iTaqI3AFH6ilAhDqpMnd/msSESNFt76DiO1ZK QMr9amVPknjfPmJISqdhgB1DlEdw34sROf6V8mZw0xfqT6PKE46LcFefzs0kbg4GORf8vjG2 Sf1tk5eU8MBiyN/bZ03bKNjNYMpODDQQwuP84kYLkX2wBxxMAhBxwbDVZudzxDZJ1C2VXujC OJVxq2kljBM9ETYuUGqd75AW2LXrLw6+MuIsHFAYAgRr7+KcwDgBAfwhPBYX34nSSiHlmLC+ KaHLeCLF5ZI2vKm3HEeCTtlOg7xZEONgwzL+fdKo+D6SoC8RRxJKs8a3sVfI4t6CnrQzvJbB n6gxdgCu5i29J1QCYrCYvql2UyFPAK+do99/1jOXT4m2836j1wARAQABzSBQYXVsIEVnZ2Vy dCA8ZWdnZXJ0QGNzLnVjbGEuZWR1PsLBfgQTAQIAKAUCTIByZAIbAwUJEswDAAYLCQgHAwIG FQgCCQoLBBYCAwECH Content-Language: en-US X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 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.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:147469 Archived-At: This is a multi-part message in MIME format. --------------200693BE6EBF92F49695F538 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Tags: patch The memory-limit function has an implementation that is a relic of long-ago days when the heap was allocated via sbrk. This assumption is often no longer true now that ASLR is popular, and once we get portable dumping work it'll be true even less often. Since memory-limit returns nonsense so often and since nobody cares, we can and should mark memory-limit as obsolete. On its way out we can move it to a Lisp implementation and cause it to be at least somewhat more plausible. Proposed patches attached. The first patch moves memory-limit to Lisp, the second one marks it obsolete. I didn't know where to put the Lisp implementation so I put it into lisp/subr.el. --------------200693BE6EBF92F49695F538 Content-Type: text/x-patch; name="0001-Rewrite-memory-limit-in-Lisp.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="0001-Rewrite-memory-limit-in-Lisp.patch" >From 52f4585c1353c3c12079bc7bfe85ef44755134db Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Fri, 15 Jun 2018 18:05:28 -0700 Subject: [PATCH 1/2] Rewrite memory-limit in Lisp Have it return Emacs virtual memory size, not the sbrk value which is often useless newadays. * doc/lispref/internals.texi (Garbage Collection): * etc/NEWS: Document this. * lisp/subr.el (memory-limit): New implementation in Lisp, written in terms of process-attributes, and which returns virtual memory size. * src/alloc.c (Fmemory_limit): Remove C implementation. --- doc/lispref/internals.texi | 6 ++---- etc/NEWS | 3 +++ lisp/subr.el | 4 ++++ src/alloc.c | 19 ------------------- 4 files changed, 9 insertions(+), 23 deletions(-) diff --git a/doc/lispref/internals.texi b/doc/lispref/internals.texi index 9cf1a4f9a3..faaf26f4f7 100644 --- a/doc/lispref/internals.texi +++ b/doc/lispref/internals.texi @@ -507,10 +507,8 @@ Garbage Collection memory Emacs is currently using. @defun memory-limit -This function returns the address of the last byte Emacs has allocated, -divided by 1024. We divide the value by 1024 to make sure it fits in a -Lisp integer. - +This function returns an estimate of the total amount of bytes of +virtual memory that Emacs is currently using, divided by 1024. You can use this to get a general idea of how your actions affect the memory usage. @end defun diff --git a/etc/NEWS b/etc/NEWS index e89402db13..30409a89b5 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -656,6 +656,9 @@ socket has been passed to Emacs (Bug#24218). instead of just Microsoft platforms. This fixes a 'get-free-disk-space' bug on OS X 10.8 and later (Bug#28639). ++++ +** 'memory-limit' now returns a better estimate of memory consumption. + +++ ** New macro 'combine-change-calls' arranges to call the change hooks ('before-change-functions' and 'after-change-functions') just once diff --git a/lisp/subr.el b/lisp/subr.el index 914112ccef..e4da2b2075 100644 --- a/lisp/subr.el +++ b/lisp/subr.el @@ -2182,6 +2182,10 @@ process-put (set-process-plist process (plist-put (process-plist process) propname value))) +(defun memory-limit () + "Return an estimate of Emacs virtual memory usage, divided by 1024." + (or (cdr (assq 'vsize (process-attributes (emacs-pid)))) 0)) + ;;;; Input and display facilities. diff --git a/src/alloc.c b/src/alloc.c index 7b2140501e..52620a54ac 100644 --- a/src/alloc.c +++ b/src/alloc.c @@ -7120,24 +7120,6 @@ or memory information can't be obtained, return nil. */) /* Debugging aids. */ -DEFUN ("memory-limit", Fmemory_limit, Smemory_limit, 0, 0, 0, - doc: /* Return the address of the last byte Emacs has allocated, divided by 1024. -This may be helpful in debugging Emacs's memory usage. -We divide the value by 1024 to make sure it fits in a Lisp integer. */) - (void) -{ - Lisp_Object end; - -#if defined HAVE_NS || defined __APPLE__ || !HAVE_SBRK - /* Avoid warning. sbrk has no relation to memory allocated anyway. */ - XSETINT (end, 0); -#else - XSETINT (end, (intptr_t) (char *) sbrk (0) / 1024); -#endif - - return end; -} - DEFUN ("memory-use-counts", Fmemory_use_counts, Smemory_use_counts, 0, 0, 0, doc: /* Return a list of counters that measure how much consing there has been. Each of these counters increments for a certain kind of object. @@ -7495,7 +7477,6 @@ The time is in seconds as a floating point value. */); defsubr (&Smake_finalizer); defsubr (&Spurecopy); defsubr (&Sgarbage_collect); - defsubr (&Smemory_limit); defsubr (&Smemory_info); defsubr (&Smemory_use_counts); defsubr (&Ssuspicious_object); -- 2.17.1 --------------200693BE6EBF92F49695F538 Content-Type: text/x-patch; name="0002-Obsolete-memory-limit.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="0002-Obsolete-memory-limit.patch" >From 5645d547959780e21fe7c5eff12a0d0ae22702da Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Fri, 15 Jun 2018 18:21:10 -0700 Subject: [PATCH 2/2] Obsolete memory-limit * doc/lispref/internals.texi (Garbage Collection): Remove documentation of memory-limit. * etc/NEWS: Say it's obsolete. * lisp/subr.el (memory-limit): Declare that it's obsolete. --- doc/lispref/internals.texi | 7 ------- etc/NEWS | 3 ++- lisp/subr.el | 1 + 3 files changed, 3 insertions(+), 8 deletions(-) diff --git a/doc/lispref/internals.texi b/doc/lispref/internals.texi index faaf26f4f7..e8fe26856c 100644 --- a/doc/lispref/internals.texi +++ b/doc/lispref/internals.texi @@ -506,13 +506,6 @@ Garbage Collection function @code{memory-limit} provides information on the total amount of memory Emacs is currently using. -@defun memory-limit -This function returns an estimate of the total amount of bytes of -virtual memory that Emacs is currently using, divided by 1024. -You can use this to get a general idea of how your actions affect the -memory usage. -@end defun - @defvar memory-full This variable is @code{t} if Emacs is nearly out of memory for Lisp objects, and @code{nil} otherwise. diff --git a/etc/NEWS b/etc/NEWS index 30409a89b5..a1f853e8cd 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -657,7 +657,8 @@ instead of just Microsoft platforms. This fixes a 'get-free-disk-space' bug on OS X 10.8 and later (Bug#28639). +++ -** 'memory-limit' now returns a better estimate of memory consumption. +** The 'memory-limit' function is now obsolete. You can use +the 'vsize' component of (process-attributes (emacs-pid)) instead. +++ ** New macro 'combine-change-calls' arranges to call the change hooks diff --git a/lisp/subr.el b/lisp/subr.el index e4da2b2075..6af32c95bc 100644 --- a/lisp/subr.el +++ b/lisp/subr.el @@ -2184,6 +2184,7 @@ process-put (defun memory-limit () "Return an estimate of Emacs virtual memory usage, divided by 1024." + (declare (obsolete process-attributes "27.1")) (or (cdr (assq 'vsize (process-attributes (emacs-pid)))) 0)) -- 2.17.1 --------------200693BE6EBF92F49695F538--