From: Michal Hocko <mhocko@suse.com>
To: Kent Overstreet <kent.overstreet@gmail.com>
Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org,
linux-fsdevel@vger.kernel.org, hch@lst.de, hannes@cmpxchg.org,
akpm@linux-foundation.org, linux-clk@vger.kernel.org,
linux-tegra@vger.kernel.org, linux-input@vger.kernel.org,
roman.gushchin@linux.dev
Subject: Re: [PATCH v2 3/8] mm/memcontrol.c: Convert to printbuf
Date: Fri, 22 Apr 2022 14:28:03 +0200 [thread overview]
Message-ID: <YmKfU20B5GIS1e3v@dhcp22.suse.cz> (raw)
In-Reply-To: <20220421234837.3629927-9-kent.overstreet@gmail.com>
On Thu 21-04-22 19:48:32, Kent Overstreet wrote:
> This converts memory_stat_format() from seq_buf to printbuf. Printbuf is
> simalar to seq_buf except that it heap allocates the string buffer:
> here, we were already heap allocating the buffer with kmalloc() so the
> conversion is trivial.
What is the advantage of changing a well tested seq_buf with a different
way to do the same thing here?
I do not see this to be a noticeable simplification of the existing
code. The only advantage I can see is that the string storage allocation
is implicit and it would expand in case we ever overflow over a single
page. But is this really worth the code churn?
> Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
> ---
> mm/memcontrol.c | 68 ++++++++++++++++++++++++-------------------------
> 1 file changed, 33 insertions(+), 35 deletions(-)
>
> diff --git a/mm/memcontrol.c b/mm/memcontrol.c
> index 36e9f38c91..4cb0b7bc1c 100644
> --- a/mm/memcontrol.c
> +++ b/mm/memcontrol.c
> @@ -61,7 +61,7 @@
> #include <linux/file.h>
> #include <linux/tracehook.h>
> #include <linux/psi.h>
> -#include <linux/seq_buf.h>
> +#include <linux/printbuf.h>
> #include "internal.h"
> #include <net/sock.h>
> #include <net/ip.h>
> @@ -1436,13 +1436,9 @@ static inline unsigned long memcg_page_state_output(struct mem_cgroup *memcg,
>
> static char *memory_stat_format(struct mem_cgroup *memcg)
> {
> - struct seq_buf s;
> + struct printbuf buf = PRINTBUF;
> int i;
>
> - seq_buf_init(&s, kmalloc(PAGE_SIZE, GFP_KERNEL), PAGE_SIZE);
> - if (!s.buffer)
> - return NULL;
> -
> /*
> * Provide statistics on the state of the memory subsystem as
> * well as cumulative event counters that show past behavior.
> @@ -1459,49 +1455,51 @@ static char *memory_stat_format(struct mem_cgroup *memcg)
> u64 size;
>
> size = memcg_page_state_output(memcg, memory_stats[i].idx);
> - seq_buf_printf(&s, "%s %llu\n", memory_stats[i].name, size);
> + pr_buf(&buf, "%s %llu\n", memory_stats[i].name, size);
>
> if (unlikely(memory_stats[i].idx == NR_SLAB_UNRECLAIMABLE_B)) {
> size += memcg_page_state_output(memcg,
> NR_SLAB_RECLAIMABLE_B);
> - seq_buf_printf(&s, "slab %llu\n", size);
> + pr_buf(&buf, "slab %llu\n", size);
> }
> }
>
> /* Accumulated memory events */
>
> - seq_buf_printf(&s, "%s %lu\n", vm_event_name(PGFAULT),
> - memcg_events(memcg, PGFAULT));
> - seq_buf_printf(&s, "%s %lu\n", vm_event_name(PGMAJFAULT),
> - memcg_events(memcg, PGMAJFAULT));
> - seq_buf_printf(&s, "%s %lu\n", vm_event_name(PGREFILL),
> - memcg_events(memcg, PGREFILL));
> - seq_buf_printf(&s, "pgscan %lu\n",
> - memcg_events(memcg, PGSCAN_KSWAPD) +
> - memcg_events(memcg, PGSCAN_DIRECT));
> - seq_buf_printf(&s, "pgsteal %lu\n",
> - memcg_events(memcg, PGSTEAL_KSWAPD) +
> - memcg_events(memcg, PGSTEAL_DIRECT));
> - seq_buf_printf(&s, "%s %lu\n", vm_event_name(PGACTIVATE),
> - memcg_events(memcg, PGACTIVATE));
> - seq_buf_printf(&s, "%s %lu\n", vm_event_name(PGDEACTIVATE),
> - memcg_events(memcg, PGDEACTIVATE));
> - seq_buf_printf(&s, "%s %lu\n", vm_event_name(PGLAZYFREE),
> - memcg_events(memcg, PGLAZYFREE));
> - seq_buf_printf(&s, "%s %lu\n", vm_event_name(PGLAZYFREED),
> - memcg_events(memcg, PGLAZYFREED));
> + pr_buf(&buf, "%s %lu\n", vm_event_name(PGFAULT),
> + memcg_events(memcg, PGFAULT));
> + pr_buf(&buf, "%s %lu\n", vm_event_name(PGMAJFAULT),
> + memcg_events(memcg, PGMAJFAULT));
> + pr_buf(&buf, "%s %lu\n", vm_event_name(PGREFILL),
> + memcg_events(memcg, PGREFILL));
> + pr_buf(&buf, "pgscan %lu\n",
> + memcg_events(memcg, PGSCAN_KSWAPD) +
> + memcg_events(memcg, PGSCAN_DIRECT));
> + pr_buf(&buf, "pgsteal %lu\n",
> + memcg_events(memcg, PGSTEAL_KSWAPD) +
> + memcg_events(memcg, PGSTEAL_DIRECT));
> + pr_buf(&buf, "%s %lu\n", vm_event_name(PGACTIVATE),
> + memcg_events(memcg, PGACTIVATE));
> + pr_buf(&buf, "%s %lu\n", vm_event_name(PGDEACTIVATE),
> + memcg_events(memcg, PGDEACTIVATE));
> + pr_buf(&buf, "%s %lu\n", vm_event_name(PGLAZYFREE),
> + memcg_events(memcg, PGLAZYFREE));
> + pr_buf(&buf, "%s %lu\n", vm_event_name(PGLAZYFREED),
> + memcg_events(memcg, PGLAZYFREED));
>
> #ifdef CONFIG_TRANSPARENT_HUGEPAGE
> - seq_buf_printf(&s, "%s %lu\n", vm_event_name(THP_FAULT_ALLOC),
> - memcg_events(memcg, THP_FAULT_ALLOC));
> - seq_buf_printf(&s, "%s %lu\n", vm_event_name(THP_COLLAPSE_ALLOC),
> - memcg_events(memcg, THP_COLLAPSE_ALLOC));
> + pr_buf(&buf, "%s %lu\n", vm_event_name(THP_FAULT_ALLOC),
> + memcg_events(memcg, THP_FAULT_ALLOC));
> + pr_buf(&buf, "%s %lu\n", vm_event_name(THP_COLLAPSE_ALLOC),
> + memcg_events(memcg, THP_COLLAPSE_ALLOC));
> #endif /* CONFIG_TRANSPARENT_HUGEPAGE */
>
> - /* The above should easily fit into one page */
> - WARN_ON_ONCE(seq_buf_has_overflowed(&s));
> + if (buf.allocation_failure) {
> + printbuf_exit(&buf);
> + return NULL;
> + }
>
> - return s.buffer;
> + return buf.buf;
> }
>
> #define K(x) ((x) << (PAGE_SHIFT-10))
> --
> 2.35.2
--
Michal Hocko
SUSE Labs
next prev parent reply other threads:[~2022-04-22 12:28 UTC|newest]
Thread overview: 58+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-04-21 23:48 [PATCH 0/4] Printbufs & shrinker OOM reporting Kent Overstreet
2022-04-21 23:48 ` [PATCH 1/4] lib/printbuf: New data structure for heap-allocated strings Kent Overstreet
2022-04-21 23:48 ` [PATCH 2/4] mm: Add a .to_text() method for shrinkers Kent Overstreet
2022-04-22 12:21 ` Michal Hocko
2022-04-21 23:48 ` [PATCH 3/4] mm: Centralize & improve oom reporting in show_mem.c Kent Overstreet
2022-04-21 23:48 ` [PATCH 4/4] bcachefs: shrinker.to_text() methods Kent Overstreet
2022-04-21 23:48 ` [PATCH v2 0/8] Printbufs & improved shrinker debugging Kent Overstreet
2022-04-21 23:48 ` [PATCH v2 1/8] lib/printbuf: New data structure for heap-allocated strings Kent Overstreet
2022-04-22 4:20 ` Christoph Hellwig
2022-04-22 5:14 ` Kent Overstreet
2022-04-22 5:22 ` Christoph Hellwig
2022-04-22 5:40 ` Kent Overstreet
2022-04-22 5:52 ` Christoph Hellwig
2022-04-22 6:06 ` Kent Overstreet
2022-04-22 6:11 ` Christoph Hellwig
2022-04-22 6:18 ` Kent Overstreet
2022-04-22 15:37 ` Steven Rostedt
2022-04-22 19:30 ` Kent Overstreet
2022-04-22 19:39 ` Steven Rostedt
2022-04-22 20:30 ` Kent Overstreet
2022-04-22 20:47 ` Steven Rostedt
2022-04-22 21:51 ` Kent Overstreet
2022-04-22 22:20 ` Steven Rostedt
2022-04-22 20:03 ` James Bottomley
2022-04-22 21:13 ` Kent Overstreet
2022-04-23 14:16 ` Rust and Kernel Vendoring [Was Re: [PATCH v2 1/8] lib/printbuf: New data structure for heap-allocated strings] James Bottomley
2022-04-24 20:36 ` Kent Overstreet
2022-04-26 2:22 ` James Bottomley
2022-04-24 23:46 ` [PATCH v2 1/8] lib/printbuf: New data structure for heap-allocated strings Joe Perches
2022-04-25 0:45 ` Kent Overstreet
2022-04-25 2:44 ` Matthew Wilcox
2022-04-25 4:19 ` Kent Overstreet
2022-04-25 4:48 ` Joe Perches
2022-04-25 4:59 ` Kent Overstreet
2022-04-25 5:00 ` Joe Perches
2022-04-25 5:56 ` Kent Overstreet
2022-04-21 23:48 ` [PATCH v2 2/8] Input/joystick/analog: Convert from seq_buf -> printbuf Kent Overstreet
2022-04-21 23:48 ` [PATCH v2 3/8] mm/memcontrol.c: Convert to printbuf Kent Overstreet
2022-04-22 12:28 ` Michal Hocko [this message]
2022-04-21 23:48 ` [PATCH v2 4/8] clk: tegra: bpmp: " Kent Overstreet
2022-04-21 23:48 ` [PATCH v2 5/8] mm: Add a .to_text() method for shrinkers Kent Overstreet
2022-04-21 23:48 ` [PATCH v2 6/8] mm: Count requests to free & nr freed per shrinker Kent Overstreet
2022-04-21 23:48 ` [PATCH v2 7/8] mm: Move lib/show_mem.c to mm/ Kent Overstreet
2022-04-22 12:32 ` Michal Hocko
2022-04-21 23:48 ` [PATCH v2 8/8] mm: Centralize & improve oom reporting in show_mem.c Kent Overstreet
2022-04-22 12:58 ` Michal Hocko
2022-04-22 15:09 ` Roman Gushchin
2022-04-22 23:48 ` Kent Overstreet
2022-04-23 0:27 ` Roman Gushchin
2022-04-23 0:46 ` Kent Overstreet
2022-04-23 1:25 ` Roman Gushchin
2022-04-23 11:48 ` Tetsuo Handa
2022-04-25 9:28 ` Michal Hocko
2022-04-25 15:28 ` Kent Overstreet
2022-04-26 7:17 ` Michal Hocko
2022-04-26 7:26 ` Kent Overstreet
2022-04-26 7:40 ` Michal Hocko
2022-04-30 4:00 ` [PATCH 0/4] Printbufs & shrinker OOM reporting Dave Young
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=YmKfU20B5GIS1e3v@dhcp22.suse.cz \
--to=mhocko@suse.com \
--cc=akpm@linux-foundation.org \
--cc=hannes@cmpxchg.org \
--cc=hch@lst.de \
--cc=kent.overstreet@gmail.com \
--cc=linux-clk@vger.kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-input@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=linux-tegra@vger.kernel.org \
--cc=roman.gushchin@linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox