mirror of
https://git.rtems.org/rtems-libbsd/
synced 2025-07-25 06:17:21 +08:00
rtems-kernel-page: Add used pages counter
This commit is contained in:
parent
5ede682973
commit
7533adcf09
@ -58,31 +58,34 @@ void **rtems_bsd_page_object_table;
|
|||||||
|
|
||||||
uintptr_t rtems_bsd_page_area_begin;
|
uintptr_t rtems_bsd_page_area_begin;
|
||||||
|
|
||||||
static rtems_rbheap_control page_heap;
|
static struct {
|
||||||
|
struct mtx mtx;
|
||||||
struct mtx page_heap_mtx;
|
rtems_rbheap_control heap;
|
||||||
|
size_t used;
|
||||||
|
} page_alloc;
|
||||||
|
|
||||||
void *
|
void *
|
||||||
rtems_bsd_page_alloc(uintptr_t size_in_bytes, int wait)
|
rtems_bsd_page_alloc(uintptr_t size_in_bytes, int wait)
|
||||||
{
|
{
|
||||||
void *addr;
|
void *addr;
|
||||||
|
|
||||||
mtx_lock(&page_heap_mtx);
|
mtx_lock(&page_alloc.mtx);
|
||||||
|
|
||||||
addr = rtems_rbheap_allocate(&page_heap, size_in_bytes);
|
addr = rtems_rbheap_allocate(&page_alloc.heap, size_in_bytes);
|
||||||
if (addr == NULL && wait) {
|
if (addr == NULL && wait) {
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for (i = 0; i < 8; i++) {
|
for (i = 0; i < 8; i++) {
|
||||||
mtx_unlock(&page_heap_mtx);
|
mtx_unlock(&page_alloc.mtx);
|
||||||
uma_reclaim();
|
uma_reclaim();
|
||||||
mtx_lock(&page_heap_mtx);
|
mtx_lock(&page_alloc.mtx);
|
||||||
|
|
||||||
addr = rtems_rbheap_allocate(&page_heap, size_in_bytes);
|
addr = rtems_rbheap_allocate(&page_alloc.heap,
|
||||||
|
size_in_bytes);
|
||||||
if (addr != NULL)
|
if (addr != NULL)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
msleep(&page_heap, &page_heap_mtx, 0,
|
msleep(&page_alloc.heap, &page_alloc.mtx, 0,
|
||||||
"page alloc", (hz / 4) * (i + 1));
|
"page alloc", (hz / 4) * (i + 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -91,7 +94,8 @@ rtems_bsd_page_alloc(uintptr_t size_in_bytes, int wait)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
mtx_unlock(&page_heap_mtx);
|
page_alloc.used += (addr != NULL) ? 1 : 0;
|
||||||
|
mtx_unlock(&page_alloc.mtx);
|
||||||
|
|
||||||
#ifdef INVARIANTS
|
#ifdef INVARIANTS
|
||||||
wait |= M_ZERO;
|
wait |= M_ZERO;
|
||||||
@ -107,10 +111,12 @@ rtems_bsd_page_alloc(uintptr_t size_in_bytes, int wait)
|
|||||||
void
|
void
|
||||||
rtems_bsd_page_free(void *addr)
|
rtems_bsd_page_free(void *addr)
|
||||||
{
|
{
|
||||||
mtx_lock(&page_heap_mtx);
|
|
||||||
rtems_rbheap_free(&page_heap, addr);
|
mtx_lock(&page_alloc.mtx);
|
||||||
wakeup(&page_heap);
|
--page_alloc.used;
|
||||||
mtx_unlock(&page_heap_mtx);
|
rtems_rbheap_free(&page_alloc.heap, addr);
|
||||||
|
wakeup(&page_alloc.heap);
|
||||||
|
mtx_unlock(&page_alloc.mtx);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -124,7 +130,7 @@ rtems_bsd_page_init(void *arg)
|
|||||||
size_t n;
|
size_t n;
|
||||||
uintptr_t heap_size;
|
uintptr_t heap_size;
|
||||||
|
|
||||||
mtx_init(&page_heap_mtx, "page heap", NULL, MTX_DEF);
|
mtx_init(&page_alloc.mtx, "page heap", NULL, MTX_DEF);
|
||||||
|
|
||||||
heap_size = rtems_bsd_get_allocator_domain_size(
|
heap_size = rtems_bsd_get_allocator_domain_size(
|
||||||
RTEMS_BSD_ALLOCATOR_DOMAIN_PAGE);
|
RTEMS_BSD_ALLOCATOR_DOMAIN_PAGE);
|
||||||
@ -133,11 +139,11 @@ rtems_bsd_page_init(void *arg)
|
|||||||
0);
|
0);
|
||||||
BSD_ASSERT(area != NULL);
|
BSD_ASSERT(area != NULL);
|
||||||
|
|
||||||
sc = rtems_rbheap_initialize(&page_heap, area, heap_size, PAGE_SIZE,
|
sc = rtems_rbheap_initialize(&page_alloc.heap, area, heap_size,
|
||||||
rtems_rbheap_extend_descriptors_with_malloc, NULL);
|
PAGE_SIZE, rtems_rbheap_extend_descriptors_with_malloc, NULL);
|
||||||
BSD_ASSERT(sc == RTEMS_SUCCESSFUL);
|
BSD_ASSERT(sc == RTEMS_SUCCESSFUL);
|
||||||
|
|
||||||
rtems_rbheap_set_extend_descriptors(&page_heap,
|
rtems_rbheap_set_extend_descriptors(&page_alloc.heap,
|
||||||
rtems_rbheap_extend_descriptors_never);
|
rtems_rbheap_extend_descriptors_never);
|
||||||
|
|
||||||
n = heap_size / PAGE_SIZE;
|
n = heap_size / PAGE_SIZE;
|
||||||
@ -146,7 +152,7 @@ rtems_bsd_page_init(void *arg)
|
|||||||
BSD_ASSERT(chunks != NULL);
|
BSD_ASSERT(chunks != NULL);
|
||||||
|
|
||||||
for (i = 0; i < n; ++i) {
|
for (i = 0; i < n; ++i) {
|
||||||
rtems_rbheap_add_to_spare_descriptor_chain(&page_heap,
|
rtems_rbheap_add_to_spare_descriptor_chain(&page_alloc.heap,
|
||||||
&chunks[i]);
|
&chunks[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user