Skip to content

Commit 5cd8648

Browse files
committed
Keep SHM_LARGE_FRAG_SIZE fixed a 32 KiB for release & debug. Fixes unit-test bug.
1 parent 21ae229 commit 5cd8648

File tree

3 files changed

+28
-16
lines changed

3 files changed

+28
-16
lines changed

src/platform_linux/shmem.c

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -57,20 +57,6 @@ typedef struct shm_frag_info {
5757
int shm_line;
5858
} shm_frag_info;
5959

60-
/*
61-
* All memory allocations of this size or larger will be tracked in the
62-
* above fragment tracker array. For large inserts workload, we allocate large
63-
* memory chunks for fingerprint array, which is more than a MiB. For scans,
64-
* splinterdb_iterator_init() allocates memory for an iterator which is ~92+KiB.
65-
* Set this to a lower value so we can re-cycle free fragments for iterators
66-
* also.
67-
*/
68-
#if SPLINTER_DEBUG
69-
# define SHM_LARGE_FRAG_SIZE (90 * KiB)
70-
#else
71-
# define SHM_LARGE_FRAG_SIZE (38 * KiB)
72-
#endif // SPLINTER_DEBUG
73-
7460
/*
7561
* In the worst case we may have all threads performing activities that need
7662
* such large memory fragments. We track up to twice the # of configured

src/platform_linux/shmem.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,17 @@
88

99
typedef struct shmem_info shmem_info;
1010

11+
/*
12+
* All memory allocations of this size or larger will be tracked in the
13+
* a fragment tracker array. For large inserts workload, we allocate large
14+
* memory chunks for fingerprint array, which is more than a MiB. For scans,
15+
* splinterdb_iterator_init() allocates memory for an iterator which is ~42+KiB.
16+
* Set this to a lower value so we can re-cycle free fragments for iterators
17+
* also. (Keep the limit same for release/debug builds to get consistent
18+
* behaviour.)
19+
*/
20+
#define SHM_LARGE_FRAG_SIZE (32 * KiB)
21+
1122
platform_status
1223
platform_shmcreate(size_t size,
1324
platform_heap_handle *heap_handle,

tests/unit/platform_apis_test.c

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -267,15 +267,30 @@ CTEST2(platform_api, test_large_TYPED_MALLOC)
267267
platform_free(data->hid, iter);
268268
}
269269

270+
/*
271+
* Basic test case to verify that memory for large fragments is being
272+
* recycled as expected.
273+
*/
270274
CTEST2(platform_api, test_large_TYPED_MALLOC_free_and_MALLOC)
271275
{
272-
trunk_range_iterator *iter = TYPED_MALLOC(data->hid, iter);
276+
trunk_range_iterator *iter = TYPED_MALLOC(data->hid, iter);
277+
// This struct should be larger than the threshold at which large
278+
// free fragment strategy kicks-in.
279+
ASSERT_TRUE(sizeof(*iter) >= SHM_LARGE_FRAG_SIZE);
280+
273281
trunk_range_iterator *save_iter = iter;
274282
platform_free(data->hid, iter);
275283

276284
trunk_range_iterator *new_iter = TYPED_MALLOC(data->hid, iter);
285+
277286
// Memory for large structures should be recycled from shared memory
278-
ASSERT_TRUE(!data->use_shmem || (save_iter == new_iter));
287+
ASSERT_TRUE(!data->use_shmem || (save_iter == new_iter),
288+
"use_shmem=%d, save_iter=%p, new_iter=%p"
289+
", sizeof() requested struct=%lu",
290+
data->use_shmem,
291+
save_iter,
292+
new_iter,
293+
sizeof(*iter));
279294
platform_free(data->hid, new_iter);
280295
}
281296

0 commit comments

Comments
 (0)