Skip to content

A set of 3 refactoring commits - #2

Closed
poige wants to merge 3 commits into
jemalloc:devfrom
poige:dev
Closed

poige wants to merge 3 commits into
jemalloc:devfrom
poige:dev

Conversation

@poige

@poige poige commented Oct 22, 2013

Copy link
Copy Markdown
Contributor

No description provided.

@jasone

jasone commented Nov 30, 2013

Copy link
Copy Markdown
Member

I committed the desirable part of this patch set as addad09. Thanks!

@jasone jasone closed this Nov 30, 2013
@alpha2z alpha2z mentioned this pull request Aug 30, 2014
krzycz added a commit to krzycz/jemalloc that referenced this pull request Oct 29, 2015
@lasarojc lasarojc mentioned this pull request Aug 8, 2017
@gyl30 gyl30 mentioned this pull request Mar 21, 2022
ilvokhin added a commit to ilvokhin/jemalloc that referenced this pull request Jan 13, 2025
This commit allows to enable sanitizers with autoconf options, instead
of modifying `CFLAGS`, `CXXFLAGS` and `LDFLAGS` directly.

* `--enable-tsan` option to enable Thread Sanitizer.
* `--enable-ubsan` option to enable Undefined Behaviour Sanitizer.
* And `--enable-asan` to enable Address Sanitizer.

End goal is to speedup development by finding problems quickly, early
and easier. Eventually, when all current issues will be fixed, we can
enable sanitizers in CI. Fortunately, there are not a lot of problems we
need to fix.

Address Sanitizer have a limited benefit for tests that exercise memory
allocation functions (`malloc`, `calloc` etc), because jemalloc logic
*will not be executed*, but still useful to find problems in test code
itself.

Below are couple of examples of how tests look like under different
sanitizers at the moment.

```
$  ../configure --enable-tsan --enable-debug
<...>
asan               : 0
tsan               : 1
ubsan              : 0
$ make -j`nproc` check
<...>
  Thread T13 (tid=332043, running) created by main thread at:
    #0 pthread_create <null> (libtsan.so.0+0x61748)
    jemalloc#1 thd_create ../test/src/thd.c:25 (bin_batching+0x5631ca)
    jemalloc#2 stress_run ../test/unit/bin_batching.c:148
(bin_batching+0x40364c)
    jemalloc#3 test_races ../test/unit/bin_batching.c:249
(bin_batching+0x403d79)
    jemalloc#4 p_test_impl ../test/src/test.c:149 (bin_batching+0x562811)
    jemalloc#5 p_test_no_reentrancy ../test/src/test.c:213
(bin_batching+0x562d35)
    jemalloc#6 main ../test/unit/bin_batching.c:268 (bin_batching+0x40417e)

SUMMARY: ThreadSanitizer: data race
../include/jemalloc/internal/edata.h:498 in edata_nfree_inc
```

```
$ ../configure --enable-ubsan --enable-debug
<...>
asan               : 0
tsan               : 0
ubsan              : 1
$ make -j`nproc` check
<...>
=== test/unit/hash ===
../test/unit/hash.c:119:16: runtime error: left shift of 176 by 24
places cannot be represented in type 'int'
<...>
```

```
$ ../configure --enable-asan --enable-debug
<...>
asan               : 1
tsan               : 0
ubsan              : 0
$ make -j`nproc` check
<...>
=== test/integration/slab_sizes ===
test_arena_reset (non-reentrant): pass
=================================================================
==389846==ERROR: AddressSanitizer: odr-violation (0x00000042c660):
  [1] size=8 'malloc_message' ../src/malloc_io.c:74:24
  [2] size=8 'malloc_message' ../src/malloc_io.c:74:24
```
ilvokhin added a commit to ilvokhin/jemalloc that referenced this pull request Jan 20, 2025
This commit allows to enable sanitizers with autoconf options, instead
of modifying `CFLAGS`, `CXXFLAGS` and `LDFLAGS` directly.

* `--enable-tsan` option to enable Thread Sanitizer.
* `--enable-ubsan` option to enable Undefined Behaviour Sanitizer.
* And `--enable-asan` to enable Address Sanitizer.

