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/<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]
This commit is contained in:
Aurelien DARRAGON 2024-05-24 10:41:28 +02:00
parent 9d37c4b989
commit c9af6d5414
4 changed files with 7 additions and 6 deletions

View 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);

View 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;
}

View 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]);

View File

@ -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;
}