zsh-workers
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: zsh-workers@sunsite.dk
Cc: 245678-submitter@bugs.debian.org
Subject: Re: Bug#245678: zsh: built-in rm -rf fills up the memory
Date: Sun, 9 May 2004 15:48:42 -0700 (PDT)	[thread overview]
Message-ID: <Pine.LNX.4.44.0405091518180.29962-100000@toltec.zanshin.com> (raw)
In-Reply-To: <20040508140207.GA25045@scowler.net>

On Sat, 8 May 2004, Clint Adams wrote:

> So, for example, if you have a directory with one hundred files with
> 9-byte filenames, zsh might allocate one hundred 4096-byte areas.

If that's really what's happening, it's a bug somewhere else, because zsh
should only allocate another heap page if the current heap page doesn't
have room for the requested growth.

That is, 409 9-byte file names should need 4090 bytes (add 1 to each for
the NUL byte), and it should put all 4090 of those bytes in the same
4096-byte heap block.  It shouldn't allocate a new heap block until it
gets to the 410th file, at which point it should allocate another
8192-byte block and copy the old block into it, and return the original
4096-byte block to the heap pool for re-use.

(Where I'm assuming HEAP_ARENA_SIZE is 4096 here.)

The following code should *never* be executed unless hrealloc() has
previously been used to *shrink* a block:

    if (p + old < arena(h) + h->used) {
	if (new > old) {
	    char *ptr = (char *) zhalloc(new);
	    memcpy(ptr, p, old);
#ifdef ZSH_MEM_DEBUG
	    memset(p, 0xff, old);
#endif
	    unqueue_signals();
	    return ptr;
	} else {
	    unqueue_signals();
	    return new ? p : NULL;
	}
    }

Because unless we shrank, (p + old == arena(h) + h->used), as asserted by
the DPUTS() that immediately follows.

So, taking #ifdefs for MMAP into account, this code is what should run:

    if (h->used + (new - old) <= HEAP_ARENA_SIZE) {
	h->used += new - old;
	unqueue_signals();
	return p;
    } else {
	char *t = zhalloc(new);
	memcpy(t, p, old > new ? new : old);
	h->used -= old;
#ifdef ZSH_MEM_DEBUG
	memset(p, 0xff, old);
#endif
	unqueue_signals();
	return t;
    }

And you're saying that (h->used + (new - old) <= HEAP_ARENA_SIZE) is 
always false, so the zhalloc() is always called?

If that's not what you find to be the case, then the bug is elsewhere and
we need to keep looking.  If it is what you find, then there's a problem
with h->used record-keeping, or something.


  parent reply	other threads:[~2004-05-10  0:00 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20040424162150.GA4210@ay.vinc17.org>
2004-04-25  1:36 ` Clint Adams
2004-04-25 20:45   ` Bart Schaefer
2004-04-25 21:12     ` Clint Adams
2004-04-25 21:38       ` Clint Adams
2004-04-26 17:10       ` Bart Schaefer
2004-05-08  4:35         ` Clint Adams
2004-05-08 14:02           ` Clint Adams
2004-05-08 14:13             ` Clint Adams
2004-05-09 22:54               ` Bart Schaefer
2004-05-09 22:48             ` Bart Schaefer [this message]
2004-05-09 23:30               ` Clint Adams
2004-05-09 23:36                 ` Clint Adams
2004-05-09 23:51                   ` Bart Schaefer
2004-05-10 10:16                     ` Peter Stephenson
2004-05-10 14:09                       ` Clint Adams
2004-05-10 15:54                       ` Bart Schaefer
2004-05-10 16:19                     ` Peter Stephenson
2004-05-10 16:51                       ` Bart Schaefer
2004-05-10 17:23                         ` Peter Stephenson

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=Pine.LNX.4.44.0405091518180.29962-100000@toltec.zanshin.com \
    --to=schaefer@brasslantern.com \
    --cc=245678-submitter@bugs.debian.org \
    --cc=zsh-workers@sunsite.dk \
    /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).