File: fill_flush.c

package info (click to toggle)
redis 5%3A8.0.2-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 22,304 kB
  • sloc: ansic: 216,903; tcl: 51,562; sh: 4,625; perl: 4,214; cpp: 3,568; python: 2,954; makefile: 2,055; ruby: 639; javascript: 30; csh: 7
file content (76 lines) | stat: -rw-r--r-- 1,893 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include "test/jemalloc_test.h"
#include "test/bench.h"

#define SMALL_ALLOC_SIZE 128
#define LARGE_ALLOC_SIZE SC_LARGE_MINCLASS
#define NALLOCS 1000

/*
 * We make this volatile so the 1-at-a-time variants can't leave the allocation
 * in a register, just to try to get the cache behavior closer.
 */
void *volatile allocs[NALLOCS];

static void
array_alloc_dalloc_small(void) {
	for (int i = 0; i < NALLOCS; i++) {
		void *p = mallocx(SMALL_ALLOC_SIZE, 0);
		assert_ptr_not_null(p, "mallocx shouldn't fail");
		allocs[i] = p;
	}
	for (int i = 0; i < NALLOCS; i++) {
		sdallocx(allocs[i], SMALL_ALLOC_SIZE, 0);
	}
}

static void
item_alloc_dalloc_small(void) {
	for (int i = 0; i < NALLOCS; i++) {
		void *p = mallocx(SMALL_ALLOC_SIZE, 0);
		assert_ptr_not_null(p, "mallocx shouldn't fail");
		allocs[i] = p;
		sdallocx(allocs[i], SMALL_ALLOC_SIZE, 0);
	}
}

TEST_BEGIN(test_array_vs_item_small) {
	compare_funcs(1 * 1000, 10 * 1000,
	    "array of small allocations", array_alloc_dalloc_small,
	    "small item allocation", item_alloc_dalloc_small);
}
TEST_END

static void
array_alloc_dalloc_large(void) {
	for (int i = 0; i < NALLOCS; i++) {
		void *p = mallocx(LARGE_ALLOC_SIZE, 0);
		assert_ptr_not_null(p, "mallocx shouldn't fail");
		allocs[i] = p;
	}
	for (int i = 0; i < NALLOCS; i++) {
		sdallocx(allocs[i], LARGE_ALLOC_SIZE, 0);
	}
}

static void
item_alloc_dalloc_large(void) {
	for (int i = 0; i < NALLOCS; i++) {
		void *p = mallocx(LARGE_ALLOC_SIZE, 0);
		assert_ptr_not_null(p, "mallocx shouldn't fail");
		allocs[i] = p;
		sdallocx(allocs[i], LARGE_ALLOC_SIZE, 0);
	}
}

TEST_BEGIN(test_array_vs_item_large) {
	compare_funcs(100, 1000,
	    "array of large allocations", array_alloc_dalloc_large,
	    "large item allocation", item_alloc_dalloc_large);
}
TEST_END

int main(void) {
	return test_no_reentrancy(
	    test_array_vs_item_small,
	    test_array_vs_item_large);
}