From patchwork Wed Nov 22 23:25:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kent Overstreet X-Patchwork-Id: 13465558 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 90BDBC61D97 for ; Wed, 22 Nov 2023 23:25:30 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 134716B05EB; Wed, 22 Nov 2023 18:25:30 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 06E136B05EC; Wed, 22 Nov 2023 18:25:29 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DB3FD6B05ED; Wed, 22 Nov 2023 18:25:29 -0500 (EST) 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 C16676B05EB for ; Wed, 22 Nov 2023 18:25:29 -0500 (EST) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 8956AC16DA for ; Wed, 22 Nov 2023 23:25:29 +0000 (UTC) X-FDA: 81487173978.22.7556182 Received: from out-178.mta0.migadu.com (out-178.mta0.migadu.com [91.218.175.178]) by imf06.hostedemail.com (Postfix) with ESMTP id C39D7180020 for ; Wed, 22 Nov 2023 23:25:27 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=OYAGGmY3; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf06.hostedemail.com: domain of kent.overstreet@linux.dev designates 91.218.175.178 as permitted sender) smtp.mailfrom=kent.overstreet@linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1700695527; a=rsa-sha256; cv=none; b=L114y/x7JttG0qT1tEkDCHoLibKmiw9rQTjbIjf8hdCOg7x9c//gFTUNmfUtnUvsuQekb/ wLxllQqLdvBTv4jD6HtF1CxM5Zi0n95SgaB1HEoPO0/bOt5FSSuFz9qoqBpmsgVN6vidBv K9EEW2wgGdOLJxEuoH3rV85q4snvbz8= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=OYAGGmY3; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf06.hostedemail.com: domain of kent.overstreet@linux.dev designates 91.218.175.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=1700695527; 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=YRuFFmQdC+GEPgfI4SIAkxSEqgU4CuzXncjpbXVOgmA=; b=aGasRzfOtr2qEwdpKdOvaZl8TfZV0mD0W0SP4jXu0255f+SNNZkNtuoxrzS6kKYlU+iW+7 Sx0lO1N64SwxrmVvUawbIlUk0TqTAuiOHQpjWCYUR+cwCdQ7J8xXpTer3hTMwKFrbq2nvH O2PvYD67fHl5HGzp6KjN2dwwiqzvxmk= 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=1700695526; 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=YRuFFmQdC+GEPgfI4SIAkxSEqgU4CuzXncjpbXVOgmA=; b=OYAGGmY34QArkmiHjXDebJ27PVWXyHMvnQZdKucHfTgjB1wcWYWZBFp8TmHRA8jCBIi8v4 yvW1Y2FRd872H0c4q3qoiHR5jVSk8jX1HncoAHfmzh1blP3uywzK+6Ze2zyzcQKJnohAOI ZqfJdF5DZ+e1jm6U7nga+mewJb4vhXs= From: Kent Overstreet To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Kent Overstreet Subject: [PATCH 1/7] seq_buf: seq_buf_human_readable_u64() Date: Wed, 22 Nov 2023 18:25:06 -0500 Message-ID: <20231122232515.177833-2-kent.overstreet@linux.dev> In-Reply-To: <20231122232515.177833-1-kent.overstreet@linux.dev> References: <20231122232515.177833-1-kent.overstreet@linux.dev> MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: C39D7180020 X-Stat-Signature: xobje7m9afx4xxwprdjgiedezk8ugonz X-HE-Tag: 1700695527-637798 X-HE-Meta: U2FsdGVkX19hBZfDoBn6FYstbfnEreZhwO//8TC2kJ9A/aql6hBAIceY9yC1BOkim2idwtppmbDLRUkPLr2xaKDuKae5bB+YC5Q3xxERktLq6B8ha4MFb8z6xJLkvFdBz/eEacrk7fs2abI1WNfSM1Em+N9n/wDRRswcyC1KrYDOLRrpVNPcXkQ1s5ji5TkQTkoQ7YI+F9jC1kPObPd7JQZnjucNJRcwT8SWwv6tD9BSUrHQlok2LVZ0fm34X8AU0Tn9gU83ijmUYT3AA5RbHF8HGP0TsqCsyQ1UgwVeuxgRumJzVMovEwTACIoNkWVcYmhBVwzZtW+G/N+pi1qOvdf33r1l+PP/EHp9cTsqVJn8EUuqRuSNjhTLjxL0ruWjh0qxDBA5CkoqcNcbLtlxY5kbTlGin8MZLtuWiPMH9Sb4AVhJ+1xEr2S5NQj98+3MIfE3rUeVQ/RdtDNN/zIV5SL2LBFn34y1NztUAnLYEvItZ3lEEQIiYXrUC7FM4IWH8Yz0JRvYWl9rE/ktsD09dVOJndVVU7G8BfFpdreoq5VtRFJd7c0m7e6eTes9D8MINj6OT8x1pO9ouXKtSjsmsO5mG/By6uglWawKEXYgObaR4CmhtoSC1sJs0cdKJiHIvGB1vhDRbAw2FydaCpfFrldyqpMBiCuctUibyX+ZpjGC2o1WD0XUp4EWp7Pnrae1JNz7SPIJ+ZP9dCztpORvujtKn0mzmSI7Ri98nuFxeEtDLQsARTV01kAScOtT2fl6BKoRgft1iwm88vJjtioQ8P1dZXuqL2uQ+vmno0zLSiXLi4KJ9Gr0q1iVzv/7LgyRn6gJanv0L8Qsx2sI/k/OcUBE3ER+BVpFF3y7L8GZ9WB5lojT1PQw0zFxFyegot5ECxgspzg0eRwdLLdICPUO3JzBEtcTobENXV9JeuPooYMm/6hNbxgqh9WTMw/h0gyyd9Uc2GrE/3kIxRCIDnN hYLHBTnd od+AtlUirc48mgowxWjckI3ZFFFT664syB4V2Wzc9oKoZF6w0nSxBSAA6vfs2zVSgEEhHBalP1aY7KnxsmRdNNtADuVMyjOvz4UEz88y5JSzY1kW4rIbi04yfNGCvuPxnwEVa 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 5fb1f12c33f9..dfcd0f367d6a 100644 --- a/include/linux/seq_buf.h +++ b/include/linux/seq_buf.h @@ -171,4 +171,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 010c730ca7fc..9d4e4d5f43b4 100644 --- a/lib/seq_buf.c +++ b/lib/seq_buf.c @@ -425,3 +425,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 Wed Nov 22 23:25:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kent Overstreet X-Patchwork-Id: 13465559 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 4EF15C61DA7 for ; Wed, 22 Nov 2023 23:25:32 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AF77B6B05EC; Wed, 22 Nov 2023 18:25:30 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id A801A6B05ED; Wed, 22 Nov 2023 18:25:30 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8F8A46B05EE; Wed, 22 Nov 2023 18:25:30 -0500 (EST) 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 771186B05EC for ; Wed, 22 Nov 2023 18:25:30 -0500 (EST) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 43D63160FC6 for ; Wed, 22 Nov 2023 23:25:30 +0000 (UTC) X-FDA: 81487174020.07.E1BC926 Received: from out-173.mta0.migadu.com (out-173.mta0.migadu.com [91.218.175.173]) by imf20.hostedemail.com (Postfix) with ESMTP id 7D2CA1C000C for ; Wed, 22 Nov 2023 23:25:28 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=RwDGCsBx; spf=pass (imf20.hostedemail.com: domain of kent.overstreet@linux.dev designates 91.218.175.173 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=1700695528; a=rsa-sha256; cv=none; b=3I8ScfTdV1QQ42AmYI+a7DBiti1qAJxEwboReUM56qIGdhcMWP6ymO+2v2RaRMkWm1Ij8y wS0AQGv8XKkCepisDAxh1DSMmeAVNbvao1T4UuLELJ/sjXlsQ+RNdaeNQsAqPdTomgzGdQ 8J9sA4vF53pg3vPU2wvDMXR/e0Ql4to= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=RwDGCsBx; spf=pass (imf20.hostedemail.com: domain of kent.overstreet@linux.dev designates 91.218.175.173 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=1700695528; 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=ce6mQdeWYA7JZiZSelXeyRte1bT790UpclDUySrWbbI=; b=47Rl9bGYvh3RVveyUdHlWpu+9lRsYTph4bL7RtD6pqCah9360Qa7K1s9V5Gs9XJGP8ue5T 13HN0mfBvVx4EHARHrcKghtTagh1AN/owNpzOvem5Bgt+69eq8BidaqdgM+JJtZwEW+Lxz RjhYRrQMo+gpcRl2qfyyfzZj5q0+O3s= 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=1700695527; 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=ce6mQdeWYA7JZiZSelXeyRte1bT790UpclDUySrWbbI=; b=RwDGCsBxUOAeC14xj7ENLjAvR8IPMtphog88OnO0JhzfsIcs+mraOc5OHgWapTIGcLSRsp Eu6N2oJ5sNyByGKgzowShHq/oDCtx/SHNWZszz3Jq5vB9+XfTDyzs5kpuj8NlrxAXhVCaG bk8karUNujFdsVJa4kR7ZHnGQ3NZheM= From: Kent Overstreet To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Kent Overstreet , Andrew Morton , Qi Zheng , Roman Gushchin Subject: [PATCH 2/7] mm: shrinker: Add a .to_text() method for shrinkers Date: Wed, 22 Nov 2023 18:25:07 -0500 Message-ID: <20231122232515.177833-3-kent.overstreet@linux.dev> In-Reply-To: <20231122232515.177833-1-kent.overstreet@linux.dev> References: <20231122232515.177833-1-kent.overstreet@linux.dev> MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 7D2CA1C000C X-Stat-Signature: gpcucxrj7cbm4rfxztrk7ddwfbrpx7g6 X-Rspam-User: X-HE-Tag: 1700695528-132450 X-HE-Meta: U2FsdGVkX1/9fX4jSuwrY/u1+Ya8wqtPAFSfuNVTlMJLWtUoyyxSnFEePb22/rc8OoXbghWAoGq5IHwEQc+jGJpkN3pCqVf1hoR9qk9FVmXiP78WKJEQxVB4T9XUkpMi6D5RD66UCKSjKrODOvvi1HiqNGssob8YowuIRe2cVSaJNIbURvS/rvrU3zg2XUZCu0z9bMJdlHuIAb/cJThIh9n0JDQDGDzeaiCbiBF1MDakWR/yH30hzrYIV2M6c0ghSDukeapAnbcz6Zpjdq/Y747Jynk4JcAmxfMQa9FgXFWzglb/poEZPnX32Htln1xUlZXzznoatZwGSh5NiRzdqMNekqgCuGvRxkd45TLOymLf9ke8UX2tHcV4fo8KTDIcm3iNay10u+l5SkqAW9nvKpSeSk3FEk0p99+jjyGQEqFV3rtrfnUomN5McO2dksICtHpi+qrD1PSe/jI7gfuYws0XJ22gqqqmxRysTC94ll7FbTWJonKfz89x5qWt+GlF+Lz+wqcqTAvGeFI01r/1tQu2WmMjrPN53GvxQY1YdqgpsYzpYGJviyF50kvg9Lcobx23RsUYLe9awy2esVlo0Fklj+tabEMbzjLudRhDu2G4+/rjLnayM0QU2xDHH5x5V0eqk0gd8HxkxmRIZXk0UvBFIx1Q75QxyIz123hjD1MHFVjIUD6RNNySFs7DIuIH5rYBzt4kl0riPthLn5i7Z9Roj/3eJPXT5jTcgi/geP3PTCrPuKJmPZZQFtv0YnSXu9M5BFVRjmn+eVusWb4bn1XkL1IiWXqfyN4kg7pgw19mz14sWy+YTu42Rsp/6ZdpYo3IYcOEegPC/3eV9ATMDARWEIkI0Oi9m4S3CKO2wC8eNqb9pv8XXMvfWpgH6E4pkS7PQd0ycoFwVXBTU9SgylhFsnK8F1dCjhuOjOQpDBjbACHlLNJK0RdzJ+dFKIs5KRXnjAukcA6GnDwZ7Gr V5S4SLha IZ6GhBmxrj4hvZGxWINH6EIFagDYqViQ2NQXPT4UigJHEenglBxboBAX3z6ffH3/huVzAFR3YCUWW3MwF5gRgOvxffFboZqLCXANm9Um6jD36LO6rjGw8sLMsLvjzDtIE0lOcGZgrPiMJf1E4uC0pIiBiU8PWvRjezvQquRcN7LBMSWnRYi3226xq/GCEkqIuJUFETnxocoBCwQvYlamgQhYo/GPVmtqx5hreKdpRlrn3c7QybAazYNWE6OrpixYw6rMj/FK0/k/f2eX7QKV/SMJl5VGosqHlHkI9gnUl2MtlszG7QqblI9wSBQ== 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 | 6 +++- mm/shrinker.c | 73 +++++++++++++++++++++++++++++++++++++++- 2 files changed, 77 insertions(+), 2 deletions(-) diff --git a/include/linux/shrinker.h b/include/linux/shrinker.h index 1a00be90d93a..968c55474e78 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,7 @@ __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 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 dd91eab43ed3..4976dbac4c83 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 Wed Nov 22 23:25:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kent Overstreet X-Patchwork-Id: 13465560 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 2C816C61D9C for ; Wed, 22 Nov 2023 23:25:34 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A82776B05ED; Wed, 22 Nov 2023 18:25:31 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id A0B326B05EF; Wed, 22 Nov 2023 18:25:31 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8833C6B05F0; Wed, 22 Nov 2023 18:25:31 -0500 (EST) 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 6F2AA6B05ED for ; Wed, 22 Nov 2023 18:25:31 -0500 (EST) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 51524B67C6 for ; Wed, 22 Nov 2023 23:25:31 +0000 (UTC) X-FDA: 81487174062.28.D5AF74E Received: from out-183.mta0.migadu.com (out-183.mta0.migadu.com [91.218.175.183]) by imf10.hostedemail.com (Postfix) with ESMTP id 7C486C000C for ; Wed, 22 Nov 2023 23:25:29 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=O6Wa1Pq7; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf10.hostedemail.com: domain of kent.overstreet@linux.dev designates 91.218.175.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=1700695529; 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=h7yT/gNa8WVPOQ61JKqXqNgHJRrqgXjHTIF9eRajh2g=; b=Shp7lUgc1980QqF3sbNXAkLeu0LOyvCqAvKspgOeTJN613dIXSwYVnQDE79ienAPCpU++3 MZmepqP7KswJvbF7DeWmrspf3B70FLeJlLrtlAbREt2+Tq10NmDbcOqMWIbJ7igFaO6CJa kjL0psrildW7IG0YCANhSzRmUy7qFik= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=O6Wa1Pq7; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf10.hostedemail.com: domain of kent.overstreet@linux.dev designates 91.218.175.183 as permitted sender) smtp.mailfrom=kent.overstreet@linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1700695529; a=rsa-sha256; cv=none; b=krBWCKa5i8AX99Et9qbnJ8KpV+vAQAOUeFk8GEdubLo6S3zPqAfjnJZ9/+iUvNIQ4laNw4 4syQ2RqM2MlWSwx8fvwTEc71osw/fd3p8CT0iMDd6RFSh9sM/9mUMqmemNakwxRTEeeyRX OqUSbzhefkanXSAlE+Sw4GNA3pw7iSI= 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=1700695528; 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=h7yT/gNa8WVPOQ61JKqXqNgHJRrqgXjHTIF9eRajh2g=; b=O6Wa1Pq7Futp9HUKsVGvdg+Z5w+n3MO/N9v0rDnM9VMU80eqJlKtDs5MCdlB/RLuq3zB75 DFQ+Bbi5//mR819xx4Wrz6FRF25hy8ONIL+PG+xyufurdr4QS6+jDEsypsEnexxM7IRVd+ TH/mv9J3tjkNle2GRCxH+jXEE/7wAlg= From: Kent Overstreet To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Kent Overstreet , Andrew Morton , Qi Zheng , Roman Gushchin Subject: [PATCH 3/7] mm: shrinker: Add new stats for .to_text() Date: Wed, 22 Nov 2023 18:25:08 -0500 Message-ID: <20231122232515.177833-4-kent.overstreet@linux.dev> In-Reply-To: <20231122232515.177833-1-kent.overstreet@linux.dev> References: <20231122232515.177833-1-kent.overstreet@linux.dev> MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Rspamd-Queue-Id: 7C486C000C X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: roaopzjxnympwhqyh66xomazhs4ewjo8 X-HE-Tag: 1700695529-794396 X-HE-Meta: U2FsdGVkX1+PtTeiwZqwWz4UjMDYY+amIxXTvooE+0a3IvLCtHxkMlIqBZ7r3//NhF6AcIAesXcoAes3ZZZ/od578YDC8TJILB6A14o6bSrM8aeeELWJ03oeoGpiraaT6iNbTn3p+9m/5AT5DU+gE6PrlAbcHUj0R4pWUSnCQ2VLr5THPtar231gkwjLFP/lwZz47JQkwsFohs/6jOkmESjdyfUJvXHr+Pl2HfJyLD4TddCrclq1AVNoi08Aee4FRNErCkQp2aHd3wvGJ3knSlnjZFivQfiZnqcXx4/iE4TAMJzIQDPeZymmfllDOMzVkAXHniB6iUB2ifyYQN0L2e4alhuCoS6FF8Y5XqF520azPnNHqMLZF3k15ebCHKLrcdWSvOMh0pfUbuQp1e/hwwYrlmKXJP1uUv2+hTRPiovlLUsucHAB+zAGBg4Q6NycUaRkdRnyriMEKa8TBdXI0P9eFiJ3hCnQD6JdWCDOccnX8Lc0ITnR34JGwVb1cIhvwOFDH6TVSWY6GAAMw7SXcJcDhtocrMEWWkb4cPI6/Lrhqu+5Jn085NYErOHcsKVARW3229nBkMEUCye69it/5QUESTzggeaN4gFCfW+QmxkAyPxCsIsVrY31XRHCERCHHutY2A038m7RFfAun5Cbow1oIXI8BFoQaWMn8aeXh3X/v9lSrq9FQ7xFroyb6PWeElv4KixnSuRQ12PJriaNBVlJ3WpwNV+7E4Y2JX3VWvoKJzzFSu8nK8GvTLGAck+t6AGSRiNsZOZX0gMTmvB+pHTQH4Vjqmq9jb6kxDuc8CX671s87FqueUm0iUnDb4gL9iM0IYTa6k6s6wCXq5/qKqpH+GmG5Kp2PggAuTtVZMOLCoTzeOL4ZcmtSnc2sRtytCz+Rie7IKGMsCokGPWn0Sa043mJR+wTb2Yfx9pLmAUMuvdgzMww2bJ4SvWQoP2stunQvzQmuOpqxHmut4C W0V+5c8r tcfDqNgcOf4zwj/XZfVadVUq7iN5IEePdBmhO8+rUlusfmrnE8/KduLbUg+kqBRcXGeKpu07vzq9+m0H5t3PoARIn4At0KbiXZd/xXSQK2Ln6EfTVtXjWLuzVG69qk37YCiJzgQhee97ND2Ilaqt1cYb4efbeTd5aso/Uqm7UHSyY1XmkmBZxAS1cvcaqzuqfVOwiNVXe7y6YsNIyxiV5flGpEOCgw6ChYeb1k+tG/fp5GdPm5kMgSQ6dLCU2uA4cwvUDuvVaSPZi0MPNStNinQgr8+zRFs80IZRqgVz75wTMZV8= 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 | 5 +++++ mm/shrinker.c | 18 +++++++++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/include/linux/shrinker.h b/include/linux/shrinker.h index 968c55474e78..497a7e8e348c 100644 --- a/include/linux/shrinker.h +++ b/include/linux/shrinker.h @@ -118,6 +118,11 @@ 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; + atomic_long_t last_freed; + 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 4976dbac4c83..acfc3f92f552 100644 --- a/mm/shrinker.c +++ b/mm/shrinker.c @@ -430,13 +430,20 @@ 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; + atomic_long_add(ret, &shrinker->objects_freed); + atomic_long_set(&shrinker->last_freed, ret); count_vm_events(SLABS_SCANNED, shrinkctl->nr_scanned); total_scan -= shrinkctl->nr_scanned; @@ -812,9 +819,18 @@ 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", shrinker->count_objects(shrinker, &sc)); + seq_buf_printf(out, "requested to free: %lu", atomic_long_read(&shrinker->objects_requested_to_free)); + seq_buf_printf(out, "objects freed: %lu", nr_freed); + seq_buf_printf(out, "last freed: %lu", atomic_long_read(&shrinker->last_freed)); + seq_buf_printf(out, "ns per object freed: %llu", nr_freed + ? div64_ul(atomic64_read(&shrinker->ns_run), nr_freed) + : 0); if (shrinker->to_text) { shrinker->to_text(out, shrinker); From patchwork Wed Nov 22 23:25:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kent Overstreet X-Patchwork-Id: 13465561 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 D64D2C61D97 for ; Wed, 22 Nov 2023 23:25:35 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A5B186B05EF; Wed, 22 Nov 2023 18:25:32 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 921256B05F0; Wed, 22 Nov 2023 18:25:32 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 775FE6B05F1; Wed, 22 Nov 2023 18:25:32 -0500 (EST) 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 607026B05EF for ; Wed, 22 Nov 2023 18:25:32 -0500 (EST) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 39189A0F08 for ; Wed, 22 Nov 2023 23:25:32 +0000 (UTC) X-FDA: 81487174104.22.3F3C234 Received: from out-181.mta0.migadu.com (out-181.mta0.migadu.com [91.218.175.181]) by imf08.hostedemail.com (Postfix) with ESMTP id 7B4AF16000D for ; Wed, 22 Nov 2023 23:25:30 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=KVh3wxKI; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf08.hostedemail.com: domain of kent.overstreet@linux.dev designates 91.218.175.181 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=1700695530; 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=RfcqUFguaDDZw+gf+d0LSy3BejslhVkAhwRYXLWAYww=; b=F6usg9crMoms9NCeB4jh97iOG1LS6bbBXJWTkvnn1J5DamChIyvNJptD1RCb2/cpBjMkpT koamTDfdJX65RdHo3l68xcm8l2XIQpW+vSph1+huEKBT4fglr/e4gpPxXFlTsk5SW8ZlCJ oIN0nbXxFua2JgV27ReRYk/sP3C5WzI= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=KVh3wxKI; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf08.hostedemail.com: domain of kent.overstreet@linux.dev designates 91.218.175.181 as permitted sender) smtp.mailfrom=kent.overstreet@linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1700695530; a=rsa-sha256; cv=none; b=1s1ljvtmlMetb9BehLskd3YYFGSNEKgL59LZmYk+fe8yKYfDQ/MWfiBDHZvRWkuy5S+X0C seVnntWWzorA6mmjc5syBP3/m9zy+Bl4T+ruvOMDfuoDC6X7peWkRCMIXnz3zujwHBMUAo gAg2voRdoRpdPhUG1mx4mpvXr7ButD4= 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=1700695529; 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=RfcqUFguaDDZw+gf+d0LSy3BejslhVkAhwRYXLWAYww=; b=KVh3wxKIo4UY3M0nKsfWud9MNgWoL2E3pERfHvOTCAkXnvsURoSqAEjUmPalhXUSNLrOps qL0Vq27zCcEV27nYL27phxtsnLF4sUXNJKSd1c90XA5LM5BNTphc9LQscyej8ZjxlFAQtj zdogso5LeCN9DCAJz2BtPcz5+k96adw= From: Kent Overstreet To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Kent Overstreet , Andrew Morton , Qi Zheng , Roman Gushchin Subject: [PATCH 4/7] mm: Centralize & improve oom reporting in show_mem.c Date: Wed, 22 Nov 2023 18:25:09 -0500 Message-ID: <20231122232515.177833-5-kent.overstreet@linux.dev> In-Reply-To: <20231122232515.177833-1-kent.overstreet@linux.dev> References: <20231122232515.177833-1-kent.overstreet@linux.dev> MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 7B4AF16000D X-Stat-Signature: 58kfu7fuhpxpp9aqga8ge53timywyb3f X-HE-Tag: 1700695530-288587 X-HE-Meta: U2FsdGVkX18LIohezR+NXkXHZB2tVFmrGdqJ0oFPBw5xbAPvrWxKzFUzRRd+oPy4bNU7h9jvgY1dahMgHs+e972NzgfwPXChSnBFoLt6exIdJ0tY2QGk5jOPdqgKWmpBhU16UaHmj6wbgDBMwn71CxQo4rc6xlzoXPxGn7XSPQo/YGsHP5b72LJ61fkJZKeLYb243KOkf76pMn4UE2sfex8MHOTSikvS3fR5C+kHQ+fdMVJNhx4qqQha8/iZ2ooGmcLsd/NxoFuhpzCDM+9YDEgptrFsatFAcctY2+y3pZ5oKjAj87nnX0qj6T/ywOHHH4QMHGU6MuiJNQIhP7AtHWv3CSCiQ6bRqpAFPgpRTXEOlXnUmZTjEa5c3WGbbeMifpr++uSZiMmO+iaDCt5OCM+znfrZ74Odl9Q0dj0dktfxeyjOVZOtHRC13+IJ9dLf/EEEA5jqpLHi/31sp14Gvz9xt4u+iEUil3KBLig3dkbMBo99p6QQMXB9OczZCya2NxeZJ042sHmBX4lpz0ud5P/ven6wS3ngLGIc6lAdW0qECh8KOJs/6SmoN+SJMJV0RdWkjC8BsESovEsXjlyNuSHaqtfIArdXxhiLsymYvZmoOJUxyg8Liwxk6+vcS7+1Mvz2pTiStada/atRTe33eV0qP8/t5CmTyM5EY11xKvM3TwQ2zr+b5WZ7QKVgRO4p4MNyDgsdF5F8umzUMKKh+jfb+tvXyDxWf3Mp2j/rA7dEGZqtfzpfOgGPinUJ2hxzbIhE/Zpv2w2iGLytcrVaFKJb9NIk9v7pzQpf/Od3px8yetG/Dp5GYIuSb0aTwQ2Zz3WJkfpbg1tBn6wl7w7Hw3xdonTqzIXJ+k+zxda1PX5lvWuS0VVwpkuGH8I7koXiXWaBv8nd4JaUX2SEfPLBlYND1xLFtS1pDKqecrLWksVNAttCRpmjAGFQVuBgB+enJncElAH/q+E+owqLuON 0nDQQD7o ZSPD+dG7t8y3ncTA3xP3Ge8RxgED6qaHbqJXCtHhoNOaxpdZQ5+3M1A4q9jn5AMhdvqh6f5zEuaN7YuBwmrXNbYgCl2qy5N5AdXaXBcCHp7HUWG8+qxVdeiiQh3NuzskjnHGEwUqQCTBIGzwYKOj01zv40EL3jirJ5W84KVJ9ZeHNpDPbyItxAdPqgZtLdEVrLElQ0/vm6fD5/1BMmttQrTRzNmBmWKnItH2vIuRdNIPgcg6zI5/QNd9f1MgZdb0yviD62ZHwQraCiQh2E+WMVddAN1otlYCu0z6VOhrEMIqUcUJdjgxh6WinTg== 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 | 20 +++++++++++++++++++ mm/slab.h | 6 ++++-- mm/slab_common.c | 52 +++++++++++++++++++++++++++++++++++++++--------- 4 files changed, 67 insertions(+), 34 deletions(-) diff --git a/mm/oom_kill.c b/mm/oom_kill.c index 9e6071fde34a..4b825a2b353f 100644 --- a/mm/oom_kill.c +++ b/mm/oom_kill.c @@ -168,27 +168,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 @@ -462,8 +441,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 ba0808d6917f..ab258ab1161c 100644 --- a/mm/show_mem.c +++ b/mm/show_mem.c @@ -12,10 +12,12 @@ #include #include #include +#include #include #include #include "internal.h" +#include "slab.h" #include "swap.h" atomic_long_t _totalram_pages __read_mostly; @@ -401,6 +403,7 @@ 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); @@ -423,4 +426,21 @@ void __show_mem(unsigned int filter, nodemask_t *nodemask, int max_zone_idx) #ifdef CONFIG_MEMORY_FAILURE printk("%lu pages hwpoisoned\n", atomic_long_read(&num_poisoned_pages)); #endif + + buf = kmalloc(4096, GFP_ATOMIC); + if (buf) { + struct seq_buf s; + + printk("Unreclaimable slab info:\n"); + seq_buf_init(&s, buf, 4096); + dump_unreclaimable_slab(&s); + printk("%s", seq_buf_str(&s)); + + printk("Shrinkers:\n"); + seq_buf_init(&s, buf, 4096); + shrinkers_to_text(&s); + printk("%s", seq_buf_str(&s)); + + kfree(buf); + } } diff --git a/mm/slab.h b/mm/slab.h index 3d07fb428393..c16358a8424c 100644 --- a/mm/slab.h +++ b/mm/slab.h @@ -818,10 +818,12 @@ static inline struct kmem_cache_node *get_node(struct kmem_cache *s, int node) if ((__n = get_node(__s, __node))) +struct seq_buf; + #if defined(CONFIG_SLAB) || defined(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 8d431193c273..1eadff512422 100644 --- a/mm/slab_common.c +++ b/mm/slab_common.c @@ -26,6 +26,7 @@ #include #include #include +#include #include #include "internal.h" @@ -1295,10 +1296,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 @@ -1308,24 +1314,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 Wed Nov 22 23:25:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kent Overstreet X-Patchwork-Id: 13465562 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 6CC75C61D9C for ; Wed, 22 Nov 2023 23:25:38 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 275206B05F0; Wed, 22 Nov 2023 18:25:33 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 1F7156B05F1; Wed, 22 Nov 2023 18:25:33 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EECE56B05F2; Wed, 22 Nov 2023 18:25:32 -0500 (EST) 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 D7CA86B05F0 for ; Wed, 22 Nov 2023 18:25:32 -0500 (EST) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id A6D2B12095E for ; Wed, 22 Nov 2023 23:25:32 +0000 (UTC) X-FDA: 81487174104.23.77950BF Received: from out-174.mta0.migadu.com (out-174.mta0.migadu.com [91.218.175.174]) by imf13.hostedemail.com (Postfix) with ESMTP id 0937B2000F for ; Wed, 22 Nov 2023 23:25:30 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=BHd1Y+nn; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf13.hostedemail.com: domain of kent.overstreet@linux.dev designates 91.218.175.174 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=1700695531; 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=hhFyhh1rGVdN8KU7zA1YO/xWC9r61TLiUr+vYD/9YWg=; b=w4uheNnnZRxyBNYyl2ETPya6ooqTPOaFfR+7axZSRZxaJj0Gr/mXZ+g/dbh3BdaACCJB6I hDabmYjn5H2XCxBKHoM6fjC4wWGKC+HCR3wBkVvMwlls0OhBnRceD9KZpgelnK7N3aRO60 j5GpY75jsJwIa2zsz8qbhNgT0tkvvV0= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=BHd1Y+nn; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf13.hostedemail.com: domain of kent.overstreet@linux.dev designates 91.218.175.174 as permitted sender) smtp.mailfrom=kent.overstreet@linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1700695531; a=rsa-sha256; cv=none; b=CBAS1dLgZs1/J5wd2nqB7YN/LB1lD2yPrKgB+kGmhFRfd4KVCkTQvVR6Z8cbbGl6eaOrZ+ c6rKOMRD0SDMGZV/Qr6GLQ2AUxP7WFOl1xVmnv3Y55Bb6y87t70x+qoe4hREg4o0k4xSR6 ScOvUmUOiP6piFZwOfgxv29AlqqXmVw= 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=1700695529; 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=hhFyhh1rGVdN8KU7zA1YO/xWC9r61TLiUr+vYD/9YWg=; b=BHd1Y+nn87jfgs0JPV5W9mQnj/jbSljivlaWBWB01hjhj/kWczcqBvz5Z6L0HpvjZCtsmd /dVQdVskpae/TXe1lhJkyqwhQBEja9RxyeQj/qFWuwDRlz1zUC1oNymeFeLzQPPjOqHaw5 +p/p0qYljzIyMnmljGtQZZIcQd8+3JE= From: Kent Overstreet To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Kent Overstreet Subject: [PATCH 5/7] mm: shrinker: Add shrinker_to_text() to debugfs interface Date: Wed, 22 Nov 2023 18:25:10 -0500 Message-ID: <20231122232515.177833-6-kent.overstreet@linux.dev> In-Reply-To: <20231122232515.177833-1-kent.overstreet@linux.dev> References: <20231122232515.177833-1-kent.overstreet@linux.dev> MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 0937B2000F X-Stat-Signature: wiceznx85tp9aqnyhpssqpt7bn4nbxu3 X-Rspam-User: X-HE-Tag: 1700695530-626814 X-HE-Meta: U2FsdGVkX18bzcxfMw/PAMGmNkq7kk8IdYTSDGPlseO5UC4J5xRAjgsNzqgIFK25dsvmAn04SxOqeTRKdvZ202rDHQ5KcEp1bOzPXUouxRhzNHpGhneewze7xErw+H+zxuESdJW78iXRSvNas8V9Ej5Eept0yzfoNMl94oCiAnHAjKPJkjNaRDCOCaf6r6NZvji8lAT/6NNpJ0bFRCODIAkSHBw2O3t3FBAa6rMcdKbUUWa/ISuTFiRXMTdudvKSuvBsYU4CcNUlLyDbm+6/F/MHbs3iyzargT7cyJrwJS0qTJ+0W/pfC8z1FdHoOOf3Q7CLaIGN+Zy2r95zMM+V0FyJMk1ar9F51yPhYNbX9IPTOw5jyyJq6RkNqCYswP8Ce/vb0a2x0RHLyV5bxeiVSm3blujxBoAn3764l8lZFM0crpcIiE8QXKSCmONwgNxk971og7XSobyMmhivzIFhyl0k97OjtaHZRaKE87Ros33eKsTs5mIR1Esv5PssEOIwYYmrvWzh04r47Yx5K3yOP9j9i3D3yHgwNEJJL3OhEE7ld4WthKblLuxdFN+UTJU7EsEWwkvlDtoxBzXiC7HYEIGiO0tKPiwD8ykiLc0g69F7QYynQw5eh/znxBqqM/7clEfrf6m70Sy4NEaRSHuOa3wr3OfJlqLVCaCYhkTC1F+lNQ1EC6gHOeejEXmB1tWYo/FLe2AIng4vBhDjAS7qDrXyLTYMp+IiI8tnwsUs8bvJoVFgdbVDqiA4ZV2A0uIV7HvkERiUVTDktvfI8vJkHy5Wd7EgfWdMBH7l+gVg5I1oz1IKUaIFr3swRgpDoXqpGkJ89ibSdOu9NTqDKBTQzxj/75QyCC0bMISmrLkCgkDmGLF7ga3CZ29KK4LlbURvr0YHuUGaxSeOu7We/6Gz5aSHdULtfVYKkC7ee1ZsDgbYztIpay9Vtt8I9ghcGLDkz1ALorkrHNhjCPIosgd re7C2bhN C6cf3pYzNqW3LO3tSl2iUI2AJ9PTOjt8ZtxT3cl/mB12UpEhn/bHnaYkRelA34EMOuEmdYvZu5hIntOgRFWUnvb5oqRfuypU6SIYDGc7tBncPg2xhF4kfMZqOubCxmsSlYLIn 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 --- include/linux/shrinker.h | 1 + mm/shrinker_debug.c | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/include/linux/shrinker.h b/include/linux/shrinker.h index 497a7e8e348c..b8e57afabbcc 100644 --- a/include/linux/shrinker.h +++ b/include/linux/shrinker.h @@ -143,6 +143,7 @@ __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_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 Wed Nov 22 23:25:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kent Overstreet X-Patchwork-Id: 13465563 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 D1815C27C40 for ; Wed, 22 Nov 2023 23:25:40 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A866C6B05F1; Wed, 22 Nov 2023 18:25:33 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id A0AEF6B05F2; Wed, 22 Nov 2023 18:25:33 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8859C6B05F3; Wed, 22 Nov 2023 18:25:33 -0500 (EST) 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 6C71F6B05F1 for ; Wed, 22 Nov 2023 18:25:33 -0500 (EST) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 5602BA14E2 for ; Wed, 22 Nov 2023 23:25:33 +0000 (UTC) X-FDA: 81487174146.17.0234F79 Received: from out-181.mta0.migadu.com (out-181.mta0.migadu.com [91.218.175.181]) by imf06.hostedemail.com (Postfix) with ESMTP id AC71C180014 for ; Wed, 22 Nov 2023 23:25:31 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b="o3CvX/g1"; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf06.hostedemail.com: domain of kent.overstreet@linux.dev designates 91.218.175.181 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=1700695531; 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=+xIe2DoE21qrt9LSNcAUwIwIwHsNrxaH9AQLMP04McM=; b=f1FLHNUn8Yb8frSzo1T6e2bedUw8RbHtBdgCpIahmy/A9akkstbfcRQQ68i/vXb9/v93yr gjeq8dgG2kwVEUhFhFFtIxDHw1t+6SsnlKUF7dGRXkl5YynV6Pv1EmLaczfUuOxbe6zG6D 5KpHD7VP4KNQiVrtbgMbhKCkJ09DFyM= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b="o3CvX/g1"; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf06.hostedemail.com: domain of kent.overstreet@linux.dev designates 91.218.175.181 as permitted sender) smtp.mailfrom=kent.overstreet@linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1700695531; a=rsa-sha256; cv=none; b=LkbCn09+laLh0VnLSWVtrM88qnraPfgmIkH6L39njpkA9wMv/eucDPrXNH2ZAySU82xiqx dTMLgSZf1cbpkz26V+Noy1WS85qU23Wizevj12rZaxksR073qooBSr0EyRcCzvONgRn6lm 7l3XjBepV+0L89+8m5TJGboXWlL/5Ao= 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=1700695530; 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=+xIe2DoE21qrt9LSNcAUwIwIwHsNrxaH9AQLMP04McM=; b=o3CvX/g1Mo37OAG87L/6Vu3aVXW2glLs+ZCCGUrP4H0SA8cPtcuDyYy22kVuLNkWtpIA9Q /HbvDCodA7ny8mu2ew1QagbLzcTglJHQRpbARFoW4RvMBKCAQNlLos+/qEMrNpU12NLKky vaSlk3dtsvcNkFHaJ0XGnT1dL407Frk= From: Kent Overstreet To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Kent Overstreet Subject: [PATCH 6/7] bcachefs: shrinker.to_text() methods Date: Wed, 22 Nov 2023 18:25:11 -0500 Message-ID: <20231122232515.177833-7-kent.overstreet@linux.dev> In-Reply-To: <20231122232515.177833-1-kent.overstreet@linux.dev> References: <20231122232515.177833-1-kent.overstreet@linux.dev> MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: AC71C180014 X-Stat-Signature: rjide6f7xz4xn538pbje6ciz4wweftnx X-HE-Tag: 1700695531-749832 X-HE-Meta: U2FsdGVkX1/l4+hqlGebh9zVmftH23YLjoDxR9PQrrp8Qt4FInyJmy56YdYCvVnC/Ps1eiHmPkm2WqHlHZfrQllto6q0mYSFozoQwTEDDdHxjDQ0kZxiYwlhlVFvuRyBdDYXQXWVJFamPH0UioaGN2FR6m4rvCJDTCCX60z/qNGZcdcI6xu0K6g23w13/sDII4LRlRxxL7YmFJRTrff9qzMzjM+1tlXOHsvGhL1MCWJc09CArVCNQG2auAQkn51nJ0+6wGPYnWlb6K/Dk9a7/7eHpqDK9OukVFgpO5Rs1jp79X7apOXyd613nTmccyTJ48zvV4O8Xa+vRPVsdeK9c6mPL/hJLQHBC1IyS4qiWkmeU4mTHF0N7EJd8dHyKQSaNN4VKD7cW3mPRmtcHmuzWGyvzjTqCGDsLhFJdCMRw3fG7kh6fG3d4QvFSK9wdxoVC66ncKmz13aVzd8T5mT1PAab9YDCpiCB6Oacyesjc+OFMj/ZnBO6oF40Z/38nfAt5T6PwfGPSk/DCij5SWSmXLyhMUwk1GXzi6MZuaP+kGQ62vrCgkUM0tYpGZTYZbz7do5V555NrgbLWNjJIU9V+/n691gH8iCwS+ui6Me42/9cNpsSZsJdk1FnCBGGAVjADoMKoivCsKuuPqq8d6MKS5FenDlaYh7vFPB+GqPHAOPfoouwmq/uhX4rmf/mkbCwDStQf7qJ0h51HOnovF1XWpa4HYxrDQYknqlVJDKiIC8fxFR48qf0HhaJzFZGTOTwFkHcvncek6qYaKFEa/ZILqBjgmbFsfWbB6HOk8sqbzAIThtfOD41LRhDYqbmyMUUC5G/cr5rUYCCmBD7MAvJ8U210R5MKLqof2Eh5yTti9XiOVVrN0/TCzpPEA5fJVOivJ6o58PxvnMDJ9kI6xAJVUjP6fUpDJidLfXQuq170XpsZUr7UJxqSYlz6rDsSMrzTFhz+EOqRrp7H5gXR8T QBjzawWy rOHjGjdv94R0yLeVT8G94lTx2gNBOpQlpAhVKY23uOkGPobQQOZcQecdCKfV7fPxc1aRSc/rWUm4cI8Ftk4wwXi1epFoaRHZDnR5nkTQaFjP2kP4JecfZ5631vKlB9D6WmnFA 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 47e7770d0583..aab279dff944 100644 --- a/fs/bcachefs/btree_cache.c +++ b/fs/bcachefs/btree_cache.c @@ -13,6 +13,7 @@ #include #include +#include const char * const bch2_btree_node_flags[] = { #define x(f) #f, @@ -392,6 +393,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); + seq_buf_commit(s, out.pos); +} + void bch2_fs_btree_cache_exit(struct bch_fs *c) { struct btree_cache *bc = &c->btree_cache; @@ -478,6 +490,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 4402cf068c56..e14e9b4cd029 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) { @@ -1028,6 +1029,18 @@ void bch2_fs_btree_key_cache_init_early(struct btree_key_cache *c) INIT_LIST_HEAD(&c->freed_nonpcpu); } +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); @@ -1051,6 +1064,7 @@ int bch2_fs_btree_key_cache_init(struct btree_key_cache *bc) shrink->seeks = 0; 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->private_data = c; shrinker_register(shrink); return 0; From patchwork Wed Nov 22 23:25:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kent Overstreet X-Patchwork-Id: 13465564 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 22691C61D97 for ; Wed, 22 Nov 2023 23:25:43 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A0DAE6B05F3; Wed, 22 Nov 2023 18:25:34 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 96FFD6B05F6; Wed, 22 Nov 2023 18:25:34 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 774C96B05F8; Wed, 22 Nov 2023 18:25:34 -0500 (EST) 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 5F2B96B05F3 for ; Wed, 22 Nov 2023 18:25:34 -0500 (EST) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 37ABBC16DA for ; Wed, 22 Nov 2023 23:25:34 +0000 (UTC) X-FDA: 81487174188.05.93E6DD6 Received: from out-187.mta0.migadu.com (out-187.mta0.migadu.com [91.218.175.187]) by imf29.hostedemail.com (Postfix) with ESMTP id 6B613120019 for ; Wed, 22 Nov 2023 23:25:32 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b="L/6Ssih/"; spf=pass (imf29.hostedemail.com: domain of kent.overstreet@linux.dev designates 91.218.175.187 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=1700695532; 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=1NMfXBsonhz+ezAg3sKaNXQeyap2g8yZZq48bhQ7Wec=; b=M9LC4I0mlHEq8ERhyqeIyIMhOZrJhpWaCDqYn8K1yy+s9l4leUsl/tA2yum8xZfLQY1PBf NMSQDV9FFrRoyIC8zQc+Mw8a/hMkR6wA0lRB0Kg0guHhlM5pp8EbQkNV82Q7aD5Yb6PILE 5E7czxVtFk+dtO33WZ6vbZzZzINsFjU= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1700695532; a=rsa-sha256; cv=none; b=NbtZ/UugSvR004T0JmUZCY/bYna+97sPOtccxO2CrwUvktDgB8y09RBWrNLAmYouRD1FUi AKvEA46sdcxAgnXhctdYb/PNAa480IZs7/IWz2pI3glsZtMTZPF1HwzefQsIF1hjRse4d9 30YoEB/PZDbjNPu4fKqUSyqESuJMqSk= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b="L/6Ssih/"; spf=pass (imf29.hostedemail.com: domain of kent.overstreet@linux.dev designates 91.218.175.187 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=1700695531; 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=1NMfXBsonhz+ezAg3sKaNXQeyap2g8yZZq48bhQ7Wec=; b=L/6Ssih/O7QhT9069T31VThCTNukc3MMvLU+/VMAZ3jnXRJbm6rGc+TMETY0offdQtngVp 6jDxcKMISPFQdNLC7MDtwdDuraODTV+7GC8ozeT/P6g2dMkS3qcUJPEzMFbmowqy23RWPc TvwAmvR6OWymxacMWlUCPuncKjfbn0Y= From: Kent Overstreet To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Daniel Hill , Kent Overstreet Subject: [PATCH 7/7] bcachefs: add counters for failed shrinker reclaim Date: Wed, 22 Nov 2023 18:25:12 -0500 Message-ID: <20231122232515.177833-8-kent.overstreet@linux.dev> In-Reply-To: <20231122232515.177833-1-kent.overstreet@linux.dev> References: <20231122232515.177833-1-kent.overstreet@linux.dev> MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Rspamd-Queue-Id: 6B613120019 X-Rspam-User: X-Stat-Signature: b44pgfjmpesg7hn4szdu9citndqcwj9p X-Rspamd-Server: rspam03 X-HE-Tag: 1700695532-759344 X-HE-Meta: U2FsdGVkX1+ttRMmsBarg1bHgh4PQnsCnTqLTCHjhOXj0dCMHfFovuaZy2KXw/eAhf+3oxYj3mRXLZgb2DxedJkI0ieiRwvhIrfxj69lbrYh6dONzBsKKwKBMQxaMKvAfvsuSgxi4NNNURUmKGcq1gSvhgXBrq3pHHFvXQEgDUpwAvArXgsBcELB7Gae27uzNuH+TpfUZSu1ReOV+VPuiYMFTnHFTMHXSMyg8MAJgTxCzx7r3y0CvAd75VTrhJFzVMrv6rJx9EZFphUnC+3SwDeVGeAvuHrrdOv09585QA5n8U3q0Wz3y9Nv/qrthjncSX9EfOtGjAJvXkb1FQ8rGkhScTzunj5lejZjPW8VLfK5eYZiBcwhxekm220+6Q352b9H61oW/EuPoS3QlPpfIvyW3sCQ30xsOPR2oAKZxcSbUmSMnI0bPtbXmZBHfuMN46QM4xF2PbDd1N0oqJFyJvxxzNrkututsPSevtNw9z4gW0tn//JMg0+SqJ0M5goWkyIpEx3VVXrqZ3K5Fx3cjsAjft2SHbm1JJFRF9/i9ijvnCNuW25WStLEk2WTds+6G9l29zGPC9J7wqjabyiL3Xqqcc4eanBnzEZbkONIyvxGoXe6eGxcB2qCpTnTjvXx4fq7ZvsJ1555PF9LKPUN96KnNcVvmrBP/SK/txHwr+WkxpMdJapT/rCYO57b5H+9zWcDXjnywS8JiWZIzGGTAbFg8+Ooi9Byt6uqPwxXAFrF9LvEASGbQIzvf+38GN6N3IDXCmTiwwvQ0/BBudK58Pzr28UwYBnL0DUeqb+Ic2LH7/XlObq8vATzTJRNq1CIrDvwXaXOCxFXb6R+ZX1T5kHPTyccW7holBgYnv+fNzjd5GX1iTOQ+QgohTxZlkzy0Yi+fhkM5SrBkCPvMZ+cg6N+p6pPz7KSK6djc5CnGcW56x419bDpFy0W/77TV1Ea194Yf9hUsnCv3i7DpDR 1LNmthKR 4sPgLx13Tz3njJPPfg6qNyHnLFQ1qD63j3/f6lsLedzZji5/JOXAEVn9+hWADbTYdTzv4NIP8NOgu3H4YglOdxs7v2bhpYZ2Qf6toEfBBv52rlCw= 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: From: Daniel Hill This adds distinct counters for every reason the btree node shrinker can fail to free an object - if our shrinker isn't making progress, this will tell us why. Signed-off-by: Daniel Hill Signed-off-by: Kent Overstreet --- fs/bcachefs/btree_cache.c | 91 +++++++++++++++++++++++++++++---------- fs/bcachefs/btree_cache.h | 2 +- fs/bcachefs/btree_types.h | 10 +++++ fs/bcachefs/sysfs.c | 2 +- 4 files changed, 81 insertions(+), 24 deletions(-) diff --git a/fs/bcachefs/btree_cache.c b/fs/bcachefs/btree_cache.c index aab279dff944..72dea90e12fa 100644 --- a/fs/bcachefs/btree_cache.c +++ b/fs/bcachefs/btree_cache.c @@ -15,6 +15,12 @@ #include #include +#define BTREE_CACHE_NOT_FREED_INCREMENT(counter) \ +do { \ + if (shrinker_counter) \ + bc->not_freed_##counter++; \ +} while (0) + const char * const bch2_btree_node_flags[] = { #define x(f) #f, BTREE_FLAGS() @@ -202,7 +208,7 @@ static inline struct btree *btree_cache_find(struct btree_cache *bc, * this version is for btree nodes that have already been freed (we're not * reaping a real btree node) */ -static int __btree_node_reclaim(struct bch_fs *c, struct btree *b, bool flush) +static int __btree_node_reclaim(struct bch_fs *c, struct btree *b, bool flush, bool shrinker_counter) { struct btree_cache *bc = &c->btree_cache; int ret = 0; @@ -212,38 +218,64 @@ static int __btree_node_reclaim(struct bch_fs *c, struct btree *b, bool flush) if (b->flags & ((1U << BTREE_NODE_dirty)| (1U << BTREE_NODE_read_in_flight)| (1U << BTREE_NODE_write_in_flight))) { - if (!flush) + if (!flush) { + if (btree_node_dirty(b)) + BTREE_CACHE_NOT_FREED_INCREMENT(dirty); + else if (btree_node_read_in_flight(b)) + BTREE_CACHE_NOT_FREED_INCREMENT(read_in_flight); + else if (btree_node_write_in_flight(b)) + BTREE_CACHE_NOT_FREED_INCREMENT(write_in_flight); return -BCH_ERR_ENOMEM_btree_node_reclaim; + } /* XXX: waiting on IO with btree cache lock held */ bch2_btree_node_wait_on_read(b); bch2_btree_node_wait_on_write(b); } - if (!six_trylock_intent(&b->c.lock)) + if (!six_trylock_intent(&b->c.lock)) { + BTREE_CACHE_NOT_FREED_INCREMENT(lock_intent); return -BCH_ERR_ENOMEM_btree_node_reclaim; + } - if (!six_trylock_write(&b->c.lock)) + if (!six_trylock_write(&b->c.lock)) { + BTREE_CACHE_NOT_FREED_INCREMENT(lock_write); goto out_unlock_intent; + } /* recheck under lock */ if (b->flags & ((1U << BTREE_NODE_read_in_flight)| (1U << BTREE_NODE_write_in_flight))) { - if (!flush) + if (!flush) { + if (btree_node_read_in_flight(b)) + BTREE_CACHE_NOT_FREED_INCREMENT(read_in_flight); + else if (btree_node_write_in_flight(b)) + BTREE_CACHE_NOT_FREED_INCREMENT(write_in_flight); goto out_unlock; + } six_unlock_write(&b->c.lock); six_unlock_intent(&b->c.lock); goto wait_on_io; } - if (btree_node_noevict(b) || - btree_node_write_blocked(b) || - btree_node_will_make_reachable(b)) + if (btree_node_noevict(b)) { + BTREE_CACHE_NOT_FREED_INCREMENT(noevict); + goto out_unlock; + } + if (btree_node_write_blocked(b)) { + BTREE_CACHE_NOT_FREED_INCREMENT(write_blocked); + goto out_unlock; + } + if (btree_node_will_make_reachable(b)) { + BTREE_CACHE_NOT_FREED_INCREMENT(will_make_reachable); goto out_unlock; + } if (btree_node_dirty(b)) { - if (!flush) + if (!flush) { + BTREE_CACHE_NOT_FREED_INCREMENT(dirty); goto out_unlock; + } /* * Using the underscore version because we don't want to compact * bsets after the write, since this node is about to be evicted @@ -273,14 +305,14 @@ static int __btree_node_reclaim(struct bch_fs *c, struct btree *b, bool flush) goto out; } -static int btree_node_reclaim(struct bch_fs *c, struct btree *b) +static int btree_node_reclaim(struct bch_fs *c, struct btree *b, bool shrinker_counter) { - return __btree_node_reclaim(c, b, false); + return __btree_node_reclaim(c, b, false, shrinker_counter); } static int btree_node_write_and_reclaim(struct bch_fs *c, struct btree *b) { - return __btree_node_reclaim(c, b, true); + return __btree_node_reclaim(c, b, true, false); } static unsigned long bch2_btree_cache_scan(struct shrinker *shrink, @@ -328,11 +360,12 @@ static unsigned long bch2_btree_cache_scan(struct shrinker *shrink, if (touched >= nr) goto out; - if (!btree_node_reclaim(c, b)) { + if (!btree_node_reclaim(c, b, true)) { btree_node_data_free(c, b); six_unlock_write(&b->c.lock); six_unlock_intent(&b->c.lock); freed++; + bc->freed++; } } restart: @@ -341,9 +374,11 @@ static unsigned long bch2_btree_cache_scan(struct shrinker *shrink, if (btree_node_accessed(b)) { clear_btree_node_accessed(b); - } else if (!btree_node_reclaim(c, b)) { + bc->not_freed_access_bit++; + } else if (!btree_node_reclaim(c, b, true)) { freed++; btree_node_data_free(c, b); + bc->freed++; bch2_btree_node_hash_remove(bc, b); six_unlock_write(&b->c.lock); @@ -400,7 +435,7 @@ static void bch2_btree_cache_shrinker_to_text(struct seq_buf *s, struct shrinker size_t buflen = seq_buf_get_buf(s, &cbuf); struct printbuf out = PRINTBUF_EXTERN(cbuf, buflen); - bch2_btree_cache_to_text(&out, c); + bch2_btree_cache_to_text(&out, &c->btree_cache); seq_buf_commit(s, out.pos); } @@ -564,7 +599,7 @@ static struct btree *btree_node_cannibalize(struct bch_fs *c) struct btree *b; list_for_each_entry_reverse(b, &bc->live, list) - if (!btree_node_reclaim(c, b)) + if (!btree_node_reclaim(c, b, false)) return b; while (1) { @@ -600,7 +635,7 @@ struct btree *bch2_btree_node_mem_alloc(struct btree_trans *trans, bool pcpu_rea * disk node. Check the freed list before allocating a new one: */ list_for_each_entry(b, freed, list) - if (!btree_node_reclaim(c, b)) { + if (!btree_node_reclaim(c, b, false)) { list_del_init(&b->list); goto got_node; } @@ -626,7 +661,7 @@ struct btree *bch2_btree_node_mem_alloc(struct btree_trans *trans, bool pcpu_rea * the list. Check if there's any freed nodes there: */ list_for_each_entry(b2, &bc->freeable, list) - if (!btree_node_reclaim(c, b2)) { + if (!btree_node_reclaim(c, b2, false)) { swap(b->data, b2->data); swap(b->aux_data, b2->aux_data); btree_node_to_freedlist(bc, b2); @@ -1222,9 +1257,21 @@ void bch2_btree_node_to_text(struct printbuf *out, struct bch_fs *c, const struc stats.failed); } -void bch2_btree_cache_to_text(struct printbuf *out, const struct bch_fs *c) +void bch2_btree_cache_to_text(struct printbuf *out, const struct btree_cache *bc) { - prt_printf(out, "nr nodes:\t\t%u\n", c->btree_cache.used); - prt_printf(out, "nr dirty:\t\t%u\n", atomic_read(&c->btree_cache.dirty)); - prt_printf(out, "cannibalize lock:\t%p\n", c->btree_cache.alloc_lock); + prt_printf(out, "nr nodes:\t\t%u\n", bc->used); + prt_printf(out, "nr dirty:\t\t%u\n", atomic_read(&bc->dirty)); + prt_printf(out, "cannibalize lock:\t%p\n", bc->alloc_lock); + + prt_printf(out, "freed:\t\t\t\t%u\n", bc->freed); + prt_printf(out, "not freed, dirty:\t\t%u\n", bc->not_freed_dirty); + prt_printf(out, "not freed, write in flight:\t%u\n", bc->not_freed_write_in_flight); + prt_printf(out, "not freed, read in flight:\t%u\n", bc->not_freed_read_in_flight); + prt_printf(out, "not freed, lock intent failed:\t%u\n", bc->not_freed_lock_intent); + prt_printf(out, "not freed, lock write failed:\t%u\n", bc->not_freed_lock_write); + prt_printf(out, "not freed, access bit:\t\t%u\n", bc->not_freed_access_bit); + prt_printf(out, "not freed, no evict failed:\t%u\n", bc->not_freed_noevict); + prt_printf(out, "not freed, write blocked:\t%u\n", bc->not_freed_write_blocked); + prt_printf(out, "not freed, will make reachable:\t%u\n", bc->not_freed_will_make_reachable); + } diff --git a/fs/bcachefs/btree_cache.h b/fs/bcachefs/btree_cache.h index cfb80b201d61..bfe1d7482cbc 100644 --- a/fs/bcachefs/btree_cache.h +++ b/fs/bcachefs/btree_cache.h @@ -126,6 +126,6 @@ static inline struct btree *btree_node_root(struct bch_fs *c, struct btree *b) const char *bch2_btree_id_str(enum btree_id); void bch2_btree_pos_to_text(struct printbuf *, struct bch_fs *, const struct btree *); void bch2_btree_node_to_text(struct printbuf *, struct bch_fs *, const struct btree *); -void bch2_btree_cache_to_text(struct printbuf *, const struct bch_fs *); +void bch2_btree_cache_to_text(struct printbuf *, const struct btree_cache *); #endif /* _BCACHEFS_BTREE_CACHE_H */ diff --git a/fs/bcachefs/btree_types.h b/fs/bcachefs/btree_types.h index 2326bceb34f8..14983e778756 100644 --- a/fs/bcachefs/btree_types.h +++ b/fs/bcachefs/btree_types.h @@ -162,6 +162,16 @@ struct btree_cache { /* Number of elements in live + freeable lists */ unsigned used; unsigned reserve; + unsigned freed; + unsigned not_freed_lock_intent; + unsigned not_freed_lock_write; + unsigned not_freed_dirty; + unsigned not_freed_read_in_flight; + unsigned not_freed_write_in_flight; + unsigned not_freed_noevict; + unsigned not_freed_write_blocked; + unsigned not_freed_will_make_reachable; + unsigned not_freed_access_bit; atomic_t dirty; struct shrinker *shrink; diff --git a/fs/bcachefs/sysfs.c b/fs/bcachefs/sysfs.c index ab743115f169..264c46b456c2 100644 --- a/fs/bcachefs/sysfs.c +++ b/fs/bcachefs/sysfs.c @@ -402,7 +402,7 @@ SHOW(bch2_fs) bch2_btree_updates_to_text(out, c); if (attr == &sysfs_btree_cache) - bch2_btree_cache_to_text(out, c); + bch2_btree_cache_to_text(out, &c->btree_cache); if (attr == &sysfs_btree_key_cache) bch2_btree_key_cache_to_text(out, &c->btree_key_cache);