server-skynet-source-3rd-je.../test/unit
Azat Khuzhin a943172b73 Add runtime detection for MADV_DONTNEED zeroes pages (mostly for qemu)
qemu does not support this, yet [1], and you can get very tricky assert
if you will run program with jemalloc in use under qemu:

    <jemalloc>: ../contrib/jemalloc/src/extent.c:1195: Failed assertion: "p[i] == 0"

  [1]: https://patchwork.kernel.org/patch/10576637/

Here is a simple example that shows the problem [2]:

    // Gist to check possible issues with MADV_DONTNEED
    // For example it does not supported by qemu user
    // There is a patch for this [1], but it hasn't been applied.
    //   [1]: https://lists.gnu.org/archive/html/qemu-devel/2018-08/msg05422.html

    #include <sys/mman.h>
    #include <stdio.h>
    #include <stddef.h>
    #include <assert.h>
    #include <string.h>

    int main(int argc, char **argv)
    {
        void *addr = mmap(NULL, 1<<16, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
        if (addr == MAP_FAILED) {
            perror("mmap");
            return 1;
        }
        memset(addr, 'A', 1<<16);

        if (!madvise(addr, 1<<16, MADV_DONTNEED)) {
            puts("MADV_DONTNEED does not return error. Check memory.");
            for (int i = 0; i < 1<<16; ++i) {
                assert(((unsigned char *)addr)[i] == 0);
            }
        } else {
            perror("madvise");
        }

        if (munmap(addr, 1<<16)) {
            perror("munmap");
            return 1;
        }

        return 0;
    }

  ### unpatched qemu

      $ qemu-x86_64-static /tmp/test-MADV_DONTNEED
      MADV_DONTNEED does not return error. Check memory.
      test-MADV_DONTNEED: /tmp/test-MADV_DONTNEED.c:19: main: Assertion `((unsigned char *)addr)[i] == 0' failed.
      qemu: uncaught target signal 6 (Aborted) - core dumped
      Aborted (core dumped)

  ### patched qemu (by returning ENOSYS error)

      $ qemu-x86_64 /tmp/test-MADV_DONTNEED
      madvise: Success

  ### patch for qemu to return ENOSYS

      diff --git a/linux-user/syscall.c b/linux-user/syscall.c
      index 897d20c076..5540792e0e 100644
      --- a/linux-user/syscall.c
      +++ b/linux-user/syscall.c
      @@ -11775,7 +11775,7 @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1,
                  turns private file-backed mappings into anonymous mappings.
                  This will break MADV_DONTNEED.
                  This is a hint, so ignoring and returning success is ok.  */
      -        return 0;
      +        return ENOSYS;
       #endif
       #ifdef TARGET_NR_fcntl64
           case TARGET_NR_fcntl64:

  [2]: https://gist.github.com/azat/12ba2c825b710653ece34dba7f926ece

v2:
- review fixes
- add opt_dont_trust_madvise
v3:
- review fixes
- rename opt_dont_trust_madvise to opt_trust_madvise
2021-01-20 20:08:30 -08:00
..
a0.c Change assert_* to expect_* in tests 2020-02-19 16:03:16 -08:00
arena_decay.c Allow opt.tcache_max to accept small size classes. 2020-10-24 20:43:44 -07:00
arena_decay.sh Allow opt.tcache_max to accept small size classes. 2020-10-24 20:43:44 -07:00
arena_reset_prof.c Use MALLOC_CONF rather than malloc_conf for tests. 2017-02-23 08:57:02 -08:00
arena_reset_prof.sh Use MALLOC_CONF rather than malloc_conf for tests. 2017-02-23 08:57:02 -08:00
arena_reset.c PA: Parameterize emap. Move emap_global to arena. 2020-04-10 13:12:47 -07:00
atomic.c Change assert_* to expect_* in tests 2020-02-19 16:03:16 -08:00
background_thread_enable.c Change assert_* to expect_* in tests 2020-02-19 16:03:16 -08:00
background_thread.c Change assert_* to expect_* in tests 2020-02-19 16:03:16 -08:00
base.c Change assert_* to expect_* in tests 2020-02-19 16:03:16 -08:00
batch_alloc_prof.c Add batch allocation API 2020-07-31 09:16:50 -07:00
batch_alloc_prof.sh Add batch allocation API 2020-07-31 09:16:50 -07:00
batch_alloc.c Route batch allocation of small batch size to tcache 2020-11-16 20:58:01 -08:00
batch_alloc.sh Add batch allocation API 2020-07-31 09:16:50 -07:00
binshard.c PA: Parameterize emap. Move emap_global to arena. 2020-04-10 13:12:47 -07:00
binshard.sh Add unit test for sharded bins. 2018-12-03 17:17:03 -08:00
bit_util.c bit_util: Guarantee popcount's presence. 2020-12-07 06:21:08 -08:00
bitmap.c bitset test: Pull NBITS_TAB into its own file. 2020-07-30 15:25:23 -07:00
buf_writer.c Add piping API to buffered writer 2020-04-01 09:41:20 -07:00
cache_bin.c cache_bin: Separate out local and remote accesses. 2021-01-08 14:18:08 -08:00
ckh.c Change assert_* to expect_* in tests 2020-02-19 16:03:16 -08:00
counter.c Migrate counter to use locked int 2020-05-12 08:23:15 -07:00
decay.c Decay: Add a (mostly stub) test case. 2020-04-10 13:12:47 -07:00
div.c Change assert_* to expect_* in tests 2020-02-19 16:03:16 -08:00
double_free.c Eagerly detect double free and sized dealloc bugs for large sizes. 2020-10-15 10:03:16 -07:00
double_free.h Eagerly detect double free and sized dealloc bugs for large sizes. 2020-10-15 10:03:16 -07:00
edata_cache.c Edata cache small: rewrite. 2020-11-05 12:34:43 -08:00
emitter.c Change assert_* to expect_* in tests 2020-02-19 16:03:16 -08:00
extent_quantize.c Change assert_* to expect_* in tests 2020-02-19 16:03:16 -08:00
flat_bitmap.c flat bitmap: add scount / ucount functions. 2020-12-07 06:21:08 -08:00
fork.c Change assert_* to expect_* in tests 2020-02-19 16:03:16 -08:00
fxp.c Add fxp: A fixed-point math library. 2020-12-04 23:48:19 -08:00
hash.c Change assert_* to expect_* in tests 2020-02-19 16:03:16 -08:00
hook.c Change assert_* to expect_* in tests 2020-02-19 16:03:16 -08:00
hpa_central.c Add hpa_central module 2020-10-05 19:55:57 -07:00
hpa.c Introduce hpdata_t. 2020-12-07 06:21:08 -08:00
hpdata.c hpdata: Add a test. 2020-12-07 06:21:08 -08:00
huge.c Change assert_* to expect_* in tests 2020-02-19 16:03:16 -08:00
inspect.c Inspect test: Reduce checks when profiling is on. 2020-03-12 11:58:09 -07:00
junk_alloc.c Use MALLOC_CONF rather than malloc_conf for tests. 2017-02-23 08:57:02 -08:00
junk_alloc.sh Use MALLOC_CONF rather than malloc_conf for tests. 2017-02-23 08:57:02 -08:00
junk_free.c Use MALLOC_CONF rather than malloc_conf for tests. 2017-02-23 08:57:02 -08:00
junk_free.sh Use MALLOC_CONF rather than malloc_conf for tests. 2017-02-23 08:57:02 -08:00
junk.c Don't do reentrant testing in junk tests. 2020-04-07 15:45:40 -07:00
junk.sh Use MALLOC_CONF rather than malloc_conf for tests. 2017-02-23 08:57:02 -08:00
log.c Change assert_* to expect_* in tests 2020-02-19 16:03:16 -08:00
mallctl.c Add runtime detection for MADV_DONTNEED zeroes pages (mostly for qemu) 2021-01-20 20:08:30 -08:00
malloc_conf_2.c Add malloc_conf_2_conf_harder 2020-03-31 06:25:08 -07:00
malloc_conf_2.sh Add malloc_conf_2_conf_harder 2020-03-31 06:25:08 -07:00
malloc_io.c IO: Support 0-padding for unsigned numbers. 2020-08-13 10:03:15 -07:00
math.c Change assert_* to expect_* in tests 2020-02-19 16:03:16 -08:00
mq.c Change assert_* to expect_* in tests 2020-02-19 16:03:16 -08:00
mtx.c Change assert_* to expect_* in tests 2020-02-19 16:03:16 -08:00
nstime.c High Resolution Timestamps for Profiling 2020-06-15 12:12:49 -07:00
oversize_threshold.c Add a per-arena oversize_threshold. 2020-11-13 13:45:35 -08:00
pa.c Add a per-arena oversize_threshold. 2020-11-13 13:45:35 -08:00
pack.c Change assert_* to expect_* in tests 2020-02-19 16:03:16 -08:00
pack.sh Refactor *decay_time into *decay_ms. 2017-05-18 11:33:45 -07:00
pages.c Change assert_* to expect_* in tests 2020-02-19 16:03:16 -08:00
peak.c Add peak_t, for tracking allocator net max. 2020-06-11 13:54:22 -07:00
ph.c Change assert_* to expect_* in tests 2020-02-19 16:03:16 -08:00
prng.c PRNG test: cleanups. 2020-10-05 19:55:57 -07:00
prof_accum.c Move file handling logic in prof_data to prof_sys 2020-06-29 14:27:50 -07:00
prof_accum.sh Use MALLOC_CONF rather than malloc_conf for tests. 2017-02-23 08:57:02 -08:00
prof_active.c Expose prof_data testing internals only in prof tests 2020-06-29 14:27:50 -07:00
prof_active.sh Use MALLOC_CONF rather than malloc_conf for tests. 2017-02-23 08:57:02 -08:00
prof_gdump.c HPA: Tie components into a PAI implementation. 2020-10-23 11:14:34 -07:00
prof_gdump.sh Use MALLOC_CONF rather than malloc_conf for tests. 2017-02-23 08:57:02 -08:00
prof_idump.c Move file handling logic in prof_data to prof_sys 2020-06-29 14:27:50 -07:00
prof_idump.sh Remove --disable-tcache. 2017-04-21 10:06:12 -07:00
prof_log.c prof_log: cassert(config_prof) in public functions 2021-01-04 14:55:49 -08:00
prof_log.sh Add unit tests for logging 2018-08-01 13:27:11 -07:00
prof_mdump.c Move file handling logic in prof_data to prof_sys 2020-06-29 14:27:50 -07:00
prof_mdump.sh Push error handling logic out of core dumping logic 2020-06-29 14:27:50 -07:00
prof_recent.c Add sample interval to prof last-N dump 2020-11-13 15:33:27 -08:00
prof_recent.sh Last-N profiling mode 2019-12-30 15:58:57 -08:00
prof_reset.c No need to intercept prof_dump_header() in tests 2020-06-29 14:27:50 -07:00
prof_reset.sh Last-N profiling mode 2019-12-30 15:58:57 -08:00
prof_stats.c Add alignment tests for prof stats 2021-01-07 20:39:49 -08:00
prof_stats.sh Track per size class internal fragmentation 2021-01-07 20:39:49 -08:00
prof_sys_thread_name.c Create prof_sys module for reading system thread name 2020-06-29 14:27:50 -07:00
prof_sys_thread_name.sh Improve naming for prof system thread name option 2020-06-24 14:32:01 -07:00
prof_tctx.c Generalize prof_cnt_all() for testing 2020-06-29 14:27:50 -07:00
prof_tctx.sh Use MALLOC_CONF rather than malloc_conf for tests. 2017-02-23 08:57:02 -08:00
prof_thread_name.c Change assert_* to expect_* in tests 2020-02-19 16:03:16 -08:00
prof_thread_name.sh Use MALLOC_CONF rather than malloc_conf for tests. 2017-02-23 08:57:02 -08:00
psset.c psset unit test: fix a bug. 2020-12-07 06:21:08 -08:00
ql.c Add move constructor to ql module 2020-04-06 09:50:27 -07:00
qr.c Optimize meld in qr module 2020-04-06 09:50:27 -07:00
rb.c Change assert_* to expect_* in tests 2020-02-19 16:03:16 -08:00
retained.c Rename geom_grow -> exp_grow. 2020-11-13 13:42:33 -08:00
rtree.c Edata: rename "ranged" bit to "pai". 2020-09-18 12:39:25 -07:00
safety_check.c Change assert_* to expect_* in tests 2020-02-19 16:03:16 -08:00
safety_check.sh Safety checks: Add a redzoning feature. 2019-04-15 16:48:12 -07:00
sc.c Change assert_* to expect_* in tests 2020-02-19 16:03:16 -08:00
sec.c Add SEC module: a small extent cache. 2020-10-23 11:14:34 -07:00
seq.c Change assert_* to expect_* in tests 2020-02-19 16:03:16 -08:00
SFMT.c Change assert_* to expect_* in tests 2020-02-19 16:03:16 -08:00
size_check.c Eagerly detect double free and sized dealloc bugs for large sizes. 2020-10-15 10:03:16 -07:00
size_classes.c Change assert_* to expect_* in tests 2020-02-19 16:03:16 -08:00
slab.c Edata: rename "ranged" bit to "pai". 2020-09-18 12:39:25 -07:00
smoothstep.c Change assert_* to expect_* in tests 2020-02-19 16:03:16 -08:00
spin.c Header refactoring: unify and de-catchall rtree module. 2017-05-31 13:08:45 -07:00
stats_print.c Change assert_* to expect_* in tests 2020-02-19 16:03:16 -08:00
stats.c HPA: Tie components into a PAI implementation. 2020-10-23 11:14:34 -07:00
tcache_max.c Allow opt.tcache_max to accept small size classes. 2020-10-24 20:43:44 -07:00
tcache_max.sh Allow opt.tcache_max to accept small size classes. 2020-10-24 20:43:44 -07:00
test_hooks.c Change assert_* to expect_* in tests 2020-02-19 16:03:16 -08:00
thread_event.c Remove thread_event_rollback() 2020-03-12 13:55:00 -07:00
thread_event.sh Build a general purpose thread event handler 2019-11-04 11:15:50 -08:00
ticker.c Change assert_* to expect_* in tests 2020-02-19 16:03:16 -08:00
tsd.c Change assert_* to expect_* in tests 2020-02-19 16:03:16 -08:00
witness.c Change assert_* to expect_* in tests 2020-02-19 16:03:16 -08:00
zero_realloc_abort.c Change assert_* to expect_* in tests 2020-02-19 16:03:16 -08:00
zero_realloc_abort.sh Realloc: Make behavior of realloc(ptr, 0) configurable. 2019-10-29 17:48:44 -07:00
zero_realloc_free.c Change assert_* to expect_* in tests 2020-02-19 16:03:16 -08:00
zero_realloc_free.sh Realloc: Make behavior of realloc(ptr, 0) configurable. 2019-10-29 17:48:44 -07:00
zero_realloc_strict.c Change assert_* to expect_* in tests 2020-02-19 16:03:16 -08:00
zero_realloc_strict.sh Realloc: Make behavior of realloc(ptr, 0) configurable. 2019-10-29 17:48:44 -07:00
zero_reallocs.c Change assert_* to expect_* in tests 2020-02-19 16:03:16 -08:00
zero_reallocs.sh Add stats counters for number of zero reallocs 2019-10-29 17:48:44 -07:00
zero.c Change assert_* to expect_* in tests 2020-02-19 16:03:16 -08:00
zero.sh Use MALLOC_CONF rather than malloc_conf for tests. 2017-02-23 08:57:02 -08:00