From: "Mattias Engdegård" <mattiase@acm.org>
To: Tom Gillespie <tgbugs@gmail.com>
Cc: greghendershott@gmail.com, 56623@debbugs.gnu.org
Subject: bug#56623: memory leak introduced by new nonrecursive lisp reader
Date: Wed, 27 Jul 2022 11:20:11 +0200 [thread overview]
Message-ID: <7DC3EB6A-097E-46F1-806E-33C02F01EA47@acm.org> (raw)
In-Reply-To: <ED92BA10-2FBC-45C2-AEBD-F118F4A492DE@acm.org>
It just struck me that you may just be unlucky.
The GC scans the C stack conservatively. The reader rewrite reduced the number of activation records on the stack; instead there is a much more compact marking stack which is scanned precisely, which is both much faster and, well, more precise.
However, in the absence of recursion the size of an on-stack data buffer in the reader was increased substantially (from 64 to 1024) because the danger from stack overflow was gone, and it made for a measurable increase in reading performance.
This means that when the GC now scans the C stack, it has to scan 1024 bytes of typically uninitialised data left over from previous stack activations which could very well include pointers to otherwise dead objects that will now be retained.
A counter-argument is that these undead objects will only be kept artificially alive as long as GC only takes place in the reader. Anyway, the hunch is easily tested: try either or both of these changes:
1. reduce stackbufsize:
--- a/src/lread.c
+++ b/src/lread.c
@@ -2919,7 +2919,7 @@ digit_to_number (int character, int base)
/* Size of the fixed-size buffer used during reading.
It should be at least big enough for `invalid_radix_integer' but
can usefully be much bigger than that. */
-enum { stackbufsize = 1024 };
+enum { stackbufsize = 64 };
static void
invalid_radix_integer (EMACS_INT radix, char stackbuf[VLA_ELEMS (stackbufsize)],
2. zero the buffer on entry:
--- a/src/lread.c
+++ b/src/lread.c
@@ -3678,6 +3678,7 @@ read_stack_push (struct read_stack_entry e)
read0 (Lisp_Object readcharfun, bool locate_syms)
{
char stackbuf[stackbufsize];
+ memset (stackbuf, 0, stackbufsize);
char *read_buffer = stackbuf;
ptrdiff_t read_buffer_size = sizeof stackbuf;
char *heapbuf = NULL;
If either makes things better, maybe we can come up with a solution that doesn't hurt performance.
next prev parent reply other threads:[~2022-07-27 9:20 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-07-17 22:03 bug#56623: memory leak introduced by new nonrecursive lisp reader Tom Gillespie
2022-07-18 11:21 ` Mattias Engdegård
2022-07-27 9:20 ` Mattias Engdegård [this message]
2022-08-27 15:35 ` Lars Ingebrigtsen
2022-08-28 17:29 ` Greg Hendershott
2022-08-28 21:06 ` Tom Gillespie
2022-08-29 12:59 ` Greg Hendershott
2022-08-29 15:20 ` Mattias Engdegård
2022-08-29 15:52 ` Mattias Engdegård
2022-08-29 8:44 ` Gerd Möllmann
2022-08-29 9:38 ` Gerd Möllmann
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=7DC3EB6A-097E-46F1-806E-33C02F01EA47@acm.org \
--to=mattiase@acm.org \
--cc=56623@debbugs.gnu.org \
--cc=greghendershott@gmail.com \
--cc=tgbugs@gmail.com \
/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).