From: "Ludovic Courtès" <ludo@gnu.org>
To: 59021-done@debbugs.gnu.org
Cc: Andy Wingo <wingo@pobox.com>
Subject: bug#59021: Unbounded heap growth when combining dynamic states & delimited continuation
Date: Sun, 20 Nov 2022 18:28:13 +0100 [thread overview]
Message-ID: <87mt8l5ydu.fsf@gnu.org> (raw)
In-Reply-To: <877d09hxcp.fsf@gnu.org> ("Ludovic Courtès"'s message of "Sat, 05 Nov 2022 23:04:22 +0100")
Hi,
Ludovic Courtès <ludo@gnu.org> skribis:
> Ludovic Courtès <ludo@gnu.org> skribis:
>
>> Consider this code:
>>
>> ;; https://issues.guix.gnu.org/58631
>> ;; https://github.com/wingo/fibers/issues/65
>>
>> (define loss
>> (make-vector 1000000))
>>
>> (let ((tag (make-prompt-tag "my prompt")))
>> (define handler
>> (lambda (k i)
>> (when (zero? (modulo i 2000000))
>> (pk 'heap-size (assoc-ref (gc-stats) 'heap-size)))
>>
>> (call-with-prompt tag
>> (lambda ()
>> (k (modulo (+ 1 i) 10000000)))
>> handler)))
>>
>> (call-with-prompt tag
>> (let ((state (current-dynamic-state)))
>> (lambda ()
>> ;; (define (with-dynamic-state state thunk)
>> ;; (let ((previous #f))
>> ;; (dynamic-wind
>> ;; (lambda () (set! previous (set-current-dynamic-state state)))
>> ;; thunk
>> ;; (lambda () (set-current-dynamic-state previous)))))
>> (with-dynamic-state state
>> (lambda ()
>> (let loop ((i 0))
>> (loop (abort-to-prompt tag i)))))))
>> handler))
>>
>> On Guile 3.0.8, this program exhibits seemingly unbounded heap growth.
>
> This is fixed by the patch below (tested against the test case above and
> the Fibers and Shepherd test cases mentioned before):
Pushed as e47a153317c046ea5d335940412999e7dc604c33.
> Using a simple heap profiler (more on that later), I noticed that the
> stacks allocated at ‘p->stack_bottom’ would be partly retained,
> explaining the heap growth.
>
> I couldn’t pinpoint what exactly is keeping a pointer to the stack, but
> what I can tell is that the trick above makes that impossible (because
> we disable interior pointer tracing), hence the difference.
>
> Also, why changing the SCM_DYNSTACK_TYPE_DYNAMIC_STATE entry to an
> SCM_DYNSTACK_TYPE_UNWINDER entry would make a difference remains a
> mystery to me.
>
> I’m interested in theories that would explain all this in more detail!
> I’ll go ahead with the fix above if there are no objections.
I still am. :-)
Ludo’.
next prev parent reply other threads:[~2022-11-20 17:28 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-04 18:24 bug#59021: Unbounded heap growth when combining dynamic states & delimited continuation Ludovic Courtès
2022-11-05 22:04 ` Ludovic Courtès
2022-11-20 17:28 ` Ludovic Courtès [this message]
2022-11-07 16:03 ` Maxim Cournoyer
2022-11-07 21:52 ` Maxim Cournoyer
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/guile/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87mt8l5ydu.fsf@gnu.org \
--to=ludo@gnu.org \
--cc=59021-done@debbugs.gnu.org \
--cc=wingo@pobox.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.
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).