Skip to content

Commit 7fa784a

Browse files
authored
Disable mem usage test case for non-jemalloc allocators (#1685)
Attempt to fix non-jemalloc builds by disabling this test case on non-jemalloc builds: ``` *** [err]: Memory usage of embedded string value in tests/unit/type/string.tcl Expected '40' to be less than or equal to '32' (context: type eval line 5 cmd {assert_lessthan_equal [r memory usage quux] 32} proc ::test) ``` We can't assume anything about allocation size classes for arbitrary allocators. Glibc malloc seems to give usable sizes of 24, 40, 56, 72, 88, 104, ..., not similar to jemalloc size classes. Additional change: encode unused robj allocation space in the EMBSTR sds header. This makes the test case able to correctly calculate the memory overhead of the different structures in 32-bit builds, where there is some unused space in the allocation (because the `robj` header is smaller). --------- Signed-off-by: Viktor Söderqvist <[email protected]>
1 parent e9ed53c commit 7fa784a

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

src/object.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,8 +195,10 @@ static robj *createEmbeddedStringObjectWithKeyAndExpire(const char *val_ptr,
195195
data += key_sds_size;
196196
}
197197

198-
/* Copy embedded value (EMBSTR) always as SDS TYPE 8. */
199-
o->ptr = sdswrite(data, val_sds_size, SDS_TYPE_8, val_ptr, val_len);
198+
/* Copy embedded value (EMBSTR) always as SDS TYPE 8. Account for unused
199+
* memory in the SDS alloc field. */
200+
size_t remaining_size = bufsize - (data - (char *)(void *)o);
201+
o->ptr = sdswrite(data, remaining_size, SDS_TYPE_8, val_ptr, val_len);
200202

201203
return o;
202204
}

tests/unit/type/string.tcl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -756,6 +756,7 @@ if {[string match {*jemalloc*} [s mem_allocator]]} {
756756
lappend res [r get bar]
757757
} {12 12}
758758

759+
if {[string match {*jemalloc*} [s mem_allocator]]} {
759760
test {Memory usage of embedded string value} {
760761
# Check that we can fit 9 bytes of key + value into a 32 byte
761762
# allocation, including the serverObject itself.
@@ -779,4 +780,6 @@ if {[string match {*jemalloc*} [s mem_allocator]]} {
779780
set sds_overhead [expr {$obj_alloc + $val_alloc - $obj_header_size - 1 - $content_size - $avail}]
780781
assert_equal 6 $sds_overhead
781782
} {} {needs:debug}
783+
} ; # if jemalloc
784+
782785
}

0 commit comments

Comments
 (0)