[kvm-unit-tests PATCH 23/32] lib: x86: store free pages in ascending order

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Peter Feiner <pfeiner@xxxxxxxxxx>

Makes allocation of contiguous physical pages simpler.

Signed-off-by: Peter Feiner <pfeiner@xxxxxxxxxx>
Signed-off-by: David Matlack <dmatlack@xxxxxxxxxx>
---
 lib/x86/vm.c | 27 ++++++++++++++++++++++-----
 1 file changed, 22 insertions(+), 5 deletions(-)

diff --git a/lib/x86/vm.c b/lib/x86/vm.c
index cda4c5f46da3..8bd0c88e141e 100644
--- a/lib/x86/vm.c
+++ b/lib/x86/vm.c
@@ -7,12 +7,29 @@ static void *vfree_top = 0;
 
 static void free_memory(void *mem, unsigned long size)
 {
-    while (size >= PAGE_SIZE) {
-	*(void **)mem = free;
+	void *end;
+
+	assert_msg((unsigned long) mem % PAGE_SIZE == 0,
+		   "mem not page aligned: %p", mem);
+
+	assert_msg(size % PAGE_SIZE == 0, "size not page aligned: 0x%lx", size);
+
+	assert_msg(size == 0 || mem + size > mem,
+		   "mem + size overflow: %p + 0x%lx", mem, size);
+
+	if (size == 0) {
+		free = NULL;
+		return;
+	}
+
 	free = mem;
-	mem += PAGE_SIZE;
-	size -= PAGE_SIZE;
-    }
+	end = mem + size;
+	while (mem + PAGE_SIZE != end) {
+		*(void **)mem = (mem + PAGE_SIZE);
+		mem += PAGE_SIZE;
+	}
+
+	*(void **)mem = NULL;
 }
 
 void *alloc_page()
-- 
2.12.2.816.g2cccc81164-goog




[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux