From patchwork Sat Aug 24 19:10:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kent Overstreet X-Patchwork-Id: 13776492 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 6C656C5472E for ; Sat, 24 Aug 2024 19:10:34 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2DCA6800ED; Sat, 24 Aug 2024 15:10:33 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 264E8800E9; Sat, 24 Aug 2024 15:10:33 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 001386B0487; Sat, 24 Aug 2024 15:10:32 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id CE3906B0487 for ; Sat, 24 Aug 2024 15:10:32 -0400 (EDT) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 6AE5280894 for ; Sat, 24 Aug 2024 19:10:32 +0000 (UTC) X-FDA: 82488080304.26.A9BBAB3 Received: from out-175.mta1.migadu.com (out-175.mta1.migadu.com [95.215.58.175]) by imf11.hostedemail.com (Postfix) with ESMTP id A1A4940009 for ; Sat, 24 Aug 2024 19:10:29 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=xZ4wABTa; spf=pass (imf11.hostedemail.com: domain of kent.overstreet@linux.dev designates 95.215.58.175 as permitted sender) smtp.mailfrom=kent.overstreet@linux.dev; dmarc=pass (policy=none) header.from=linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1724526546; 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=z4DTT9AInmX29fCUItJ/fQQQ+2P1VUsJ4Sn1mHHvlmQ=; b=yw2OeVZlONagBTvWbi6rnTr2mQOxUzgOy4scEKwtrMiLQNyFBnFYjchooC5UqbX7pzNe9z FwJTzqF9Vs8kKMxia0OjIe1PGJbW9m/jWzwgagGLMizwrPva6OmczViQiM2i/So+kF4zed OFAiSr3TytRO4WB8MNWPN1mFvzafGuI= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1724526546; a=rsa-sha256; cv=none; b=jPn68jbW0ir5gXkA1+2nHfXOC3tDYhqEgT0dZyexxbRHsTgiGvXwYifPG3rG3PLVI2eEri kd8WTXRdsLt6aYWHOBLSTa1Qp/bWmGp2IRDOmZz5Y43oANNkI+0djO+5/8LtEtcKOz6DKh i/yREObM84/XjyI1Mtd3AI7ilTX7s9s= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=xZ4wABTa; spf=pass (imf11.hostedemail.com: domain of kent.overstreet@linux.dev designates 95.215.58.175 as permitted sender) smtp.mailfrom=kent.overstreet@linux.dev; dmarc=pass (policy=none) header.from=linux.dev X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1724526628; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=z4DTT9AInmX29fCUItJ/fQQQ+2P1VUsJ4Sn1mHHvlmQ=; b=xZ4wABTa6vq9Jts/HvTDzs72F9781v3Yg3ujOS8GOgj0WFCPwq6S9/orkPTgPVCY4WSYa5 gDzPJ5Ixpp0Fqgwr1wM1P5LQvy6SVpl8XcxOR7KKH0UOUDyANYepoPgZYCcda1oZaaNMGu k2LZBiYiqsm6IX5U40ahz8xqUJE54r4= From: Kent Overstreet To: david@fromorbit.com, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org Cc: Kent Overstreet Subject: [PATCH 01/10] seq_buf: seq_buf_human_readable_u64() Date: Sat, 24 Aug 2024 15:10:08 -0400 Message-ID: <20240824191020.3170516-2-kent.overstreet@linux.dev> In-Reply-To: <20240824191020.3170516-1-kent.overstreet@linux.dev> References: <20240824191020.3170516-1-kent.overstreet@linux.dev> MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: A1A4940009 X-Stat-Signature: wkiy5ej8y8hgkrizseezu6tr3wnwoz3r X-HE-Tag: 1724526629-946327 X-HE-Meta: U2FsdGVkX18qEwsrPkzF4ZF+z5zgzwKCtI8WgMEUZ1uh+ZsPbG/7rkolPXxi7K9xDJHZepQILGLxZlXkr3gfXHn8wRJBwjYqWNJq07KkL5N7uvKO+gqimpY/oEINl5BCbcNHbkDdIAtJ2GNXw3o5WjUoYlRFpRz2h5dx53uwkQG0nYQ4chsm+b0kyyWQC+N9sHKvx2C4F9n6iOsNEHJunxB5myudVqwsN+PYj9cqHMtE1ua1hC1WxbAVfdY+Hvrtl4ucsI5OnK0WezgWh2fnZKXhZEPUCI+5R2eh6r/MOPqdGTNQQxi06xWRXlG0q63r5H+ekaFdRYxDiFUXzW272Px/lK87X/IGdU0GcVqHWqf3uuGkPawjyxNLGxCg3vvXcAXLnn11zEaH9c9p01j1qwsWDXYoaY5xxtsZ/dH4LCWoJZaVogMeV7sEk2ovNOSehJu+Lbdj86RrcPojbiXuh4yQllgNxbiXHDR4jx7cSUSKet/VLSAG0gJ3/ga5uNAwDxJQGETczCzN9GO/83E/7abE41mg8p5mi21PReDVEkv60zYgA/uVe4GWap7On3QCi9b3Z4z5i3vlJVce4vB4vPYOlGS+9G0D4B+Sme+vOfX84Jv/eTiPqa4SG4ZBLMAvnwnpPR6Y4PhoFg4jtm8OjkV+IC5EjVOHJUx/Kmgu7Cb6An4pjLMm5Kl/wImwghkZB7MKVJnN0pp36UHtPc+d5CicO3HcZ3XHbJ2FQTnEikSi8ll14oEu1yvqZh6k2dez7URdMOEBEYBW8mGV34fhgZr5uaneYl4Jpi08NjYM+deftlwlJrVv10IDElu6zX5tcovi2FfHWn6hiN7+thn6WgwtnHYRKReZCGeD4pPzOy8JxplQst9X3G/w14rXIyslXAqF1eJrMUlqQGzB71L1LHXAjYZca+S24jWXCR3B2vM8z/t3TwWG4qp8vtnSriAFbDac5AtZtkDBDkLb754 grG3qxmN XNYmDrgBun118oTaiUNfQ9/i43SSrSoIqIpMjF1ePQtTwQCn2hFQEjlw2+oeSWApJ+0Hvz+jaNDDHcR3ZMk+nSc2/GxGI/7fyWWOxkuz2LzmP9HRU07n+yQ1BOQw6DxSm27rJvbtLNb4+SSLmu4IAD9Vf5g== 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: List-Subscribe: List-Unsubscribe: This adds a seq_buf wrapper for string_get_size(). Signed-off-by: Kent Overstreet --- include/linux/seq_buf.h | 4 ++++ lib/seq_buf.c | 10 ++++++++++ 2 files changed, 14 insertions(+) diff --git a/include/linux/seq_buf.h b/include/linux/seq_buf.h index fe41da005970..1cba369e1821 100644 --- a/include/linux/seq_buf.h +++ b/include/linux/seq_buf.h @@ -173,4 +173,8 @@ seq_buf_bprintf(struct seq_buf *s, const char *fmt, const u32 *binary); void seq_buf_do_printk(struct seq_buf *s, const char *lvl); +enum string_size_units; +void seq_buf_human_readable_u64(struct seq_buf *s, u64 v, + const enum string_size_units units); + #endif /* _LINUX_SEQ_BUF_H */ diff --git a/lib/seq_buf.c b/lib/seq_buf.c index f3f3436d60a9..3c41ca83a0c3 100644 --- a/lib/seq_buf.c +++ b/lib/seq_buf.c @@ -436,3 +436,13 @@ int seq_buf_hex_dump(struct seq_buf *s, const char *prefix_str, int prefix_type, } return 0; } + +void seq_buf_human_readable_u64(struct seq_buf *s, u64 v, const enum string_size_units units) +{ + char *buf; + size_t size = seq_buf_get_buf(s, &buf); + int wrote = string_get_size(v, 1, units, buf, size); + + seq_buf_commit(s, wrote); +} +EXPORT_SYMBOL(seq_buf_human_readable_u64); From patchwork Sat Aug 24 19:10:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kent Overstreet X-Patchwork-Id: 13776493 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 D2D8FC5320E for ; Sat, 24 Aug 2024 19:10:36 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5A93F6B0487; Sat, 24 Aug 2024 15:10:33 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 39EA3800EE; Sat, 24 Aug 2024 15:10:33 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1C9DB6B048A; Sat, 24 Aug 2024 15:10:33 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id E72E4800E9 for ; Sat, 24 Aug 2024 15:10:32 -0400 (EDT) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 8D95140888 for ; Sat, 24 Aug 2024 19:10:32 +0000 (UTC) X-FDA: 82488080304.17.998D962 Received: from out-189.mta1.migadu.com (out-189.mta1.migadu.com [95.215.58.189]) by imf25.hostedemail.com (Postfix) with ESMTP id BBA14A0012 for ; Sat, 24 Aug 2024 19:10:30 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=hd8pUDRY; spf=pass (imf25.hostedemail.com: domain of kent.overstreet@linux.dev designates 95.215.58.189 as permitted sender) smtp.mailfrom=kent.overstreet@linux.dev; dmarc=pass (policy=none) header.from=linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1724526547; 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=5EwinnhQJWLN2dpAsOdfTffV0dyCCM/ESmRUthjs8fA=; b=VNwpExF5Gm843UuvU3aNhaT6qIGIvnlAdNDeyVsCX0wsue6A9UafVd6LdR9FFXzYR5ie/+ ZV10FN5CF+RxQZs52KMvxrCPaeEkQAgNoHLrYrfEyG5+CWObUidXUEz7k59LlN7WOAVo/S IJ/+pOwzbOl00JWMmg8tWFnXiN8tuTY= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1724526547; a=rsa-sha256; cv=none; b=kxm0OzddizalevOaQUO4fvb7fMINg+HTkO8gH4E779I+qnZTzimHxIBwACSjeAkiBmT2z/ HD7Fu0brnBjsNXf75HJvsQQ9QGw6kNLsQht9OBtg4mr7yiyLgJhS8X49MXqpQfCbpmjkCs sS1msobyHEdHXKRpezv6oO1BvahGl6Y= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=hd8pUDRY; spf=pass (imf25.hostedemail.com: domain of kent.overstreet@linux.dev designates 95.215.58.189 as permitted sender) smtp.mailfrom=kent.overstreet@linux.dev; dmarc=pass (policy=none) header.from=linux.dev X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1724526629; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=5EwinnhQJWLN2dpAsOdfTffV0dyCCM/ESmRUthjs8fA=; b=hd8pUDRYBSAWcHds+IcAqN78oUmonPqT+4y7lH2sUVv5krRH0pvFcgoJ4Djj25e25KUd1G mxD5LSlRWMkLPaxOyPd8+cN6zRNf1PXH4B+L+55uJpKMskDO1PgVM+FG9mF/fgdf8Oeigt hXDSXbFiS2guQ9CO5iKc2r52cY7syxo= From: Kent Overstreet To: david@fromorbit.com, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org Cc: Kent Overstreet , Andrew Morton , Qi Zheng , Roman Gushchin Subject: [PATCH 02/10] mm: shrinker: Add a .to_text() method for shrinkers Date: Sat, 24 Aug 2024 15:10:09 -0400 Message-ID: <20240824191020.3170516-3-kent.overstreet@linux.dev> In-Reply-To: <20240824191020.3170516-1-kent.overstreet@linux.dev> References: <20240824191020.3170516-1-kent.overstreet@linux.dev> MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Stat-Signature: j6g95tpr8a8mibatybcm6c91kjn67kti X-Rspamd-Queue-Id: BBA14A0012 X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1724526630-376755 X-HE-Meta: U2FsdGVkX18IF+Yl1kH3U9P+Z5g5iMW9ZbbKCgNJV2gVARlaZwXeOpm7wZ2J8u8zIW4/sR/4/VzdveWytAIDaAQshp3I7Kck+FEdztwIabi4b2XPp5tozBQGoKjUviZWis4nTtHN9rlEYKKZb/Gbc19QwiHXgB+T1tO92yRi0FTzNCdSRzw2di5cPhqIHyPVT6fLaqFGugOCNxHtz9FdrhaGRMxOuw8+V4Y61UqQ9okv819D4YSETzWuXpLmdHJp+dVeNskJJeNwat3HXFbPp8e9L2+zFQzoWIT55mQBekym9TOX3Hs+FBNhTHL2zoemywywxn13cNT7hwwaEat0YedALoV74OGrk/SQnl1PtZNz9qEobXaWJp3KhhMnm02gH0kBZyKoLL8C5jafUTRI4DBq0Wf6zHfqmDzOM6vcO5LUsnrt9dJl9Dfx43+mwpr8b370euhdtwl0qXKTbRNj3pzhkqKaP5qL59QfehDH4p5q2miWDxRr8FYOREM9r8m/G4amEHHT68TWGN90uCkJAsO8jW2yQ21EwL6SnvkMl68FbGHFKT+/NTROy/b1URatKUTZEL77uSz3Mfr73Cg/Z+CUXpUy/GMJH51AT5DI4usf0QHLyiuPZ5Kgx9pKJ0SgCHO0qYFHwMsDgxwAUNq+I2DFescSmkhxdkTbJhY/VQXooObDkBs6YYde6I7kkS7PGSXYyCKfrRy6+gR4hJfv9aArA7LGvPdg32hsXpdQ5x7k5m3z7BL7USUDjXUUEi1TtRRjtl7jkBLcvywh+3npvYq6RQ+a7UZ3KovucYsXmCZYbAdX+nugDXVnAqEOfu6dHmxc4WkXnWmpp5YrCcCpMcoxUYa+QJ0/wd6tXoqg6I/D7dkL+zxKKc4qLfZAerFxylnIAG6B6sL9T+dOkb3Vej+6nZiSs5ld+224239KlaNXmkzcS3oLBP5Nu8Tk8M7oo0psycHY91BDcG9lxPU xgGdBlQW coV6iZ+qWWsV8Cqnw4yHaExEsJUdhyAU+yAdszPoq0lM7ddmohCqulMpU1EHsynP+fY8RzFWugsPRvesnk/BY4DtfLFqhnhvFvH32RlKhmgopjcq8x7FKMbCp7j5TbeLuLl5j5kUP6GBqYCp9QjAglRQ9RPDpLYxVNhQQGGYXLAI2CpXxSWKOuWbQ4MBXcuUTeBiRbBMg8z9BZszh2wi2A209cn9xklpc9mbOSq4APyPTKCMBoz+t9c9CNHZeWyZV9EKHnnoZCp4+4x8V6ni0x1/hiBdt+cKnzhpW2dtOm7o7t5YEBh5ggOaLYyAgBrIiud1t1nnopEBIs3YkAIyFoM4+dg== 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: List-Subscribe: List-Unsubscribe: This adds a new callback method to shrinkers which they can use to describe anything relevant to memory reclaim about their internal state, for example object dirtyness. This patch also adds shrinkers_to_text(), which reports on the top 10 shrinkers - by object count - in sorted order, to be used in OOM reporting. Cc: Andrew Morton Cc: Qi Zheng Cc: Roman Gushchin Cc: linux-mm@kvack.org Signed-off-by: Kent Overstreet --- include/linux/shrinker.h | 7 +++- mm/shrinker.c | 73 +++++++++++++++++++++++++++++++++++++++- 2 files changed, 78 insertions(+), 2 deletions(-) diff --git a/include/linux/shrinker.h b/include/linux/shrinker.h index 1a00be90d93a..6193612617a1 100644 --- a/include/linux/shrinker.h +++ b/include/linux/shrinker.h @@ -24,6 +24,8 @@ struct shrinker_info { struct shrinker_info_unit *unit[]; }; +struct seq_buf; + /* * This struct is used to pass information from page reclaim to the shrinkers. * We consolidate the values for easier extension later. @@ -80,10 +82,12 @@ struct shrink_control { * @flags determine the shrinker abilities, like numa awareness */ struct shrinker { + const char *name; unsigned long (*count_objects)(struct shrinker *, struct shrink_control *sc); unsigned long (*scan_objects)(struct shrinker *, struct shrink_control *sc); + void (*to_text)(struct seq_buf *, struct shrinker *); long batch; /* reclaim batch size, 0 = default */ int seeks; /* seeks to recreate an obj */ @@ -110,7 +114,6 @@ struct shrinker { #endif #ifdef CONFIG_SHRINKER_DEBUG int debugfs_id; - const char *name; struct dentry *debugfs_entry; #endif /* objs pending delete, per node */ @@ -135,6 +138,8 @@ __printf(2, 3) struct shrinker *shrinker_alloc(unsigned int flags, const char *fmt, ...); void shrinker_register(struct shrinker *shrinker); void shrinker_free(struct shrinker *shrinker); +void shrinker_to_text(struct seq_buf *, struct shrinker *); +void shrinkers_to_text(struct seq_buf *); static inline bool shrinker_try_get(struct shrinker *shrinker) { diff --git a/mm/shrinker.c b/mm/shrinker.c index dc5d2a6fcfc4..ad52c269bb48 100644 --- a/mm/shrinker.c +++ b/mm/shrinker.c @@ -1,8 +1,9 @@ // SPDX-License-Identifier: GPL-2.0 #include +#include #include +#include #include -#include #include #include "internal.h" @@ -807,3 +808,73 @@ void shrinker_free(struct shrinker *shrinker) call_rcu(&shrinker->rcu, shrinker_free_rcu_cb); } EXPORT_SYMBOL_GPL(shrinker_free); + +void shrinker_to_text(struct seq_buf *out, struct shrinker *shrinker) +{ + struct shrink_control sc = { .gfp_mask = GFP_KERNEL, }; + + seq_buf_puts(out, shrinker->name); + seq_buf_printf(out, " objects: %lu\n", shrinker->count_objects(shrinker, &sc)); + + if (shrinker->to_text) { + shrinker->to_text(out, shrinker); + seq_buf_puts(out, "\n"); + } +} + +/** + * shrinkers_to_text - Report on shrinkers with highest usage + * + * This reports on the top 10 shrinkers, by object counts, in sorted order: + * intended to be used for OOM reporting. + */ +void shrinkers_to_text(struct seq_buf *out) +{ + struct shrinker *shrinker; + struct shrinker_by_mem { + struct shrinker *shrinker; + unsigned long mem; + } shrinkers_by_mem[10]; + int i, nr = 0; + + if (!mutex_trylock(&shrinker_mutex)) { + seq_buf_puts(out, "(couldn't take shrinker lock)"); + return; + } + + list_for_each_entry(shrinker, &shrinker_list, list) { + struct shrink_control sc = { .gfp_mask = GFP_KERNEL, }; + unsigned long mem = shrinker->count_objects(shrinker, &sc); + + if (!mem || mem == SHRINK_STOP || mem == SHRINK_EMPTY) + continue; + + for (i = 0; i < nr; i++) + if (mem < shrinkers_by_mem[i].mem) + break; + + if (nr < ARRAY_SIZE(shrinkers_by_mem)) { + memmove(&shrinkers_by_mem[i + 1], + &shrinkers_by_mem[i], + sizeof(shrinkers_by_mem[0]) * (nr - i)); + nr++; + } else if (i) { + i--; + memmove(&shrinkers_by_mem[0], + &shrinkers_by_mem[1], + sizeof(shrinkers_by_mem[0]) * i); + } else { + continue; + } + + shrinkers_by_mem[i] = (struct shrinker_by_mem) { + .shrinker = shrinker, + .mem = mem, + }; + } + + for (i = nr - 1; i >= 0; --i) + shrinker_to_text(out, shrinkers_by_mem[i].shrinker); + + mutex_unlock(&shrinker_mutex); +} From patchwork Sat Aug 24 19:10:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kent Overstreet X-Patchwork-Id: 13776494 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 4C203C5472E for ; Sat, 24 Aug 2024 19:10:39 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1F49F800E9; Sat, 24 Aug 2024 15:10:34 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 042BB6B049A; Sat, 24 Aug 2024 15:10:33 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D3C52800E9; Sat, 24 Aug 2024 15:10:33 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id A1B356B0493 for ; Sat, 24 Aug 2024 15:10:33 -0400 (EDT) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 559FF120510 for ; Sat, 24 Aug 2024 19:10:33 +0000 (UTC) X-FDA: 82488080346.21.FD14765 Received: from out-182.mta1.migadu.com (out-182.mta1.migadu.com [95.215.58.182]) by imf09.hostedemail.com (Postfix) with ESMTP id A018B140017 for ; Sat, 24 Aug 2024 19:10:31 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=mOFSbInu; spf=pass (imf09.hostedemail.com: domain of kent.overstreet@linux.dev designates 95.215.58.182 as permitted sender) smtp.mailfrom=kent.overstreet@linux.dev; dmarc=pass (policy=none) header.from=linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1724526548; 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=b1cr4HFsHjQtQrwgw0v0pluuE8by2jRYsZZv2/hFaZA=; b=Ol0qToIiDYs3JfMjUemFxfLFMFMX8vAQ+4d+bQvJDMbusaBamaak+0oqIf6G2C67cu9kxQ xAJpXUXRg9b54NsDtMsky4bE4bTdrE5mhlMkoSMiWmEeYgj0zLLx0KYwRtgcLJ5v27Qc5S QdpBVo4R9mFxVurQcsPlLXy91PUk6c4= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1724526548; a=rsa-sha256; cv=none; b=vgQJgiPXsERRVaW8lDtyaCLndaBcycVMKWrHDokCWrskEBEfrrUU0FPriKRVXac/bcYYwA DfUpJMrSYJBuUOwJVpTWL5Xy/G5UWsWX04LvNUU2kwHV1Q5eOZKhCcZElNb4z04DRx76YV Ov1dhgml2qdMkZ/2r5hCNVJANd/3gQw= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=mOFSbInu; spf=pass (imf09.hostedemail.com: domain of kent.overstreet@linux.dev designates 95.215.58.182 as permitted sender) smtp.mailfrom=kent.overstreet@linux.dev; dmarc=pass (policy=none) header.from=linux.dev X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1724526630; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=b1cr4HFsHjQtQrwgw0v0pluuE8by2jRYsZZv2/hFaZA=; b=mOFSbInuxgFq+u/fOX/6C9WLyUJGY9mSzJq4tD1hydoyKwt2ZiyRfq2g0k0gdwhM1DrDhk mleK8/Enn9E4KlM3TPHMXS9m6SFeXp78D8JTUN/NKHNSN3D4JYt8xkUScCLEZ2N6QS3uOm LEPLvNrFi3gEArsTjL4Jcg+ha1kifik= From: Kent Overstreet To: david@fromorbit.com, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org Cc: Kent Overstreet , Andrew Morton , Qi Zheng , Roman Gushchin Subject: [PATCH 03/10] mm: shrinker: Add new stats for .to_text() Date: Sat, 24 Aug 2024 15:10:10 -0400 Message-ID: <20240824191020.3170516-4-kent.overstreet@linux.dev> In-Reply-To: <20240824191020.3170516-1-kent.overstreet@linux.dev> References: <20240824191020.3170516-1-kent.overstreet@linux.dev> MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: A018B140017 X-Stat-Signature: atmjwe9a4br6cp74tqiqd7cj8c59kd79 X-HE-Tag: 1724526631-248726 X-HE-Meta: U2FsdGVkX1/TFtRF1Nwl0o4yOCONSEMK+GpFDCqZ1mnFhiOUi0h5wS41ejJcB1f0Kpob3M+KKw1/QiU17Vfqwi7zsrLx7WERpv2EBE4Mor7rn01qzELVjpzKPUWvHzDBUpMRPKo5WFafBT8OnPw0uzb9Vhgxegy2EdXfDKQ14ex6uqQa2GQMT3Uh2MRUjAZ2qq6vpW98NAfd0GKD3axpGzXQby0nXyN+G09EJfYz48kHvuaTRAfOHr8OIVGZmAx1dsrbaL03f8ZbRxBD13Ej8tphby4Qu7rrPOzGoXGiv0uz15SruB++RgFjlYEvz9SP2UKsNmXFjafzYeVwByXTa8iKHEc8/0qvY2LJlfWp1S/FEgSjA41zx8oi42CbFMwWbb/MX4bPqkhgwmXAFHvI1YsEQSD6eEquQtGYoWcJpizmG4TLZBjKezmBoAW9FC6yvRVa2T5Ct5u0m6QsOOMD7GtDc6Bk+ugQYkBK3H7oK6/RuQeY0nS/kKMTVOtFxqxPwMC6tWgSyVRHzX1BGqapDrIyB45tSPSVp2CPmgZv+ZuC+Qo6KXDDQ21PLnOG7rRS1QhxkrulmX6kz76o6qDs9wucg67u/iYlP003MVLZzXJSB+I+cKvpP+qb9jVQybmWl3VmejkDO/5ckjl6XXyIs6k6lAgnAlFOPWF4d5/+YtYk2mSEFV8d654/7jbGP41FIHUZE1qCrwSfyty0Obe9MkSibt+BaeBR7GMMzyWdhUilFqwebb6NiM6SG6gBQRV2UudxxxmizbOY6TcKFSbsUkP1MrnFrXXoF910gPhajdG57lOnDnk/zNjEzYHhHzIwRWVX41Ffdz7oVErgjJyetA37iQxpxVlXUpU8gn5wvDnvO8kfdfMnKd7IIxD78OSMVJeq2L7ITYXyn/RKJatdSyungaMsC5OQKA+hyUkfzetb9wBP8A8cFjeNsbxaxj3X5C6BJFeSWCRcw8YQlDW CHbJHujX nbqyEIVEMEqsmahJXcV37uS4hgjaBBVWxTIQNWN1AuEnScPbgwIaK1QSgocRZP7CS5WI/Pl9fgY0l6EAm1cd0oXAFDzQf80tVz1FO57aPqFLpBzJL9fmBLMOKczzfd0GdpM0CK6O3yToe0XtZ4Gz/Mx0nJWunBwlHkvrM8SlcWgVN3ozL2CdgzZKamGT0hjgAbnUvyDBcCeidcbbwprP3WP1GyFVZiBWCyLF8GEE1e8z4/51MT3hzD8u9Rc6tWKYVAHoVEmzT3WZB+U+SgXGDxR0zjGYEBAIL7iuuqxyb5f1hGncxjSQm//dOo7nvIhobAxP4+3gE1jpEDTA/vXkX4ZeoZA== 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: List-Subscribe: List-Unsubscribe: Add a few new shrinker stats. number of objects requested to free, number of objects freed: Shrinkers won't necessarily free all objects requested for a variety of reasons, but if the two counts are wildly different something is likely amiss. .scan_objects runtime: If one shrinker is taking an excessive amount of time to free objects that will block kswapd from running other shrinkers. Cc: Andrew Morton Cc: Qi Zheng Cc: Roman Gushchin Cc: linux-mm@kvack.org Signed-off-by: Kent Overstreet --- include/linux/shrinker.h | 6 ++++++ mm/shrinker.c | 23 ++++++++++++++++++++++- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/include/linux/shrinker.h b/include/linux/shrinker.h index 6193612617a1..106622ddac77 100644 --- a/include/linux/shrinker.h +++ b/include/linux/shrinker.h @@ -118,6 +118,12 @@ struct shrinker { #endif /* objs pending delete, per node */ atomic_long_t *nr_deferred; + + atomic_long_t objects_requested_to_free; + atomic_long_t objects_freed; + unsigned long last_freed; /* timestamp, in jiffies */ + unsigned long last_scanned; /* timestamp, in jiffies */ + atomic64_t ns_run; }; #define DEFAULT_SEEKS 2 /* A good number if you don't know better. */ diff --git a/mm/shrinker.c b/mm/shrinker.c index ad52c269bb48..feaa8122afc9 100644 --- a/mm/shrinker.c +++ b/mm/shrinker.c @@ -430,13 +430,24 @@ static unsigned long do_shrink_slab(struct shrink_control *shrinkctl, total_scan >= freeable) { unsigned long ret; unsigned long nr_to_scan = min(batch_size, total_scan); + u64 start_time = ktime_get_ns(); + + atomic_long_add(nr_to_scan, &shrinker->objects_requested_to_free); shrinkctl->nr_to_scan = nr_to_scan; shrinkctl->nr_scanned = nr_to_scan; ret = shrinker->scan_objects(shrinker, shrinkctl); + + atomic64_add(ktime_get_ns() - start_time, &shrinker->ns_run); if (ret == SHRINK_STOP) break; freed += ret; + unsigned long now = jiffies; + if (ret) { + atomic_long_add(ret, &shrinker->objects_freed); + shrinker->last_freed = now; + } + shrinker->last_scanned = now; count_vm_events(SLABS_SCANNED, shrinkctl->nr_scanned); total_scan -= shrinkctl->nr_scanned; @@ -812,9 +823,19 @@ EXPORT_SYMBOL_GPL(shrinker_free); void shrinker_to_text(struct seq_buf *out, struct shrinker *shrinker) { struct shrink_control sc = { .gfp_mask = GFP_KERNEL, }; + unsigned long nr_freed = atomic_long_read(&shrinker->objects_freed); seq_buf_puts(out, shrinker->name); - seq_buf_printf(out, " objects: %lu\n", shrinker->count_objects(shrinker, &sc)); + seq_buf_putc(out, '\n'); + + seq_buf_printf(out, "objects: %lu\n", shrinker->count_objects(shrinker, &sc)); + seq_buf_printf(out, "requested to free: %lu\n", atomic_long_read(&shrinker->objects_requested_to_free)); + seq_buf_printf(out, "objects freed: %lu\n", nr_freed); + seq_buf_printf(out, "last scanned: %li sec ago\n", (jiffies - shrinker->last_scanned) / HZ); + seq_buf_printf(out, "last freed: %li sec ago\n", (jiffies - shrinker->last_freed) / HZ); + seq_buf_printf(out, "ns per object freed: %llu\n", nr_freed + ? div64_ul(atomic64_read(&shrinker->ns_run), nr_freed) + : 0); if (shrinker->to_text) { shrinker->to_text(out, shrinker); From patchwork Sat Aug 24 19:10:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kent Overstreet X-Patchwork-Id: 13776495 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 0D275C52D6F for ; Sat, 24 Aug 2024 19:10:41 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 48CE06B04B3; Sat, 24 Aug 2024 15:10:36 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3C67B800EF; Sat, 24 Aug 2024 15:10:36 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1CDBA800EE; Sat, 24 Aug 2024 15:10:36 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id D4C526B04B3 for ; Sat, 24 Aug 2024 15:10:35 -0400 (EDT) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 81C83160878 for ; Sat, 24 Aug 2024 19:10:35 +0000 (UTC) X-FDA: 82488080430.05.B910603 Received: from out-179.mta1.migadu.com (out-179.mta1.migadu.com [95.215.58.179]) by imf12.hostedemail.com (Postfix) with ESMTP id C7C5540008 for ; Sat, 24 Aug 2024 19:10:33 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=oj3Zemxp; spf=pass (imf12.hostedemail.com: domain of kent.overstreet@linux.dev designates 95.215.58.179 as permitted sender) smtp.mailfrom=kent.overstreet@linux.dev; dmarc=pass (policy=none) header.from=linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1724526550; 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=mkkf9bPKkUQD5+0NEMylYPBF2rZLY+sZgAz6x5jg4XE=; b=IyPzdiJodtf2TR9VCeguZTAxLQW9MQ2ZTk1BCCYuKQ/xlWWS1OboGnqL0lW1wDBJQ6lnLP xT4bWBjtR/Af/d9Ucl/w8zu+Mk9WnOPtMMeb7Tevxxvt617EdmXBeNtG/IpObhxwdI9FWm 1uHO8DJm5O/tjFRUnxqNiOi81ghmRko= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1724526550; a=rsa-sha256; cv=none; b=CZPn6zX+9rGO8cwV+rWJXwQl61T3CBQggYUq/sobDMRt105KpuwY7WzHkKCdJtwvxvuIK3 /nfiywLunv7OLJ4wsUG8u3jSd0y/8lSJQZqiFJUuJn6WbVGq0dY6vQig41jkJc4fge06Yk z6vEjAW/OC/rQVWiB6MYa0Qci6PHvYc= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=oj3Zemxp; spf=pass (imf12.hostedemail.com: domain of kent.overstreet@linux.dev designates 95.215.58.179 as permitted sender) smtp.mailfrom=kent.overstreet@linux.dev; dmarc=pass (policy=none) header.from=linux.dev X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1724526632; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=mkkf9bPKkUQD5+0NEMylYPBF2rZLY+sZgAz6x5jg4XE=; b=oj3ZemxpRFF/l0tgdqkjXGsIZmxnLsax/vpXKoEBc9jfBGNz3yZZ3Nxh/PlMV4LATg8u7+ 2W3qx6ciQR2V72/gSnSAeWcIwxRBjyilwjFtV3JLdGRjCTwFn/6pXDQY1RV2/jVR/fZyAV au6I+9Sgweb5qJhtlNdRg/6IvbHBus4= From: Kent Overstreet To: david@fromorbit.com, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org Cc: Kent Overstreet , Andrew Morton , Qi Zheng , Roman Gushchin Subject: [PATCH 04/10] mm: Centralize & improve oom reporting in show_mem.c Date: Sat, 24 Aug 2024 15:10:11 -0400 Message-ID: <20240824191020.3170516-5-kent.overstreet@linux.dev> In-Reply-To: <20240824191020.3170516-1-kent.overstreet@linux.dev> References: <20240824191020.3170516-1-kent.overstreet@linux.dev> MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: C7C5540008 X-Stat-Signature: f6m3fh87q7au6tkcbkfuraggeqzpkaaj X-HE-Tag: 1724526633-689386 X-HE-Meta: U2FsdGVkX19NnBlMyPjZgXa1uVfNg1rSGuAfghi0YB1SyPPkKT42AiVaHtSRflaFwvDro6KgfNzj+r8RDYGPe9mubBfmPKKGYxllyotBekv0yb+i623B9dUa/C7t3798e46BYAkD1TUvhdia69uXnasoeOI9HqMJLVDA14fbYbBrTWTfe8FrbYl7J6AnSRkRQJwXgCL+D0jVB4zQCJeD8F7Um5Bt+lhq5NrIlnqpWW0FHYd+mIxb1qeIOhwJ7c2/4mN5Avia+sCDM6t6tIZ2/l7rUqZrYwHb2+pfTN53XhQhyiJi617wsWw+oKpSxx/PGegTXZeCe94e1/PCOSHMv0oqpDMN1IKA08xoPflJWEAkgSzxXtcLUUVH3b3Sblv02NEQpsk6KGkeFLrILflr45eM1gmvmdeWNylqp1e51HPiV5gKBs/Vm9E/T1rRp2zrwocpqwwQnPQOiMhY7r0nDNgRFaDq558sM9nqduGE8GvTrwZZFsOMQXkKfqp5x5tIHFWTj2hNoiONNuTiF/fL4b2KvJw/QtktWEV5aYoZfeOlFwp6xy9i6Kohvqh7zMIEJ1btrpE1Z6hpronuFYHEXW71oESS7wb//oXw4GKDtpdlOy6nv/rfLnzmWleiVTrG6hEmXR7WQsMzB6fLTPWLGns441ukuAio8kt8R5oznsFdfhI8XL4e0XqDvL3+YOYQFiuRQWNmY0sfbx0sWrtlVxKTWHgb52nCp5ZmxlTnf5GjlaoH9f6FymIHxH93+pi8Y4q6FFjgwxiksYuwaVzzqKm/S0rp2VeHUjZg9L3RhVDIlaotjxpGDjA00QxAIyfgncNQrZYiIf7nFWraZbIEJanwI2IpDV0csTBBH5TwA7857e81IsLzy4po5S7t+oXVNSJMH8kuki6W6G/HBB0h3aQVZKNKfjJGIJdHD8IuL/UdjDiKDQPhdusfaBFD4lp6sbmF947RtKlzDJwF7c5 K3hzAylN yxrAWVlRxKhnsIBXqNiDPje5I94BG4xX1WC+d4G9yPghdK7rCqPjXnnPLJK+PeXveOJXTnwWyUswcQYY7buCo1xK9G/XbQtNir8nyB+X9sUp40toj9k95h/aF6cyZBFzwztdlXeP4Xf0Wi0EwwBHKLfxL83PoChQiGO26z/cqMiZcMJAZJ6qcHEe4zijjFYnV5u0yF4Uw1TatTLNOZRGtvHsuPV+mC0tpHlKA7lXuN3jFQ2Ln8dPuDLGNyWg0db/nlRJgRpJ0fUhO7UJbVwvewkWI+uSS6KjiiH8oK6iIgggBW7QuZlE4nEjDiuMTHg6UD6AHlCOcicEZkRY= 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: List-Subscribe: List-Unsubscribe: This patch: - Changes show_mem() to always report on slab usage - Instead of reporting on all slabs, we only report on top 10 slabs, and in sorted order - Also reports on shrinkers, with the new shrinkers_to_text(). Shrinkers need to be included in OOM/allocation failure reporting because they're responsible for memory reclaim - if a shrinker isn't giving up its memory, we need to know which one and why. More OOM reporting can be moved to show_mem.c and improved, this patch is only a start. New example output on OOM/memory allocation failure: 00177 Mem-Info: 00177 active_anon:13706 inactive_anon:32266 isolated_anon:16 00177 active_file:1653 inactive_file:1822 isolated_file:0 00177 unevictable:0 dirty:0 writeback:0 00177 slab_reclaimable:6242 slab_unreclaimable:11168 00177 mapped:3824 shmem:3 pagetables:1266 bounce:0 00177 kernel_misc_reclaimable:0 00177 free:4362 free_pcp:35 free_cma:0 00177 Node 0 active_anon:54824kB inactive_anon:129064kB active_file:6612kB inactive_file:7288kB unevictable:0kB isolated(anon):64kB isolated(file):0kB mapped:15296kB dirty:0kB writeback:0kB shmem:12kB writeback_tmp:0kB kernel_stack:3392kB pagetables:5064kB all_unreclaimable? no 00177 DMA free:2232kB boost:0kB min:88kB low:108kB high:128kB reserved_highatomic:0KB active_anon:2924kB inactive_anon:6596kB active_file:428kB inactive_file:384kB unevictable:0kB writepending:0kB present:15992kB managed:15360kB mlocked:0kB bounce:0kB free_pcp:0kB local_pcp:0kB free_cma:0kB 00177 lowmem_reserve[]: 0 426 426 426 00177 DMA32 free:15092kB boost:5836kB min:8432kB low:9080kB high:9728kB reserved_highatomic:0KB active_anon:52196kB inactive_anon:122392kB active_file:6176kB inactive_file:7068kB unevictable:0kB writepending:0kB present:507760kB managed:441816kB mlocked:0kB bounce:0kB free_pcp:72kB local_pcp:0kB free_cma:0kB 00177 lowmem_reserve[]: 0 0 0 0 00177 DMA: 284*4kB (UM) 53*8kB (UM) 21*16kB (U) 11*32kB (U) 0*64kB 0*128kB 0*256kB 0*512kB 0*1024kB 0*2048kB 0*4096kB = 2248kB 00177 DMA32: 2765*4kB (UME) 375*8kB (UME) 57*16kB (UM) 5*32kB (U) 0*64kB 0*128kB 0*256kB 0*512kB 0*1024kB 0*2048kB 0*4096kB = 15132kB 00177 4656 total pagecache pages 00177 1031 pages in swap cache 00177 Swap cache stats: add 6572399, delete 6572173, find 488603/3286476 00177 Free swap = 509112kB 00177 Total swap = 2097148kB 00177 130938 pages RAM 00177 0 pages HighMem/MovableOnly 00177 16644 pages reserved 00177 Unreclaimable slab info: 00177 9p-fcall-cache total: 8.25 MiB active: 8.25 MiB 00177 kernfs_node_cache total: 2.15 MiB active: 2.15 MiB 00177 kmalloc-64 total: 2.08 MiB active: 2.07 MiB 00177 task_struct total: 1.95 MiB active: 1.95 MiB 00177 kmalloc-4k total: 1.50 MiB active: 1.50 MiB 00177 signal_cache total: 1.34 MiB active: 1.34 MiB 00177 kmalloc-2k total: 1.16 MiB active: 1.16 MiB 00177 bch_inode_info total: 1.02 MiB active: 922 KiB 00177 perf_event total: 1.02 MiB active: 1.02 MiB 00177 biovec-max total: 992 KiB active: 960 KiB 00177 Shrinkers: 00177 super_cache_scan: objects: 127 00177 super_cache_scan: objects: 106 00177 jbd2_journal_shrink_scan: objects: 32 00177 ext4_es_scan: objects: 32 00177 bch2_btree_cache_scan: objects: 8 00177 nr nodes: 24 00177 nr dirty: 0 00177 cannibalize lock: 0000000000000000 00177 00177 super_cache_scan: objects: 8 00177 super_cache_scan: objects: 1 Cc: Andrew Morton Cc: Qi Zheng Cc: Roman Gushchin Cc: linux-mm@kvack.org Signed-off-by: Kent Overstreet --- mm/oom_kill.c | 23 --------------------- mm/show_mem.c | 43 +++++++++++++++++++++++++++++++++++++++ mm/slab.h | 6 ++++-- mm/slab_common.c | 52 +++++++++++++++++++++++++++++++++++++++--------- 4 files changed, 90 insertions(+), 34 deletions(-) diff --git a/mm/oom_kill.c b/mm/oom_kill.c index 4d7a0004df2c..dc56239ff057 100644 --- a/mm/oom_kill.c +++ b/mm/oom_kill.c @@ -169,27 +169,6 @@ static bool oom_unkillable_task(struct task_struct *p) return false; } -/* - * Check whether unreclaimable slab amount is greater than - * all user memory(LRU pages). - * dump_unreclaimable_slab() could help in the case that - * oom due to too much unreclaimable slab used by kernel. -*/ -static bool should_dump_unreclaim_slab(void) -{ - unsigned long nr_lru; - - nr_lru = global_node_page_state(NR_ACTIVE_ANON) + - global_node_page_state(NR_INACTIVE_ANON) + - global_node_page_state(NR_ACTIVE_FILE) + - global_node_page_state(NR_INACTIVE_FILE) + - global_node_page_state(NR_ISOLATED_ANON) + - global_node_page_state(NR_ISOLATED_FILE) + - global_node_page_state(NR_UNEVICTABLE); - - return (global_node_page_state_pages(NR_SLAB_UNRECLAIMABLE_B) > nr_lru); -} - /** * oom_badness - heuristic function to determine which candidate task to kill * @p: task struct of which task we should calculate @@ -464,8 +443,6 @@ static void dump_header(struct oom_control *oc) mem_cgroup_print_oom_meminfo(oc->memcg); else { __show_mem(SHOW_MEM_FILTER_NODES, oc->nodemask, gfp_zone(oc->gfp_mask)); - if (should_dump_unreclaim_slab()) - dump_unreclaimable_slab(); } if (sysctl_oom_dump_tasks) dump_tasks(oc); diff --git a/mm/show_mem.c b/mm/show_mem.c index bdb439551eef..a8ea4c41ced5 100644 --- a/mm/show_mem.c +++ b/mm/show_mem.c @@ -7,15 +7,18 @@ #include #include +#include #include #include #include #include #include +#include #include #include #include "internal.h" +#include "slab.h" #include "swap.h" atomic_long_t _totalram_pages __read_mostly; @@ -397,10 +400,31 @@ static void show_free_areas(unsigned int filter, nodemask_t *nodemask, int max_z show_swap_cache_info(); } +static void print_string_as_lines(const char *prefix, const char *lines) +{ + if (!lines) { + printk("%s (null)\n", prefix); + return; + } + + bool locked = console_trylock(); + + while (1) { + const char *p = strchrnul(lines, '\n'); + printk("%s%.*s\n", prefix, (int) (p - lines), lines); + if (!*p) + break; + lines = p + 1; + } + if (locked) + console_unlock(); +} + void __show_mem(unsigned int filter, nodemask_t *nodemask, int max_zone_idx) { unsigned long total = 0, reserved = 0, highmem = 0; struct zone *zone; + char *buf; printk("Mem-Info:\n"); show_free_areas(filter, nodemask, max_zone_idx); @@ -449,4 +473,23 @@ void __show_mem(unsigned int filter, nodemask_t *nodemask, int max_zone_idx) } } #endif + + const unsigned buf_size = 8192; + buf = kmalloc(buf_size, GFP_ATOMIC); + if (buf) { + struct seq_buf s; + + printk("Unreclaimable slab info:\n"); + seq_buf_init(&s, buf, buf_size); + dump_unreclaimable_slab(&s); + print_string_as_lines(KERN_NOTICE, seq_buf_str(&s)); + + printk("Shrinkers:\n"); + seq_buf_init(&s, buf, buf_size); + shrinkers_to_text(&s); + print_string_as_lines(KERN_NOTICE, seq_buf_str(&s)); + /* previous output doesn't get flushed without this - why? */ + + kfree(buf); + } } diff --git a/mm/slab.h b/mm/slab.h index dcdb56b8e7f5..b523b3e3d9d3 100644 --- a/mm/slab.h +++ b/mm/slab.h @@ -611,10 +611,12 @@ static inline size_t slab_ksize(const struct kmem_cache *s) return s->size; } +struct seq_buf; + #ifdef CONFIG_SLUB_DEBUG -void dump_unreclaimable_slab(void); +void dump_unreclaimable_slab(struct seq_buf *); #else -static inline void dump_unreclaimable_slab(void) +static inline void dump_unreclaimable_slab(struct seq_buf *out) { } #endif diff --git a/mm/slab_common.c b/mm/slab_common.c index 40b582a014b8..bd50a57161cf 100644 --- a/mm/slab_common.c +++ b/mm/slab_common.c @@ -27,6 +27,7 @@ #include #include #include +#include #include #include "internal.h" @@ -1181,10 +1182,15 @@ static int slab_show(struct seq_file *m, void *p) return 0; } -void dump_unreclaimable_slab(void) +void dump_unreclaimable_slab(struct seq_buf *out) { struct kmem_cache *s; struct slabinfo sinfo; + struct slab_by_mem { + struct kmem_cache *s; + size_t total, active; + } slabs_by_mem[10], n; + int i, nr = 0; /* * Here acquiring slab_mutex is risky since we don't prefer to get @@ -1194,24 +1200,52 @@ void dump_unreclaimable_slab(void) * without acquiring the mutex. */ if (!mutex_trylock(&slab_mutex)) { - pr_warn("excessive unreclaimable slab but cannot dump stats\n"); + seq_buf_puts(out, "excessive unreclaimable slab but cannot dump stats\n"); return; } - pr_info("Unreclaimable slab info:\n"); - pr_info("Name Used Total\n"); - list_for_each_entry(s, &slab_caches, list) { if (s->flags & SLAB_RECLAIM_ACCOUNT) continue; get_slabinfo(s, &sinfo); - if (sinfo.num_objs > 0) - pr_info("%-17s %10luKB %10luKB\n", s->name, - (sinfo.active_objs * s->size) / 1024, - (sinfo.num_objs * s->size) / 1024); + if (!sinfo.num_objs) + continue; + + n.s = s; + n.total = sinfo.num_objs * s->size; + n.active = sinfo.active_objs * s->size; + + for (i = 0; i < nr; i++) + if (n.total < slabs_by_mem[i].total) + break; + + if (nr < ARRAY_SIZE(slabs_by_mem)) { + memmove(&slabs_by_mem[i + 1], + &slabs_by_mem[i], + sizeof(slabs_by_mem[0]) * (nr - i)); + nr++; + } else if (i) { + i--; + memmove(&slabs_by_mem[0], + &slabs_by_mem[1], + sizeof(slabs_by_mem[0]) * i); + } else { + continue; + } + + slabs_by_mem[i] = n; } + + for (i = nr - 1; i >= 0; --i) { + seq_buf_printf(out, "%-17s total: ", slabs_by_mem[i].s->name); + seq_buf_human_readable_u64(out, slabs_by_mem[i].total, STRING_UNITS_2); + seq_buf_printf(out, " active: "); + seq_buf_human_readable_u64(out, slabs_by_mem[i].active, STRING_UNITS_2); + seq_buf_putc(out, '\n'); + } + mutex_unlock(&slab_mutex); } From patchwork Sat Aug 24 19:10:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kent Overstreet X-Patchwork-Id: 13776496 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 99994C5320E for ; Sat, 24 Aug 2024 19:10:44 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A57556B04B4; Sat, 24 Aug 2024 15:10:36 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9E0DB800EE; Sat, 24 Aug 2024 15:10:36 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 859FD6B04B6; Sat, 24 Aug 2024 15:10:36 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 565216B04B4 for ; Sat, 24 Aug 2024 15:10:36 -0400 (EDT) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 0796B140880 for ; Sat, 24 Aug 2024 19:10:36 +0000 (UTC) X-FDA: 82488080472.21.93170DD Received: from out-183.mta1.migadu.com (out-183.mta1.migadu.com [95.215.58.183]) by imf13.hostedemail.com (Postfix) with ESMTP id 56FD620008 for ; Sat, 24 Aug 2024 19:10:34 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=ck5gsv4Z; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf13.hostedemail.com: domain of kent.overstreet@linux.dev designates 95.215.58.183 as permitted sender) smtp.mailfrom=kent.overstreet@linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1724526541; 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=gLXUgRI7sBHgtq1Zgi7tzIKwC1ZgZVmc7Lbaw9gZGks=; b=wyOYqgBoigXXgLALLnNuVOgJNfEtGXesDAz/hXMfE8ZPSHahXinCr09/8SZvVIfIdMz9ht ycPxTWRZaUc/BOIF0VVEWzeQ+C16n9GNT7EKHMuFTIwy5eoA98xW89UnNYNKWLFgWisaRf cQfPQgyEXZLyBvjnO73XKJf5dml2yyY= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1724526541; a=rsa-sha256; cv=none; b=WqGEgzHNVU0fu3UL4JpiLPJIenaYsuevyWC64WCb2hvtR5MQkx3ouIeYwRG4l6SmScw9jn PpVVpCwuNuI/6MhupIf1Y4pPWCm2M1zRJuNsEvzQBeTCBjfotUe2M85ob4pjCk9bMGhiOf asfDxbR+eGRpkc9yOL6WO8DYUA4Y140= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=ck5gsv4Z; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf13.hostedemail.com: domain of kent.overstreet@linux.dev designates 95.215.58.183 as permitted sender) smtp.mailfrom=kent.overstreet@linux.dev X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1724526633; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=gLXUgRI7sBHgtq1Zgi7tzIKwC1ZgZVmc7Lbaw9gZGks=; b=ck5gsv4ZoR5pxp5TUsQpbSPzWrRJTwaGYooqyAjp11QDTN/pIWspc3dTbamzmDUGeVggGC N8BJRfwiDcdd/iy84JeDNLEE6NPtBa6oUXUF2t0a2oFHHwv1CYfnVjHIVlap2dt81b5b4i CHzI+EMCI75H2EO/9enT5UD+XbFqqZE= From: Kent Overstreet To: david@fromorbit.com, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org Cc: Kent Overstreet Subject: [PATCH 05/10] mm: shrinker: Add shrinker_to_text() to debugfs interface Date: Sat, 24 Aug 2024 15:10:12 -0400 Message-ID: <20240824191020.3170516-6-kent.overstreet@linux.dev> In-Reply-To: <20240824191020.3170516-1-kent.overstreet@linux.dev> References: <20240824191020.3170516-1-kent.overstreet@linux.dev> MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 56FD620008 X-Stat-Signature: ppoeihk3xnr7c7h9c91ny3wfqeuyrznj X-Rspam-User: X-HE-Tag: 1724526634-150681 X-HE-Meta: U2FsdGVkX19hRZJ1dqlIxI+rbaagTxuOi+4On0WAm8moZbVqS2aQN6+LV7re5zYwR0af1bMj7X+gYkp0UH50NBa9f15xpwFoS19i0QDL6oLmFRmt66mk6qa4Mbjzbq/d3bM2NUn8rAm5pfWZOzQ3SXdZ2yoOSeEfgX8P3GRFQjL6cevjoV7t5hJhbrFr4e50KO5rKjuAhIwV1MYhKLb0luFDGr1uV50Ph0KcDDMHJ19V/9oqKzQracVzs5jCREMAR3ucpVYhBjRaM/A+cu7T3Xp6qjkH2LC/V4q9WT+FWnIfIJnG1jPEc/8ZIClUyqpYWznJlFYuGlwExt8PPkm5pRjWry/M9pMOXXpS1i8qKXyB3+J7luyNCFv9vQfQAskHWJzzDyoyJCwlf0aATGfWoFSPPmFNF+ZWZFoyCSyNG3FpjqOMI5w9MLJk25ssvqqVdwIOECrbnMTSNuhpPKQj6NxBNPegDcfbeuLoueZdU/Z1l+PpHRLxOTD9bYRD5JEqb80NYxZEBiWmLVdTBz8VEWkwgMQz/KIO8VYz2Pev5XzuowLZSdmw/oySsZ0RFIZkPodYUodgB1hQQiMXI1CF2Lalzk/6Yaai+1x9f13s7ZR7QIQ97NzIybm6cgno9OpU3s0W3sLgD+1ePfKpcpDGpZoIPLjLIlzdRC1IKfTrdxR7uAl5c4pNfqU2rBCWZFn8jwhWeWpP3k5CkrcmB4e9+VX29tnKVWzaaIByITTESYeT8WIbLc/0hTTkB7p80zmcqheJEp/Zvo6cB8AurBMja3QQyaAhGDBUf0ydZU9tGUmVQ/2v4yHbxuoHJfIgVsUYnFjyroQ+XAp7P63cu/R3JhkvQjXHI1N6oCys2tLEkHc5D9gW9tNb1DCRMYNOwEqlX7Psl53ny1Cz97SNnTIY9pblvHVhX8n4O9ZkzWrW43geELi9u83O9jwGcVgCrbJ6MTadtWxdCGnlMumfwOe +YR0zg0A Z7hMgwY7y/Wxocwhzwtb5Mk8ptLF71OOdAcARYi+0Mfnt1GZmyV71By8QSlJfLErHmGNI+gwD4jhwVXTY+P8PGP3LKVEIBVbKDtmTN2v7tmbYQ/c9cW7uwv1or34ia82nmzLNCZTYiVlQ+SnXvQPgBEPDF7z+mOn7Gw4N 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: List-Subscribe: List-Unsubscribe: Previously, we added shrinker_to_text() and hooked it up to the OOM report - now, the same report is available via debugfs. Signed-off-by: Kent Overstreet --- mm/shrinker_debug.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/mm/shrinker_debug.c b/mm/shrinker_debug.c index 12ea5486a3e9..39342aa9f4ca 100644 --- a/mm/shrinker_debug.c +++ b/mm/shrinker_debug.c @@ -2,6 +2,7 @@ #include #include #include +#include #include #include #include @@ -159,6 +160,21 @@ static const struct file_operations shrinker_debugfs_scan_fops = { .write = shrinker_debugfs_scan_write, }; +static int shrinker_debugfs_report_show(struct seq_file *m, void *v) +{ + struct shrinker *shrinker = m->private; + char *bufp; + size_t buflen = seq_get_buf(m, &bufp); + struct seq_buf out; + + seq_buf_init(&out, bufp, buflen); + shrinker_to_text(&out, shrinker); + seq_commit(m, seq_buf_used(&out)); + + return 0; +} +DEFINE_SHOW_ATTRIBUTE(shrinker_debugfs_report); + int shrinker_debugfs_add(struct shrinker *shrinker) { struct dentry *entry; @@ -190,6 +206,8 @@ int shrinker_debugfs_add(struct shrinker *shrinker) &shrinker_debugfs_count_fops); debugfs_create_file("scan", 0220, entry, shrinker, &shrinker_debugfs_scan_fops); + debugfs_create_file("report", 0440, entry, shrinker, + &shrinker_debugfs_report_fops); return 0; } From patchwork Sat Aug 24 19:10:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kent Overstreet X-Patchwork-Id: 13776497 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 3ED30C5320E for ; Sat, 24 Aug 2024 19:10:47 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DBE13800EF; Sat, 24 Aug 2024 15:10:37 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D3BA1800EE; Sat, 24 Aug 2024 15:10:37 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BB66E800EF; Sat, 24 Aug 2024 15:10:37 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 9481D800EE for ; Sat, 24 Aug 2024 15:10:37 -0400 (EDT) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 4B2C31A081C for ; Sat, 24 Aug 2024 19:10:37 +0000 (UTC) X-FDA: 82488080514.30.3BA0530 Received: from out-178.mta1.migadu.com (out-178.mta1.migadu.com [95.215.58.178]) by imf03.hostedemail.com (Postfix) with ESMTP id 1758D20007 for ; Sat, 24 Aug 2024 19:10:34 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=mCLuZi00; spf=pass (imf03.hostedemail.com: domain of kent.overstreet@linux.dev designates 95.215.58.178 as permitted sender) smtp.mailfrom=kent.overstreet@linux.dev; dmarc=pass (policy=none) header.from=linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1724526593; a=rsa-sha256; cv=none; b=1HEnPPbBp7twTFsCpP8d65++Fy1Tg8Nwl7d8LD73e3sQZc6eufC22P8PZckm8F2la7eUrC FnfGVzAm0dU2vAr3DY0qVj36vASRW9K5fcmkiGbHUi79fBK3tP8jqrqwCEOTLxKtd3m11f ARX4iIpXqVyQb9y8RFiJ9N2gyZaJk3I= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=mCLuZi00; spf=pass (imf03.hostedemail.com: domain of kent.overstreet@linux.dev designates 95.215.58.178 as permitted sender) smtp.mailfrom=kent.overstreet@linux.dev; dmarc=pass (policy=none) header.from=linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1724526593; 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=zKBGRtsPyUvtp5wY3XaRsK5eF/sYhIfHRSgUQREqSSc=; b=r5BQMmT3iGCyrBgUzyaAWnh7DJnC7FckA14PPCKbNCbPbZkDKRmVfkTnRvEbWGSFE/X3hw H2q4qfJnCSGC6RbhNvbgyT1hzCfULy7c0vYHjCwylV1T+Rb2W5QzbjT+7Vknp7x3gDr9A7 ykIF8KoBD4rS3wkgM3ySbHOiGUpYCrk= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1724526633; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=zKBGRtsPyUvtp5wY3XaRsK5eF/sYhIfHRSgUQREqSSc=; b=mCLuZi006yPmOyvt4ug0F4H1yPxKHuV9w05Ji8hemfGYpuf7LzRQHiP+mDAQOJd31WpCHF A33rHCZsgG1Pu04hRLc9VGB3RSXW3BcUNa5eYsPdzVsl04tag5XniOIN+/gE/SXw8dJrJ2 vqZXONnqFtGa2PzU4Y6k31vMpVt0cu8= From: Kent Overstreet To: david@fromorbit.com, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org Cc: Kent Overstreet Subject: [PATCH 06/10] bcachefs: shrinker.to_text() methods Date: Sat, 24 Aug 2024 15:10:13 -0400 Message-ID: <20240824191020.3170516-7-kent.overstreet@linux.dev> In-Reply-To: <20240824191020.3170516-1-kent.overstreet@linux.dev> References: <20240824191020.3170516-1-kent.overstreet@linux.dev> MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Stat-Signature: 6xx911q9sfc7q61zx47m6fdmmz1uyb1n X-Rspamd-Queue-Id: 1758D20007 X-Rspam-User: X-Rspamd-Server: rspam10 X-HE-Tag: 1724526634-730566 X-HE-Meta: U2FsdGVkX1/dQmpTwQtJBSfnc4vClYqiSttaI+2Uw1NT73SubeFtgXt4vwYwnNvQw5OX9tapQh6kLi2kdwh+E4sRx3M7HLXEDm5gUIrPzauyFzRx2vo1imz9pirDHch9oAF6NVzjS0X2Xl/cLlmYQX5ZD7GE6cg8wlXqKJZelO8MAGayoCt2yZ4LRgIZcq3R3zHm4LrzpPMVPLDPHtBMLuZXIYy117WZl9ZY78gExuYD/oGVsxCEe2zX3+SRHeBj2tJcESF9N9Oanj7Nl2aQHuQBJKjqktYn141L+fGGxd90b8z9PZ9/idJD50slONb/uRC9+fpjIk4zNj8s2SO2tr3jarJsvO2AdRmpmzH3DWsUTfTAp7UkdicHQ+WL+moeCl0vbQuGPLt6QhCnsCYRn15dRhOovhN+GPsHaASEiwhmbQa37pNJ31wQUMSz1f0t9JYI9k+X0H70O0v4+zTpGplf/0MunsnAvln2T//BoZWQoGAd6t2JdqggBdeqpKZ9GguqgnFbbrrQA555T1cnwGkBftZUvWqgMrd0dkEOC4n+CHUSTH0mNg2S6ixFYLfu1WVQwplswlHtacaNLJh7d/h19j2T3LZkN9Rms3DdY+3/aM2FgN6EQWVhjGklIx8ScJKxo1QL4X7TsVWLPKKQ1CMXNVV3SETjc/NU989pYSMbY3r/yV8+u1pCqLUPWmC3B63wda1OGigLe7FlkkT1WWUR9+4Sw1qnSBs7GV/IQ5N0m84hLNvN2tqUU+1k//fLRCIvQhJUtNhldVzRydJXs3qlclCI6uGBmTZM4H5E7eAzML/J2YMNM6Q0CHjKnaZGmWTNUoUDvmojTGn9EzYtB6MczLmxqxgLjlsHO3e8wZiGVQkj4vaxh5HaeidPtlLuyXIQjckr0rF2orejlwZNOLXgPWwZVXfIFNlBJWlD+Ac890LLvEs0E9/7PnCcPQR2NvhIbAAD1pW5WShn1MW dgFxU7m3 3lfLBH9E6vXTbfjba4bUluoJoyCjIUl137UzfhyZoTBmXSU+i+63nMs/bmuuG7S7JwYiuLelLZA7HOmdAnnwScFTrrOTdElOegEy9FUhvEtqcx2lzlsTk/59v9JvwK/ZSB7FGJBCHC+zkdXjGbdNBeguhMYxNekwOV5VK 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: List-Subscribe: List-Unsubscribe: This adds shrinker.to_text() methods for our shrinkers and hooks them up to our existing to_text() functions. Signed-off-by: Kent Overstreet --- fs/bcachefs/btree_cache.c | 13 +++++++++++++ fs/bcachefs/btree_key_cache.c | 14 ++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/fs/bcachefs/btree_cache.c b/fs/bcachefs/btree_cache.c index 662f0f79b7af..9f096fdcaf9a 100644 --- a/fs/bcachefs/btree_cache.c +++ b/fs/bcachefs/btree_cache.c @@ -15,6 +15,7 @@ #include #include +#include #define BTREE_CACHE_NOT_FREED_INCREMENT(counter) \ do { \ @@ -487,6 +488,17 @@ static unsigned long bch2_btree_cache_count(struct shrinker *shrink, return btree_cache_can_free(bc); } +static void bch2_btree_cache_shrinker_to_text(struct seq_buf *s, struct shrinker *shrink) +{ + struct bch_fs *c = shrink->private_data; + char *cbuf; + size_t buflen = seq_buf_get_buf(s, &cbuf); + struct printbuf out = PRINTBUF_EXTERN(cbuf, buflen); + + bch2_btree_cache_to_text(&out, &c->btree_cache); + seq_buf_commit(s, out.pos); +} + void bch2_fs_btree_cache_exit(struct bch_fs *c) { struct btree_cache *bc = &c->btree_cache; @@ -570,6 +582,7 @@ int bch2_fs_btree_cache_init(struct bch_fs *c) bc->shrink = shrink; shrink->count_objects = bch2_btree_cache_count; shrink->scan_objects = bch2_btree_cache_scan; + shrink->to_text = bch2_btree_cache_shrinker_to_text; shrink->seeks = 4; shrink->private_data = c; shrinker_register(shrink); diff --git a/fs/bcachefs/btree_key_cache.c b/fs/bcachefs/btree_key_cache.c index 2e49ca71194f..af84516fb607 100644 --- a/fs/bcachefs/btree_key_cache.c +++ b/fs/bcachefs/btree_key_cache.c @@ -13,6 +13,7 @@ #include "trace.h" #include +#include static inline bool btree_uses_pcpu_readers(enum btree_id id) { @@ -746,6 +747,18 @@ void bch2_fs_btree_key_cache_init_early(struct btree_key_cache *c) { } +static void bch2_btree_key_cache_shrinker_to_text(struct seq_buf *s, struct shrinker *shrink) +{ + struct bch_fs *c = shrink->private_data; + struct btree_key_cache *bc = &c->btree_key_cache; + char *cbuf; + size_t buflen = seq_buf_get_buf(s, &cbuf); + struct printbuf out = PRINTBUF_EXTERN(cbuf, buflen); + + bch2_btree_key_cache_to_text(&out, bc); + seq_buf_commit(s, out.pos); +} + int bch2_fs_btree_key_cache_init(struct btree_key_cache *bc) { struct bch_fs *c = container_of(bc, struct bch_fs, btree_key_cache); @@ -770,6 +783,7 @@ int bch2_fs_btree_key_cache_init(struct btree_key_cache *bc) bc->shrink = shrink; shrink->count_objects = bch2_btree_key_cache_count; shrink->scan_objects = bch2_btree_key_cache_scan; + shrink->to_text = bch2_btree_key_cache_shrinker_to_text; shrink->batch = 1 << 14; shrink->seeks = 0; shrink->private_data = c; From patchwork Sat Aug 24 19:10:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kent Overstreet X-Patchwork-Id: 13776498 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 E121BC52D6F for ; Sat, 24 Aug 2024 19:10:49 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A0E20800F1; Sat, 24 Aug 2024 15:10:39 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 96CA3800EE; Sat, 24 Aug 2024 15:10:39 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 797F8800F1; Sat, 24 Aug 2024 15:10:39 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 5111E800F0 for ; Sat, 24 Aug 2024 15:10:39 -0400 (EDT) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id E689DA802D for ; Sat, 24 Aug 2024 19:10:38 +0000 (UTC) X-FDA: 82488080556.26.21DDD3B Received: from out-178.mta1.migadu.com (out-178.mta1.migadu.com [95.215.58.178]) by imf29.hostedemail.com (Postfix) with ESMTP id 2EE3212000A for ; Sat, 24 Aug 2024 19:10:35 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b="il4cNM1/"; spf=pass (imf29.hostedemail.com: domain of kent.overstreet@linux.dev designates 95.215.58.178 as permitted sender) smtp.mailfrom=kent.overstreet@linux.dev; dmarc=pass (policy=none) header.from=linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1724526525; 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=dHJr4su3KzsflXo6gchJ2B6JfeJstKzSoEoijiSdexY=; b=jDtCvlJpFLrix6AdZIIi81Yo4avix4J7t5mAdWEYseMeBthxqBlPAjIUcV32FGUa5sN7I1 k3zCbd+8wnL5iQkxQ1tz49pirjtwKLduI/J/nRJlUjigcNmjO5qxJI3d3u0PVMyWb++ePz lZYpoAWY4HKCQYaH9L2rXFtZFJPZidg= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b="il4cNM1/"; spf=pass (imf29.hostedemail.com: domain of kent.overstreet@linux.dev designates 95.215.58.178 as permitted sender) smtp.mailfrom=kent.overstreet@linux.dev; dmarc=pass (policy=none) header.from=linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1724526525; a=rsa-sha256; cv=none; b=nrhBVY/5Va36B0hTdnoRXCVeFrHJpZMWn9nh300iAOfKf6IuuyzYJirSh6VHIUnhernKRA HB26XGHVdZjnnaTrroam1NFk/KytcAyYl7tZsRgBeL7mqSte+gJ25EMDCnP4MKjsQgwOQ+ rt/+b4PE5CInet/557lnLKKTOyIAodE= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1724526634; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=dHJr4su3KzsflXo6gchJ2B6JfeJstKzSoEoijiSdexY=; b=il4cNM1/7oj7XYsuHh1W1JNzs4Oq8+fDTy6JvD4Z511p+2xPkkP9wOvvzwe4YnQoziTFYw r0FkAsv8qjNLoGwPvEttI9Y6Q+RRSVD1WBAfURE9dCu6369wU2dC//Sp+tP23BA3CWrQfj Uxn9vImAHZ/0ZmIV1TedThnII+RIVw8= From: Kent Overstreet To: david@fromorbit.com, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org Cc: Kent Overstreet , Alexander Viro , linux-fsdevel@vger.krenel.org, Tejun Heo Subject: [PATCH 07/10] percpu: per_cpu_sum() Date: Sat, 24 Aug 2024 15:10:14 -0400 Message-ID: <20240824191020.3170516-8-kent.overstreet@linux.dev> In-Reply-To: <20240824191020.3170516-1-kent.overstreet@linux.dev> References: <20240824191020.3170516-1-kent.overstreet@linux.dev> MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 2EE3212000A X-Stat-Signature: mn68m4yqwocx1r49bqscdxeh4qytu8n7 X-Rspam-User: X-HE-Tag: 1724526635-483382 X-HE-Meta: U2FsdGVkX1+Mjt3XOWBGBoqyKTNvwNmtRCIy9mC0ojooEgtaLhLiHwY3k40e/cMuWPIKBQ2Vk4YSmEljRHteUIbHjnFNsmLBx0f8quxZ/dAPKIvHZwpeWE4UShtdAE20iquDPh26mvRpBOWlMir5G/vzuDR12uVBFdoFe+gqhym2HwS17BpMWtlIS3Y0jakSqtMnKiDqnfExKmbLOltr5yp4HZVObplqU/F1BKI+2fC2trz/W447iXGC/pic4fC39yadsKvBp736og4jAl+y0HHdLzI17bLhwTle2CS4sICoLu4Nif2Y/UkakwPxaHeSXESB5m1Z+OAGVT/pp58Lt7rV3P5ipZZScBHF0EfprxxbCiOOsEEXCFs5JYZxaTg9AikUrH2ZecSQd89/u963IieESYMXaI8XSkcLgE52UM3rJe6Knh7T3GWEsj2Ejai7aMqfNMutVM6TKjXvgWCfzvn8zpP0vy7o9Yj6ID9OmnFaO5Z9MFRVyaPhJ78CnThByX8m2SJTrcoQGXdMxQPXeUIEvDdDAH6HBQB+BeNegjr9KNCBU30fk1W9QF6RxhUGXw2vj4UhRc8Dh0dm9ntJYeyhWdaRVGpK5sPnyCcvlMYHgxv5PdL+mpzlOQ+atimiRNxDltDJqJKfuuwK3rA1/AtZgCBmkNCbHVBJXrbeH8F7AQ8JBG5ljfrjkRlZOG9ZlFNJtGjTAhKIhXEXtVNnAgMb2SvSEbOFiglMYV102J0OitMG9iHNwqsSn2BjO6/3O77QBChLCjIOm+maWJ3eXIRCwbcTJ+54C5BKO8dWWHuKalT7PwacGDvdXVZ0ajfKwTL7SIm0wQbiJiOfUXF/CT/7qhCNnvRc6SP4XbUdli/O2NuNn4OMd6vLAP17RQzL26husR2N8bG9DD4v9+Fn1xaA1rImaIhWevFsgHVxjBFTlSYJ8ZCgNeMEIvNjx4vyEXCpPW1/duf0xhwKUTx 6pzJIrXh Kq0GszI3uhD+/NkylwrmUPD6iD9LbfOZeaJQMtsIlOMn7SgMLn6yqicL2WVBVe335GAhyHnEF1h+5fb/c9GzwP60ssF++uKSWnPqy/ZV7vAdOCgSGTVxVl7bC/Jx2EYYJcC1N0bY+1sLf9xoT9MCBjJM2zwAa+CmzLcxo3jp1sfPW/SY+VDRFz2bwSmhzXn6XY1hTur8/pJpS22JJpsZIwqgTMxU+5bCyGMIza6vxQF4OqQgeR33FEtLs+/SLmKhyaxU3zS+q+d+K1UQb6VHH1c3+tYZDy/pUor/2w8yYTukoHoT7LYbq5QoWXkwdr7jYP/UGJSMV8kMUW6mdI5kk4lORjw== 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: List-Subscribe: List-Unsubscribe: Add a little helper to replace open coded versions. Signed-off-by: Kent Overstreet Cc: Alexander Viro Cc: linux-fsdevel@vger.krenel.org Cc: Tejun Heo Signed-off-by: Kent Overstreet --- fs/bcachefs/util.h | 10 ---------- fs/dcache.c | 16 +++------------- include/linux/percpu.h | 10 ++++++++++ 3 files changed, 13 insertions(+), 23 deletions(-) diff --git a/fs/bcachefs/util.h b/fs/bcachefs/util.h index fb02c1c36004..e90c2f546007 100644 --- a/fs/bcachefs/util.h +++ b/fs/bcachefs/util.h @@ -584,16 +584,6 @@ do { \ } \ } while (0) -#define per_cpu_sum(_p) \ -({ \ - typeof(*_p) _ret = 0; \ - \ - int cpu; \ - for_each_possible_cpu(cpu) \ - _ret += *per_cpu_ptr(_p, cpu); \ - _ret; \ -}) - static inline u64 percpu_u64_get(u64 __percpu *src) { return per_cpu_sum(src); diff --git a/fs/dcache.c b/fs/dcache.c index 3d8daaecb6d1..64108cbd52f6 100644 --- a/fs/dcache.c +++ b/fs/dcache.c @@ -151,29 +151,19 @@ static struct dentry_stat_t dentry_stat = { */ static long get_nr_dentry(void) { - int i; - long sum = 0; - for_each_possible_cpu(i) - sum += per_cpu(nr_dentry, i); + long sum = per_cpu_sum(&nr_dentry); return sum < 0 ? 0 : sum; } static long get_nr_dentry_unused(void) { - int i; - long sum = 0; - for_each_possible_cpu(i) - sum += per_cpu(nr_dentry_unused, i); + long sum = per_cpu_sum(&nr_dentry_unused); return sum < 0 ? 0 : sum; } static long get_nr_dentry_negative(void) { - int i; - long sum = 0; - - for_each_possible_cpu(i) - sum += per_cpu(nr_dentry_negative, i); + long sum = per_cpu_sum(&nr_dentry_negative); return sum < 0 ? 0 : sum; } diff --git a/include/linux/percpu.h b/include/linux/percpu.h index 4b2047b78b67..0df28ff54f66 100644 --- a/include/linux/percpu.h +++ b/include/linux/percpu.h @@ -162,4 +162,14 @@ extern phys_addr_t per_cpu_ptr_to_phys(void *addr); extern unsigned long pcpu_nr_pages(void); +#define per_cpu_sum(_p) \ +({ \ + typeof(*(_p)) sum = 0; \ + int cpu; \ + \ + for_each_possible_cpu(cpu) \ + sum += *per_cpu_ptr(_p, cpu); \ + sum; \ +}) + #endif /* __LINUX_PERCPU_H */ From patchwork Sat Aug 24 19:10:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kent Overstreet X-Patchwork-Id: 13776499 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 B8BE7C5320E for ; Sat, 24 Aug 2024 19:10:52 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CB04E800EE; Sat, 24 Aug 2024 15:10:39 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B3F94800F3; Sat, 24 Aug 2024 15:10:39 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8FBFF800F0; Sat, 24 Aug 2024 15:10:39 -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 51095800EE for ; Sat, 24 Aug 2024 15:10:39 -0400 (EDT) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id C8B221A082F for ; Sat, 24 Aug 2024 19:10:38 +0000 (UTC) X-FDA: 82488080556.06.A0060ED Received: from out-178.mta1.migadu.com (out-178.mta1.migadu.com [95.215.58.178]) by imf10.hostedemail.com (Postfix) with ESMTP id 27808C0003 for ; Sat, 24 Aug 2024 19:10:36 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=wTNonfQ8; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf10.hostedemail.com: domain of kent.overstreet@linux.dev designates 95.215.58.178 as permitted sender) smtp.mailfrom=kent.overstreet@linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1724526575; a=rsa-sha256; cv=none; b=mkTm/R++yMP0scvwl97XLb/24haaNJh3r0Ggt3ePyeM6ETU3xKpvEi8bbB17kLc7t5rgTK XX9DW7uREEiL/qnsMXINdmhO54s/qkykxNy1Yn7DX/onFpR/TZnEyleReHDm6wrlhVozmt R7c+rVHEkotowSCrhtz2plOlxgjgCMM= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=wTNonfQ8; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf10.hostedemail.com: domain of kent.overstreet@linux.dev designates 95.215.58.178 as permitted sender) smtp.mailfrom=kent.overstreet@linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1724526575; 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=bkjDXacJBIE1tnl8yjf2hTWkksioVHF2A/Lmh31BWug=; b=KtMrF4lpSk8mCozn4SPSGRqsNqDChWGqIloZOZOKBFuTFPO7nbUXoSB3h5yQ0GuWi0jab0 INHVbeDEtvu0+DelE+UCO1B8VtdpH4W7ATmdUM4ti8JdkkZcGpEqiPQaL1tkm/+vfjLq5P iU22SyN6Le7mxJbyhfHZNucbveoQzAs= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1724526635; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=bkjDXacJBIE1tnl8yjf2hTWkksioVHF2A/Lmh31BWug=; b=wTNonfQ8/pgi2wT6SpzNvV1SNBGipnFrxT4NfhyDeL4N7vyQtDB52h1ymy/Cw91TCBmyq4 NMuN/t0hl+jsEGr3Jii46H75JjUhzOIlcDwgZ49INWfPV4i/Kqp/X+vVMVTrZK4R5juNwe 482emWvPc/dZrYuIJGexZ6pMGuggzW0= From: Kent Overstreet To: david@fromorbit.com, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org Cc: Kent Overstreet , Alexander Viro , Christian Brauner Subject: [PATCH 08/10] fs: Add super_block->s_inodes_nr Date: Sat, 24 Aug 2024 15:10:15 -0400 Message-ID: <20240824191020.3170516-9-kent.overstreet@linux.dev> In-Reply-To: <20240824191020.3170516-1-kent.overstreet@linux.dev> References: <20240824191020.3170516-1-kent.overstreet@linux.dev> MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Rspamd-Queue-Id: 27808C0003 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: z9b1uaketwtt5ajpu65699tf3zy63tqp X-HE-Tag: 1724526636-211118 X-HE-Meta: U2FsdGVkX19JA0+vwglMGlcA8Kv2mPFWk/XM3mYv8y13tYnCZgYuRcxMASHZV1gasqWCN/b9/cQIj/MjA5eTprSgNOgasdF/h+OVH+aJTCczexZJM2C6b2A6xNTNoHBWuKhr7iwK9LH2W0AxgPqeIOc2V4w0fdBjx9+WIxcIjQIe873IYjhHIWDUyKU0JjkSyJZYtaNC5IGZuaIhdfzFPpZp+mIbwTKdUSUotwrv5tPLI+RakZFPlEA7dfSrx2sTcASSs+0OSpdV0JpdQl1T9oQr18DYxUDirKlDxNaftIjH3hg+HBC+bRTvY/4PL0CGlqZU1DnUeqmxMrBTXpgC2+KBLfeH0Ch+jgb9txvLYO7LH6OC8mZlLh7aT6Dq6ZPd/69VXXUpCUAwNe4Ar9XZ0PSwKe+/f5IH5kUfRN6cTlDGs5U6lMgnFUNndcYdyinYgezRZa0zmgi96h+7xuDaHvPsARE1h7aJO/uRPvQm/95XYDf1e8GNUFnw5T9a83f7xA0ywqzg6Joa2Gu619rEEcQN3G6uo5CL2U/gIg2pTOwH5UsIM4CexDX5YYVQmdxim6rcF2O80sDZ7ELsjv9BJAHwSfBHn/R2PKPFV2k5INiemB98kHXqBX5IfTiimDD1VhFuCe4FyS8aOxkXaEuyjDI4xXxTql6J1bM4ZuKd+1fQ9+WdorSTdVmC3a0NILq/70soPm015tzoTHrhva0y+VLwKmrz5AERaxWzaw3jvk6zdEYozeky+wmN3KGGic3qkGAeyPeLRGDH0RHc83ZLUvmSlYAZBEh1YCxXGlI6SY5aUv4d6ofO2s7nWAi4PefVsVAbqagBmu8rkalHohaHznHJp1Z6w3pDTIlEZUpGNRos62Bl1HX6VBXUvNYgQ2CUwKLzM2jkqqpoNViTej7fN710Pkx16bEscXHJ7ZqzL5h3j4hpby8TqF0UMV9WW1UI9lfjJvHC8R2Faq2b+TU uSXKam0u b3Rl72J0XTk90r0ag3saGTMK2hD8Jp8UdVOANov1JO2/fxk22ddVGD6h1AEybsFQhWbfefz4fk7S4I8JO+oLv9cHm2o3SDuzM9YeyTP5Izhqd0D2VFtDmkax++TYz9yrzIOyLWbF8ib2ka08o82/bMwNsc/qSF509JobadsuBMJfCd/EGfO8jM+Srvk2C2iL+ZtmkfIexAlnYd3ZRNsLUw+LXjMfAnF8kDmyyEgE557tqQuV2l7mxGj8tFxh7M0NAcpa3yDpNxJfDnB4Mw8ZiUIvKDbPO5IC5LLKkSmihLPaPY07ZFo/8cYrOnPiIhKlVg7oZtG8qn6Jq63hKHWRXUroSFg== 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: List-Subscribe: List-Unsubscribe: Upcoming shrinker debugging patchset is going to give us a callback for reporting on all memory owned by a shrinker. This adds a counter for total number of inodes allocated for a given superblock, so we can compare with the number of reclaimable inodes we already have. Cc: Alexander Viro Cc: Christian Brauner Cc: Dave Chinner Signed-off-by: Kent Overstreet --- fs/inode.c | 2 ++ fs/super.c | 7 +++++++ include/linux/fs.h | 1 + 3 files changed, 10 insertions(+) diff --git a/fs/inode.c b/fs/inode.c index 5e7dcdeedd4d..2650c5ce74e1 100644 --- a/fs/inode.c +++ b/fs/inode.c @@ -489,12 +489,14 @@ void inode_sb_list_add(struct inode *inode) spin_lock(&inode->i_sb->s_inode_list_lock); list_add(&inode->i_sb_list, &inode->i_sb->s_inodes); spin_unlock(&inode->i_sb->s_inode_list_lock); + this_cpu_inc(*inode->i_sb->s_inodes_nr); } EXPORT_SYMBOL_GPL(inode_sb_list_add); static inline void inode_sb_list_del(struct inode *inode) { if (!list_empty(&inode->i_sb_list)) { + this_cpu_dec(*inode->i_sb->s_inodes_nr); spin_lock(&inode->i_sb->s_inode_list_lock); list_del_init(&inode->i_sb_list); spin_unlock(&inode->i_sb->s_inode_list_lock); diff --git a/fs/super.c b/fs/super.c index b7913b55debc..b1b6ae491b6c 100644 --- a/fs/super.c +++ b/fs/super.c @@ -278,6 +278,7 @@ static void destroy_super_work(struct work_struct *work) security_sb_free(s); put_user_ns(s->s_user_ns); kfree(s->s_subtype); + free_percpu(s->s_inodes_nr); for (int i = 0; i < SB_FREEZE_LEVELS; i++) percpu_free_rwsem(&s->s_writers.rw_sem[i]); kfree(s); @@ -298,6 +299,7 @@ static void destroy_unused_super(struct super_block *s) super_unlock_excl(s); list_lru_destroy(&s->s_dentry_lru); list_lru_destroy(&s->s_inode_lru); + free_percpu(s->s_inodes_nr); shrinker_free(s->s_shrink); /* no delays needed */ destroy_super_work(&s->destroy_work); @@ -375,6 +377,10 @@ static struct super_block *alloc_super(struct file_system_type *type, int flags, s->s_time_min = TIME64_MIN; s->s_time_max = TIME64_MAX; + s->s_inodes_nr = alloc_percpu(size_t); + if (!s->s_inodes_nr) + goto fail; + s->s_shrink = shrinker_alloc(SHRINKER_NUMA_AWARE | SHRINKER_MEMCG_AWARE, "sb-%s", type->name); if (!s->s_shrink) @@ -408,6 +414,7 @@ static void __put_super(struct super_block *s) WARN_ON(s->s_dentry_lru.node); WARN_ON(s->s_inode_lru.node); WARN_ON(!list_empty(&s->s_mounts)); + WARN_ON(per_cpu_sum(s->s_inodes_nr)); call_rcu(&s->rcu, destroy_super_rcu); } } diff --git a/include/linux/fs.h b/include/linux/fs.h index 8fc4bad3b6ae..86636831b9d0 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -1346,6 +1346,7 @@ struct super_block { /* s_inode_list_lock protects s_inodes */ spinlock_t s_inode_list_lock ____cacheline_aligned_in_smp; struct list_head s_inodes; /* all inodes */ + size_t __percpu *s_inodes_nr; spinlock_t s_inode_wblist_lock; struct list_head s_inodes_wb; /* writeback inodes */ From patchwork Sat Aug 24 19:10:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kent Overstreet X-Patchwork-Id: 13776500 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 17AF9C52D6F for ; Sat, 24 Aug 2024 19:10:55 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 65FCC800F3; Sat, 24 Aug 2024 15:10:40 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 5EC74800F0; Sat, 24 Aug 2024 15:10:40 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 43C72800F3; Sat, 24 Aug 2024 15:10:40 -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 1AF92800F0 for ; Sat, 24 Aug 2024 15:10:40 -0400 (EDT) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id C1055C082E for ; Sat, 24 Aug 2024 19:10:39 +0000 (UTC) X-FDA: 82488080598.22.54B2568 Received: from out-178.mta1.migadu.com (out-178.mta1.migadu.com [95.215.58.178]) by imf16.hostedemail.com (Postfix) with ESMTP id 14678180004 for ; Sat, 24 Aug 2024 19:10:37 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b="HCl/LWmJ"; spf=pass (imf16.hostedemail.com: domain of kent.overstreet@linux.dev designates 95.215.58.178 as permitted sender) smtp.mailfrom=kent.overstreet@linux.dev; dmarc=pass (policy=none) header.from=linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1724526596; a=rsa-sha256; cv=none; b=dfALT4woa6M61mgKphMN4Q+pb91n93slHvPZpV7jFE7jp6fe8UQ8wBlT+ehDYodxpJVytX Gh/wOc6XxGqC4Uqi2n5alDsSiSt/2XwWZsaFipO+d6YZghbhkrZau2AtW+fOXSyT7rZwHT N2x+dAmBqdKa1mvudly57rZCrGib3Ec= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b="HCl/LWmJ"; spf=pass (imf16.hostedemail.com: domain of kent.overstreet@linux.dev designates 95.215.58.178 as permitted sender) smtp.mailfrom=kent.overstreet@linux.dev; dmarc=pass (policy=none) header.from=linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1724526596; 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=lIF02eH9k6dm0NzZMiixaw+oq+xhVtrthbaRSnodZvc=; b=HyVnJRq4hkJG9SgjXPQf99hzQ0l6R4StxYDcSHGyiNN2r430QBmoVOufKNEsEQWmRrNusC TV/vgElnDbzhhfciGok+8a/x1qK/+f0CDmykmhoiPwJbKyyxLvef9T6L7aBdcpsva42LQG 2OtRm/t73LqnMlXUZyTpXM8Bebpadns= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1724526636; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=lIF02eH9k6dm0NzZMiixaw+oq+xhVtrthbaRSnodZvc=; b=HCl/LWmJbPvVzwn/ZY3aUrgi1pxURTXeresHi0kDKfH12r0Dn81Qxcx3IsFaNWZka7CS+a 4lRwMz2Qw5uIGa50IsWt9GUBstO5XMK+fyTy8fJ936oYKvxsHAuvebZUw7S4f0ovBdErkx loDj/C2bOYdsxcPpgzTpsvnBl5Mn7rQ= From: Kent Overstreet To: david@fromorbit.com, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org Cc: Kent Overstreet , Alexander Viro , Christian Brauner Subject: [PATCH 09/10] fs/dcache: Add per-sb accounting for nr dentries Date: Sat, 24 Aug 2024 15:10:16 -0400 Message-ID: <20240824191020.3170516-10-kent.overstreet@linux.dev> In-Reply-To: <20240824191020.3170516-1-kent.overstreet@linux.dev> References: <20240824191020.3170516-1-kent.overstreet@linux.dev> MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Stat-Signature: zfxacbu7mytoyyog6c7bz7qdf6ghbrsx X-Rspamd-Queue-Id: 14678180004 X-Rspam-User: X-Rspamd-Server: rspam10 X-HE-Tag: 1724526637-671858 X-HE-Meta: U2FsdGVkX18/z4/2iBlaPdIw8kChmcRFQsolWC0kUKkIfWTZHH+pEQLz4X3Gqe1V4W9BSh+VY+ycuRB6ch2Hc14gWFM5wzCMYN1ef08h9IYxkQoVxhw25S36RdGoAmj27m5QXv+4R/JhMGhGzBDGp5edYeLC4PbXpi5r/jD7/4UPs1O2IRinqEtuEskEe+lIJTyntJ8dRo/c+ka0KwRv/RYD1GYnxd6EFOmqbFjTBQXGhifnN31BcICpxfmcLrKSEWb8CqElCEGKTz/blmFoXCZ3bqd+/DQgSum90ilk8QeDQYfceJra6GJUjXGf9IfYAEz4nwKJKWfHWaUfduMeW3Amkh5f30VgQyTNN2gFEZAM+01M7Iaqh1uO9K/oFOq5xz3d9PrTTUzNrG3xMXb40vt2a+L7PXSLH23OS4Q1E89ukCg11szgHD/fbMLIxGeTOCcFUmskS/TUrp1yn+CPgPlHLZG//4uds10SlZHop4T+dj1lRjvN918u8lA1chCu5P3CCiQ5UHStFY7WnL157cuH+0EhfnxxftBhyuUn9kTVeGzALtN31Pg9bSt1CL0hocioRD+/OSUb5Ca1PY3QXYp7vqGzGeVPvq0KDct8kd2CQzWLlCjDTHOw9YP3L0m+KbBR0lXluXUcOD0aVIUH2/l92iDP7ydUiWl1MhM+HdpLMhuZWKabphs1cqlWnE57Gkzrjh1FXGgZ6plRdI0w3UTnYJOyZriF89ueKgHi8B4pokTdpOZPvcJsVDR4u0iszcz1f1oZJJBSE9EhmYfXK8Vk0yulT8CbdQ4K2s/sTPB1OPB4mJT2/gkKNmcth0U1Xqx37hiLdaLTjvblM7/Yg3PeGnIXxEkCN7m3uVxdugtRQ+yskALedlDrXFnXxQN+P0U9S56ih8ey7Y31WTypdqMx5X6CwmWtrdsaZUn7Zku6X2rPONlS6hdZy62sKf6hzyTcsd59+jGH9uPwLdn BMOjWx9k vTZF2Rmns5N/9NTlzjEUswO7gB9pUvacW406vqLVHwCfpX1VQWJxnKZfbE0NVpXLms+wiO08Q4YweKVDYmf4EzZQqaCaQYUhiU2BlEecsw+t+iXi7TQmcmRtkDDyHvanrrQSDp7HdTWdj5eUxe0aSWr6DlG/13CF1HxcvBonSt6qeAJ5UguMgE9NGcihRHGLZSdKDrAyjgObykupQTN7sra9bG0Xe2X0kf/5QoFfxKOfczbjWn79Jgx6QzHESezbAgG3mTI7+urMqe87li/P/ks1joQ== 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: List-Subscribe: List-Unsubscribe: Like the previous patch, add a counter for total dentries, so we can print total vs. reclaimable. Cc: Alexander Viro Cc: Christian Brauner Cc: Dave Chinner Signed-off-by: Kent Overstreet --- fs/dcache.c | 2 ++ fs/super.c | 6 ++++++ include/linux/fs.h | 1 + 3 files changed, 9 insertions(+) diff --git a/fs/dcache.c b/fs/dcache.c index 64108cbd52f6..4bbb2c87f824 100644 --- a/fs/dcache.c +++ b/fs/dcache.c @@ -601,6 +601,7 @@ static struct dentry *__dentry_kill(struct dentry *dentry) else spin_unlock(&dentry->d_lock); this_cpu_dec(nr_dentry); + this_cpu_dec(*dentry->d_sb->s_dentry_nr); if (dentry->d_op && dentry->d_op->d_release) dentry->d_op->d_release(dentry); @@ -1683,6 +1684,7 @@ static struct dentry *__d_alloc(struct super_block *sb, const struct qstr *name) } this_cpu_inc(nr_dentry); + this_cpu_inc(*sb->s_dentry_nr); return dentry; } diff --git a/fs/super.c b/fs/super.c index b1b6ae491b6c..5b0fea6ff1cd 100644 --- a/fs/super.c +++ b/fs/super.c @@ -278,6 +278,7 @@ static void destroy_super_work(struct work_struct *work) security_sb_free(s); put_user_ns(s->s_user_ns); kfree(s->s_subtype); + free_percpu(s->s_dentry_nr); free_percpu(s->s_inodes_nr); for (int i = 0; i < SB_FREEZE_LEVELS; i++) percpu_free_rwsem(&s->s_writers.rw_sem[i]); @@ -299,6 +300,7 @@ static void destroy_unused_super(struct super_block *s) super_unlock_excl(s); list_lru_destroy(&s->s_dentry_lru); list_lru_destroy(&s->s_inode_lru); + free_percpu(s->s_dentry_nr); free_percpu(s->s_inodes_nr); shrinker_free(s->s_shrink); /* no delays needed */ @@ -381,6 +383,10 @@ static struct super_block *alloc_super(struct file_system_type *type, int flags, if (!s->s_inodes_nr) goto fail; + s->s_dentry_nr = alloc_percpu(size_t); + if (!s->s_dentry_nr) + goto fail; + s->s_shrink = shrinker_alloc(SHRINKER_NUMA_AWARE | SHRINKER_MEMCG_AWARE, "sb-%s", type->name); if (!s->s_shrink) diff --git a/include/linux/fs.h b/include/linux/fs.h index 86636831b9d0..493fb8e72bf0 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -1332,6 +1332,7 @@ struct super_block { * There is no need to put them into separate cachelines. */ struct list_lru s_dentry_lru; + size_t __percpu *s_dentry_nr; struct list_lru s_inode_lru; struct rcu_head rcu; struct work_struct destroy_work; From patchwork Sat Aug 24 19:10:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kent Overstreet X-Patchwork-Id: 13776501 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 21EE1C52D6F for ; Sat, 24 Aug 2024 19:10:58 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5EB8C800F4; Sat, 24 Aug 2024 15:10:41 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 573E1800F0; Sat, 24 Aug 2024 15:10:41 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 41684800F4; Sat, 24 Aug 2024 15:10:41 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 1D814800F0 for ; Sat, 24 Aug 2024 15:10:41 -0400 (EDT) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id D45F016087D for ; Sat, 24 Aug 2024 19:10:40 +0000 (UTC) X-FDA: 82488080640.10.2329013 Received: from out-188.mta1.migadu.com (out-188.mta1.migadu.com [95.215.58.188]) by imf14.hostedemail.com (Postfix) with ESMTP id 2A49D100010 for ; Sat, 24 Aug 2024 19:10:38 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=uLTTvEzA; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf14.hostedemail.com: domain of kent.overstreet@linux.dev designates 95.215.58.188 as permitted sender) smtp.mailfrom=kent.overstreet@linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1724526571; a=rsa-sha256; cv=none; b=ludukc0A3C5749M+skW84aQvlW1iBjQ/EOLO3eMEU3z5GPx/rIHnh+KztJ5/rZpUFZOQFP BRkIp7OdA1cMzo3JiJyqW5uLYv5gF476/2CWzudr0L9ZZmO5JmpNBQsoV/u7REKc4VuPpn gJMUe9Hrkhm5YIIje0zw6E+NhhJl4Aw= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=uLTTvEzA; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf14.hostedemail.com: domain of kent.overstreet@linux.dev designates 95.215.58.188 as permitted sender) smtp.mailfrom=kent.overstreet@linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1724526571; 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=4/6BjvYC74gmac1jn75OzS49TGeIbW4Qt8X6sz89g0E=; b=2PjZ/Zqup1BQyFN1Yg1Vjp+BjKawUVUG0qSi62Ek9FOpIfLeMJaqLWrbMCq35dyCLjzmIB SiLc6x5DEkLHJ8qny81y68o1GPq/y7+kbOJWTy3xxly6Uu6TrDJuemVi9jpHnLvtkHhB6/ id+O7SnzOZssIir7D+pY6SYwiRkTrFc= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1724526637; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=4/6BjvYC74gmac1jn75OzS49TGeIbW4Qt8X6sz89g0E=; b=uLTTvEzAmARYGg6WMItjxULIrOooAHWcR1U1Iq5IWriDIXInrJPfTm7cifzOilxCeEAm2U 5IZXCh2j9e45pp9trnFvC3jeTQXWCfhgFsuZf/WIY7+metYuj+pGV7w7VUPQA5h7y/Yo5r z4rS4OOztEOz0kMF8FXMpgTNMw7IC4w= From: Kent Overstreet To: david@fromorbit.com, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org Cc: Kent Overstreet , Alexander Viro , Christian Brauner Subject: [PATCH 10/10] fs: super_cache_to_text() Date: Sat, 24 Aug 2024 15:10:17 -0400 Message-ID: <20240824191020.3170516-11-kent.overstreet@linux.dev> In-Reply-To: <20240824191020.3170516-1-kent.overstreet@linux.dev> References: <20240824191020.3170516-1-kent.overstreet@linux.dev> MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 2A49D100010 X-Stat-Signature: thzodrddxyt3a3n5rbb79gdxghmkhmhq X-Rspam-User: X-HE-Tag: 1724526638-882515 X-HE-Meta: U2FsdGVkX1/qBzs8Lc0o7NijFJ01SbNGf98ndmIa4+5JrVYivux+StIa8RBxrFReGxfnTS6pd6l0FWaF/6V+jSql2H/k/bfKcopEB4yBGsq4OCcusC++sHH0wyyZGHr4oTQjkvcBdcf54vVJFTGFZvvC5BGfBEXL552As47jyDqX6f8/JUfGrdG+Hd88wUc+j5RAM4tqbFTE/q9jtRO1UGl1j0VFZZdqNsh9ohKfswf7cPN/zXU2KSi1GQ6Uox02oJMXygqE9RKbuAggrr1JCXnzO9WsiniiK1OcaRgRkSBRNcHXsLO+FVYhjpfx887gfgU/JCF1H8gWUSNKmAEnfuBbZGyJTRtXv8O3vvDYqAgN9Gy2BlI1YcRJkV61BaZKAQuzawWZtoFi8h7aHFQDKfK+hFPHqeLZWYAQUblC8gKj+RWZxPDOoSJywaEJQWl+m8uxf38UZC1ksq/RnnJnHsfhfwLqgn6iRZtF1WCI6byoEKPuh6/hdxcShaPuNtxVA6Dbz9Fvlu6Vz5m5dArkFaACgdHFvJZ6Kpk+9/br9UANFpejloCaeC6s5jFc9l+Bpy2YWUhBq6f4x0aISq/B+O0HeOIUp0VGALBy+UGwmh51P7MjBnfsYLGdLXY/RNOCYzNNVaTdAINEnlEbrmDQV4SOfMUswsk79G4bX9rLG4CYb1mWoFQ0V/70T3fENERlQBamqvV7DGSUb7jDlfO5yDZlClGQcpIWqb4K8ydFvAEhnXQqR2HCBvbzwMOdt4wTZTUQAiidX09Dh0PrPFbWrDB0QzogWin4+GwKj+HW581ygpPH7UFakisiWL1sIB/e/e3HuP+n2Abq2PeeT8esJrFvuCs/uPvvJT7lmcA08DWzby8Y4Hw4Gu5MlJCPJqLaZ8DSY6UtjOqUc6LcrAFB/wV86uXzaJdp9JRvq7bP6HtgXkUllbdflXT/FhJBiZ80Eih76PBFjmT+vuMN4St LV4lueky D7DjAmOfyvC9lv2/V1/T9HZYBswBSFlpmTbcnW8s8f8omd0bkDr95MYqDSb4KTHGyaRHbNzN/CmBvbwrXLI9wz6SIcMq0FeZkK9qfU0rEP+Tm7JfBhmjwY0FDkRqDy8zKyo+qfCqYSKEe7RADaC3DxGoD1+vU/iy2cJINpsd9NKrLWHqoUUBzDXqFvTjQGnmkrve0BbGous6UtlcbCzctjKH9lvTQ68y0MEFpW/WYGX1k565Xh8+HgrZrTx7lJmQqH66EQ0XmahPiHA6cudMBMAXF7DZ2qR6/PnqGXEcVsOcgb6pWhdPJgA04jeFQp/dVj9lgCmWDAmu8E6XPXScWJu8iZA== 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: List-Subscribe: List-Unsubscribe: Implement shrinker.to_text() for the superblock shrinker: print out nr of dentries and inodes, total and shrinkable. Cc: Alexander Viro Cc: Christian Brauner Cc: Dave Chinner Signed-off-by: Kent Overstreet --- fs/super.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/fs/super.c b/fs/super.c index 5b0fea6ff1cd..d3e43127e311 100644 --- a/fs/super.c +++ b/fs/super.c @@ -36,6 +36,7 @@ #include #include #include +#include #include #include "internal.h" @@ -270,6 +271,16 @@ static unsigned long super_cache_count(struct shrinker *shrink, return total_objects; } +static void super_cache_to_text(struct seq_buf *out, struct shrinker *shrink) +{ + struct super_block *sb = shrink->private_data; + + seq_buf_printf(out, "inodes: total %zu shrinkable %lu\n", + per_cpu_sum(sb->s_inodes_nr), list_lru_count(&sb->s_inode_lru)); + seq_buf_printf(out, "dentries: toal %zu shrinkbale %lu\n", + per_cpu_sum(sb->s_dentry_nr), list_lru_count(&sb->s_dentry_lru)); +} + static void destroy_super_work(struct work_struct *work) { struct super_block *s = container_of(work, struct super_block, @@ -394,6 +405,7 @@ static struct super_block *alloc_super(struct file_system_type *type, int flags, s->s_shrink->scan_objects = super_cache_scan; s->s_shrink->count_objects = super_cache_count; + s->s_shrink->to_text = super_cache_to_text; s->s_shrink->batch = 1024; s->s_shrink->private_data = s;