unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
From: Ian Grant <ian.a.n.grant@googlemail.com>
To: Stefan Israelsson Tampe <stefan.itampe@gmail.com>
Cc: guile-devel <guile-devel@gnu.org>
Subject: Re: implementation idea for infinite cons lists aka scon(e)s lists.
Date: Mon, 15 Sep 2014 14:38:01 -0400	[thread overview]
Message-ID: <CAKFjmdzApwVN0VWLL1UbLvr_3pH+uu2=s8hnJqU124kviQCTRQ@mail.gmail.com> (raw)
In-Reply-To: <CAGua6m1WmqCE0+gE8HvWR0PWfKr+yOdJr3HfWa9t8Sq=gABRMw@mail.gmail.com>

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

On Sat, Sep 13, 2014 at 7:13 AM, Stefan Israelsson Tampe <
stefan.itampe@gmail.com> wrote:

> it is saved from gc by havinga special reference and that we also can see
> if the cons cell have been referenced outside of the
> special references. Then in the sweep phase one can decide to modify the
> cons list to set the cdr to null in say 1000 cons from the
> head. But this modding is only done if there is now referncing of it
> outside the special references. This means that the rest of the tail
> will gc normally and be reclaimed. If however a function wants to analyze
> a part of the list it just references the head and by that the gc
> will not mod any part of the rest of the list and the algorithm can safely
> do it's work. It's in the gc's sweep phase that the list is cut with a
> setcdr!
>
> I think I am beginning to get the picture. This sounds a little like
something I started trying to do with the CAML gc. I called it "recycling
garbage" or "resurrection" because the idea is to have a process whereby
one can reclaim "weak" references which were not really dead. The
theological difficulties with this idea might be considerable, but I
thought this would be good thing to do because some structures are
expensive to allocate: double-precision floats and GMP mpzs, for example.
And in evaluating arithmetic expressions the  CAML runtime repeatedly
throws intermediate values away, and immediately does a far malloc call to
allocate another. I thought if we could keep an array of weak references
and recycle some or all of them between the mark and sweep phases, then
these could make a 'pool' of pre-allocated objects that could reclaimed
just by pointing at them.

Does this fit with your idea? Could we combine these as two reasons to do
this change?

I implemented it, but you may not be too interested in the horrible details
of the ancient CAML gc.
https://github.com/IanANGrant/red-october/commit/1e76f6746eab2f0afa7dbbcd78d3013029e8187b

On a related theme, I have a suggestion for Guile's memory allocation
strategy, which is to document a method of preallocating a page-sized block
of cons cells, for example, Then when one has a fragment of machine code
that is constructing s-exp representations of something or other, that code
can do its own memory management just by switching pointers. I think this
is a sort of simple-minded slab allocator maybe? I had a brief look at the
way the BDW collector does things, and it seemed to me that this could be
done right now, just by directly calling GC_MALLOC from the machine code,
and SCM references which were pointers to the inside of the GC_ALLOCed
block would be enough to keep it from being swept up.  And it looks as if
whatever memory was optimistically allocated this way, and unused at the
end of the construction process, could be freed. Provided it was a
contiguous region, which it usually will be, the BDW collector would split
the block, and free the unused part.

So I don't think there's anything we would need to do to actually implement
this. The only thing is that if it is not enshrined in the Guile API spec,
then it is vulnerable to being 'patched out' without warning one day. So
maybe it only needs a comment in the code somewhere, and a paragraph in the
manual.

Since you've also  spent some time down there in the garbage chute, maybe
you can confirm/deny this?

Ian

[-- Attachment #2: Type: text/html, Size: 4029 bytes --]

  reply	other threads:[~2014-09-15 18:38 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-09-12 20:08 implementation idea for infinite cons lists aka scon(e)s lists Ian Grant
2014-09-13  1:22 ` Ian Grant
2014-09-13 11:19   ` Stefan Israelsson Tampe
2014-09-15 14:37     ` Ian Grant
2014-09-13 11:13 ` Stefan Israelsson Tampe
2014-09-15 18:38   ` Ian Grant [this message]
  -- strict thread matches above, loose matches on Subject: below --
2014-09-10 20:10 Stefan Israelsson Tampe

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='CAKFjmdzApwVN0VWLL1UbLvr_3pH+uu2=s8hnJqU124kviQCTRQ@mail.gmail.com' \
    --to=ian.a.n.grant@googlemail.com \
    --cc=guile-devel@gnu.org \
    --cc=stefan.itampe@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.
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).