This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Perfomance of gc-simple



> > I recall Alexandre Oliva starting discussion about making gc-page use simple
> > malloc(), what about that?
> 
> You can easily use malloc() instead of mmap().  Just call malloc() with
> size+page_size-1 and align the return value.

What about a vmalloc that wraps calls to malloc?

Here is a crude implementation I came up with:

vmalloc_wrap.c:

#include <stdlib.h>
#include <unistd.h>

#ifndef HAVE_VMALLOC

#define VMALLOC_FREE(x) vmalloc_free (x)

static const unsigned int ptr_size = sizeof(char *);

void *
vmalloc (size_t size)
{
  char *unaligned_ptr, *aligned_ptr;
  int page_size = getpagesize();

  /* Provide space for aligning the returned pointer.  */
  size += page_size - 1;

  unaligned_ptr = malloc (size);

  /* Now align the pointer.  */
  aligned_ptr = (char *)((unsigned long)(unaligned_ptr + page_size) & ~(page_size - 
1));

  /* Record location to pass to free() in unused allocated space.  */
  *((char **)(aligned_ptr - ptr_size)) = unaligned_ptr;
  
  return aligned_ptr;
}


void
vmalloc_free (void *aligned_ptr)
{
  /* Recover the pointer allocated with malloc.  */
  char *unaligned_ptr = *(char **)((char *)(aligned_ptr - ptr_size));

  free (unaligned_ptr);
}
#else
#define VMALLOC_FREE(x) free (x)
#endif


Then use VMALLOC_FREE in ggc-page.c instead of free.

Mark


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]