unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Po Lu via "Bug reports for GNU Emacs, the Swiss army knife of text editors" <bug-gnu-emacs@gnu.org>
To: "Mattias Engdegård" <mattiase@acm.org>
Cc: Lars Ingebrigtsen <larsi@gnus.org>, 54698@debbugs.gnu.org
Subject: bug#54698: non-recursive GC marking [PATCH]
Date: Tue, 05 Apr 2022 16:39:30 +0800	[thread overview]
Message-ID: <87czhv53gd.fsf@yahoo.com> (raw)
In-Reply-To: <5BBEDBDA-4C85-4237-9EF7-5635A4950365@acm.org> ("Mattias Engdegård"'s message of "Tue, 5 Apr 2022 10:08:11 +0200")

Mattias Engdegård <mattiase@acm.org> writes:

> Good question! In theory the answer is simple: abort, as with any
> other failed xmalloc.

I think a failed xmalloc will also make Emacs prompt to "C-x s, then
exit".  But the regular memory_full codepath might not work during
garbage collection.  (Mark bits get left around, for example).

> In practice, though, malloc probably won't fail at all -- more likely
> the OS will keep handing out addresses from its 64-bit space and
> slowly swap itself to death. On Linux, the out-of-memory killer will
> murder some essential processes at some point. If you have a hard disk
> you will at least get a premonition of what is going to happen from
> the rumbling.
>
> But it would take a lot of heap for the mark stack requirements to
> become that big; it's much more likely that you run out of memory
> allocating your Lisp objects (or something else) first.

Indeed.

> That's nice! I'm using a monolithic stack because it's easiest and
> gives good performance. A segmented stack would be an alternative for
> extreme memory conditions but the extra segment underflow checks would
> make the common case slower. (I have a patch for using a segmented
> stack in the bytecode engine, where it makes more sense and the
> overhead is lower, but it's still nonzero.)

I agree.

> Frankly I wouldn't trust saving buffers to be possible when growing
> the mark stack wasn't. Have you actually tested this?

That code wasn't tested in an actual out-of-memory situation yet (it's
too soon to consider this), but hopefully it will work.  I think it
works when running out of memory in general, because otherwise it
wouldn't be what memory_full eventually asks the user to do.

Emacs keeps a small amount of malloc'd "spare memory" around during
normal execution, and frees it when running out of memory, so that some
allocation might be able to continue.  I didn't yet touch that
mechanism, but it should perhaps be replaced by a mechanism that
directly allocates objects out of that spare memory.

> That requires some careful invariant maintenance but I could see it
> working. Is the collector generational as well?

It isn't.

> Otherwise I suppose the total GC cost is higher than before, right?

Yes, the total GC cost is higher than before.  Lisp execution during the
garbage collection is also much slower than otherwise, since (for
starters) a linear search through the page aligned "block" of objects is
used every time a hardware write barrier is hit.  There's a lot of other
low hanging fruit for optimization as well, but it's too early to work
on those, since at present the garbage collector is not even working due
to the recent changes that added a manually managed stack to the
bytecode interpreter.

Thanks.






  reply	other threads:[~2022-04-05  8:39 UTC|newest]

Thread overview: 43+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-03 18:40 bug#54698: non-recursive GC marking [PATCH] Mattias Engdegård
2022-04-04 11:01 ` Lars Ingebrigtsen
2022-04-04 11:16   ` Mattias Engdegård
2022-04-04 11:29     ` Lars Ingebrigtsen
2022-04-04 11:31       ` Lars Ingebrigtsen
2022-04-04 11:38     ` Eli Zaretskii
2022-04-04 11:57       ` Mattias Engdegård
2022-04-04 12:25         ` Eli Zaretskii
2022-04-04 17:18           ` Mattias Engdegård
2022-04-05  1:15     ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-04-05  8:08       ` Mattias Engdegård
2022-04-05  8:39         ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors [this message]
2022-04-05 11:11           ` Mattias Engdegård
2022-04-05 11:26             ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-04-05 11:43         ` Eli Zaretskii
2022-04-05 12:31           ` Philipp Stephani
2022-04-05 13:12             ` Eli Zaretskii
2022-04-06  4:09               ` Richard Stallman
2022-04-06  5:48                 ` Phil Sainty
2022-04-06 10:59                 ` Eli Zaretskii
2022-04-06 12:05                   ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-04-06 12:23                     ` Eli Zaretskii
2022-04-06 12:34                       ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-04-06 14:10                         ` Eli Zaretskii
2022-04-06 12:52                       ` Lars Ingebrigtsen
2022-04-08  4:24                     ` Richard Stallman
2022-04-08  5:49                       ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-04-08  6:16                         ` Eli Zaretskii
2022-04-08  7:41                           ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-04-08 11:15                             ` Eli Zaretskii
2022-04-08 11:32                               ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-04-08 11:55                             ` Lars Ingebrigtsen
2022-04-08 11:58                               ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-04-08 12:07                                 ` Lars Ingebrigtsen
2022-04-08 12:16                                   ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-04-08 13:07                                     ` Lars Ingebrigtsen
2022-04-09  0:28                                       ` Phil Sainty
2022-04-08 12:13                               ` Eli Zaretskii
2022-04-04 14:32 ` Andrea Corallo
2022-04-04 14:39   ` Mattias Engdegård
2022-04-04 15:44     ` Andrea Corallo
2022-04-04 16:04       ` Mattias Engdegård
2022-04-05  9:10         ` Andrea Corallo

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

  List information: https://www.gnu.org/software/emacs/

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

  git send-email \
    --in-reply-to=87czhv53gd.fsf@yahoo.com \
    --to=bug-gnu-emacs@gnu.org \
    --cc=54698@debbugs.gnu.org \
    --cc=larsi@gnus.org \
    --cc=luangruo@yahoo.com \
    --cc=mattiase@acm.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 public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).