get_pages uses the algorithm "first fit", but starts now at the last hit

This commit is contained in:
Stefan Lankes 2014-12-04 21:04:22 +01:00
parent 09acfdfdf3
commit 49016fc0c2

View file

@ -90,6 +90,7 @@ inline static void page_clear_mark(size_t i)
size_t get_pages(size_t npages) size_t get_pages(size_t npages)
{ {
size_t cnt, off; size_t cnt, off;
static size_t alloc_start = (size_t) -1;
if (BUILTIN_EXPECT(!npages, 0)) if (BUILTIN_EXPECT(!npages, 0))
return 0; return 0;
@ -98,13 +99,18 @@ size_t get_pages(size_t npages)
spinlock_lock(&bitmap_lock); spinlock_lock(&bitmap_lock);
if (alloc_start == (size_t)-1)
alloc_start = ((size_t) &kernel_end >> PAGE_BITS);
off = 1; off = 1;
while (off <= BITMAP_SIZE*8 - npages) { while (off <= BITMAP_SIZE*8 - npages) {
for (cnt=0; cnt<npages; cnt++) { for (cnt=0; cnt<npages; cnt++) {
if (page_marked(off+cnt)) if (page_marked(((off+alloc_start)%(BITMAP_SIZE*8 - npages))+cnt))
goto next; goto next;
} }
off = (off+alloc_start) % (BITMAP_SIZE*8 - npages);
alloc_start = off+npages;
for (cnt=0; cnt<npages; cnt++) { for (cnt=0; cnt<npages; cnt++) {
page_set_mark(off+cnt); page_set_mark(off+cnt);
} }