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

[UNIKRAFT PATCH 09/18] lib/ukalloc: Introduce `uk_alloc_availmem_total(), `uk_alloc_pavail_total()`



This commit introduces helper functions to retrieve the total available
memory of all registered allocators. In case an allocator does not support
querying the amount of free memory, it is considered as 0 bytes free for
this particular allocator.

Signed-off-by: Simon Kuenzer <simon.kuenzer@xxxxxxxxx>
---
 lib/ukalloc/alloc.c            | 30 ++++++++++++++++++++++++++++++
 lib/ukalloc/exportsyms.uk      |  2 ++
 lib/ukalloc/include/uk/alloc.h |  4 ++++
 3 files changed, 36 insertions(+)

diff --git a/lib/ukalloc/alloc.c b/lib/ukalloc/alloc.c
index bb92301d..1bf596b0 100644
--- a/lib/ukalloc/alloc.c
+++ b/lib/ukalloc/alloc.c
@@ -542,3 +542,33 @@ long uk_alloc_pavail_compat(struct uk_alloc *a)
 
        return (long) (mem >> __PAGE_SHIFT);
 }
+
+size_t uk_alloc_availmem_total(void)
+{
+       struct uk_alloc *a;
+       ssize_t availmem;
+       size_t total;
+
+       total = 0;
+       uk_alloc_foreach(a) {
+               availmem = uk_alloc_availmem(a);
+               if (availmem > 0)
+                       total += availmem;
+       }
+       return total;
+}
+
+unsigned long uk_alloc_pavail_total(void)
+{
+       struct uk_alloc *a;
+       long pavail;
+       unsigned long total;
+
+       total = 0;
+       uk_alloc_foreach(a) {
+               pavail = uk_alloc_pavail(a);
+               if (pavail > 0)
+                       total += pavail;
+       }
+       return total;
+}
diff --git a/lib/ukalloc/exportsyms.uk b/lib/ukalloc/exportsyms.uk
index a99551bd..7c25a70c 100644
--- a/lib/ukalloc/exportsyms.uk
+++ b/lib/ukalloc/exportsyms.uk
@@ -17,4 +17,6 @@ uk_palloc_compat
 uk_pfree_compat
 uk_alloc_pmaxalloc_compat
 uk_alloc_pavail_compat
+uk_alloc_availmem_total
+uk_alloc_pavail_total
 _uk_alloc_head
diff --git a/lib/ukalloc/include/uk/alloc.h b/lib/ukalloc/include/uk/alloc.h
index d7eba237..fc19551e 100644
--- a/lib/ukalloc/include/uk/alloc.h
+++ b/lib/ukalloc/include/uk/alloc.h
@@ -279,6 +279,10 @@ static inline long uk_alloc_pavail(struct uk_alloc *a)
        return a->pavail(a);
 }
 
+size_t uk_alloc_availmem_total(void);
+
+unsigned long uk_alloc_pavail_total(void);
+
 #ifdef __cplusplus
 }
 #endif
-- 
2.20.1



 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.