Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3832218imu; Mon, 28 Jan 2019 11:36:53 -0800 (PST) X-Google-Smtp-Source: ALg8bN6CQmWuHPgpDLLIRSpPae1yGHtqHMB8Njv3ZsySA61cUVH4zR0p9VPThZ0crvg6Uq+/MGMr X-Received: by 2002:a62:1484:: with SMTP id 126mr22859684pfu.257.1548704213806; Mon, 28 Jan 2019 11:36:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548704213; cv=none; d=google.com; s=arc-20160816; b=q1XR8u58mG0WfpaY+bl4TlS5VRMROcu+dgTXFj1hFprpTSyVbZmXmtFwIBXKaMTxFo A17vXp+Yp9DufHgk8PBYEfP6KjfwkE5AaPayI92QPWEDpl6eBcsyofEuLD7fgD3xLPtF Ip4yTtqNoDFlTqEyNtKCI8DeRkVl8cDhQxvlf9kld0zjwHzAuFnLYEtc9poA0g7I1nHE c/ausmY5d0EAu2bK1qYa+uH58H6ZrxKub2sJErL3t+TPokyrHWMDZ7vK9jzOcwOVoZqv ceIoFVl1znQ+kKlhW0YkONpUnFfrl1vVTJqHzYhhuq5SDbMtjwtpqTHeaLROK1Kmc3OA TIqA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:subject:cc:to:from:date; bh=QE+fDjOW2/2KHYiahIYiRMMiB4vV7w3SM+TfLqvRjGY=; b=pETCWO++yGsGJ3HDbaCY+HRb6RwuRJgdmwCaZs3FSgtGvXLCM/py2sCWcDhYkgb33y x0zK3YQ9QVSryNiuU0TIJLL5e9dzFA1dMbLXSQS0ZcPUMgrkhOIcapdATZKoGmQ+Vt0C 0BKCp7NU0P376aG0gv4Doqylidh1jsq1wJz7er+JQj0Zipm2xQ89aiVur0w6OMyv5mqq pT45lf6pRWyNtIv7VK2Hb7mksEknGP/ojehDjJFUjkXaGhOdu1Ohcp3Q1ZIx50vkBazV ZekFflBMPT6Dyd+fpK/LvF9RDtijDCWoGsCQuCiJsUvqFYQUUaGeJy7/SDVcFHaFTubY 9/SA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v16si8701240plo.182.2019.01.28.11.36.38; Mon, 28 Jan 2019 11:36:53 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728075AbfA1TgN (ORCPT + 99 others); Mon, 28 Jan 2019 14:36:13 -0500 Received: from shelob.surriel.com ([96.67.55.147]:42906 "EHLO shelob.surriel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726862AbfA1TgL (ORCPT ); Mon, 28 Jan 2019 14:36:11 -0500 Received: from [2001:470:1f07:12aa:6e0b:84ff:fee2:98bb] (helo=imladris.surriel.com) by shelob.surriel.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.91) (envelope-from ) id 1goChS-0006oM-NH; Mon, 28 Jan 2019 14:36:06 -0500 Date: Mon, 28 Jan 2019 14:35:35 -0500 From: Rik van Riel To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, kernel-team@fb.com, Johannes Weiner , Chris Mason , Roman Gushchin , Andrew Morton , Michal Hocko Subject: [PATCH] mm,slab,vmscan: accumulate gradual pressure on small slabs Message-ID: <20190128143535.7767c397@imladris.surriel.com> X-Mailer: Claws Mail 3.16.0 (GTK+ 2.24.32; x86_64-redhat-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org There are a few issues with the way the number of slab objects to scan is calculated in do_shrink_slab. First, for zero-seek slabs, we could leave the last object around forever. That could result in pinning a dying cgroup into memory, instead of reclaiming it. The fix for that is trivial. Secondly, small slabs receive much more pressure, relative to their size, than larger slabs, due to "rounding up" the minimum number of scanned objects to batch_size. We can keep the pressure on all slabs equal relative to their size by accumulating the scan pressure on small slabs over time, resulting in sometimes scanning an object, instead of always scanning several. This results in lower system CPU use, and a lower major fault rate, as actively used entries from smaller caches get reclaimed less aggressively, and need to be reloaded/recreated less often. Fixes: 4b85afbdacd2 ("mm: zero-seek shrinkers") Fixes: 172b06c32b94 ("mm: slowly shrink slabs with a relatively small number of objects") Cc: Johannes Weiner Cc: Chris Mason Cc: Roman Gushchin Cc: kernel-team@fb.com Tested-by: Chris Mason --- include/linux/shrinker.h | 1 + mm/vmscan.c | 16 +++++++++++++--- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/include/linux/shrinker.h b/include/linux/shrinker.h index 9443cafd1969..7a9a1a0f935c 100644 --- a/include/linux/shrinker.h +++ b/include/linux/shrinker.h @@ -65,6 +65,7 @@ struct shrinker { long batch; /* reclaim batch size, 0 = default */ int seeks; /* seeks to recreate an obj */ + int small_scan; /* accumulate pressure on slabs with few objects */ unsigned flags; /* These are for internal use */ diff --git a/mm/vmscan.c b/mm/vmscan.c index a714c4f800e9..0e375bd7a8b6 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -488,18 +488,28 @@ static unsigned long do_shrink_slab(struct shrink_control *shrinkctl, * them aggressively under memory pressure to keep * them from causing refetches in the IO caches. */ - delta = freeable / 2; + delta = (freeable + 1)/ 2; } /* * Make sure we apply some minimal pressure on default priority - * even on small cgroups. Stale objects are not only consuming memory + * even on small cgroups, by accumulating pressure across multiple + * slab shrinker runs. Stale objects are not only consuming memory * by themselves, but can also hold a reference to a dying cgroup, * preventing it from being reclaimed. A dying cgroup with all * corresponding structures like per-cpu stats and kmem caches * can be really big, so it may lead to a significant waste of memory. */ - delta = max_t(unsigned long long, delta, min(freeable, batch_size)); + if (!delta) { + shrinker->small_scan += freeable; + + delta = shrinker->small_scan >> priority; + shrinker->small_scan -= delta << priority; + + delta *= 4; + do_div(delta, shrinker->seeks); + + } total_scan += delta; if (total_scan < 0) {