zsh-workers
 help / color / mirror / code / Atom feed
From: Han Pingtian <hanpt@linux.vnet.ibm.com>
To: zsh-workers@zsh.org
Subject: Re: argv subscript range uses too many memory
Date: Fri, 23 Nov 2012 06:33:08 +0800	[thread overview]
Message-ID: <20121122223308.GB2576@localhost.localdomain> (raw)
In-Reply-To: <121120152257.ZM5937@torch.brasslantern.com>

Hi Bart,

I have tried your suggestion. Looks like this patch on 5.0 resolve both
problem. The for loop of 29175 run about 5 seconds on my loptop and the
while loop only used ~180M memory on my loptop, it does't trigger
oom-killer any more.


diff --git a/Src/mem.c b/Src/mem.c
index 5275c6c..0e4d258 100644
--- a/Src/mem.c
+++ b/Src/mem.c
@@ -106,7 +106,7 @@ union mem_align {
 };
 
 #define H_ISIZE  sizeof(union mem_align)
-#define HEAPSIZE (16384 - H_ISIZE)
+#define HEAPSIZE (163840 - H_ISIZE)
 /* Memory available for user data in default arena size */
 #define HEAP_ARENA_SIZE (HEAPSIZE - sizeof(struct heap))
 #define HEAPFREE (16384 - H_ISIZE)
@@ -319,28 +319,8 @@ freeheap(void)
     h_free++;
 #endif
 
-    /* At this point we used to do:
     fheap = NULL;
-     *
-     * When pushheap() is called, it sweeps over the entire heaps list of
-     * arenas and marks every one of them with the amount of free space in
-     * that arena at that moment.  zhalloc() is then allowed to grab bits
-     * out of any of those arenas that have free space.
-     *
-     * With the above reset of fheap, the loop below sweeps back over the
-     * entire heap list again, resetting the free space in every arena to
-     * the amount stashed by pushheap() and finding the first arena with
-     * free space to optimize zhalloc()'s next search.  When there's a lot
-     * of stuff already on the heap, this is an enormous amount of work,
-     * and performance goes to hell.
-     *
-     * However, there doesn't seem to be any reason to reset fheap before
-     * beginning this loop.  Either it's already correct, or it has never
-     * been set and this loop will do it, or it'll be reset from scratch
-     * on the next popheap().  So all that's needed here is to pick up
-     * the scan wherever the last pass [or the last popheap()] left off.
-     */
-    for (h = (fheap ? fheap : heaps); h; h = hn) {
+    for (h = heaps; h; h = hn) {
 	hn = h->next;
 	if (h->sp) {
 #ifdef ZSH_MEM_DEBUG
@@ -377,7 +357,7 @@ freeheap(void)
     if (hl)
 	hl->next = NULL;
     else
-	heaps = fheap = NULL;
+	heaps = NULL;
 
     unqueue_signals();
 }


      reply	other threads:[~2012-11-22 22:33 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
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 [this message]

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=20121122223308.GB2576@localhost.localdomain \
    --to=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).