Integrate kmemleak into CAS

Kmemleak is a tool which allows to detect memory leaks in kernel. It requires
`CONFIG_DEBUG_KMEMLEAK` to be enabled during kernel compilation. Otherwise all
the kmemleak_* functions are NOPs.

Signed-off-by: Michal Mielewczyk <michal.mielewczyk@intel.com>
This commit is contained in:
Michal Mielewczyk
2022-08-12 10:25:55 +02:00
parent 90106d545a
commit 38bef1f7fe
3 changed files with 23 additions and 3 deletions

View File

@@ -7,6 +7,7 @@
#include "utils_rpool.h"
#include "ocf_env.h"
#include "../cas_cache.h"
#include <linux/kmemleak.h>
#define CAS_UTILS_RPOOL_DEBUG 0
#if 1 == CAS_UTILS_RPOOL_DEBUG
@@ -216,6 +217,8 @@ void *cas_rpool_try_get(struct cas_reserve_pool *rpool_master, int *cpu)
entry = RPOOL_ITEM_TO_ENTRY(rpool_master, item);
list_del(item);
atomic_dec(&current_rpool->count);
/* The actuall allocation - kmemleak should start tracking page */
kmemleak_alloc(entry, rpool_master->entry_size, 1, GFP_NOIO);
}
spin_unlock_irqrestore(&current_rpool->lock, flags);
@@ -248,6 +251,8 @@ int cas_rpool_try_put(struct cas_reserve_pool *rpool_master, void *entry, int cp
item = RPOOL_ENTRY_TO_ITEM(rpool_master, entry);
list_add_tail(item, &current_rpool->list);
/* Freeing memory chunk */
kmemleak_free(entry);
atomic_inc(&current_rpool->count);