From c25bcbfbab29cca91e87bb5ba6f0750175071aed Mon Sep 17 00:00:00 2001 From: mengwenhua Date: Fri, 13 Jan 2023 15:06:57 +0800 Subject: [PATCH] Buffer stats printing Signed-off-by: mengwenhua --- backport-0001-Buffer-stats-printing.patch | 54 +++++++++++++++++++++++ jemalloc.spec | 7 ++- 2 files changed, 60 insertions(+), 1 deletion(-) create mode 100644 backport-0001-Buffer-stats-printing.patch diff --git a/backport-0001-Buffer-stats-printing.patch b/backport-0001-Buffer-stats-printing.patch new file mode 100644 index 0000000..40ce329 --- /dev/null +++ b/backport-0001-Buffer-stats-printing.patch @@ -0,0 +1,54 @@ +From 28ed9b9a5198ed866750361fe2c36f83742900ac Mon Sep 17 00:00:00 2001 +From: Yinan Zhang +Date: Thu, 18 Jul 2019 10:10:45 -0700 +Subject: [PATCH] Buffer stats printing + +Without buffering `malloc_stats_print` would invoke the write back +call (which could mean an expensive `malloc_write_fd` call) for every +single `printf` (including printing each line break and each leading +tab/space for indentation). +--- + src/jemalloc.c | 17 ++++++++++++++++- + 1 file changed, 16 insertions(+), 1 deletion(-) + +diff --git a/src/jemalloc.c b/src/jemalloc.c +index ed13718d..dec987c5 100644 +--- a/src/jemalloc.c ++++ b/src/jemalloc.c +@@ -3704,6 +3704,7 @@ je_mallctlbymib(const size_t *mib, size_t miblen, void *oldp, size_t *oldlenp, + return ret; + } + ++#define STATS_PRINT_BUFSIZE 65536 + JEMALLOC_EXPORT void JEMALLOC_NOTHROW + je_malloc_stats_print(void (*write_cb)(void *, const char *), void *cbopaque, + const char *opts) { +@@ -3713,10 +3714,24 @@ je_malloc_stats_print(void (*write_cb)(void *, const char *), void *cbopaque, + + tsdn = tsdn_fetch(); + check_entry_exit_locking(tsdn); +- stats_print(write_cb, cbopaque, opts); ++ ++ if (config_debug) { ++ stats_print(write_cb, cbopaque, opts); ++ } else { ++ char *stats_print_buf = (char *)iallocztm(tsdn, ++ STATS_PRINT_BUFSIZE, sz_size2index(STATS_PRINT_BUFSIZE), ++ false, NULL, true, arena_get(TSDN_NULL, 0, true), true); ++ buf_writer_arg_t stats_print_buf_arg = {write_cb, cbopaque, ++ stats_print_buf, STATS_PRINT_BUFSIZE - 1, 0}; ++ stats_print(buffered_write_cb, &stats_print_buf_arg, opts); ++ buf_writer_flush(&stats_print_buf_arg); ++ idalloctm(tsdn, stats_print_buf, NULL, NULL, true, true); ++ } ++ + check_entry_exit_locking(tsdn); + LOG("core.malloc_stats_print.exit", ""); + } ++#undef STATS_PRINT_BUFSIZE + + JEMALLOC_EXPORT size_t JEMALLOC_NOTHROW + je_malloc_usable_size(JEMALLOC_USABLE_SIZE_CONST void *ptr) { +-- +2.37.3.windows.1 + diff --git a/jemalloc.spec b/jemalloc.spec index 8dcf4d5..481969a 100644 --- a/jemalloc.spec +++ b/jemalloc.spec @@ -12,7 +12,7 @@ Name: jemalloc Version: 5.2.1 -Release: 8 +Release: 9 Summary: General-purpose scalable concurrent malloc implementation License: BSD-2-Clause URL: http://www.canonware.com/jemalloc/ @@ -24,6 +24,7 @@ Patch3: backport-Jemalloc-5.2.1-patch-3-fix-tcaches-mutex-pre-post-fork- Patch4: 0001-jemalloc-5.2.1-add-loongarch-support.patch Patch6000: backport-0001-Correct-tsd-layout-graph.patch +Patch6001: backport-0001-Buffer-stats-printing.patch BuildRequires: libxslt perl-generators gcc @@ -52,6 +53,7 @@ The help package contains manual pages and other related files for jemalloc. %patch4 -p1 %endif %patch6000 -p1 +%patch6001 -p1 %build export LDFLAGS="%{?__global_ldflags} -lrt" @@ -93,6 +95,9 @@ make check %{_mandir}/man3/jemalloc.3* %changelog +* Mon Jan 16 2023 mengwenhua - 5.2.1-9 +- Buffer stats printing + * Mon Jan 9 2023 mengwenhua - 5.2.1-8 - Correct tsd layout graph -- Gitee