[haiku-gsoc] Re: Implementation Queries

  • From: Vivek Roy <vivekroyandroid@xxxxxxxxx>
  • To: haiku-gsoc@xxxxxxxxxxxxx
  • Date: Wed, 28 Jun 2017 14:50:07 +0530


It depends which flags are used. You didn't tell us which flags kmalloc
is using in your use cases.

If you don't know which flags are used, I would start with something like
this:

void* kmalloc(size_t size, uint32_t flags)
{
        if (flags & CONTIGUOUS_MEMORY)
                PANIC("kmalloc doesn't know how to do contiguous memory
yet!");

        if (flags & ...)
                ...

        // ok, nothing special required. few!
        return malloc(size);
}


kmalloc mostly takes GFP flags (GFP_KERNEL being the most popularly used).
Presently I am working with GFP_KERNEL (which is the same as BSD's
M_WAITOK).

From makelinux.net <http://www.makelinux.net/ldd3/chp-8-sect-1>: Using
GFP_KERNEL means that kmalloc can put the current process to sleep waiting
for a page when called in low-memory situations. A function that allocates
memory using GFP_KERNEL must, therefore, be reentrant and cannot be running
in atomic context. While the current process sleeps, the kernel takes
proper action to locate some free memory, either by flushing buffers to
disk or by swapping out memory from a user process.

Thanks

-----
Vivek

Other related posts: