[haiku-gsoc] Re: Implementation Queries
- From: Axel Dörfler <axeld@xxxxxxxxxxxxxxxx>
- To: haiku-gsoc@xxxxxxxxxxxxx
- Date: Wed, 28 Jun 2017 13:46:56 +0200
Am 28/06/2017 um 10:38 schrieb Hamish Morrison:
On Wed, Jun 28, 2017 at 6:35 AM, Adrien Destugues
<pulkomandy@xxxxxxxxxxxxx> wrote:
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);
}
The problem is that kmalloc on Linux always returns contiguous memory
(because Linux maps some range of physical memory 1:1 into kernel
virtual address space). So for a correct implementation we need to
always return contiguous memory (although this will be quite expensive
on Haiku).
But if there is a flag called CONTIGUOUS_MEMORY, the software that does
not specify it, and rely on the memory block being contiguous, is buggy.
So I would *not* always hand out contiguous memory until it proves to be
problematic. If there is no software that actually specifies this flag,
I would not do anything to support it right now.
If we start running into problems, we can easily add an allocator that
supports this flag, or even use it as default. If that actually solves
the problem, we could improve that solution, and file bug reports with
the problematic software (that did not specify the flag, but relied on
its outcome).
Contiguous memory is always expensive, and it makes sense to only aks
for it when required.
Bye,
Axel.
Other related posts: