Re: allocate memory in userspace

From: William Lee Irwin III (wli@holomorphy.com)
Date: Tue Jul 02 2002 - 03:44:18 EST


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.

Cheers,
Bill
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/



This archive was generated by hypermail 2b29 : Sun Jul 07 2002 - 22:00:09 EST