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