From b444df8cee98f49cd40c798d85a13b151388c458 Mon Sep 17 00:00:00 2001 From: Piotr Balcer <piotr.balcer@intel.com> Date: Fri, 12 Jun 2020 09:29:21 +0200 Subject: [PATCH] obj: fix run allocated recalculation --- src/libpmemobj/heap.c | 2 +- src/test/obj_ctl_stats/obj_ctl_stats.c | 25 ++++++++++++++++++++++++- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/src/libpmemobj/heap.c b/src/libpmemobj/heap.c index 2374e0c4d..1604bcf67 100644 --- a/src/libpmemobj/heap.c +++ b/src/libpmemobj/heap.c @@ -616,7 +616,7 @@ heap_reclaim_run(struct palloc_heap *heap, struct memory_block *m, int startup) STATS_INC(heap->stats, transient, heap_run_active, m->size_idx * CHUNKSIZE); STATS_INC(heap->stats, transient, heap_run_allocated, - c->run.nallocs - e.free_space); + (c->run.nallocs - e.free_space) * run->hdr.block_size); } if (recycler_put(heap->rt->recyclers[c->id], m, e) < 0) diff --git a/src/test/obj_ctl_stats/obj_ctl_stats.c b/src/test/obj_ctl_stats/obj_ctl_stats.c index 7e443a190..e613482fe 100644 --- a/src/test/obj_ctl_stats/obj_ctl_stats.c +++ b/src/test/obj_ctl_stats/obj_ctl_stats.c @@ -1,5 +1,5 @@ /* - * Copyright 2017-2019, Intel Corporation + * Copyright 2017-2020, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -122,6 +122,29 @@ main(int argc, char *argv[]) UT_ASSERTeq(ret, 0); UT_ASSERTeq(tmp, run_allocated); /* shouldn't change */ + /* the deallocated object shouldn't be reflected in rebuilt stats */ + pmemobj_free(&oid); + + pmemobj_close(pop); + + pop = pmemobj_open(path, "ctl"); + UT_ASSERTne(pop, NULL); + + /* stats are rebuilt lazily, so initially this should be 0 */ + tmp = 0; + ret = pmemobj_ctl_get(pop, "stats.heap.run_allocated", &tmp); + UT_ASSERTeq(ret, 0); + UT_ASSERTeq(tmp, 0); + + ret = pmemobj_alloc(pop, NULL, 1, 0, NULL, NULL); + UT_ASSERTeq(ret, 0); + + /* after first alloc, the previously allocated object will be found */ + tmp = 0; + ret = pmemobj_ctl_get(pop, "stats.heap.run_allocated", &tmp); + UT_ASSERTeq(ret, 0); + UT_ASSERTeq(tmp, run_allocated + oid_size); + pmemobj_close(pop); DONE(NULL); -- GitLab