From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Ludovic =?UTF-8?Q?Court=C3=A8s?= Newsgroups: gmane.lisp.guile.bugs Subject: bug#59021: Unbounded heap growth when combining dynamic states & delimited continuation Date: Sun, 20 Nov 2022 18:28:13 +0100 Message-ID: <87mt8l5ydu.fsf@gnu.org> References: <87h6zelgr1.fsf@inria.fr> <877d09hxcp.fsf@gnu.org> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="31170"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.2 (gnu/linux) Cc: Andy Wingo To: 59021-done@debbugs.gnu.org Original-X-From: bug-guile-bounces+guile-bugs=m.gmane-mx.org@gnu.org Sun Nov 20 18:29:27 2022 Return-path: Envelope-to: guile-bugs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1owo8E-0007oH-Fk for guile-bugs@m.gmane-mx.org; Sun, 20 Nov 2022 18:29:26 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1owo7s-0002oZ-ED; Sun, 20 Nov 2022 12:29:04 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1owo7r-0002oD-16 for bug-guile@gnu.org; Sun, 20 Nov 2022 12:29:03 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1owo7q-0008Ub-OE for bug-guile@gnu.org; Sun, 20 Nov 2022 12:29:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1owo7q-0002cc-Jg for bug-guile@gnu.org; Sun, 20 Nov 2022 12:29:02 -0500 Resent-From: Ludovic =?UTF-8?Q?Court=C3=A8s?= Original-Sender: "Debbugs-submit" Resent-To: bug-guile@gnu.org Resent-Date: Sun, 20 Nov 2022 17:29:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: cc-closed 59021 X-GNU-PR-Package: guile Mail-Followup-To: 59021@debbugs.gnu.org, ludo@gnu.org, ludo@gnu.org Original-Received: via spool by 59021-done@debbugs.gnu.org id=D59021.166896530710023 (code D ref 59021); Sun, 20 Nov 2022 17:29:02 +0000 Original-Received: (at 59021-done) by debbugs.gnu.org; 20 Nov 2022 17:28:27 +0000 Original-Received: from localhost ([127.0.0.1]:44471 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1owo7G-0002bb-MQ for submit@debbugs.gnu.org; Sun, 20 Nov 2022 12:28:26 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:48474) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1owo7E-0002bP-Jh for 59021-done@debbugs.gnu.org; Sun, 20 Nov 2022 12:28:25 -0500 Original-Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1owo79-0008Rg-8M; Sun, 20 Nov 2022 12:28:19 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=MIME-Version:In-Reply-To:Date:References:Subject:To: From; bh=77EnR5Gv1ltEfXut8Sst0Tu+hpJPpBuE/E3sm9f+CU0=; b=fyUsQcgmUOzj+RMuUclh GVNESvBfSMFiDrFQsLILpmwU0o4X0MXG6jnc75qUabc+i5KJllhGGFz5twT/N/MD04lFS6kpD38L8 jf/lgWX8yQZWU4p5TvIOeOCvNliGyiabMR9mMolpd3Mms/H0mG08dptRPymfYdBwCHcFTWtz5s45t e63dtSsZnlEWiuIx6+T39puX49WTXuPUjgRF4ViYoH+bXLfIlMlzpLdCORym/ykkvgEr04FQBoSiZ uXNndGrWmlDz4nYfUIp/mR835MfDV0f6H1pNuawoKwpDRCDc7h+ETLS6TowhrgRj/hFJKhmH9KmHE xTmVdUtcHFdonw==; Original-Received: from [2a01:e0a:1d:7270:af76:b9b:ca24:c465] (helo=ribbon) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1owo77-0006P0-2n; Sun, 20 Nov 2022 12:28:18 -0500 In-Reply-To: <877d09hxcp.fsf@gnu.org> ("Ludovic =?UTF-8?Q?Court=C3=A8s?="'s message of "Sat, 05 Nov 2022 23:04:22 +0100") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-guile@gnu.org List-Id: "Bug reports for GUILE, GNU's Ubiquitous Extension Language" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-guile-bounces+guile-bugs=m.gmane-mx.org@gnu.org Original-Sender: bug-guile-bounces+guile-bugs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.lisp.guile.bugs:10440 Archived-At: Hi, Ludovic Court=C3=A8s skribis: > Ludovic Court=C3=A8s 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 st= ate))) >> ;; 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 =E2=80=98p->stack_bottom=E2=80=99 would be partly ret= ained, > explaining the heap growth. > > I couldn=E2=80=99t pinpoint what exactly is keeping a pointer to the stac= k, 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=E2=80=99m interested in theories that would explain all this in more de= tail! > I=E2=80=99ll go ahead with the fix above if there are no objections. I still am. :-) Ludo=E2=80=99.