all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Dmitry Antipov <dmantipov@yandex.ru>
To: emacs-devel@gnu.org
Subject: Re: Memory again
Date: Mon, 19 Dec 2011 12:28:36 +0400	[thread overview]
Message-ID: <4EEEF5B4.3050806@yandex.ru> (raw)
In-Reply-To: <jwvaa6p8i5i.fsf-monnier+emacs@gnu.org>

[-- Attachment #1: Type: text/plain, Size: 2320 bytes --]

On 12/19/2011 05:34 AM, Stefan Monnier wrote:

> `garbage-collect' is supposed to give that info.  At least it does give
> info about the data that's kept under alloc.c's control because
> of fragmentation (these are counted as "free cells").

I would like to propose a function which explicitly says how much free memory
the Emacs process holds. It's especially useful when there is a way to ask
system malloc about how much free memory is in the heap. This may be helpful
to distinguish real heap fragmentation from memory leaks and other misuses -
if the sum of values returned by 'memory-free' is, say, 10% of heap size,
then the real fragmentation enters into the game.

> Re-read what I wrote: I'm talking about the case where alloc.c free'd the
> data, but malloc did not munmap it.

I read it as 'even if we will fix allocation to use mmap and munmap, unmapped
memory would really be unused and still appear in process RSS, thus giving
higher RSS value than the process really has, until the memory pressure bump
it out of RAM'. That was obviously incorrect because RSS is recalculated
each time when mmap/mremap/munmap/brk is (successfully) called.

> It's easy to predict what it does in terms of "what is the benefit when
> I have a lot of fragmentation".  It's much more difficult to predict
> what it does in terms of "how is it going to affect Emacs's behavior for
> those 99% cases where it currently works just fine".

There is an interesting research paper about moving PLT Scheme from mark-sweep
GC to an accurate copying GC: http://www.cs.utah.edu/plt/publications/ismm09-rwrf.pdf.
In short, it's said about getting rid out of the most fragmentation issues at the cost
of 10-20% slowdown (although I consider their approach as practically inapplicable
beyond the pure research efforts).

> I agree that we're probably going to see better overall results by
> improving general memory use than by trying to attack
> fragmentation problems.

Among this list's subscribers, Nix <nix@[hidden]> is constantly reporting an enormous
memory usage caused by Gnus. Since I newer seen such a heap usage in my own test cases,
I offered him a 'cumulative' patch (against 24.0.92) with both immediate strings and
block vector allocator. He has said that we can expect the first results after Christmas :-).

Dmitry

[-- Attachment #2: memory_free.patch --]
[-- Type: text/plain, Size: 2175 bytes --]

=== modified file 'src/alloc.c'
--- src/alloc.c	2011-12-12 05:32:49 +0000
+++ src/alloc.c	2011-12-19 06:06:04 +0000
@@ -75,6 +75,10 @@
 
 #define MMAP_MAX_AREAS 100000000
 
+/* Value of mallinfo ().fordblks as seen at the end of last GC.  */
+
+static int bytes_free;
+
 #else /* not DOUG_LEA_MALLOC */
 
 /* The following come from gmalloc.c.  */
@@ -5271,6 +5275,10 @@
   total[7] = Fcons (make_number (total_strings),
 		    make_number (total_free_strings));
 
+#ifdef DOUG_LEA_MALLOC
+  bytes_free = mallinfo ().fordblks;
+#endif
+
 #if GC_MARK_STACK == GC_USE_GCPROS_CHECK_ZOMBIES
   {
     /* Compute average percentage of zombies.  */
@@ -6221,6 +6229,33 @@
   return end;
 }
 
+DEFUN ("memory-free", Fmemory_free, Smemory_free, 0, 0, 0,
+       doc: /* Return a list of two counters that measure how much free
+memory is hold by the Emacs process. Both counters are
+in KBytes. First counter shows how much memory holds in
+a free lists maintained by the Emacs itself. Second counter
+shows how much free memory is in the heap. If the second
+counter is zero, heap statistics is not available.  */)
+     (void)
+{
+  Lisp_Object data[2];
+  
+  data[0] = make_number
+    (min (MOST_POSITIVE_FIXNUM,
+	  (total_free_conses * sizeof (struct Lisp_Cons) +
+	   total_free_markers * sizeof (union Lisp_Misc) +
+	   total_free_symbols * sizeof (struct Lisp_Symbol) +
+	   total_free_floats * sizeof (struct Lisp_Float) +
+	   total_free_intervals * sizeof (struct interval) +
+	   total_free_strings * sizeof (struct Lisp_String)) / 1024));
+#ifdef DOUG_LEA_MALLOC
+  data[1] = make_number (min (MOST_POSITIVE_FIXNUM, bytes_free / 1024));
+#else
+  data[1] = make_number (0);
+#endif
+  return Flist (2, data);
+}
+
 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.
@@ -6474,6 +6509,7 @@
   defsubr (&Spurecopy);
   defsubr (&Sgarbage_collect);
   defsubr (&Smemory_limit);
+  defsubr (&Smemory_free);
   defsubr (&Smemory_use_counts);
 
 #if GC_MARK_STACK == GC_USE_GCPROS_CHECK_ZOMBIES


  reply	other threads:[~2011-12-19  8:28 UTC|newest]

Thread overview: 87+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-11-26 13:26 Memory again Carsten Mattner
2011-11-26 13:28 ` Carsten Mattner
2011-11-26 14:35 ` Dmitry Antipov
2011-11-26 14:48   ` Eli Zaretskii
2011-11-26 17:37     ` Dmitry Antipov
2011-11-26 20:19       ` Eli Zaretskii
2011-11-26 14:58   ` Carsten Mattner
2011-11-26 16:23     ` Eli Zaretskii
2011-11-26 19:02       ` Carsten Mattner
2011-11-26 20:31         ` Eli Zaretskii
2011-11-26 21:00           ` Eli Zaretskii
2011-11-27 10:29           ` Carsten Mattner
2011-11-27 10:43             ` Andreas Schwab
2011-11-27 13:53               ` Carsten Mattner
2011-11-27 13:11             ` Eli Zaretskii
2011-11-27 13:53               ` Carsten Mattner
2011-11-27 16:44                 ` Eli Zaretskii
2011-11-27 17:37                   ` Carsten Mattner
2011-11-27 17:59                   ` Carsten Mattner
2011-12-06  4:02       ` Óscar Fuentes
2011-12-06  5:08         ` Eli Zaretskii
2011-12-06  9:35           ` Carsten Mattner
2011-12-06 10:24             ` Dmitry Antipov
2011-12-06 13:07               ` Eli Zaretskii
2011-12-06 13:29               ` Stefan Monnier
2011-12-06 17:20                 ` Eli Zaretskii
2011-12-06 20:25                   ` Stefan Monnier
2011-12-07  7:52                     ` Eli Zaretskii
2011-12-07  8:15                       ` Dmitry Antipov
2011-12-07 13:06                         ` Eli Zaretskii
2011-12-07 14:01                           ` Stefan Monnier
2011-12-08 17:30                             ` Carsten Mattner
2011-12-09  3:39                               ` Dmitry Antipov
2011-12-09 13:52                                 ` Carsten Mattner
2011-12-06 13:12             ` Eli Zaretskii
2011-12-06 16:28           ` Óscar Fuentes
2011-12-06 19:53             ` Stefan Monnier
2011-12-11 17:49               ` Nix
2011-12-15  3:52               ` Tim Connors
2011-12-15  4:09                 ` Eli Zaretskii
2011-12-15  4:38                   ` Tim Connors
2011-12-15  5:52                     ` Eli Zaretskii
2011-12-15  4:50                   ` Óscar Fuentes
2011-12-15  6:04                     ` Eli Zaretskii
2011-12-16 21:55                 ` Stefan Monnier
2011-12-17 17:40                   ` Nix
2011-12-18 15:13                   ` Dmitry Antipov
2011-12-19  1:34                     ` Stefan Monnier
2011-12-19  8:28                       ` Dmitry Antipov [this message]
2011-12-19 11:26                         ` Stefan Monnier
2012-01-23 16:49                           ` Nix
2012-01-25 16:19                             ` Ted Zlatanov
2011-11-26 17:54     ` Dmitry Antipov
2011-11-26 18:47       ` martin rudalics
2011-11-26 19:09       ` Carsten Mattner
2011-11-28  4:27     ` Stefan Monnier
2011-11-28  9:24       ` Carsten Mattner
2011-11-28 15:31         ` Davis Herring
2011-11-28 21:33           ` Carsten Mattner
  -- strict thread matches above, loose matches on Subject: below --
2011-12-19 19:51 emacs user
2011-12-20  5:32 ` Dmitry Antipov
2012-01-06 14:28 ` Chong Yidong
2012-01-06 15:53   ` emacs user
2011-12-20  6:34 emacs user
2011-12-20  7:43 ` Eli Zaretskii
2011-12-20 12:05   ` emacs user
2011-12-20 13:04     ` Eli Zaretskii
2011-12-20 22:07       ` Jan Djärv
2011-12-21  8:07       ` Jan Djärv
2011-12-21 10:39         ` Carsten Mattner
2011-12-21 17:55         ` emacs user
2011-12-22 14:08           ` Jan Djärv
2011-12-22 14:58             ` emacs user
2011-12-22 18:54               ` emacs user
2011-12-22 19:15                 ` Jan Djärv
2011-12-23  4:41                   ` YAMAMOTO Mitsuharu
2012-01-17 10:04                     ` emacs user
2012-01-17 10:58                       ` YAMAMOTO Mitsuharu
2012-01-17 13:14                         ` emacs user
2012-01-18  1:30                           ` YAMAMOTO Mitsuharu
2011-12-22 23:09                 ` Carsten Mattner
2011-12-23  0:39               ` Stefan Monnier
2011-12-23 10:44                 ` emacs user
2012-01-05  6:13                   ` emacs user
2012-01-05 22:37                     ` Jan Djärv
2012-01-06  9:58                       ` emacs user
2012-01-06 11:10                         ` Carsten Mattner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4EEEF5B4.3050806@yandex.ru \
    --to=dmantipov@yandex.ru \
    --cc=emacs-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.