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

Re: [UNIKRAFT PATCH] lib/ukalloc: per-library stats: Return ENOMEM



Hey Simon,

This patch looks good to me.

Cezar

Reviewed-by: Cezar Craciunoiu <cezar.craciunoiu@xxxxxxxxx>

On 2020-11-23 14:21:21, Simon Kuenzer <simon.kuenzer@xxxxxxxxx> wrote:

The per-library wrapper returns ENOMEM instead of failing in an assertions
when the default allocator is not yet initialized.

Signed-off-by: Simon Kuenzer
---
This patch depends on patch series: 1574
https://patchwork.unikraft.org/project/unikraft/list/?series=1574
---
lib/ukalloc/libstats.c | 30 +++++++++++++++++++++++++-----
1 file changed, 25 insertions(+), 5 deletions(-)

diff --git a/lib/ukalloc/libstats.c b/lib/ukalloc/libstats.c
index d49d9dcc..b2831ba2 100644
--- a/lib/ukalloc/libstats.c
+++ b/lib/ukalloc/libstats.c
@@ -45,6 +45,7 @@

#include
#include
+#include
#include

static inline struct uk_alloc *_uk_alloc_get_actual_default(void)
@@ -114,7 +115,11 @@ static void *wrapper_malloc(struct uk_alloc *a, __sz size)
__sz alloc_size;
void *ret;

- UK_ASSERT(p);
+ if (unlikely(!p)) {
+ update_stats(&a->_stats, 0, 1, 0, 0);
+ errno = ENOMEM;
+ return NULL;
+ }

WATCH_STATS_START(p);
ret = uk_do_malloc(p, size);
@@ -132,7 +137,11 @@ static void *wrapper_calloc(struct uk_alloc *a, __sz nmemb, __sz size)
__sz alloc_size;
void *ret;

- UK_ASSERT(p);
+ if (unlikely(!p)) {
+ update_stats(&a->_stats, 0, 1, 0, 0);
+ errno = ENOMEM;
+ return NULL;
+ }

WATCH_STATS_START(p);
ret = uk_do_calloc(p, nmemb, size);
@@ -151,7 +160,10 @@ static int wrapper_posix_memalign(struct uk_alloc *a, void **memptr,
__sz alloc_size;
int ret;

- UK_ASSERT(p);
+ if (unlikely(!p)) {
+ update_stats(&a->_stats, 0, 1, 0, 0);
+ return ENOMEM;
+ }

WATCH_STATS_START(p);
ret = uk_do_posix_memalign(p, memptr, align, size);
@@ -168,7 +180,11 @@ static void *wrapper_memalign(struct uk_alloc *a, __sz align, __sz size)
__sz alloc_size;
void *ret;

- UK_ASSERT(p);
+ if (unlikely(!p)) {
+ update_stats(&a->_stats, 0, 1, 0, 0);
+ errno = ENOMEM;
+ return NULL;
+ }

WATCH_STATS_START(p);
ret = uk_do_memalign(p, align, size);
@@ -185,7 +201,11 @@ static void *wrapper_realloc(struct uk_alloc *a, void *ptr, __sz size)
__sz alloc_size;
void *ret;

- UK_ASSERT(p);
+ if (unlikely(!p)) {
+ update_stats(&a->_stats, 0, 1, 0, 0);
+ errno = ENOMEM;
+ return NULL;
+ }

WATCH_STATS_START(p);
ret = uk_do_realloc(p, ptr, size);
--
2.20.1


 


Rackspace

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