diff options
author | Ian Moffett <ian@osmora.org> | 2024-01-10 18:56:44 -0500 |
---|---|---|
committer | Ian Moffett <ian@osmora.org> | 2024-01-10 18:57:12 -0500 |
commit | a4e6328b6e91d582c4579554c293995e3d4f8851 (patch) | |
tree | 06e8ecd6842c3b0ad35472ab20bb416e4e2c8b07 /sys | |
parent | 6a43636fc0be60fcb9b6761981480f2bb9da41f8 (diff) |
kernel: vm: Cleanup pageframe allocation
Signed-off-by: Ian Moffett <ian@osmora.org>
Diffstat (limited to 'sys')
-rw-r--r-- | sys/vm/vm_physseg.c | 70 |
1 files changed, 16 insertions, 54 deletions
diff --git a/sys/vm/vm_physseg.c b/sys/vm/vm_physseg.c index c149c34..ee7f06e 100644 --- a/sys/vm/vm_physseg.c +++ b/sys/vm/vm_physseg.c @@ -174,68 +174,30 @@ vm_physseg_bitmap_init(void) vm_physseg_bitmap_populate(); } -static uintptr_t -vm_alloc_pageframe_internal(size_t count) +uintptr_t +vm_alloc_pageframe(size_t count) { - bool can_alloc = false; + size_t pages = 0; + size_t tmp; - bool is_free; /* True if we found a free frame */ - size_t free_count = 0; /* How many we found that are free? */ - uintptr_t frame_idx = 0; /* The base index of first free frame */ + while (last_used_idx < highest_frame_idx) { + if (!bitmap_test_bit(bitmap, last_used_idx++)) { + /* We have a free page */ + if (++pages != count) + continue; - for (size_t i = last_used_idx; i < bitmap_size*8; ++i) { - if (free_count == count) { - can_alloc = true; - break; - } + tmp = last_used_idx - count; - is_free = !bitmap_test_bit(bitmap, i); + for (size_t i = tmp; i < last_used_idx; ++i) + bitmap_set_bit(bitmap, i); - if (!is_free) { - free_count = 0; - continue; + return tmp * vm_get_page_size(); + } else { + pages = 0; } - - /* Assume free here */ - if (frame_idx == 0) - frame_idx = i; - - ++free_count; } - if (!can_alloc) { - /* No free memory! */ - last_used_idx = 0; - return 0; - } - - /* Mark the memory as allocated */ - for (size_t i = frame_idx; i < frame_idx+count; ++i) { - bitmap_set_bit(bitmap, i); - } - - /* Return the physical address */ - last_used_idx = frame_idx; - return frame_idx*vm_get_page_size(); -} - -/* - * Allocates physical pageframes. - * - * @count: Number of pageframes to allocate. - */ -uintptr_t -vm_alloc_pageframe(size_t count) -{ - uintptr_t phys; - - phys = vm_alloc_pageframe_internal(count); - - if (phys == 0) - return 0; - - vm_zero_page(PHYS_TO_VIRT(phys), count); - return phys; + return 0; } /* |