From patchwork Thu Mar 11 19:08:45 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Shi X-Patchwork-Id: 12132541 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.5 required=3.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED,DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7A986C433E0 for ; Thu, 11 Mar 2021 19:09:35 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 0C65264EBB for ; Thu, 11 Mar 2021 19:09:32 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 0C65264EBB Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 8EA2F8D02F1; Thu, 11 Mar 2021 14:09:29 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 872EA8D02B2; Thu, 11 Mar 2021 14:09:29 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6797A8D02F1; Thu, 11 Mar 2021 14:09:29 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0222.hostedemail.com [216.40.44.222]) by kanga.kvack.org (Postfix) with ESMTP id 4030A8D02B2 for ; Thu, 11 Mar 2021 14:09:29 -0500 (EST) Received: from smtpin18.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id F4197181AC9CB for ; Thu, 11 Mar 2021 19:09:28 +0000 (UTC) X-FDA: 77908532058.18.CD25F58 Received: from mail-pg1-f177.google.com (mail-pg1-f177.google.com [209.85.215.177]) by imf04.hostedemail.com (Postfix) with ESMTP id 76873130 for ; Thu, 11 Mar 2021 19:09:27 +0000 (UTC) Received: by mail-pg1-f177.google.com with SMTP id q5so1630696pgk.5 for ; Thu, 11 Mar 2021 11:09:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=EGK/9wMv8jRkB25hW3W7zHOqmtj2V0f0Nz5E9gUfq7E=; b=ruApEZXuvYHuRSS42zVIXrt9gJn10TsmfS0rhjKeh7yTcyMqOtl+EUi621sWLY3dre JeLTadgUNwsgqpPn2aJrvqDzLnXySmAWzha19/qTRCmT0xHyh1WuhXdQpSIysjiUKTKV F4ShMw4xHCgAc1jmekBhITwEAR07rska7p6IgcsYESGaTX6NpLcQTE708grIJflhLBQk urtp6/waSHfkEb2Pz/w6zSGviQxZc+zw5JPdO9L4+q5QeSUIScgmLd0g65+QkyHuvM/F 8yZpU8GH3N4MLvLnAtlV8qvp7VWvd5rbMz9MtLhgCwr2+TD9hjppVEbgOxLBShEunfr4 F1xQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=EGK/9wMv8jRkB25hW3W7zHOqmtj2V0f0Nz5E9gUfq7E=; b=Le/jlAI3b3g3Z73aodjsdo+/SdeZQAXBpsybj6ibYww2vldrmusKmIfenqjcAOqrx2 EOXmhseaCZWE7pcAm3vofAXBPa469UL9cXU9MeaWSkAqOIh2qjTuFIuBBjQqBkat+Hv6 KZ1dJZvWOFgpygFvvvqToHQGHTA87lWDINXHEGwxuQIdylHIg42FmrSrYrRCuqUW0kkv b/d7dNn/+kaeMbVkBzmwPW+WUx57zmd+HvS4N4jC9e7gj0TUIefNihPa9X9F6Cx/lG7x Tw6QPAhZTndixIhPk19mozHyfQntBnruLki306W+4Xzrpke5ECQf+h1ZRM12mUj/r3Fi RJ7A== X-Gm-Message-State: AOAM532bd+EkllMfyduE4/IoOXf/4STmI8fws84xRS6LwVX+V1mEqRhr 04ZptHduoR5UD7tZOHeDO4Q= X-Google-Smtp-Source: ABdhPJzYGwUvbjrr9D3b2YYS9YyC7I1ThLnks5DFJYnKtTpSfEdsyC9fjHwBMOZQXfqjjGMp8cSnLw== X-Received: by 2002:a63:1343:: with SMTP id 3mr8397519pgt.166.1615489767493; Thu, 11 Mar 2021 11:09:27 -0800 (PST) Received: from localhost.localdomain (c-73-93-239-127.hsd1.ca.comcast.net. [73.93.239.127]) by smtp.gmail.com with ESMTPSA id t12sm2999111pfe.203.2021.03.11.11.09.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Mar 2021 11:09:26 -0800 (PST) From: Yang Shi To: guro@fb.com, ktkhai@virtuozzo.com, vbabka@suse.cz, shakeelb@google.com, david@fromorbit.com, hannes@cmpxchg.org, mhocko@suse.com, akpm@linux-foundation.org Cc: shy828301@gmail.com, linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [v10 PATCH 13/13] mm: vmscan: shrink deferred objects proportional to priority Date: Thu, 11 Mar 2021 11:08:45 -0800 Message-Id: <20210311190845.9708-14-shy828301@gmail.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210311190845.9708-1-shy828301@gmail.com> References: <20210311190845.9708-1-shy828301@gmail.com> MIME-Version: 1.0 X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 76873130 X-Stat-Signature: kizrszct6u4xwyeddjq4zs1xynt1f8mc Received-SPF: none (gmail.com>: No applicable sender policy available) receiver=imf04; identity=mailfrom; envelope-from=""; helo=mail-pg1-f177.google.com; client-ip=209.85.215.177 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1615489767-433673 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: The number of deferred objects might get windup to an absurd number, and it results in clamp of slab objects. It is undesirable for sustaining workingset. So shrink deferred objects proportional to priority and cap nr_deferred to twice of cache items. The idea is borrowed from Dave Chinner's patch: https://lore.kernel.org/linux-xfs/20191031234618.15403-13-david@fromorbit.com/ Tested with kernel build and vfs metadata heavy workload in our production environment, no regression is spotted so far. Signed-off-by: Yang Shi --- mm/vmscan.c | 46 +++++++++++----------------------------------- 1 file changed, 11 insertions(+), 35 deletions(-) diff --git a/mm/vmscan.c b/mm/vmscan.c index d0791ebd6761..163616e78a4e 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -664,7 +664,6 @@ static unsigned long do_shrink_slab(struct shrink_control *shrinkctl, */ nr = xchg_nr_deferred(shrinker, shrinkctl); - total_scan = nr; if (shrinker->seeks) { delta = freeable >> priority; delta *= 4; @@ -678,37 +677,9 @@ static unsigned long do_shrink_slab(struct shrink_control *shrinkctl, delta = freeable / 2; } + total_scan = nr >> priority; total_scan += delta; - if (total_scan < 0) { - pr_err("shrink_slab: %pS negative objects to delete nr=%ld\n", - shrinker->scan_objects, total_scan); - total_scan = freeable; - next_deferred = nr; - } else - next_deferred = total_scan; - - /* - * We need to avoid excessive windup on filesystem shrinkers - * due to large numbers of GFP_NOFS allocations causing the - * shrinkers to return -1 all the time. This results in a large - * nr being built up so when a shrink that can do some work - * comes along it empties the entire cache due to nr >>> - * freeable. This is bad for sustaining a working set in - * memory. - * - * Hence only allow the shrinker to scan the entire cache when - * a large delta change is calculated directly. - */ - if (delta < freeable / 4) - total_scan = min(total_scan, freeable / 2); - - /* - * Avoid risking looping forever due to too large nr value: - * never try to free more than twice the estimate number of - * freeable entries. - */ - if (total_scan > freeable * 2) - total_scan = freeable * 2; + total_scan = min(total_scan, (2 * freeable)); trace_mm_shrink_slab_start(shrinker, shrinkctl, nr, freeable, delta, total_scan, priority); @@ -747,10 +718,15 @@ static unsigned long do_shrink_slab(struct shrink_control *shrinkctl, cond_resched(); } - if (next_deferred >= scanned) - next_deferred -= scanned; - else - next_deferred = 0; + /* + * The deferred work is increased by any new work (delta) that wasn't + * done, decreased by old deferred work that was done now. + * + * And it is capped to two times of the freeable items. + */ + next_deferred = max_t(long, (nr + delta - scanned), 0); + next_deferred = min(next_deferred, (2 * freeable)); + /* * move the unused scan count back into the shrinker in a * manner that handles concurrent updates.