End goal is to speedup development by finding problems quickly, early
and easier. Eventually, when all current issues will be fixed, we can
enable sanitizers in CI. Fortunately, there are not a lot of problems we
need to fix.

Address Sanitizer have a limited benefit for tests that exercise memory
allocation functions (`malloc`, `calloc` etc), because jemalloc logic
*will not be executed*, but still useful to find problems in test code
itself.

Below are couple of examples of how tests look like under different
sanitizers at the moment.

```
$  ../configure --enable-tsan --enable-debug
<...>
asan               : 0
tsan               : 1
ubsan              : 0
$ make -j`nproc` check
<...>
  Thread T13 (tid=332043, running) created by main thread at:
    #0 pthread_create <null> (libtsan.so.0+0x61748)
    jemalloc#1 thd_create ../test/src/thd.c:25 (bin_batching+0x5631ca)
    jemalloc#2 stress_run ../test/unit/bin_batching.c:148
(bin_batching+0x40364c)
    jemalloc#3 test_races ../test/unit/bin_batching.c:249
(bin_batching+0x403d79)
    jemalloc#4 p_test_impl ../test/src/test.c:149 (bin_batching+0x562811)
    jemalloc#5 p_test_no_reentrancy ../test/src/test.c:213
(bin_batching+0x562d35)
    jemalloc#6 main ../test/unit/bin_batching.c:268 (bin_batching+0x40417e)

SUMMARY: ThreadSanitizer: data race
../include/jemalloc/internal/edata.h:498 in edata_nfree_inc
```

```
$ ../configure --enable-ubsan --enable-debug
<...>
asan               : 0
tsan               : 0
ubsan              : 1
$ make -j`nproc` check
<...>
=== test/unit/hash ===
../test/unit/hash.c:119:16: runtime error: left shift of 176 by 24
places cannot be represented in type 'int'
<...>
```

```
$ ../configure --enable-asan --enable-debug
<...>
asan               : 1
tsan               : 0
ubsan              : 0
$ make -j`nproc` check
<...>
=== test/integration/slab_sizes ===
test_arena_reset (non-reentrant): pass
=================================================================
==389846==ERROR: AddressSanitizer: odr-violation (0x00000042c660):
  [1] size=8 'malloc_message' ../src/malloc_io.c:74:24
  [2] size=8 'malloc_message' ../src/malloc_io.c:74:24
```
ilvokhin added a commit to ilvokhin/jemalloc that referenced this pull request Jan 24, 2025
We tried to load `g` from `bitmap[i]` before checking it is actually a
valid load. Tweaked a loop a bit to `break` early, when we are done
scanning for bits.

Before this commit undefined behaviour sanitizer from GCC 14+ was
unhappy at `test/unit/bitmap` test with following error.

```
../include/jemalloc/internal/bitmap.h:293:5: runtime error: load of
address 0x7bb1c2e08008 with insufficient space for an object of type
'const bitmap_t'
<...>
    #0 0x62671a149954 in bitmap_ffu ../include/jemalloc/internal/bitmap.h:293
    jemalloc#1 0x62671a149954 in test_bitmap_xfu_body ../test/unit/bitmap.c:275
    jemalloc#2 0x62671a14b767 in test_bitmap_xfu ../test/unit/bitmap.c:323
    jemalloc#3 0x62671a376ad1 in p_test_impl ../test/src/test.c:149
    jemalloc#4 0x62671a377135 in p_test ../test/src/test.c:200
    jemalloc#5 0x62671a13da06 in main ../test/unit/bitmap.c:336
<...>
```
ilvokhin added a commit to ilvokhin/jemalloc that referenced this pull request Jan 24, 2025
We tried to load `g` from `bitmap[i]` before checking it is actually a
valid load. Tweaked a loop a bit to `break` early, when we are done
scanning for bits.

Before this commit undefined behaviour sanitizer from GCC 14+ was
unhappy at `test/unit/bitmap` test with following error.

```
../include/jemalloc/internal/bitmap.h:293:5: runtime error: load of
address 0x7bb1c2e08008 with insufficient space for an object of type
'const bitmap_t'
<...>
    #0 0x62671a149954 in bitmap_ffu ../include/jemalloc/internal/bitmap.h:293
    jemalloc#1 0x62671a149954 in test_bitmap_xfu_body ../test/unit/bitmap.c:275
    jemalloc#2 0x62671a14b767 in test_bitmap_xfu ../test/unit/bitmap.c:323
    jemalloc#3 0x62671a376ad1 in p_test_impl ../test/src/test.c:149
    jemalloc#4 0x62671a377135 in p_test ../test/src/test.c:200
    jemalloc#5 0x62671a13da06 in main ../test/unit/bitmap.c:336
<...>
```
interwq pushed a commit that referenced this pull request Jan 28, 2025
We tried to load `g` from `bitmap[i]` before checking it is actually a
valid load. Tweaked a loop a bit to `break` early, when we are done
scanning for bits.

Before this commit undefined behaviour sanitizer from GCC 14+ was
unhappy at `test/unit/bitmap` test with following error.

```
../include/jemalloc/internal/bitmap.h:293:5: runtime error: load of
address 0x7bb1c2e08008 with insufficient space for an object of type
'const bitmap_t'
<...>
    #0 0x62671a149954 in bitmap_ffu ../include/jemalloc/internal/bitmap.h:293
    #1 0x62671a149954 in test_bitmap_xfu_body ../test/unit/bitmap.c:275
    #2 0x62671a14b767 in test_bitmap_xfu ../test/unit/bitmap.c:323
    #3 0x62671a376ad1 in p_test_impl ../test/src/test.c:149
    #4 0x62671a377135 in p_test ../test/src/test.c:200
    #5 0x62671a13da06 in main ../test/unit/bitmap.c:336
<...>
```
ilvokhin added a commit to ilvokhin/jemalloc that referenced this pull request Jan 30, 2025
This commit allows to enable sanitizers with autoconf options, instead
of modifying `CFLAGS`, `CXXFLAGS` and `LDFLAGS` directly.

* `--enable-tsan` option to enable Thread Sanitizer.
* `--enable-ubsan` option to enable Undefined Behaviour Sanitizer.

End goal is to speedup development by finding problems quickly, early
and easier. Eventually, when all current issues will be fixed, we can
enable sanitizers in CI. Fortunately, there are not a lot of problems we
need to fix.

Address Sanitizer is a bit controversial, because it replaces memory
allocator, so we decided to left it out for a while.

Below are couple of examples of how tests look like under different
sanitizers at the moment.

```
$  ../configure --enable-tsan --enable-debug
<...>
asan               : 0
tsan               : 1
ubsan              : 0
$ make -j`nproc` check
<...>
  Thread T13 (tid=332043, running) created by main thread at:
    #0 pthread_create <null> (libtsan.so.0+0x61748)
    jemalloc#1 thd_create ../test/src/thd.c:25 (bin_batching+0x5631ca)
    jemalloc#2 stress_run ../test/unit/bin_batching.c:148
(bin_batching+0x40364c)
    jemalloc#3 test_races ../test/unit/bin_batching.c:249
(bin_batching+0x403d79)
    jemalloc#4 p_test_impl ../test/src/test.c:149 (bin_batching+0x562811)
    jemalloc#5 p_test_no_reentrancy ../test/src/test.c:213
(bin_batching+0x562d35)
    jemalloc#6 main ../test/unit/bin_batching.c:268 (bin_batching+0x40417e)

SUMMARY: ThreadSanitizer: data race
../include/jemalloc/internal/edata.h:498 in edata_nfree_inc
```

```
$ ../configure --enable-ubsan --enable-debug
<...>
asan               : 0
tsan               : 0
ubsan              : 1
$ make -j`nproc` check
<...>
=== test/unit/hash ===
../test/unit/hash.c:119:16: runtime error: left shift of 176 by 24
places cannot be represented in type 'int'
<...>
```
ilvokhin added a commit to ilvokhin/jemalloc that referenced this pull request Jan 30, 2025
This commit allows to enable sanitizers with autoconf options, instead
of modifying `CFLAGS`, `CXXFLAGS` and `LDFLAGS` directly.

