From abb8412d20ba3b933165b7584c6c50b2c4aac009 Mon Sep 17 00:00:00 2001 From: Aurelien DARRAGON Date: Tue, 21 May 2024 10:21:24 +0200 Subject: [PATCH] DEBUG: pollers: add name hint for large memory areas used by pollers Thanks to ("MINOR: tools: add vma_set_name() helper"), set a name hint for large memory areas allocated by pollers upon init so that they can be easily indentified in /proc//maps. For now, only linux-compatible pollers are considered since vma_set_name() requires a recent linux kernel (>= 5.17). Depending on malloc() implementation, such memory areas will normally be merged on the heap under MMAP_THRESHOLD (128 kB by default) and will have a dedicated memory area once the threshold is exceeded. As such, when large enough, they will appear like this in /proc//maps: 7ec6b2d40000-7ec6b2d61000 rw-p 00000000 00:00 0 [anon:ev_poll:fd_evts_wr] 7ec6b2d61000-7ec6b2d82000 rw-p 00000000 00:00 0 [anon:ev_poll:fd_evts_rd] --- src/ev_epoll.c | 2 ++ src/ev_poll.c | 4 ++++ src/ev_select.c | 5 +++++ 3 files changed, 11 insertions(+) diff --git a/src/ev_epoll.c b/src/ev_epoll.c index c42cf2ea5..2a41b7373 100644 --- a/src/ev_epoll.c +++ b/src/ev_epoll.c @@ -275,6 +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"); 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 e98630c71..bc70713c5 100644 --- a/src/ev_poll.c +++ b/src/ev_poll.c @@ -25,6 +25,7 @@ #include #include #include +#include #ifndef POLLRDHUP @@ -249,6 +250,7 @@ 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"); return 1; } @@ -279,8 +281,10 @@ static int _do_init(struct poller *p) if ((fd_evts[DIR_RD] = calloc(1, fd_evts_bytes)) == NULL) goto fail_srevt; + vma_set_name(fd_evts[DIR_RD], fd_evts_bytes, "ev_poll", "fd_evts_rd"); if ((fd_evts[DIR_WR] = calloc(1, fd_evts_bytes)) == NULL) goto fail_swevt; + vma_set_name(fd_evts[DIR_WR], fd_evts_bytes, "ev_poll", "fd_evts_wr"); hap_register_per_thread_init(init_poll_per_thread); hap_register_per_thread_deinit(deinit_poll_per_thread); diff --git a/src/ev_select.c b/src/ev_select.c index eadd5888a..e41c30e17 100644 --- a/src/ev_select.c +++ b/src/ev_select.c @@ -21,6 +21,7 @@ #include #include #include +#include /* private data */ @@ -223,9 +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"); 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"); return 1; fail: free(tmp_evts[DIR_RD]); @@ -263,8 +266,10 @@ static int _do_init(struct poller *p) if ((fd_evts[DIR_RD] = calloc(1, fd_set_bytes)) == NULL) goto fail_srevt; + vma_set_name(fd_evts[DIR_RD], fd_set_bytes, "ev_select", "fd_evts_rd"); if ((fd_evts[DIR_WR] = calloc(1, fd_set_bytes)) == NULL) goto fail_swevt; + vma_set_name(fd_evts[DIR_WR], fd_set_bytes, "ev_select", "fd_evts_wr"); hap_register_per_thread_init(init_select_per_thread); hap_register_per_thread_deinit(deinit_select_per_thread);