Re: Buddy allocator - help! I thought I understood this

Linus Torvalds (torvalds@transmeta.com)
Sat, 8 Sep 2001 01:47:15 +0000 (UTC)


In article <525190103.999719280@[10.132.112.53]>,
Alex Bligh - linux-kernel <linux-kernel@alex.org.uk> wrote:
>I could swear I understood this bit of __free_pages_ok()
>Monday night, but my mind appears to have gone blank.
>
>As I recall, the memory bitmaps indicate by the
>status a bit op returns whether or not a page
>is on the free list for that particular order
>area.

No. It actually indicates that the _buddy_ of the page is on the free
list for that particular order.

Basically each bit describes two pages of the order in question, which
is sufficient because while they have four states (both free, first
free, second free, neither free), we get the "other bit" of information
from the fact that we are just freeing one page - which obviously cannot
have been free before.

Thus the games with xor'ing the bit around, and looking at the old
state.

And no, most kernel programmers don't have to actually follow that piece
of code. Ugly but efficient.

Linus
-
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/