* `--enable-tsan` option to enable Thread Sanitizer.
* `--enable-ubsan` option to enable Undefined Behaviour Sanitizer.

End goal is to speedup development by finding problems quickly, early
and easier. Eventually, when all current issues will be fixed, we can
enable sanitizers in CI. Fortunately, there are not a lot of problems we
need to fix.

Address Sanitizer is a bit controversial, because it replaces memory
allocator, so we decided to left it out for a while.

Below are couple of examples of how tests look like under different
sanitizers at the moment.

```
$  ../configure --enable-tsan --enable-debug
<...>
asan               : 0
tsan               : 1
ubsan              : 0
$ make -j`nproc` check
<...>
  Thread T13 (tid=332043, running) created by main thread at:
    #0 pthread_create <null> (libtsan.so.0+0x61748)
    jemalloc#1 thd_create ../test/src/thd.c:25 (bin_batching+0x5631ca)
    jemalloc#2 stress_run ../test/unit/bin_batching.c:148
(bin_batching+0x40364c)
    jemalloc#3 test_races ../test/unit/bin_batching.c:249
(bin_batching+0x403d79)
    jemalloc#4 p_test_impl ../test/src/test.c:149 (bin_batching+0x562811)
    jemalloc#5 p_test_no_reentrancy ../test/src/test.c:213
(bin_batching+0x562d35)
    jemalloc#6 main ../test/unit/bin_batching.c:268 (bin_batching+0x40417e)

SUMMARY: ThreadSanitizer: data race
../include/jemalloc/internal/edata.h:498 in edata_nfree_inc
```

```
$ ../configure --enable-ubsan --enable-debug
<...>
asan               : 0
tsan               : 0
ubsan              : 1
$ make -j`nproc` check
<...>
=== test/unit/hash ===
../test/unit/hash.c:119:16: runtime error: left shift of 176 by 24
places cannot be represented in type 'int'
<...>
```
interwq pushed a commit that referenced this pull request Feb 5, 2025
This commit allows to enable sanitizers with autoconf options, instead
of modifying `CFLAGS`, `CXXFLAGS` and `LDFLAGS` directly.

* `--enable-tsan` option to enable Thread Sanitizer.
* `--enable-ubsan` option to enable Undefined Behaviour Sanitizer.

End goal is to speedup development by finding problems quickly, early
and easier. Eventually, when all current issues will be fixed, we can
enable sanitizers in CI. Fortunately, there are not a lot of problems we
need to fix.

Address Sanitizer is a bit controversial, because it replaces memory
allocator, so we decided to left it out for a while.

Below are couple of examples of how tests look like under different
sanitizers at the moment.

```
$  ../configure --enable-tsan --enable-debug
<...>
asan               : 0
tsan               : 1
ubsan              : 0
$ make -j`nproc` check
<...>
  Thread T13 (tid=332043, running) created by main thread at:
    #0 pthread_create <null> (libtsan.so.0+0x61748)
    #1 thd_create ../test/src/thd.c:25 (bin_batching+0x5631ca)
    #2 stress_run ../test/unit/bin_batching.c:148
(bin_batching+0x40364c)
    #3 test_races ../test/unit/bin_batching.c:249
(bin_batching+0x403d79)
    #4 p_test_impl ../test/src/test.c:149 (bin_batching+0x562811)
    #5 p_test_no_reentrancy ../test/src/test.c:213
(bin_batching+0x562d35)
    #6 main ../test/unit/bin_batching.c:268 (bin_batching+0x40417e)

SUMMARY: ThreadSanitizer: data race
../include/jemalloc/internal/edata.h:498 in edata_nfree_inc
```

```
$ ../configure --enable-ubsan --enable-debug
<...>
asan               : 0
tsan               : 0
ubsan              : 1
$ make -j`nproc` check
<...>
=== test/unit/hash ===
../test/unit/hash.c:119:16: runtime error: left shift of 176 by 24
places cannot be represented in type 'int'
<...>
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants