Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: argv subscript range uses too many memory



On Nov 20,  9:44am, Bart Schaefer wrote:
}
} So what we need is a fast way to estimate how much uncollected garbage
} is in the heap -- or, conversely, a fast way to estimate how close we
} are to running out of memory -- so that garbage collection can be put
} off until it's necessary.

On a bit more examination, I think perhaps the "bug" is in zhalloc()
itself.

The fheaps pointer should always point to the first arena that has any
free space.  Instead zhalloc() leaves it pointing to the first arena
that has enough space for the requested allocation, or to the most-
recently-allocated arena if no arena has enough space for the request.

So what about the following?  This is still probably incomplete because
(ARENA_SIZEOF(fheap) >= (size + fheap->used)) seems like the wrong test
for whether to begin the search at fheap, but I'm curious whether this
improves the garbage collection behavior.

Index: Src/mem.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/mem.c,v
retrieving revision 1.20
diff -u -r1.20 mem.c
--- Src/mem.c   14 May 2011 17:23:23 -0000      1.20
+++ Src/mem.c   20 Nov 2012 18:12:41 -0000
@@ -507,9 +507,11 @@
 
     /* find a heap with enough free space */
 
-    for (h = ((fheap && ARENA_SIZEOF(fheap) >= (size + fheap->used))
-             ? fheap : heaps);
-        h; h = h->next) {
+    h = (fheap && ARENA_SIZEOF(fheap) >= (size + fheap->used)) ? fheap : heaps;
+    for (fheap = NULL; h; h = h->next) {
+       /* track the first heap with free space in fheap */
+       if (!fheap && h->used < ARENA_SIZEOF(h))
+           fheap = h;
        if (ARENA_SIZEOF(h) >= (n = size + h->used)) {
            void *ret;
 
@@ -566,7 +568,8 @@
            hp->next = h;
        else
            heaps = h;
-       fheap = h;
+       if (!fheap)
+           fheap = h;
 
        unqueue_signals();
 #ifdef ZSH_HEAP_DEBUG



Messages sorted by: Reverse Date, Date, Thread, Author