[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Bootmem allocator
Joseph A. Knapka wrote:
> Disclaimer: I have ignored the bootmem allocator
> thus far, but I presume it works very much like
> the old 2.2 bootmem allocation code, so I'll
> try to answer your questions on that basis... but
> maybe I'll be wrong :-)
I've looked at it and started writing some docs, but I
think I should correct my mistakes here first :-)
> A. Supreeth Reddy wrote:
>
>> Hi All,
>>
>> I am trying to understand how the bootmem allocator is designed. I
>> have the
>> following questions in the bootmem allocator.
>>
>> 1. Does it give memory in a sequential fashion in terms of pages or
>> does it
>> allow any allocation of powers of 2 ?
>
>
> Sequentially; you ask for a particular number of pages
> and you get the lowest-address available free pages.
I was wrong. You ask for a particular number of bytes with
a particular alignment (power of 2 bytes), and you get the
lowest-address available chunk that fulfills your
alignment requirement. The bootmem allocator attempts to
merge sub-page-sized requests if possible, within the
constraints of the requested alignment.
That's what all the masking and shifting is about in
__alloc_bootmem_core() around line 190 of bootmem.c,
right after the "found:" label. (I'm looking at 2.4.0 source,
incidentally).
>
>> 2. Is only 1/8 th of the whole memory after "_end" given to bootmem
>> allocator, since in init_bootmem_core () there is something like
>> mapsize = (( end - start) + 7)/8;
>
> The bootmem map is a bitmap, so 1 bit/page, not
> 1 byte/page.
Got that one right...
>> 3. Does the function __alloc_bootmem_alloc () try to concatenate 2
>> subsequent allocations to avoid internal fragmentation ?
>
>
> I expect so.
>
>
>> 4. And what is the purpose of last_offset and last_pos fields in the
>> bootmem_data_t structure, I find that they are used only in
>> __alloc_bootmem_alloc () function.
>>
>
> This may be something involving NUMA.
Bzzzt, wrong answer. last_pos is (I think) the last
page (highest address) from which an allocation was done,
and last_offset was the offset within the page of that
allocation. The offset data is used to do merges of sub-page
requests.
Regards,
-- Joe
-- Joseph Knapka
"If I ever get reincarnated... let me make certain I don't come back
as a paperclip." -- protagonist, H Murakami's "Hard-boiled Wonderland"
// Linux MM Documentation in progress:
// http://home.earthlink.net/~jknapka/linux-mm/vmoutline.html
* Evolution is an "unproven theory" in the same sense that gravity is. *
-
Kernelnewbies: Help each other learn about the Linux kernel.
Archive: http://mail.nl.linux.org/
IRC Channel: irc.openprojects.net / #kernelnewbies
Web Page: http://www.kernelnewbies.org/