[rtems-libbsd commit] rtems-kernel-page: Reclaim pages earlier

Sebastian Huber sebh at rtems.org
Mon Oct 23 07:27:50 UTC 2017


Module:    rtems-libbsd
Branch:    master
Commit:    91fb6e37537f7b3b4211f218cf03adaaf4d8a326
Changeset: http://git.rtems.org/rtems-libbsd/commit/?id=91fb6e37537f7b3b4211f218cf03adaaf4d8a326

Author:    Sebastian Huber <sebastian.huber at embedded-brains.de>
Date:      Mon Nov 21 14:57:57 2016 +0100

rtems-kernel-page: Reclaim pages earlier

---

 rtemsbsd/rtems/rtems-kernel-page.c | 22 +++++++++++++---------
 1 file changed, 13 insertions(+), 9 deletions(-)

diff --git a/rtemsbsd/rtems/rtems-kernel-page.c b/rtemsbsd/rtems/rtems-kernel-page.c
index eb96fcd..560e831 100644
--- a/rtemsbsd/rtems/rtems-kernel-page.c
+++ b/rtemsbsd/rtems/rtems-kernel-page.c
@@ -61,21 +61,24 @@ uintptr_t rtems_bsd_page_area_begin;
 static struct {
 	struct mtx mtx;
 	rtems_rbheap_control heap;
-	size_t used;
+	size_t free;
+	uint32_t reclaims;
 } page_alloc;
 
 void *
-rtems_bsd_page_alloc(uintptr_t size_in_bytes, int wait)
+rtems_bsd_page_alloc(uintptr_t size_in_bytes, int flags)
 {
 	void *addr;
 
 	mtx_lock(&page_alloc.mtx);
 
 	addr = rtems_rbheap_allocate(&page_alloc.heap, size_in_bytes);
-	if (addr == NULL && wait) {
+	if (addr == NULL && ((flags & M_WAITOK) != 0 ||
+	    page_alloc.free < 32)) {
 		int i;
 
 		for (i = 0; i < 8; i++) {
+			++page_alloc.reclaims;
 			mtx_unlock(&page_alloc.mtx);
 			uma_reclaim();
 			mtx_lock(&page_alloc.mtx);
@@ -89,19 +92,19 @@ rtems_bsd_page_alloc(uintptr_t size_in_bytes, int wait)
 			    "page alloc", (hz / 4) * (i + 1));
 		}
 
-		if (i == 8) {
+		if (addr == NULL && (flags & M_WAITOK) != 0) {
 			panic("rtems_bsd_page_alloc: page starvation");
 		}
 	}
 
-	page_alloc.used += (addr != NULL) ? 1 : 0;
+	page_alloc.free -= (addr != NULL) ? 1 : 0;
 	mtx_unlock(&page_alloc.mtx);
 
 #ifdef INVARIANTS
-	wait |= M_ZERO;
+	flags |= M_ZERO;
 #endif
 
-	if (addr != NULL && (wait & M_ZERO) != 0) {
+	if (addr != NULL && (flags & M_ZERO) != 0) {
 		memset(addr, 0, size_in_bytes);
 	}
 
@@ -113,7 +116,7 @@ rtems_bsd_page_free(void *addr)
 {
 
 	mtx_lock(&page_alloc.mtx);
-	--page_alloc.used;
+	++page_alloc.free;
 	rtems_rbheap_free(&page_alloc.heap, addr);
 	wakeup(&page_alloc.heap);
 	mtx_unlock(&page_alloc.mtx);
@@ -130,7 +133,7 @@ rtems_bsd_page_init(void *arg)
 	size_t n;
 	uintptr_t heap_size;
 
-	mtx_init(&page_alloc.mtx, "page heap", NULL, MTX_DEF);
+	mtx_init(&page_alloc.mtx, "page heap", NULL, MTX_RECURSE);
 
 	heap_size = rtems_bsd_get_allocator_domain_size(
 	    RTEMS_BSD_ALLOCATOR_DOMAIN_PAGE);
@@ -147,6 +150,7 @@ rtems_bsd_page_init(void *arg)
 	    rtems_rbheap_extend_descriptors_never);
 
 	n = heap_size / PAGE_SIZE;
+	page_alloc.free = n;
 
 	chunks = malloc(n * sizeof(*chunks), M_RTEMS_HEAP, M_NOWAIT);
 	BSD_ASSERT(chunks != NULL);



More information about the vc mailing list