From: Erik Andersen <andersen@codepoet.org>
To: William Lee Irwin III <wli@holomorphy.com>,
Timo Benk <t_benk@web.de>,
linux-kernel <linux-kernel@vger.kernel.org>
Subject: Re: allocate memory in userspace
Date: Tue, 2 Jul 2002 03:00:03 -0600 [thread overview]
Message-ID: <20020702090002.GA6370@codepoet.org> (raw)
In-Reply-To: <20020702084418.GR22961@holomorphy.com>
On Tue Jul 02, 2002 at 01:44:18AM -0700, William Lee Irwin III wrote:
> On Mon, Jul 01, 2002 at 11:49:13AM -0600, Erik Andersen wrote:
> >> void *malloc(size_t size)
> >> {
> >> void *result;
> >> if (size == 0)
> >> return NULL;
> >> result = mmap((void *) 0, size + sizeof(size_t), PROT_READ | PROT_WRITE,
> >> MAP_PRIVATE | MAP_ANONYMOUS, 0, 0);
> >> if (result == MAP_FAILED)
> >> return 0;
> >> * (size_t *) result = size;
> >> return(result + sizeof(size_t));
> >> }
>
> On Tue, Jul 02, 2002 at 01:37:37AM -0700, William Lee Irwin III wrote:
> > This looks like a very bad idea. Userspace allocators should make some
> > attempt at avoiding diving into the kernel at every allocation like this.
>
> Sorry, I also forgot the rather severe internal fragmentation this is
> likely to suffer due to page-level restrictions on mmap's operation.
Of course. No question there -- actually using such an allocator
(with a standard linux kernel) would be a terrible idea. I was
merely providing a trivial answer to his question on how to use
mmap to allocate memory.
-Erik
--
Erik B. Andersen http://codepoet-consulting.com/
--This message was written using 73% post-consumer electrons--
next prev parent reply other threads:[~2002-07-02 8:57 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-07-01 17:26 Timo Benk
2002-07-01 17:49 ` Erik Andersen
2002-07-02 8:37 ` William Lee Irwin III
2002-07-02 8:44 ` William Lee Irwin III
2002-07-02 9:00 ` Erik Andersen [this message]
2002-07-01 18:39 ` Calin A. Culianu
2002-07-02 7:51 ` allocate memory in userspace (Answer) Timo Benk
2002-07-02 10:24 ` Timo Benk
2002-07-02 12:19 ` allocate memory in userspace Brian Gerst
[not found] <20020701172659.GA4431@toshiba.suse.lists.linux.kernel>
2002-07-02 9:30 ` Andi Kleen
2002-07-02 10:21 ` Timo Benk
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=20020702090002.GA6370@codepoet.org \
--to=andersen@codepoet.org \
--cc=linux-kernel@vger.kernel.org \
--cc=t_benk@web.de \
--cc=wli@holomorphy.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.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®