This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Using ggc-page with plain malloc
- To: gcc at gcc dot gnu dot org
- Subject: Re: Using ggc-page with plain malloc
- From: Wolfram Gloger <Wolfram dot Gloger at dent dot med dot uni-muenchen dot de>
- Date: Fri, 21 Jan 2000 10:00:00 +0100 ("MET)
- References: <orembhepjt.fsf@garnize.lsd.ic.unicamp.br>
Hello,
Sorry for the late followup to this.
> >> I've been trying to arrange for ggc-page to work upon plain malloc.
> >> All it needs is some way to ask for a memory area aligned at a page
> >> boundary. It's a bit tricky, because of wide variations among the
> >> malloc() implementations, but I believe it can made to work well
> >> unless someone finds some platform that breaks the following program
> >> in a way that is too hard to fix.
>
> > Wouldn't it be simpler to use a system interface for obtaining aligned
> > memory? valloc(3) is part of Single Unix, and it gives you
> > sysconf(_SC_PAGESIZE)-aligned memory. In addition (or alternatively?),
> > memalign gives you arbitrarily-aligned memory.
>
> We already use valloc when it's available. But there are systems that
> don't support it, and that's precisely the fallback I'm trying to
> create.
I was initially going to suggest using memalign() instead of valloc(),
but that seems to be rather non-standardized (neither ANSI C nor
Single Unix mention it at all, that surprised me). Also note that SUS
marks valloc() as `Legacy' and says:
Applications should avoid using valloc() but should use malloc()
or mmap() instead. On systems with a large page size, the number
of successful valloc() operations may be zero.
A memalign() emulation via malloc() is certainly the most portable
solution, however using it a lot (for, e.g. allocating a single page)
is a dead-sure method for fragmenting the heap badly.
I would suggest to use anonymous mmap() or mmap() on /dev/zero
(whereever one of those is available) to obtain pages of memory.
Regards,
Wolfram.