]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
DEBUG: pollers/fd: add thread id suffix to per-thread memory areas name hints
authorAurelien DARRAGON <adarragon@haproxy.com>
Fri, 24 May 2024 08:41:28 +0000 (10:41 +0200)
committerAurelien DARRAGON <adarragon@haproxy.com>
Fri, 24 May 2024 10:07:18 +0000 (12:07 +0200)
Willy reported that since abb8412d2 ("DEBUG: pollers: add name hint for
large memory areas used by pollers") and 22ec2ad8b ("DEBUG: fd: add name
hint for large memory areas") multiple maps with the same name could be
found in /proc/<pid>/maps when haproxy process is started with multiple
threads, which can be annoying.

In fact this happens because some poller and fd-created memory areas are
being created for each available thread, and since the naming was done
using vma_set_name() with the same <type> and <name> inputs, the resulting
name was the same for all threads.

Thanks to the previous commit, we now use vma_set_name_id() for naming
per-thread memory areas so that "-id" prefix is appended after the name
name, where "id" equals to 'tid+1' (to match the thread numbering logic
found in config file or in ha_panic() report),  allowing to easily
identify which haproxy thread owns the map in /proc/<pid>/maps:

7d3b26200000-7d3b26a01000 rw-p 00000000 00:00 0                          [anon:ev_poll:poll_events-2]
7d3b26c00000-7d3b27001000 rw-p 00000000 00:00 0                          [anon:fd:fd_updt-2]
7d3b27200000-7d3b27a01000 rw-p 00000000 00:00 0                          [anon:ev_poll:poll_events-1]
7d3b34200000-7d3b34601000 rw-p 00000000 00:00 0                          [anon:fd:fd_updt-1]

src/ev_epoll.c
src/ev_poll.c
src/ev_select.c
src/fd.c

index 2a41b73730c9f795021cc7f6db2c48a1af3f2b03..352620d0a3db1056461be5f4d6c4e375554dd6c5 100644 (file)
@@ -275,8 +275,8 @@ static int init_epoll_per_thread()
        epoll_events = calloc(1, sizeof(struct epoll_event) * global.tune.maxpollevents);
        if (epoll_events == NULL)
                goto fail_alloc;
-       vma_set_name(epoll_events, sizeof(struct epoll_event) * global.tune.maxpollevents,
-                    "ev_epoll", "epoll_events");
+       vma_set_name_id(epoll_events, sizeof(struct epoll_event) * global.tune.maxpollevents,
+                       "ev_epoll", "epoll_events", tid + 1);
 
        if (MAX_THREADS > 1 && tid) {
                epoll_fd[tid] = epoll_create(global.maxsock + 1);
index bc70713c5deb94cd320dbfa5a74224421eafb9db..805142003d7619f76d8106bbd1db8dfb6a34912d 100644 (file)
@@ -250,7 +250,8 @@ static int init_poll_per_thread()
        poll_events = calloc(1, sizeof(struct pollfd) * global.maxsock);
        if (poll_events == NULL)
                return 0;
-       vma_set_name(poll_events, sizeof(struct pollfd) * global.maxsock, "ev_poll", "poll_events");
+       vma_set_name_id(poll_events, sizeof(struct pollfd) * global.maxsock,
+                       "ev_poll", "poll_events", tid + 1);
        return 1;
 }
 
index e41c30e17bdd621c33d29a1830af78f7642edf79..9588e8a28ad08046e0ff251781cf5a06fa9cf0d3 100644 (file)
@@ -224,11 +224,11 @@ static int init_select_per_thread()
        tmp_evts[DIR_RD] = calloc(1, fd_set_bytes);
        if (tmp_evts[DIR_RD] == NULL)
                goto fail;
-       vma_set_name(tmp_evts[DIR_RD], fd_set_bytes, "ev_select", "tmp_evts_rd");
+       vma_set_name_id(tmp_evts[DIR_RD], fd_set_bytes, "ev_select", "tmp_evts_rd", tid + 1);
        tmp_evts[DIR_WR] = calloc(1, fd_set_bytes);
        if (tmp_evts[DIR_WR] == NULL)
                goto fail;
-       vma_set_name(tmp_evts[DIR_WR], fd_set_bytes, "ev_select", "tmp_evts_wr");
+       vma_set_name_id(tmp_evts[DIR_WR], fd_set_bytes, "ev_select", "tmp_evts_wr", tid + 1);
        return 1;
   fail:
        free(tmp_evts[DIR_RD]);
index c5a27c24b786e410682b512a2bafe747d57c34eb..5262225352e3733add5f74121ba1f3a4ac7bfb5c 100644 (file)
--- a/src/fd.c
+++ b/src/fd.c
@@ -1108,7 +1108,7 @@ void poller_pipe_io_handler(int fd)
 static int alloc_pollers_per_thread()
 {
        fd_updt = calloc(global.maxsock, sizeof(*fd_updt));
-       vma_set_name(fd_updt, global.maxsock * sizeof(*fd_updt), "fd", "fd_updt");
+       vma_set_name_id(fd_updt, global.maxsock * sizeof(*fd_updt), "fd", "fd_updt", tid + 1);
        return fd_updt != NULL;
 }