zsh-workers
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: zsh-workers@zsh.org
Cc: Han Pingtian <hanpt@linux.vnet.ibm.com>
Subject: Re: argv subscript range uses too many memory
Date: Tue, 20 Nov 2012 10:24:15 -0800	[thread overview]
Message-ID: <121120102415.ZM5635@torch.brasslantern.com> (raw)
In-Reply-To: <121120094443.ZM5584@torch.brasslantern.com>

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


  reply	other threads:[~2012-11-20 18:24 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20121108084001.GA7594@localhost.localdomain>
     [not found] ` <20121108100226.575b0788@pwslap01u.europe.root.pri>
     [not found]   ` <20121110105811.GA7136@localhost.localdomain>
     [not found]     ` <121110065709.ZM4781@torch.brasslantern.com>
2012-11-10 21:16       ` Peter Stephenson
     [not found]       ` <20121120130457.GD2500@localhost.localdomain>
     [not found]         ` <121120090300.ZM5552@torch.brasslantern.com>
2012-11-20 17:44           ` Bart Schaefer
2012-11-20 18:24             ` Bart Schaefer [this message]
2012-11-22  9:28               ` Han Pingtian
2012-11-22 18:29                 ` Bart Schaefer
2012-11-25  8:11                   ` Han Pingtian
2012-11-25 19:03                     ` Bart Schaefer
2012-11-29 23:37                       ` Han Pingtian
2012-11-20 21:05             ` Peter Stephenson
2012-11-20 23:22               ` Bart Schaefer
2012-11-22 22:33                 ` Han Pingtian

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

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=121120102415.ZM5635@torch.brasslantern.com \
    --to=schaefer@brasslantern.com \
    --cc=hanpt@linux.vnet.ibm.com \
    --cc=zsh-workers@zsh.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.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

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 NNTP newsgroup(s).