From: Vladimir Davydov <vdavydov.dev@gmail.com> To: Cyrill Gorcunov <gorcunov@gmail.com> Cc: tml <tarantool-patches@freelists.org>, Alexander Turenko <alexander.turenko@tarantool.org> Subject: Re: [PATCH 3/3] test: slab_arena -- Verify madvise Date: Mon, 6 May 2019 13:45:20 +0300 [thread overview] Message-ID: <20190506104520.it7uem5woxykg5xt@esperanza> (raw) In-Reply-To: <20190501155006.14546-4-gorcunov@gmail.com> [Cc += Alexander re tests] On Wed, May 01, 2019 at 06:50:06PM +0300, Cyrill Gorcunov wrote: > Since madvise support depends on sys libraries > and kernel version we print error if only small > supports it and /proc/self/smaps provide more > less decent VmFlags. TBO I wouldn't bother testing this feature at all, because it's way too platform dependent. Alternatively, we could test it by crashing a process and checking the size of the generated core file, but then again it doesn't look like a portable way. Alexander, any ideas? > > Part of #3509 > --- > https://github.com/tarantool/tarantool/issues/3509 > > test/slab_arena.c | 90 +++++++++++++++++++++++++++++++++++++++++++++++ > 1 file changed, 90 insertions(+) > > diff --git a/test/slab_arena.c b/test/slab_arena.c > index d0a78d1..5c5085c 100644 > --- a/test/slab_arena.c > +++ b/test/slab_arena.c > @@ -3,6 +3,7 @@ > #include <stdio.h> > #include <limits.h> > #include <stdlib.h> > +#include <string.h> > #include <time.h> > #include "unit.h" > > @@ -15,6 +16,93 @@ slab_arena_print(struct slab_arena *arena) > arena->used, arena->slab_size); > } > > +#define is_hex_digit(c) \ > + (((c) >= '0' && (c) <= '9') || \ > + ((c) >= 'a' && (c) <= 'f') || \ > + ((c) >= 'A' && (c) <= 'F')) > + > +static int is_vma_range_fmt(char *line, unsigned long *start, unsigned long *end) > +{ > + char *p = line; > + while (*line && is_hex_digit(*line)) > + line++; > + > + if (*line++ != '-') > + return 0; > + > + while (*line && is_hex_digit(*line)) > + line++; > + > + if (*line++ != ' ') > + return 0; > + > + sscanf(p, "%lx-%lx", start, end); > + return 1; > +} > + > +static void > +slab_test_madvise(void) > +{ > + struct slab_arena arena; > + struct quota quota; > + FILE *f = NULL; > + void *ptr; > + > + quota_init("a, 2000000); > + slab_arena_create(&arena, "a, 3000000, 1, MAP_PRIVATE); > + > + /* > + * Will fetch from preallocated area. > + */ > + ptr = slab_map(&arena); > + if (!ptr) { > + printf("can't obtain slab\n"); > + goto out; > + } > + > + /* > + * If system supports madvise call, we should try > + * fetch the precise VMA state from smaps file, > + * but if only it exists. > + */ > + if (!slab_arena_madvise_dontdump(&arena)) { > + unsigned long start = 0, end = 0; > + char buf[1024], *tok = NULL; > + bool found = false; > + > + f = fopen("/proc/self/smaps", "r"); > + if (!f) > + goto out; > + > + while (fgets(buf, sizeof(buf), f)) { > + is_vma_range_fmt(buf, &start, &end); > + if (strncmp(buf, "VmFlags: ", 9) || (void *)start != ptr) > + continue; > + tok = buf; > + break; > + } > + > + if (tok) { > + for (tok = strtok(tok, " \n"); tok; > + tok = strtok(NULL, " \n")) { > + if (strcmp(tok, "dd")) > + continue; > + found = true; > + break; > + } > + } > + > + if (!found) > + printf("ERROR: Expected dd flag on VMA address %p\n", ptr); > + > + fclose(f); > + } > + > +out: > + slab_unmap(&arena, ptr); > + slab_arena_destroy(&arena); > +} > + > int main() > { > struct quota quota; > @@ -42,4 +130,6 @@ int main() > slab_arena_create(&arena, "a, 3000000, 1, MAP_PRIVATE); > slab_arena_print(&arena); > slab_arena_destroy(&arena); > + > + slab_test_madvise(); > }
next prev parent reply other threads:[~2019-05-06 10:45 UTC|newest] Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top 2019-05-01 15:50 [PATCH 0/3] small: Prepare ground for madvise Cyrill Gorcunov 2019-05-01 15:50 ` [PATCH 1/3] build: Check for madvise syscall Cyrill Gorcunov 2019-05-06 10:25 ` Vladimir Davydov 2019-05-06 10:39 ` Cyrill Gorcunov 2019-05-01 15:50 ` [PATCH 2/3] slab_arena: Provide slab_arena_madvise_create to madvice slabs Cyrill Gorcunov 2019-05-06 10:38 ` Vladimir Davydov 2019-05-06 11:03 ` Cyrill Gorcunov 2019-05-06 13:46 ` Alexander Turenko 2019-05-01 15:50 ` [PATCH 3/3] test: slab_arena -- Verify madvise Cyrill Gorcunov 2019-05-06 10:45 ` Vladimir Davydov [this message] 2019-05-06 10:48 ` Cyrill Gorcunov 2019-05-06 10:55 ` Vladimir Davydov 2019-05-06 10:57 ` Cyrill Gorcunov 2019-05-06 11:04 ` Alexander Turenko
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20190506104520.it7uem5woxykg5xt@esperanza \ --to=vdavydov.dev@gmail.com \ --cc=alexander.turenko@tarantool.org \ --cc=gorcunov@gmail.com \ --cc=tarantool-patches@freelists.org \ --subject='Re: [PATCH 3/3] test: slab_arena -- Verify madvise' \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox