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);