From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 28786 invoked by alias); 22 Nov 2012 09:39:19 -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: 30814 Received: (qmail 8866 invoked from network); 22 Nov 2012 09:39:07 -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=-6.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.2 Received-SPF: none (ns1.primenet.com.au: domain at linux.vnet.ibm.com does not designate permitted sender hosts) Date: Thu, 22 Nov 2012 17:28:47 +0800 From: Han Pingtian To: zsh-workers@zsh.org Subject: Re: argv subscript range uses too many memory Message-ID: <20121122092847.GA2576@localhost.localdomain> 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> <121120102415.ZM5635@torch.brasslantern.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <121120102415.ZM5635@torch.brasslantern.com> User-Agent: Mutt/1.5.21 (2010-09-15) X-Content-Scanned: Fidelis XPS MAILER x-cbid: 12112209-5518-0000-0000-00000977C7C7 On Tue, Nov 20, 2012 at 10:24:15AM -0800, Bart Schaefer wrote: > 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 I have tried this patch. Looks like with this patch on 5.0, both for i in {1..700000}; do true; done and set -- ~/**/* while ((ARGC>=3)) do print -- "${argv[1,3]}" shift 3 done will run very slow, but the memory problem is solved at the sametime.