Received: by 2002:a05:7412:e79e:b0:f3:1519:9f41 with SMTP id o30csp259206rdd; Wed, 22 Nov 2023 15:25:45 -0800 (PST) X-Google-Smtp-Source: AGHT+IHx+1maHFamFljsCyuEc4NQxugGLTmqHCnqLAwchAiRz6TBYWuJ687iTgJaFoprBgmM0F9U X-Received: by 2002:a17:90b:1d0a:b0:27d:4ab9:fcd9 with SMTP id on10-20020a17090b1d0a00b0027d4ab9fcd9mr3935347pjb.21.1700695545557; Wed, 22 Nov 2023 15:25:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700695545; cv=none; d=google.com; s=arc-20160816; b=yin4F18y2j9XKfPn+A80Luv1XYY+te+htdZCx7k/9q9Y+CqiFM+0za0UvphDxhpmpZ ZHR1JDMzrdDp+SA+iasDZ4Rr1m5o/HE67pBcR7BnQg4t4mytHVeTQxjgzVhJ39uXjMrW GZ8ME8NUpluuvDiqoPvmMn9d6qsKIhBTLmeQ0yy3Q7oDlHNSBo4+jfrkDQXHxhOgQWWe wRM9Kx0y8OnyOFZWbp1eek52a13shnMUsQj5V6BJuZLqT132hsAYmZv2P5UdPaMlvst4 6BuvAfZsEUB2OAh/Z3W2xQ2yTmeES8huvy9mo3MGUbpK7ffVyIE2Tw8JJEwgaq4jRHdF Iw7w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=h7yT/gNa8WVPOQ61JKqXqNgHJRrqgXjHTIF9eRajh2g=; fh=mDiKJtb6HwOojzT/Tj0KHsHXTEWMd8hEup+kQMFjAPQ=; b=wdYuPcGc78VoAO81Am04PvG723WHRNEQc5IYIPuQnWq2+AaqJBk4QqPy8Bu8TmvygT bJiwgNscafUfOWwVh/WtVmMSAuL5yhJsISgcJpn3cpDENpyAkgCZgMi/CtGiKOrLtJG3 PclKT4pKJFLFvh1QqHeirpNCk1Bswst/mrYCo9ACLl3yFkmJh80jYtC44ItU2+12vMiu dHiL6OFYuISC8PkS6wTN6XyLyWWcgTNYm6SSqfar5LyBGqu+iImgLnxNkHtfnvrX2dD5 L1wrRcKlzv+TlnGbKdW2SkUrDr45IXqX6zDorB926osqVc+VLAVeHaaE0PPIgoIsbaEj spWw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=O6Wa1Pq7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Return-Path: Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id r34-20020a17090a43a500b0027e31647f2bsi116641pjg.65.2023.11.22.15.25.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Nov 2023 15:25:45 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=O6Wa1Pq7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id C88088280D4E; Wed, 22 Nov 2023 15:25:42 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344590AbjKVXZh (ORCPT + 99 others); Wed, 22 Nov 2023 18:25:37 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57260 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344409AbjKVXZd (ORCPT ); Wed, 22 Nov 2023 18:25:33 -0500 Received: from out-172.mta0.migadu.com (out-172.mta0.migadu.com [IPv6:2001:41d0:1004:224b::ac]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B610D110 for ; Wed, 22 Nov 2023 15:25:29 -0800 (PST) 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 Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Wed, 22 Nov 2023 15:25:43 -0800 (PST) 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); -- 2.42.0