emacs-bug-tracker
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#59021: closed (Unbounded heap growth when combining dynamic states &


From: GNU bug Tracking System
Subject: bug#59021: closed (Unbounded heap growth when combining dynamic states & delimited continuation)
Date: Sun, 20 Nov 2022 17:29:02 +0000

Your message dated Sun, 20 Nov 2022 18:28:13 +0100
with message-id <87mt8l5ydu.fsf@gnu.org>
and subject line Re: bug#59021: Unbounded heap growth when combining dynamic 
states & delimited continuation
has caused the debbugs.gnu.org bug report #59021,
regarding Unbounded heap growth when combining dynamic states & delimited 
continuation
to be marked as done.

(If you believe you have received this mail in error, please contact
help-debbugs@gnu.org.)


-- 
59021: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=59021
GNU Bug Tracking System
Contact help-debbugs@gnu.org with problems
--- Begin Message --- Subject: Unbounded heap growth when combining dynamic states & delimited continuation Date: Fri, 04 Nov 2022 19:24:50 +0100 User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.1 (gnu/linux)
(This is a followup to <https://github.com/wingo/fibers/issues/65>,
itself a followup to <https://issues.guix.gnu.org/58631>.)

Consider this code:

--8<---------------cut here---------------start------------->8---
;; 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))
--8<---------------cut here---------------end--------------->8---

On Guile 3.0.8, this program exhibits seemingly unbounded heap growth.
Uncommenting the local ‘with-dynamic-state’ definition fixes the
problem.

Ludo’.



--- End Message ---
--- Begin Message --- Subject: Re: bug#59021: Unbounded heap growth when combining dynamic states & delimited continuation Date: Sun, 20 Nov 2022 18:28:13 +0100 User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.2 (gnu/linux)
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’.


--- End Message ---

reply via email to

[Prev in Thread] Current Thread [Next in Thread]