Merge pull request #1307 from mmichal10/kmemleak
Integrate kmemleak into CAS
This commit is contained in:
commit
de060d1d5b
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright(c) 2012-2021 Intel Corporation
|
* Copyright(c) 2012-2022 Intel Corporation
|
||||||
* SPDX-License-Identifier: BSD-3-Clause
|
* SPDX-License-Identifier: BSD-3-Clause
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@ -10,6 +10,7 @@
|
|||||||
#include "utils/utils_gc.h"
|
#include "utils/utils_gc.h"
|
||||||
#include "utils/utils_mpool.h"
|
#include "utils/utils_mpool.h"
|
||||||
#include "threads.h"
|
#include "threads.h"
|
||||||
|
#include <linux/kmemleak.h>
|
||||||
|
|
||||||
struct env_mpool *cas_bvec_pool;
|
struct env_mpool *cas_bvec_pool;
|
||||||
|
|
||||||
@ -66,6 +67,7 @@ void *_cas_alloc_page_rpool(void *allocator_ctx, int cpu)
|
|||||||
|
|
||||||
_cas_page_set_priv(page);
|
_cas_page_set_priv(page);
|
||||||
_cas_page_set_cpu(page, cpu);
|
_cas_page_set_cpu(page, cpu);
|
||||||
|
|
||||||
return page_address(page);
|
return page_address(page);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -103,6 +105,11 @@ ctx_data_t *__cas_ctx_data_alloc(uint32_t pages, bool zalloc)
|
|||||||
_cas_page_set_cpu(data->vec[i].bv_page, cpu);
|
_cas_page_set_cpu(data->vec[i].bv_page, cpu);
|
||||||
} else {
|
} else {
|
||||||
data->vec[i].bv_page = alloc_page(GFP_NOIO);
|
data->vec[i].bv_page = alloc_page(GFP_NOIO);
|
||||||
|
if (data->vec[i].bv_page) {
|
||||||
|
/* Failed to get memory from rpool but backup allocation worked.
|
||||||
|
Need to keep track of this page as well */
|
||||||
|
kmemleak_alloc(page_address(data->vec[i].bv_page), PAGE_SIZE, 1, GFP_NOIO);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!data->vec[i].bv_page)
|
if (!data->vec[i].bv_page)
|
||||||
@ -171,8 +178,11 @@ void cas_ctx_data_free(ctx_data_t *ctx_data)
|
|||||||
if (!(_cas_page_test_priv(page) && !cas_rpool_try_put(
|
if (!(_cas_page_test_priv(page) && !cas_rpool_try_put(
|
||||||
cas_bvec_pages_rpool,
|
cas_bvec_pages_rpool,
|
||||||
page_address(page),
|
page_address(page),
|
||||||
_cas_page_get_cpu(page))))
|
_cas_page_get_cpu(page)))) {
|
||||||
__free_page(page);
|
__free_page(page);
|
||||||
|
/* It wasn't a page from rpool thus need to stop tracking it explicitly */
|
||||||
|
kmemleak_free(page_address(page));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
env_mpool_del(cas_bvec_pool, data, data->size);
|
env_mpool_del(cas_bvec_pool, data, data->size);
|
||||||
|
@ -1,10 +1,11 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright(c) 2012-2021 Intel Corporation
|
* Copyright(c) 2012-2022 Intel Corporation
|
||||||
* SPDX-License-Identifier: BSD-3-Clause
|
* SPDX-License-Identifier: BSD-3-Clause
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "cas_cache.h"
|
#include "cas_cache.h"
|
||||||
#include "utils/utils_rpool.h"
|
#include "utils/utils_rpool.h"
|
||||||
|
#include <linux/kmemleak.h>
|
||||||
|
|
||||||
/* *** ALLOCATOR *** */
|
/* *** ALLOCATOR *** */
|
||||||
|
|
||||||
@ -77,6 +78,9 @@ static void *env_allocator_new_rpool(void *allocator_ctx, int cpu)
|
|||||||
item->from_rpool = 1;
|
item->from_rpool = 1;
|
||||||
item->cpu = cpu;
|
item->cpu = cpu;
|
||||||
}
|
}
|
||||||
|
/* As it isn't an actuall allocation but only a rpool preparation
|
||||||
|
kmemleak shouldn't track the allocated memory yet. */
|
||||||
|
kmemleak_free(item);
|
||||||
|
|
||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
@ -88,6 +92,7 @@ static void env_allocator_del_rpool(void *allocator_ctx, void *_item)
|
|||||||
|
|
||||||
BUG_ON(item->used);
|
BUG_ON(item->used);
|
||||||
|
|
||||||
|
kmemleak_alloc(item, allocator->item_size, 1, GFP_NOIO);
|
||||||
kmem_cache_free(allocator->kmem_cache, item);
|
kmem_cache_free(allocator->kmem_cache, item);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
#include "utils_rpool.h"
|
#include "utils_rpool.h"
|
||||||
#include "ocf_env.h"
|
#include "ocf_env.h"
|
||||||
#include "../cas_cache.h"
|
#include "../cas_cache.h"
|
||||||
|
#include <linux/kmemleak.h>
|
||||||
|
|
||||||
#define CAS_UTILS_RPOOL_DEBUG 0
|
#define CAS_UTILS_RPOOL_DEBUG 0
|
||||||
#if 1 == CAS_UTILS_RPOOL_DEBUG
|
#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);
|
entry = RPOOL_ITEM_TO_ENTRY(rpool_master, item);
|
||||||
list_del(item);
|
list_del(item);
|
||||||
atomic_dec(¤t_rpool->count);
|
atomic_dec(¤t_rpool->count);
|
||||||
|
/* The actuall allocation - kmemleak should start tracking page */
|
||||||
|
kmemleak_alloc(entry, rpool_master->entry_size, 1, GFP_NOIO);
|
||||||
}
|
}
|
||||||
|
|
||||||
spin_unlock_irqrestore(¤t_rpool->lock, flags);
|
spin_unlock_irqrestore(¤t_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);
|
item = RPOOL_ENTRY_TO_ITEM(rpool_master, entry);
|
||||||
list_add_tail(item, ¤t_rpool->list);
|
list_add_tail(item, ¤t_rpool->list);
|
||||||
|
/* Freeing memory chunk */
|
||||||
|
kmemleak_free(entry);
|
||||||
|
|
||||||
atomic_inc(¤t_rpool->count);
|
atomic_inc(¤t_rpool->count);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user