[PATCH v3] slab_arena: Enhance slab_arena_create to support madvise hints
Vladimir Davydov
vdavydov.dev at gmail.com
Wed May 15 15:37:56 MSK 2019
On Mon, May 13, 2019 at 11:01:26PM +0300, Cyrill Gorcunov wrote:
> The purpose of this extension is to be able to eliminate
> some of slab arenas from dumping, especially when huge
> amount of memory involves.
>
> To keep backward compatibility we map flags passed into
> new SLAB_ARENA_x flags. To be able to distinguish old
> and new interfaces we reserve high bit of the integer
> value and remap flags internally to syscall compatible
> form.
>
> Same time I have to modify build script to define
> _GNU_SOURCE symbol otherwise madvise bits won't be
> found.
>
> Part-of https://github.com/tarantool/tarantool/issues/3509
> ---
> v2:
> - Encode madvise hint inside slab_arena_create flags, for backward compatibility
> - Enhance test to address dynamic slabs
> - Enhance build procedure to test all falgs and functions we're interested in
> v3:
> - Keep SLAB_ARENA_ flags inside struct slab_arena
> - Use HAVE keyword in cmake
> - Move madvise into madvise_checked helper
> - Extend comment for SLAB_ARENA_ flags
>
> .gitignore | 1 +
> CMakeLists.txt | 18 ++++++
> small/config.h.cmake | 31 +++++++++++
> small/slab_arena.c | 68 +++++++++++++++++++----
> small/slab_arena.h | 23 +++++++-
> test/slab_arena.c | 128 +++++++++++++++++++++++++++++++++++++++++++
I'd also patch all places (tests, etc) where old flags (MAP_*) are used
to switch them to new flags. Sooner or later we should drop this compat
layer.
> diff --git a/small/slab_arena.c b/small/slab_arena.c
> index 26e2620..9f4baee 100644
> --- a/small/slab_arena.c
> +++ b/small/slab_arena.c
> @@ -41,17 +41,35 @@
> #include <valgrind/valgrind.h>
> #include <valgrind/memcheck.h>
>
> -#if !defined(MAP_ANONYMOUS)
> -#define MAP_ANONYMOUS MAP_ANON
> +static void
> +madvise_checked(void *ptr, size_t size, int flags)
> +{
> +#ifdef TARANTOOL_SMALL_USE_MADVISE
It would be nice to have a warning in case MADV_DONTDUMP is unavailable.
It should be printed only once. May be, here, or, even better, in
Tarantool itself (via say_warn()).
> + if (ptr && (flags & SLAB_ARENA_DONTDUMP)) {
> + if (madvise(ptr, size, MADV_DONTDUMP)) {
> + char *ignore_it;
> + char buf[64];
> +
> + ignore_it = strerror_r(errno, buf, sizeof(buf));
> + (void)ignore_it;
> +
> + fprintf(stderr, "Error in madvise(%p, %zu, 0x%x): %s\n",
> + ptr, size, MADV_DONTDUMP, buf);
> + }
> + }
> +#else
> + (void)ptr;
> + (void)size;
> + (void)flags;
> #endif
> +}
>
> static void
> munmap_checked(void *addr, size_t size)
> {
> if (munmap(addr, size)) {
> char buf[64];
> - intptr_t ignore_it = (intptr_t)strerror_r(errno, buf,
> - sizeof(buf));
> + char *ignore_it = strerror_r(errno, buf, sizeof(buf));
This wouldn't compile on OS X. Please leave it as is. Same's fair for
madvise_checked.
More information about the Tarantool-patches
mailing list