From patchwork Mon Jun 20 00:42:23 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kent Overstreet X-Patchwork-Id: 12886917 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id E02F3C433EF for ; Mon, 20 Jun 2022 00:43:32 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7121C6B007E; Sun, 19 Jun 2022 20:43:32 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 5D6766B0087; Sun, 19 Jun 2022 20:43:32 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 206856B0088; Sun, 19 Jun 2022 20:43:32 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 0FD786B007E for ; Sun, 19 Jun 2022 20:43:32 -0400 (EDT) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay12.hostedemail.com (Postfix) with ESMTP id E4AEB1201D8 for ; Mon, 20 Jun 2022 00:43:31 +0000 (UTC) X-FDA: 79596765822.20.42FB9B7 Received: from mail-qk1-f171.google.com (mail-qk1-f171.google.com [209.85.222.171]) by imf17.hostedemail.com (Postfix) with ESMTP id 6062B40084 for ; Mon, 20 Jun 2022 00:43:31 +0000 (UTC) Received: by mail-qk1-f171.google.com with SMTP id d23so6897716qke.0 for ; Sun, 19 Jun 2022 17:43:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=NyLJo+KoIiEhpVGAQ2QxyVkabvxhAF2JfmbYzoDAQFQ=; b=ZwMhY+29YOmX0RvGbQvKKpPUJ/LqiQlfG/fgzGyHH2KruyCzuGFG7Cx9DBTnJkvwbK gAaCicWiyizg4Ns7w9SJIH9poWXfXv4BSJRB8E3LDl9mvltSXu+AiBCzfX/xNZFzqIjQ v8SpfIbUg2ZXZgRZ48WZbDJ4lNh+p6rokBEkhGJAC1sQYvtHz9gEd0+35p9o8Bt+BNE1 pZmzrLUxry5FvQMPKjEHsa+YCN8WwrOA/Rhd1OQ5cJCvVgyG64UUWUMsgq1X6/YcQeP2 5fmQ5xebpkhNfdNLRNu2ImCzxKO2l/tZuPB9FyaW/6ikTd+q6pzU6aFO9/E7fP4o/7/M tMxA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=NyLJo+KoIiEhpVGAQ2QxyVkabvxhAF2JfmbYzoDAQFQ=; b=Dna0UbkDCKo996HJBSqwM3PGmhBUXYKtPrQlz430tUxpA06K/dBAaR6kLUqOYhn7W2 yK3C1SmEys6to7M7aUoii+7zeg1v0KNmPxXCzZYEEDoCflhA9N9ikc3xnsfh0AMKW2aD SzGlQ5N6eX7g/uUZBArgBVe6/6Xp+hEAOkNa/tiLuLnf0Wb9KC9AaYeUaMpaVKFF9oXJ +/DHV7rXfyxOVdE2LHK4EWWNSQFQP8akN/ZpBUpCzhNpmwsN7CuVY95lIkdWPNQ958md oSwB0qwqFSkiyB8Xq9toMcrahEpPmcoc2gwXkrtsONMzI8lskJI6dFDp6s6gaf8Dqdjy oxDw== X-Gm-Message-State: AJIora+ykc5auRAhbQj9zSD0fdLT4upU/WlWMH/pGevhpQtWW2xbSEjc BhYjoWaueuSraq51rROnnqBfRSe2S4KjsRg= X-Google-Smtp-Source: AGRyM1uaH48yIvoz9xPy//ybN6M0Bpovt4qpzmAy41Tiev9BddZLDAZCbKgQyHBrnnXmG62fhuA/aw== X-Received: by 2002:ae9:ef47:0:b0:6a6:809a:aab5 with SMTP id d68-20020ae9ef47000000b006a6809aaab5mr14526624qkg.615.1655685810646; Sun, 19 Jun 2022 17:43:30 -0700 (PDT) Received: from localhost (c-73-219-103-14.hsd1.vt.comcast.net. [73.219.103.14]) by smtp.gmail.com with ESMTPSA id g10-20020a05620a40ca00b006a791a42693sm11091058qko.133.2022.06.19.17.43.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 19 Jun 2022 17:43:29 -0700 (PDT) From: Kent Overstreet To: linux-kernel@vger.kernel.org, linux-mm@kvack.org, pmladek@suse.com Cc: Kent Overstreet , rostedt@goodmis.org, enozhatsky@chromium.org, linux@rasmusvillemoes.dk, willy@infradead.org Subject: [PATCH v4 24/34] mm/memcontrol.c: Convert to printbuf Date: Sun, 19 Jun 2022 20:42:23 -0400 Message-Id: <20220620004233.3805-25-kent.overstreet@gmail.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220620004233.3805-1-kent.overstreet@gmail.com> References: <20220620004233.3805-1-kent.overstreet@gmail.com> MIME-Version: 1.0 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1655685811; a=rsa-sha256; cv=none; b=dv+xSdUKHDTPWQi34Io+7HN/5gkCR0Xf06wll8K/bngOLXcl3hVcs2RIPeniYsBrVenfY/ daOA9s6cnh8sPavC5sMZbbswC2C+M4hNO7YNfpnz9giYudnX8N3dQt8fz+pHCnPajDIiDJ IEEhEg3Cw4ulHpiyHWox7Y3iRW+IjnA= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=ZwMhY+29; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf17.hostedemail.com: domain of kent.overstreet@gmail.com designates 209.85.222.171 as permitted sender) smtp.mailfrom=kent.overstreet@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1655685811; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=NyLJo+KoIiEhpVGAQ2QxyVkabvxhAF2JfmbYzoDAQFQ=; b=p4PYa8EOnkvInx6Lmjh79cbg3o5b6gAFjajMS0K6ADUsPdAJhYsl2PIvO1mFih5Asz8/I3 +PX2gHHbPJLkZveijCkTlIxjqjdyEDwALmG5Phf4RcBQMfE+4fnbyFTIDxtofh8ZmeM9Yl h4GU6R2MloG8hp8O4IFqWUC16M0/scA= X-Rspamd-Server: rspam01 X-Rspam-User: Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=ZwMhY+29; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf17.hostedemail.com: domain of kent.overstreet@gmail.com designates 209.85.222.171 as permitted sender) smtp.mailfrom=kent.overstreet@gmail.com X-Stat-Signature: g6q9qia8g5659jm7qtd71imzpce1tpq1 X-Rspamd-Queue-Id: 6062B40084 X-HE-Tag: 1655685811-490428 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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. Signed-off-by: Kent Overstreet --- mm/memcontrol.c | 68 ++++++++++++++++++++++++------------------------- 1 file changed, 33 insertions(+), 35 deletions(-) diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 598fece89e..57861dc9fe 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -62,7 +62,7 @@ #include #include #include -#include +#include #include "internal.h" #include #include @@ -1461,13 +1461,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. @@ -1484,49 +1480,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); + prt_printf(&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); + prt_printf(&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)); + prt_printf(&buf, "%s %lu\n", vm_event_name(PGFAULT), + memcg_events(memcg, PGFAULT)); + prt_printf(&buf, "%s %lu\n", vm_event_name(PGMAJFAULT), + memcg_events(memcg, PGMAJFAULT)); + prt_printf(&buf, "%s %lu\n", vm_event_name(PGREFILL), + memcg_events(memcg, PGREFILL)); + prt_printf(&buf, "pgscan %lu\n", + memcg_events(memcg, PGSCAN_KSWAPD) + + memcg_events(memcg, PGSCAN_DIRECT)); + prt_printf(&buf, "pgsteal %lu\n", + memcg_events(memcg, PGSTEAL_KSWAPD) + + memcg_events(memcg, PGSTEAL_DIRECT)); + prt_printf(&buf, "%s %lu\n", vm_event_name(PGACTIVATE), + memcg_events(memcg, PGACTIVATE)); + prt_printf(&buf, "%s %lu\n", vm_event_name(PGDEACTIVATE), + memcg_events(memcg, PGDEACTIVATE)); + prt_printf(&buf, "%s %lu\n", vm_event_name(PGLAZYFREE), + memcg_events(memcg, PGLAZYFREE)); + prt_printf(&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)); + prt_printf(&buf, "%s %lu\n", vm_event_name(THP_FAULT_ALLOC), + memcg_events(memcg, THP_FAULT_ALLOC)); + prt_printf(&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))