From: Aurelien DARRAGON Date: Mon, 20 May 2024 12:11:31 +0000 (+0200) Subject: DEBUG: shctx: name shared memory using vma_set_name() X-Git-Tag: v3.0-dev13~61 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=6de0da1b54295fdac46e16b5e7707b2199b305f9;p=thirdparty%2Fhaproxy.git DEBUG: shctx: name shared memory using vma_set_name() In 98d22f212 ("MEDIUM: shctx: Naming shared memory context"), David implemented prctl/PR_SET_VMA support to give a name to shctx maps when supported. Maps were named after "HAProxy $name". It turns out that it is not relevant to include "HAProxy" in the map name, given that we're already looking at maps for a given PID (and here it's HAProxy's pid). Instead, let's name shctx maps by making use of the new vma_set_name() helper introduced by previous commit. Resulting maps will be named "shctx:$name", e.g.: "shctx:globalCache", they will appear like this in /proc//maps: 7ec6aab0f000-7ec6ac000000 rw-s 00000000 00:01 405 [anon_shmem:shctx:custom_name] --- diff --git a/src/shctx.c b/src/shctx.c index 6c7ad172d1..931bc4f5f6 100644 --- a/src/shctx.c +++ b/src/shctx.c @@ -16,9 +16,7 @@ #include #include #include -#if defined(USE_PRCTL) -#include -#endif +#include /* * Reserve a new row if is null, put it in the hotlist, set the refcount to 1 @@ -295,30 +293,7 @@ int shctx_init(struct shared_context **orig_shctx, int maxblocks, int blocksize, goto err; } -#if defined(USE_PRCTL) && defined(PR_SET_VMA) - { - /** - * From Linux 5.17 (and if the `CONFIG_ANON_VMA_NAME` kernel config is set)`, - * anonymous regions can be named. - * We intentionally ignore errors as it should not jeopardize the memory context - * mapping whatsoever (e.g. older kernels). - * - * The naming can take up to 79 characters, accepting valid ASCII values - * except [, ], \, $ and '. - * As a result, when looking for /proc//maps, we can see the anonymous range - * as follow : - * `7364c4fff000-736508000000 rw-s 00000000 00:01 3540 [anon_shmem:HAProxy globalCache]` - */ - int rn; - char fullname[80]; - - rn = snprintf(fullname, sizeof(fullname), "HAProxy %s", name); - if (rn >= 0) { - (void)prctl(PR_SET_VMA, PR_SET_VMA_ANON_NAME, (uintptr_t)shctx, - totalsize, (uintptr_t)fullname); - } - } -#endif + vma_set_name(shctx, totalsize, "shctx", name); shctx->nbav = 0;