Received: by 2002:ac0:e350:0:0:0:0:0 with SMTP id g16csp209380imn; Thu, 4 Aug 2022 02:52:45 -0700 (PDT) X-Google-Smtp-Source: AA6agR4xuRd8t/atvyp1ToVHrLOa5uMVNRohcz0TdYCMq5Z8dO5UPC8K841wZ3qgISvU6g2PUseH X-Received: by 2002:a05:6402:11cd:b0:43d:7862:7c25 with SMTP id j13-20020a05640211cd00b0043d78627c25mr1224128edw.96.1659606765706; Thu, 04 Aug 2022 02:52:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659606765; cv=none; d=google.com; s=arc-20160816; b=DTbM23vT9lwHqmRa+DiuUnlL6s4913QCWemGFsM2efqSq3T+sAILtxkM+jVk5TMI8W a21SCTJse7VgAoIPC+522tdIfuM2Sqa/bMc5jYQaX9WhCE2oKk+eB5tVZwZ7Dlx7H1p3 vx1FiYn8jNTRBg32R074hQgFY5H3GxK0TWZCaZn5Khl4ViHJIHSEpjH7wG+BC6Ps/0Xo 3I6MkZyTvvI9XcgMhCj9gxsKpk1PBkua4rUutHOfmoQOSg6ugKqaWQ7kl5H5cXP9Ejiz HK0LpNwR6SOqfdqjYR8z4n2VLhTJf8yzB5dCCq8SgMDBpNc6Pv8SWUo2NtYK1oGtMpx5 9y7g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=hPL5EUA7hl5fcuknoGUTN14cLPO2f0vX7QZr+exKOYM=; b=NZkVAU6EinK189oSOqiPrhzZ5dvz/DExBEUpcD1qgbYBYo8xDsGvaVI0dsTE8byTAZ iS+GWaGxEekkPx9OYIYVFdzhIWqHDzi2NMe3gmeKhppMg6E1Tw6cZGVXOVQ1auNr8fcT X5YO+L/7SjnE1Qv2WnDkt7d6EYxgVV9R0ZXnbuz3xAfBe6+E2GppUZ4Qc+LqvadqFe+e LmeE0f7zkxMaMBNh3wtSrvlUfeCREdgKChygsSgtVbvLTUsYX4K24XVrNnP77QRl1rYI MjNh+AhQWV/RjDmqdAnGEtYQBxxEy3ndFrEe8lexZCCQ8t5bUL5d+DjzUkSRD7Gt7Gx6 l+6Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id r17-20020a05640251d100b0043cdb04b9f1si980206edd.411.2022.08.04.02.52.17; Thu, 04 Aug 2022 02:52:45 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239263AbiHDJjP (ORCPT + 99 others); Thu, 4 Aug 2022 05:39:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56522 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239268AbiHDJjL (ORCPT ); Thu, 4 Aug 2022 05:39:11 -0400 Received: from outbound-smtp63.blacknight.com (outbound-smtp63.blacknight.com [46.22.136.252]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5C5BD4199C for ; Thu, 4 Aug 2022 02:39:09 -0700 (PDT) Received: from mail.blacknight.com (pemlinmail03.blacknight.ie [81.17.254.16]) by outbound-smtp63.blacknight.com (Postfix) with ESMTPS id D6225FAC38 for ; Thu, 4 Aug 2022 10:39:07 +0100 (IST) Received: (qmail 5340 invoked from network); 4 Aug 2022 09:39:07 -0000 Received: from unknown (HELO techsingularity.net) (mgorman@techsingularity.net@[84.203.198.246]) by 81.17.254.9 with ESMTPSA (AES256-SHA encrypted, authenticated); 4 Aug 2022 09:39:07 -0000 Date: Thu, 4 Aug 2022 10:38:00 +0100 From: Mel Gorman To: Johannes Weiner Cc: Andrew Morton , Hugh Dickins , Joonsoo Kim , linux-mm@kvack.org, linux-kernel@vger.kernel.org, kernel-team@fb.com Subject: Re: [PATCH] mm: vmscan: fix extreme overreclaim and swap floods Message-ID: <20220804093800.yrmkcspzb35gvnfp@techsingularity.net> References: <20220802162811.39216-1-hannes@cmpxchg.org> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-15 Content-Disposition: inline In-Reply-To: <20220802162811.39216-1-hannes@cmpxchg.org> X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_PASS 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 On Tue, Aug 02, 2022 at 12:28:11PM -0400, Johannes Weiner wrote: > During proactive reclaim, we sometimes observe severe overreclaim, > with several thousand times more pages reclaimed than requested. > > This trace was obtained from shrink_lruvec() during such an instance: > > prio:0 anon_cost:1141521 file_cost:7767 > nr_reclaimed:4387406 nr_to_reclaim:1047 (or_factor:4190) > nr=[7161123 345 578 1111] > > While he reclaimer requested 4M, vmscan reclaimed close to 16G, most > of it by swapping. These requests take over a minute, during which the > write() to memory.reclaim is unkillably stuck inside the kernel. > > Digging into the source, this is caused by the proportional reclaim > bailout logic. This code tries to resolve a fundamental conflict: to > reclaim roughly what was requested, while also aging all LRUs fairly > and in accordance to their size, swappiness, refault rates etc. The > way it attempts fairness is that once the reclaim goal has been > reached, it stops scanning the LRUs with the smaller remaining scan > targets, and adjusts the remainder of the bigger LRUs according to how > much of the smaller LRUs was scanned. It then finishes scanning that > remainder regardless of the reclaim goal. > > This works fine if priority levels are low and the LRU lists are > comparable in size. However, in this instance, the cgroup that is > targeted by proactive reclaim has almost no files left - they've > already been squeezed out by proactive reclaim earlier - and the > remaining anon pages are hot. Anon rotations cause the priority level > to drop to 0, which results in reclaim targeting all of anon (a lot) > and all of file (almost nothing). By the time reclaim decides to bail, > it has scanned most or all of the file target, and therefor must also > scan most or all of the enormous anon target. This target is thousands > of times larger than the reclaim goal, thus causing the overreclaim. > > The bailout code hasn't changed in years, why is this failing now? > The most likely explanations are two other recent changes in anon > reclaim: > > 1. Before the series starting with commit 5df741963d52 ("mm: fix LRU > balancing effect of new transparent huge pages"), the VM was > overall relatively reluctant to swap at all, even if swap was > configured. This means the LRU balancing code didn't come into play > as often as it does now, and mostly in high pressure situations > where pronounced swap activity wouldn't be as surprising. > > 2. For historic reasons, shrink_lruvec() loops on the scan targets of > all LRU lists except the active anon one, meaning it would bail if > the only remaining pages to scan were active anon - even if there > were a lot of them. > > Before the series starting with commit ccc5dc67340c ("mm/vmscan: > make active/inactive ratio as 1:1 for anon lru"), most anon pages > would live on the active LRU; the inactive one would contain only a > handful of preselected reclaim candidates. After the series, anon > gets aged similarly to file, and the inactive list is the default > for new anon pages as well, making it often the much bigger list. > > As a result, the VM is now more likely to actually finish large > anon targets than before. > > Change the code such that only one SWAP_CLUSTER_MAX-sized nudge toward > the larger LRU lists is made before bailing out on a met reclaim goal. > > This fixes the extreme overreclaim problem. > > Fairness is more subtle and harder to evaluate. No obvious misbehavior > was observed on the test workload, in any case. Conceptually, fairness > should primarily be a cumulative effect from regular, lower priority > scans. Once the VM is in trouble and needs to escalate scan targets to > make forward progress, fairness needs to take a backseat. This is also > acknowledged by the myriad exceptions in get_scan_count(). This patch > makes fairness decrease gradually, as it keeps fairness work static > over increasing priority levels with growing scan targets. This should > make more sense - although we may have to re-visit the exact values. > > Signed-off-by: Johannes Weiner Acked-by: Mel Gorman -- Mel Gorman SUSE Labs