mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Rich Felker <dalias@aerifal.cx>
To: musl@lists.openwall.com
Subject: Re: Proposed approach for malloc to deal with failing brk
Date: Tue, 1 Apr 2014 13:03:54 -0400	[thread overview]
Message-ID: <20140401170354.GA8145@brightrain.aerifal.cx> (raw)
In-Reply-To: <20140401164057.GA8347@cachalot>

On Tue, Apr 01, 2014 at 08:40:57PM +0400, Vasily Kulikov wrote:
> On Sun, Mar 30, 2014 at 20:41 -0400, Rich Felker wrote:
> > We want brk. This is not because "brk is faster than mmap", but
> > because it takes a lot of work to replicate what brk does using mmap,
> > and there's no hope of making a complex dance of multiple syscalls
> > equally efficient. My best idea for emulating brk was to mmap a huge
> > PROT_NONE region and gradually mprotect it to PROT_READ|PROT_WRITE,
> 
> What problem do you try to solve via PROT_NONE -> PROT_WRITE?  Why not
> simply instantly mmap it as PROT_WRITE?  Linux will not allocate physical pages
> until the first access, so you don't lose physical memory when it is not
> actually used.

Commit accounting. Committing 100 megs to a process that's only asked
for (and only going to use) 100k is harmful because, in effect, it
forces people to turn on (or leave on) overcommit.

> > but it turns out this is what glibc does for per-thread arenas and
> > it's really slow, probably because it involves splitting one VMA and
> > merging into another.
> 
> Yes, both VMA split/merge and PTE/etc. changes.

Well the page table changes happen even if you just use madvise to
zero/'free' the memory and then a page fault on write to get it back,
and the latter is very fast compared to the mprotect approach, at
least as far as I can tell. So I think the VMA split/merge is the big
issue.

Rich


      parent reply	other threads:[~2014-04-01 17:03 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-03-31  0:41 Rich Felker
2014-03-31  4:32 ` Rich Felker
2014-03-31  7:44   ` u-igbb
2014-03-31 11:05 ` Szabolcs Nagy
2014-04-01 16:40 ` Vasily Kulikov
2014-04-01 17:01   ` Szabolcs Nagy
2014-04-01 17:03   ` Rich Felker [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=20140401170354.GA8145@brightrain.aerifal.cx \
    --to=dalias@aerifal.cx \
    --cc=musl@lists.openwall.com \
    /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/musl/

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).