From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 13490 invoked by alias); 20 Nov 2012 18:24:27 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 30809 Received: (qmail 26894 invoked from network); 20 Nov 2012 18:24:25 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.2 Received-SPF: none (ns1.primenet.com.au: domain at closedmail.com does not designate permitted sender hosts) From: Bart Schaefer Message-id: <121120102415.ZM5635@torch.brasslantern.com> Date: Tue, 20 Nov 2012 10:24:15 -0800 In-reply-to: <121120094443.ZM5584@torch.brasslantern.com> Comments: In reply to Bart Schaefer "Re: argv subscript range uses too many memory" (Nov 20, 9:44am) References: <20121108084001.GA7594@localhost.localdomain> <20121108100226.575b0788@pwslap01u.europe.root.pri> <20121110105811.GA7136@localhost.localdomain> <121110065709.ZM4781@torch.brasslantern.com> <20121120130457.GD2500@localhost.localdomain> <121120090300.ZM5552@torch.brasslantern.com> <121120094443.ZM5584@torch.brasslantern.com> X-Mailer: OpenZMail Classic (0.9.2 24April2005) To: zsh-workers@zsh.org Subject: Re: argv subscript range uses too many memory Cc: Han Pingtian MIME-version: 1.0 Content-type: text/plain; charset=us-ascii 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