unofficial mirror of bug-guile@gnu.org 
 help / color / mirror / Atom feed
From: Mike Gran <spk121@yahoo.com>
To: "Ludovic Courtès" <ludo@gnu.org>, "Mark H Weaver" <mhw@netris.org>
Cc: "20907@debbugs.gnu.org" <20907@debbugs.gnu.org>
Subject: bug#20907: [PATCH] Manual bug for scm_gc_protect_object
Date: Wed, 2 Sep 2015 15:36:13 +0000 (UTC)	[thread overview]
Message-ID: <1975455902.407587.1441208174259.JavaMail.yahoo@mail.yahoo.com> (raw)
In-Reply-To: <87a8t5c9bf.fsf@gnu.org>

[-- Attachment #1: Type: text/plain, Size: 1527 bytes --]

> On Wednesday, September 2, 2015 5:09 AM, Ludovic Courtès <ludo@gnu.org> wrote:

> I think the manual is correct: global C variables were *not* scanned by
> the GC.  As an example, see ‘scm_sys_protects’ in 1.8: It’s a global
> array that was explicitly scanned by the GC, because that’s basically
> the only mechanism to add new GC root:
> 
>   j = SCM_NUM_PROTECTS;
>   while (j--)
>     scm_gc_mark (scm_sys_protects[j]);
> 
> The 1.8 manual reads:
> 
>      Other references to 'SCM' objects, such as global variables of type
>   'SCM' or other random data structures in the heap that contain fields 
> of
>   type 'SCM', can be made visible to the garbage collector by calling 
> the
>   functions 'scm_gc_protect' or 'scm_permanent_object'.  You 
> normally use
>   these funtions for long lived objects such as a hash table that is
>   stored in a global variable.  For temporary references in local
>   variables or function arguments, using these functions would be too
>   expensive.

For what it is worth, the effect that I was seeing that made me
question the documentation can be demonstrated by the attached program,
where two 100MB Guile strings are stored in a C globals: one protected
and one not. 


In 1.8, a GC operation reduces memory from 200MB to 100MB, which I
assume is freeing the memory from the unprotected string.

In 2.0, the heap size always stays at 200MB.


The output of the program for Guile 1.8.8 and Guile 2.0.9 is attached.


Thanks,
Mike

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: main.c --]
[-- Type: text/x-csrc, Size: 729 bytes --]

#include <libguile.h>


#define ONE_HUNDRED_MILLION (100*1000*1000)

SCM protected_string;
SCM unprotected_string;

void inner_main (void *data, int argc, char **argv)
{
  protected_string = scm_c_make_string(ONE_HUNDRED_MILLION, SCM_MAKE_CHAR('1'));
  scm_gc_protect_object (protected_string);

  unprotected_string = scm_c_make_string(ONE_HUNDRED_MILLION, SCM_MAKE_CHAR('2'));

  scm_display(scm_c_eval_string("(gc-stats)"), scm_current_output_port());
  scm_newline(scm_current_output_port());

  scm_gc();

  scm_display(scm_c_eval_string("(gc-stats)"), scm_current_output_port());
  scm_newline(scm_current_output_port());
}

int main (int argc, char **argv)
{
  scm_boot_guile (argc, argv, inner_main, NULL);
  return 0;
}

[-- Attachment #3: out18.txt --]
[-- Type: text/plain, Size: 884 bytes --]

((gc-time-taken . 0) (cells-allocated . 61611) (total-cells-allocated . 61722) (cell-heap-size . 83383) (bytes-malloced . 200081608) (gc-malloc-threshold . 366816085) (gc-times . 4) (gc-mark-time-taken . 0) (cells-marked . 410017.0) (cells-swept . 458490.0) (malloc-yield . 0) (cell-yield . 0) (protected-objects . 1) (cell-heap-segments (162449408 . 162484224) (3076524032 . 3076694016) (3076700160 . 3076900864) (3076909056 . 3077173248)))
((gc-time-taken . 0) (cells-allocated . 61662) (total-cells-allocated . 61797) (cell-heap-size . 83383) (bytes-malloced . 100081878) (gc-malloc-threshold . 366816085) (gc-times . 5) (gc-mark-time-taken . 0) (cells-marked . 493378.0) (cells-swept . 541875.0) (malloc-yield . 0) (cell-yield . 0) (protected-objects . 1) (cell-heap-segments (162449408 . 162484224) (3076524032 . 3076694016) (3076700160 . 3076900864) (3076909056 . 3077173248)))

[-- Attachment #4: out20.txt --]
[-- Type: text/plain, Size: 370 bytes --]

((gc-time-taken . 967) (heap-size . 219127808) (heap-free-size . 16781312) (heap-total-allocated . 202352336) (heap-allocated-since-gc . 156376) (protected-objects . 40) (gc-times . 6))
((gc-time-taken . 971) (heap-size . 219127808) (heap-free-size . 16809984) (heap-total-allocated . 202354168) (heap-allocated-since-gc . 1384) (protected-objects . 40) (gc-times . 7))

  reply	other threads:[~2015-09-02 15:36 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-06-26 23:00 bug#20907: [PATCH] Manual bug for scm_gc_protect_object Mike Gran
2015-09-02  1:59 ` Mark H Weaver
2015-09-02 12:08   ` Ludovic Courtès
2015-09-02 15:36     ` Mike Gran [this message]
2015-09-02 16:16       ` Mark H Weaver
2015-09-02 16:52         ` Mark H Weaver
2015-09-02 17:12         ` Mike Gran
2015-09-02 18:05           ` Mark H Weaver
2015-09-02 18:34             ` Mike Gran
2016-06-24  6:58               ` Andy Wingo

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=1975455902.407587.1441208174259.JavaMail.yahoo@mail.yahoo.com \
    --to=spk121@yahoo.com \
    --cc=20907@debbugs.gnu.org \
    --cc=ludo@gnu.org \
    --cc=mhw@netris.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.
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).