From c9af6d5414e44e8ba3057bb33443cbefd620871f Mon Sep 17 00:00:00 2001 From: Aurelien DARRAGON Date: Fri, 24 May 2024 10:41:28 +0200 Subject: [PATCH] DEBUG: pollers/fd: add thread id suffix to per-thread memory areas name hints 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//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 and 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//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 | 4 ++-- src/ev_poll.c | 3 ++- src/ev_select.c | 4 ++-- src/fd.c | 2 +- 4 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/ev_epoll.c b/src/ev_epoll.c index 2a41b7373..352620d0a 100644 --- a/src/ev_epoll.c +++ b/src/ev_epoll.c @@ -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); diff --git a/src/ev_poll.c b/src/ev_poll.c index bc70713c5..805142003 100644 --- a/src/ev_poll.c +++ b/src/ev_poll.c @@ -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; } diff --git a/src/ev_select.c b/src/ev_select.c index e41c30e17..9588e8a28 100644 --- a/src/ev_select.c +++ b/src/ev_select.c @@ -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]); diff --git a/src/fd.c b/src/fd.c index c5a27c24b..526222535 100644 --- 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; }