From 0afac6939a50347f1ae328ddf2715461c9c66eb1 Mon Sep 17 00:00:00 2001 From: antirez Date: Wed, 11 Apr 2018 16:22:52 +0200 Subject: [PATCH] Modules API: OOM_WARNING flags. In some modules it may be useful to have an idea about being near to OOM. Anyway additionally an explicit call to get the fill ratio will be added in the future. --- src/module.c | 7 ++++++- src/redismodule.h | 2 ++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/module.c b/src/module.c index 1f1140b2..c0423a3d 100644 --- a/src/module.c +++ b/src/module.c @@ -1330,6 +1330,9 @@ int RM_GetSelectedDb(RedisModuleCtx *ctx) { * * * REDISMODULE_CTX_FLAGS_OOM: Redis is out of memory according to the * maxmemory setting. + * + * * REDISMODULE_CTX_FLAGS_OOM_WARNING: Less than 25% of memory remains before + * reaching the maxmemory level. */ int RM_GetContextFlags(RedisModuleCtx *ctx) { @@ -1369,8 +1372,10 @@ int RM_GetContextFlags(RedisModuleCtx *ctx) { } /* OOM flag. */ - if (getMaxmemoryState(NULL,NULL,NULL,NULL) == C_ERR) { + float level; + if (getMaxmemoryState(NULL,NULL,NULL,&level) == C_ERR) { flags |= REDISMODULE_CTX_FLAGS_OOM; + if (level > 0.75) flags |= REDISMODULE_CTX_FLAGS_OOM_WARNING; } return flags; diff --git a/src/redismodule.h b/src/redismodule.h index 517d1354..d500d28b 100644 --- a/src/redismodule.h +++ b/src/redismodule.h @@ -83,6 +83,8 @@ #define REDISMODULE_CTX_FLAGS_EVICT (1<<9) /* Redis is out of memory according to the maxmemory flag. */ #define REDISMODULE_CTX_FLAGS_OOM (1<<10) +/* Less than 25% of memory available according to maxmemory. */ +#define REDISMODULE_CTX_FLAGS_OOM_WARNING (1<<11) #define REDISMODULE_NOTIFY_GENERIC (1<<2) /* g */ #define REDISMODULE_NOTIFY_STRING (1<<3) /* $ */