Merge pull request #1307 from mmichal10/kmemleak

Integrate kmemleak into CAS
This commit is contained in:
Robert Baldyga 2022-10-04 10:03:37 +02:00 committed by GitHub
commit de060d1d5b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 23 additions and 3 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright(c) 2012-2021 Intel Corporation
* Copyright(c) 2012-2022 Intel Corporation
* SPDX-License-Identifier: BSD-3-Clause
*/
@ -10,6 +10,7 @@
#include "utils/utils_gc.h"
#include "utils/utils_mpool.h"
#include "threads.h"
#include <linux/kmemleak.h>
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_cpu(page, cpu);
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);
} else {
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)
@ -171,8 +178,11 @@ void cas_ctx_data_free(ctx_data_t *ctx_data)
if (!(_cas_page_test_priv(page) && !cas_rpool_try_put(
cas_bvec_pages_rpool,
page_address(page),
_cas_page_get_cpu(page))))
_cas_page_get_cpu(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);

View File

@ -1,10 +1,11 @@
/*
* Copyright(c) 2012-2021 Intel Corporation
* Copyright(c) 2012-2022 Intel Corporation
* SPDX-License-Identifier: BSD-3-Clause
*/
#include "cas_cache.h"
#include "utils/utils_rpool.h"
#include <linux/kmemleak.h>
/* *** ALLOCATOR *** */
@ -77,6 +78,9 @@ static void *env_allocator_new_rpool(void *allocator_ctx, int cpu)
item->from_rpool = 1;
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;
}
@ -88,6 +92,7 @@ static void env_allocator_del_rpool(void *allocator_ctx, void *_item)
BUG_ON(item->used);
kmemleak_alloc(item, allocator->item_size, 1, GFP_NOIO);
kmem_cache_free(allocator->kmem_cache, item);
}

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);