Rob Sumners
2017-06-11 16:03:55 UTC
Hi All,
My name is Rob Sumners, and like David Rager, I work a lot with ACL2 and am
interested in adding static conses (or immobile conses) to SBCL as David
described. David submitted a request on this a week or so ago and the
conversation can be seen -- I didn't know how to respond directly.. so sorry
for not knowing how to respond to that conversation and potentially
creating a
new one.
I've looked through SBCL code and added what I think should be a workable
solution, but I wanted to go over the changes to see if they made sense and
if
I am missing something.
I am running tests now and will for a while and have put all of these
changes
behind a build-time feature called "immobile-cons" which itself is only
relevant if one has the immobile-space feature enabled of course.
---------------------------------------------------------
A. Adding support for allocating immobile-conses to SBCL:
---------------------------------------------------------
This is primarily changes to marknsweepgc.c as follows:
1. add alloc_immobile_cons:
lispobj alloc_immobile_cons(lispobj car, lispobj cdr)
{
struct cons* c = (struct cons*)
alloc_immobile_obj(MAKE_ATTR(CEILING(CONS_SIZE,2), // spacing
CEILING(CONS_SIZE,2), // size
1), // is a cons page
car
&immobile_cons_page_hint);
// we already set this in the compare_and_swap of alloc_immobile_obj to
set the "header":
// s->car = car;
s->cdr = cdr;
return make_lispobj(s, LIST_POINTER_LOWTAG);
}
The setting of "1" for the "flags" of the attributes of the page is because
I
needed to tag which pages were "immobile_cons" pages vs. other immobile
object
pages. The reason is that for immobile-cons-pages, we need to change how a
couple of things are handled (both of which are predicated on having conses
(16-bytes on 64-bit platforms) laid out sequentially in the pages with no
extra
space inserted for headers).
2. Currently, a cell in a immobile-obj page is marked to be "free" if
cell[0]
is a fixnum. Assuming no added header to the cons cells in the immobile-cons
page, then cell[0] is the car of the cons and certainly could be a fixnum..
so,
for immobile-cons pages, I used an other-immediate tag which basically
didn't
satisfy is_cons_half and then embedded the offset to the next freelist entry
with a different shift.
3. The other immobile-objs have headers, and the visited/generation info. is
stored in the header. With no header for a cons-cell in the immobile-cons, I
decided that for immobile-cons pages only, I would allocate a 256-byte array
using just calloc with a pointer to this array stored in the fixedobj_pages
entry. This does add a pointer to the fixedobj page structure (taking it
from
12 bytes to 16 or 20 bytes and I realize this may not be desirable). This
is a
little unfortunate but I don't know where I could stuff the
visited/generation
info. in the cons-cells. Since it seems that the current generations (0-7)
and
a visited bit could be stored in a nibble, it might be possible to reduce
this
array in half, but since the generation_index_t type is "signed char" and
there
are comments about possibly supporting more generations, then I would
prefer to
stay consistent with the current code.
----------------------------------------------------------
B. The need to move and resize IMMOBILE and DYNAMIC space:
----------------------------------------------------------
Because of how we use ACL2, we need a lot of memory.. a disgusting amount.
And
this will transfer to the new immobile-cons pages as well. So, currently,
the
IMMOBILE space on linux/x86-64 is allocated to be 128MBs with only 24MB for
fixed immobile. So, we need these to be much bigger (many GBs).. so I would
like to add build-time options to be able to move and size IMMOBILE space
(and
fixed immobile subspace) and move the start of DYNAMIC space. This would be
something that members of the ACL2 community would be informed of .. i.e. if
you plan to use certain features of ACL2 that would likely exceed the
default
memory allocations in SBCL, then you need to rebuild SBCL with these
options.. (and obviously, if the mmap allocations failed (I'm talking
linux/x86-64 more than likely here).. then we can provide help in trying to
relocate the spaces in order to work).
I know that IMMOBILE SPACE must be lower in memory than DYNAMIC SPACE (and
IMMOBILE FIXED is below IMMOBILE VARY) but other than those constraints
being
upheld and aligning the start of these spaces on proper boundaries, are
there
any other limitations or constraints that we should take into account?
I believe it is safe to assume x86-64 for certain and probably Linux
(although
maybe BSD).
---------------------------------------------
C. Implementing the ACL2 interface functions:
---------------------------------------------
There are a lot of issues that I will go over with the ACL2 folks, but I
don't
think are relevant for the SBCL folks..
thanks so much for your time and attention,
-Rob
My name is Rob Sumners, and like David Rager, I work a lot with ACL2 and am
interested in adding static conses (or immobile conses) to SBCL as David
described. David submitted a request on this a week or so ago and the
conversation can be seen -- I didn't know how to respond directly.. so sorry
for not knowing how to respond to that conversation and potentially
creating a
new one.
I've looked through SBCL code and added what I think should be a workable
solution, but I wanted to go over the changes to see if they made sense and
if
I am missing something.
I am running tests now and will for a while and have put all of these
changes
behind a build-time feature called "immobile-cons" which itself is only
relevant if one has the immobile-space feature enabled of course.
---------------------------------------------------------
A. Adding support for allocating immobile-conses to SBCL:
---------------------------------------------------------
This is primarily changes to marknsweepgc.c as follows:
1. add alloc_immobile_cons:
lispobj alloc_immobile_cons(lispobj car, lispobj cdr)
{
struct cons* c = (struct cons*)
alloc_immobile_obj(MAKE_ATTR(CEILING(CONS_SIZE,2), // spacing
CEILING(CONS_SIZE,2), // size
1), // is a cons page
car
&immobile_cons_page_hint);
// we already set this in the compare_and_swap of alloc_immobile_obj to
set the "header":
// s->car = car;
s->cdr = cdr;
return make_lispobj(s, LIST_POINTER_LOWTAG);
}
The setting of "1" for the "flags" of the attributes of the page is because
I
needed to tag which pages were "immobile_cons" pages vs. other immobile
object
pages. The reason is that for immobile-cons-pages, we need to change how a
couple of things are handled (both of which are predicated on having conses
(16-bytes on 64-bit platforms) laid out sequentially in the pages with no
extra
space inserted for headers).
2. Currently, a cell in a immobile-obj page is marked to be "free" if
cell[0]
is a fixnum. Assuming no added header to the cons cells in the immobile-cons
page, then cell[0] is the car of the cons and certainly could be a fixnum..
so,
for immobile-cons pages, I used an other-immediate tag which basically
didn't
satisfy is_cons_half and then embedded the offset to the next freelist entry
with a different shift.
3. The other immobile-objs have headers, and the visited/generation info. is
stored in the header. With no header for a cons-cell in the immobile-cons, I
decided that for immobile-cons pages only, I would allocate a 256-byte array
using just calloc with a pointer to this array stored in the fixedobj_pages
entry. This does add a pointer to the fixedobj page structure (taking it
from
12 bytes to 16 or 20 bytes and I realize this may not be desirable). This
is a
little unfortunate but I don't know where I could stuff the
visited/generation
info. in the cons-cells. Since it seems that the current generations (0-7)
and
a visited bit could be stored in a nibble, it might be possible to reduce
this
array in half, but since the generation_index_t type is "signed char" and
there
are comments about possibly supporting more generations, then I would
prefer to
stay consistent with the current code.
----------------------------------------------------------
B. The need to move and resize IMMOBILE and DYNAMIC space:
----------------------------------------------------------
Because of how we use ACL2, we need a lot of memory.. a disgusting amount.
And
this will transfer to the new immobile-cons pages as well. So, currently,
the
IMMOBILE space on linux/x86-64 is allocated to be 128MBs with only 24MB for
fixed immobile. So, we need these to be much bigger (many GBs).. so I would
like to add build-time options to be able to move and size IMMOBILE space
(and
fixed immobile subspace) and move the start of DYNAMIC space. This would be
something that members of the ACL2 community would be informed of .. i.e. if
you plan to use certain features of ACL2 that would likely exceed the
default
memory allocations in SBCL, then you need to rebuild SBCL with these
options.. (and obviously, if the mmap allocations failed (I'm talking
linux/x86-64 more than likely here).. then we can provide help in trying to
relocate the spaces in order to work).
I know that IMMOBILE SPACE must be lower in memory than DYNAMIC SPACE (and
IMMOBILE FIXED is below IMMOBILE VARY) but other than those constraints
being
upheld and aligning the start of these spaces on proper boundaries, are
there
any other limitations or constraints that we should take into account?
I believe it is safe to assume x86-64 for certain and probably Linux
(although
maybe BSD).
---------------------------------------------
C. Implementing the ACL2 interface functions:
---------------------------------------------
There are a lot of issues that I will go over with the ACL2 folks, but I
don't
think are relevant for the SBCL folks..
thanks so much for your time and attention,
-Rob