The actual (de)allocation strategy can be explained by using a simple example. Let's say a device driver requests 128 KB of memory. To fulfill this request, the (simplified and conceptual) page allocator algorithm will do this:
- The algorithm expresses the amount to be allocated (128 KB here) in pages. Thus, here, it's (assuming a page size of 4 KB) 128/4 = 32 pages.
- Next, it determines to what power 2 must be raised to get 32. That's log232, which is 5 (as 25 is 32).
- Now, it checks the list on order 5 of the appropriate node:zone page allocator freelist. If a memory chunk is available (it will be of size 25 pages = 128 KB), dequeue it from the list, update the list, and allocate it to the requester. Job done! Return to caller.
Why do we say of the appropriate node:zone page allocator freelist? Does that mean there's more than one of them? Yes, indeed! We repeat: the reality...