|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [mini-os master] mm: refactor init_page_allocator()
commit 2163e3f80a095893069137cc0a9146034efa382d
Author: Juergen Gross <jgross@xxxxxxxx>
AuthorDate: Wed Jul 9 16:42:12 2025 +0200
Commit: Jan Beulich <jbeulich@xxxxxxxx>
CommitDate: Wed Jul 9 16:42:12 2025 +0200
mm: refactor init_page_allocator()
Split init_page_allocator() into three functions in order to prepare
for sparing some memory from being added to the buddy allocator.
Use a function pointer for selecting the function used for handling a
memory range, as this will be needed by a future patch. For the same
reason make iterate_memory_range() globally visible.
Signed-off-by: Juergen Gross <jgross@xxxxxxxx>
Reviewed-by: Jason Andryuk <jason.andryuk@xxxxxxx>
---
include/mm.h | 3 ++
mm.c | 111 +++++++++++++++++++++++++++++++++--------------------------
2 files changed, 66 insertions(+), 48 deletions(-)
diff --git a/include/mm.h b/include/mm.h
index 0a16d56..1dc89dd 100644
--- a/include/mm.h
+++ b/include/mm.h
@@ -95,4 +95,7 @@ void fini_mm(void);
void change_readonly(bool readonly);
+void iterate_memory_range(unsigned long min, unsigned long max,
+ void (*func)(unsigned long, unsigned long));
+
#endif /* _MM_H_ */
diff --git a/mm.c b/mm.c
index 9236db5..858dc10 100644
--- a/mm.c
+++ b/mm.c
@@ -150,16 +150,74 @@ static void dequeue_elem(chunk_head_t *elem)
elem->next->prev = elem->prev;
}
+static void add_memory_range(unsigned long r_min, unsigned long r_max)
+{
+ unsigned int i;
+ unsigned long range;
+ chunk_head_t *ch;
+
+ printk(" Adding memory range %lx-%lx\n", r_min, r_max);
+
+ /* The buddy lists are addressed in high memory. */
+ r_min = (unsigned long)to_virt(r_min);
+ r_max = (unsigned long)to_virt(r_max);
+ range = r_max - r_min;
+
+ /* Free up the memory we've been given to play with. */
+ map_free(PHYS_PFN(r_min), range >> PAGE_SHIFT);
+
+ while ( range != 0 )
+ {
+ /*
+ * Next chunk is limited by alignment of min, but also
+ * must not be bigger than remaining range.
+ */
+ for ( i = PAGE_SHIFT; (1UL << (i + 1)) <= range; i++ )
+ {
+ if ( r_min & (1UL << i) )
+ break;
+ }
+
+ ch = (chunk_head_t *)r_min;
+ r_min += 1UL << i;
+ range -= 1UL << i;
+ enqueue_elem(ch, i - PAGE_SHIFT);
+ }
+}
+
+void iterate_memory_range(unsigned long min, unsigned long max,
+ void (*func)(unsigned long, unsigned long))
+{
+ unsigned int m;
+ unsigned long r_min, r_max;
+
+ for ( m = 0; m < e820_entries; m++ )
+ {
+ if ( e820_map[m].type != E820_RAM )
+ continue;
+ if ( e820_map[m].addr + e820_map[m].size >= ULONG_MAX )
+ BUG();
+
+ r_min = e820_map[m].addr;
+ r_max = r_min + e820_map[m].size;
+ if ( r_max <= min || r_min >= max )
+ continue;
+ if ( r_min < min )
+ r_min = min;
+ if ( r_max > max )
+ r_max = max;
+
+ func(r_min, r_max);
+ }
+}
+
/*
* Initialise allocator, placing addresses [@min,@max] in free pool.
* @min and @max are PHYSICAL addresses.
*/
static void init_page_allocator(unsigned long min, unsigned long max)
{
- int i, m;
- unsigned long range;
- unsigned long r_min, r_max;
- chunk_head_t *ch;
+ int i;
printk("MM: Initialise page allocator for %lx(%lx)-%lx(%lx)\n",
(u_long)to_virt(min), min, (u_long)to_virt(max), max);
@@ -182,50 +240,7 @@ static void init_page_allocator(unsigned long min,
unsigned long max)
/* All allocated by default. */
memset(mm_alloc_bitmap, ~0, mm_alloc_bitmap_size);
- for ( m = 0; m < e820_entries; m++ )
- {
- if ( e820_map[m].type != E820_RAM )
- continue;
- if ( e820_map[m].addr + e820_map[m].size >= ULONG_MAX )
- BUG();
-
- r_min = e820_map[m].addr;
- r_max = r_min + e820_map[m].size;
- if ( r_max <= min || r_min >= max )
- continue;
- if ( r_min < min )
- r_min = min;
- if ( r_max > max )
- r_max = max;
-
- printk(" Adding memory range %lx-%lx\n", r_min, r_max);
-
- /* The buddy lists are addressed in high memory. */
- r_min = (unsigned long)to_virt(r_min);
- r_max = (unsigned long)to_virt(r_max);
- range = r_max - r_min;
-
- /* Free up the memory we've been given to play with. */
- map_free(PHYS_PFN(r_min), range >> PAGE_SHIFT);
-
- while ( range != 0 )
- {
- /*
- * Next chunk is limited by alignment of min, but also
- * must not be bigger than remaining range.
- */
- for ( i = PAGE_SHIFT; (1UL << (i + 1)) <= range; i++ )
- {
- if ( r_min & (1UL << i) )
- break;
- }
-
- ch = (chunk_head_t *)r_min;
- r_min += 1UL << i;
- range -= 1UL << i;
- enqueue_elem(ch, i - PAGE_SHIFT);
- }
- }
+ iterate_memory_range(min, max, add_memory_range);
mm_alloc_bitmap_remap();
}
--
generated by git-patchbot for /home/xen/git/mini-os.git#master
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |