[PATCH kvm-unit-tests 08/11] page_alloc: add yet another memalign

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

 



If we want both early alloc ops and alloc_page(), then it's best
to just give all the memory to page_alloc and then base the
early alloc ops on that.

Signed-off-by: Andrew Jones <drjones@xxxxxxxxxx>
---
 lib/alloc_page.c | 28 ++++++++++++++++++++++++++++
 lib/alloc_page.h |  1 +
 2 files changed, 29 insertions(+)

diff --git a/lib/alloc_page.c b/lib/alloc_page.c
index ca11496829a0..70214e262b1b 100644
--- a/lib/alloc_page.c
+++ b/lib/alloc_page.c
@@ -5,6 +5,7 @@
  * with page granularity.
  */
 #include "libcflat.h"
+#include "alloc.h"
 #include "alloc_phys.h"
 #include <asm/page.h>
 #include <asm/io.h>
@@ -134,3 +135,30 @@ void free_page(void *page)
 	freelist = page;
 	spin_unlock(&lock);
 }
+
+static void *page_memalign(size_t alignment, size_t size)
+{
+	unsigned long order;
+
+	if (!size)
+		return NULL;
+
+	order = 64 - __builtin_clzll(ALIGN(size, PAGE_SIZE) >> PAGE_SHIFT) - 1;
+	return alloc_pages(order);
+}
+
+static void page_free(void *mem, size_t size)
+{
+	free_pages(mem, size);
+}
+
+static struct alloc_ops page_alloc_ops = {
+	.memalign = page_memalign,
+	.free = page_free,
+	.align_min = PAGE_SIZE,
+};
+
+void page_alloc_ops_enable(void)
+{
+	alloc_ops = &page_alloc_ops;
+}
diff --git a/lib/alloc_page.h b/lib/alloc_page.h
index 1c2b3ec9add6..51d48414a47e 100644
--- a/lib/alloc_page.h
+++ b/lib/alloc_page.h
@@ -9,6 +9,7 @@
 #define ALLOC_PAGE_H 1
 
 bool page_alloc_initialized(void);
+void page_alloc_ops_enable(void);
 void *alloc_page();
 void *alloc_pages(unsigned long order);
 void free_page(void *page);
-- 
2.13.6




[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