]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
DEBUG: shctx: name shared memory using vma_set_name()
authorAurelien DARRAGON <adarragon@haproxy.com>
Mon, 20 May 2024 12:11:31 +0000 (14:11 +0200)
committerAurelien DARRAGON <adarragon@haproxy.com>
Tue, 21 May 2024 15:55:03 +0000 (17:55 +0200)
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/<pid>/maps:

7ec6aab0f000-7ec6ac000000 rw-s 00000000 00:01 405                        [anon_shmem:shctx:custom_name]

src/shctx.c

index 6c7ad172d106dcca1ea86067e7c782ada3cdd378..931bc4f5f68d1ac0b204d869c3013a40640a4636 100644 (file)
@@ -16,9 +16,7 @@
 #include <import/ebmbtree.h>
 #include <haproxy/list.h>
 #include <haproxy/shctx.h>
-#if defined(USE_PRCTL)
-#include <sys/prctl.h>
-#endif
+#include <haproxy/tools.h>
 
 /*
  * Reserve a new row if <first> 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/<pid>/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;