From patchwork Thu Jul 11 19:19:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yu Zhao X-Patchwork-Id: 13731019 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 9F566C3DA45 for ; Thu, 11 Jul 2024 19:20:04 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 253B96B009A; Thu, 11 Jul 2024 15:20:04 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 204356B009B; Thu, 11 Jul 2024 15:20:04 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0F43F6B009C; Thu, 11 Jul 2024 15:20:04 -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 E4E566B009A for ; Thu, 11 Jul 2024 15:20:03 -0400 (EDT) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id A1F7E1A0364 for ; Thu, 11 Jul 2024 19:20:03 +0000 (UTC) X-FDA: 82328437086.17.E30603E Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) by imf05.hostedemail.com (Postfix) with ESMTP id F2010100027 for ; Thu, 11 Jul 2024 19:20:01 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=KysMvxKM; spf=pass (imf05.hostedemail.com: domain of 3YDCQZgYKCD0xtygZnfnnfkd.bnlkhmtw-lljuZbj.nqf@flex--yuzhao.bounces.google.com designates 209.85.219.201 as permitted sender) smtp.mailfrom=3YDCQZgYKCD0xtygZnfnnfkd.bnlkhmtw-lljuZbj.nqf@flex--yuzhao.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1720725576; 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-type:content-transfer-encoding:in-reply-to: references:dkim-signature; bh=Y0IJBxGEZh8aIDvEw0KmFnuORNT4a0CNIuPo7E0B6UQ=; b=v6ajfh8jIsZxa5jjfujGbEECxoUaRkzRd7IoCW34iRI4U1eqjUX0h726jA81g+YnsV4lgG Ab+luPHXCzFAP3Bay//33g8cUGW5MCZHJIQWiN67H2P0//V3Xwm2EJftIgnsoz1VIod3hQ WhdN21c5G4P1ibErUEFg7dZhHMX0yEY= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=KysMvxKM; spf=pass (imf05.hostedemail.com: domain of 3YDCQZgYKCD0xtygZnfnnfkd.bnlkhmtw-lljuZbj.nqf@flex--yuzhao.bounces.google.com designates 209.85.219.201 as permitted sender) smtp.mailfrom=3YDCQZgYKCD0xtygZnfnnfkd.bnlkhmtw-lljuZbj.nqf@flex--yuzhao.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1720725576; a=rsa-sha256; cv=none; b=A2sexKBXjHVsNv5dyLGvTK0wed8preHRWfKKMeHs65RJiyAcWAX3QcEWhWhVu+qyU+s4mb GKyQsPwn17tcgz5WBul3/jn+xqyhBJA/kIHnQC37j9DXz58bTV1mvDzusWDs3EEGhYv0zY YjdyIjmFw4Gl/K92JlkzYHbkSiFvoAw= Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-e03a7949504so2057821276.2 for ; Thu, 11 Jul 2024 12:20:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1720725601; x=1721330401; darn=kvack.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=Y0IJBxGEZh8aIDvEw0KmFnuORNT4a0CNIuPo7E0B6UQ=; b=KysMvxKMW0Wf1pyPljjcuwf02TAyKSu5lY0x5hp2cOM8dpbw2hgc98IvUKnpZefZpl LCCORUGqR0RPGmjiDMqKD2YDUpxN//DyZvmg6ruUwkV+i5MLIBSrVTJIxH4UF74aYG5M 8h7hifxPEfV4f8d/DtoYNu2M8Ik2V8buw4x4OYafia1sUGwSniYLj4I4Bit+CCF0hSLS nvGEtQqr1sTthQ+0v1q8NjOHzZHNfiYumJrMzaHoeBV0AYo7Hug+9vzlagj1L7GK8hfc 31AZvERqMppUiWAfyV4RUcmc6ztOnjlP3ZDYE27JLS0wKGNNl8Irjr1bp2gLnBhzZsNt 0w+w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720725601; x=1721330401; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=Y0IJBxGEZh8aIDvEw0KmFnuORNT4a0CNIuPo7E0B6UQ=; b=UiU5Zp5dtSiQnroPcuhvdPOED87cCd5XY5g3OTySFWATeP33thuaOEOthMU1nG4JN/ tRenoDFkShafVCrLtA3wsKOFk4FHBT/gYvJI3mAsj3XJFuFK1U7fcNK9ihEGPZNRB+Xt xywENACm5cL4dmLbuI62z5ItD/1zfjyJaVpQ0/tZmzjsuXRl/AxhzIH5W08XywSi9w+l nGISQ1rfe0ZCADrjQQ8jkzw/4yCmv3ddXO9QZX8/pUwXGpDYusR5bc+g28p0IqzohpZ2 DSO+0v0NifWS96yDifYiXHlMRO3fQecxDvWP/yBBPcRj7jSnUeFVzTZqIVFNctklf3F1 TA/g== X-Gm-Message-State: AOJu0Yy0T7L9OkB/vrHkPzTJLim+i2Pb0TgXA8d57HUm9h5OvKU5Rnn6 vanXFk08xeYCofc2C3aZyOORKSwrS2Ktpmku03OVIufhYq4lKiTm8ybvdUlGPiB0Z++mJV8mpr4 KKA== X-Google-Smtp-Source: AGHT+IFl5/lwjZcmg0Gramun5B417BFKYSxf44G9wfJyYgQTaJof76xuc6ZiaGwXX8SHDS26hFf2arMicVw= X-Received: from yuzhao2.bld.corp.google.com ([2a00:79e0:2e28:6:7f87:3390:5055:fce9]) (user=yuzhao job=sendgmr) by 2002:a05:6902:2b0d:b0:e03:589b:cbe1 with SMTP id 3f1490d57ef6-e041b070dfbmr748760276.7.1720725600922; Thu, 11 Jul 2024 12:20:00 -0700 (PDT) Date: Thu, 11 Jul 2024 13:19:56 -0600 Mime-Version: 1.0 X-Mailer: git-send-email 2.45.2.993.g49e7a77208-goog Message-ID: <20240711191957.939105-1-yuzhao@google.com> Subject: [PATCH mm-unstable v1 1/2] mm/mglru: fix div-by-zero in vmpressure_calc_level() From: Yu Zhao To: Andrew Morton Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Yu Zhao , Wei Xu , stable@vger.kernel.org X-Stat-Signature: y9qj1ofjri4j7gqkq783s9gogpm8hhjh X-Rspam-User: X-Rspamd-Queue-Id: F2010100027 X-Rspamd-Server: rspam02 X-HE-Tag: 1720725601-176113 X-HE-Meta: U2FsdGVkX19pHwjAloAT/xwdoIeP8zXJPWe/HFFiXcym9lQNOkJ7HU0bRu7YPdrl2EsU28bF369V1pEBx+TMpv7CLfqyN3FqKPdDQMIgVuBYTICwke6ShMu932tLijXmEslELJ8S7Sk92ynraMTcovfs8nbat1t5P078AnG7etdjmmyRkYWE9dmmBj/JBCuMN7WxD9zYdh3KYbaM05uX5H5v+WOec++FWqXaA4N4cBgHeiqzGTOmacb4fnVGswsDj7gPruckniC7yRKA5Y33qD7o13uOl5hQY7iJGmCNehXdsN0hsYMUgoEt5Hr3C5vSpEp76afB/bShcTPfrSWLznnQ/JVoXoGO7JnSSis5RhZNwhlDf1SODFiInWsCIK5+4sFqp6317MRmJ98WLUbVZGmgFsvNXKhc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L4qeep8hMRbY4pIUjviCOB7G62/8kwzV7uO/kVUj7BbjPZKywiOzsv63SpJMedmSGqXZ3z7YHWE8N6hGMB6AHP6ZoL/AtiVTt3+SErMQ== X-Bogosity: Ham, tests=bogofilter, spamicity=0.001464, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: evict_folios() uses a second pass to reclaim folios that have gone through page writeback and become clean before it finishes the first pass, since folio_rotate_reclaimable() cannot handle those folios due to the isolation. The second pass tries to avoid potential double counting by deducting scan_control->nr_scanned. However, this can result in underflow of nr_scanned, under a condition where shrink_folio_list() does not increment nr_scanned, i.e., when folio_trylock() fails. The underflow can cause the divisor, i.e., scale=scanned+reclaimed in vmpressure_calc_level(), to become zero, resulting in the following crash: [exception RIP: vmpressure_work_fn+101] process_one_work at ffffffffa3313f2b Since scan_control->nr_scanned has no established semantics, the potential double counting has minimal risks. Therefore, fix the problem by not deducting scan_control->nr_scanned in evict_folios(). Reported-by: Wei Xu Fixes: 359a5e1416ca ("mm: multi-gen LRU: retry folios written back while isolated") Cc: stable@vger.kernel.org Signed-off-by: Yu Zhao --- mm/vmscan.c | 1 - 1 file changed, 1 deletion(-) diff --git a/mm/vmscan.c b/mm/vmscan.c index 0761f91b407f..6403038c776e 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -4597,7 +4597,6 @@ static int evict_folios(struct lruvec *lruvec, struct scan_control *sc, int swap /* retry folios that may have missed folio_rotate_reclaimable() */ list_move(&folio->lru, &clean); - sc->nr_scanned -= folio_nr_pages(folio); } spin_lock_irq(&lruvec->lru_lock); From patchwork Thu Jul 11 19:19:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yu Zhao X-Patchwork-Id: 13731020 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 072B2C3DA4B for ; Thu, 11 Jul 2024 19:20:08 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 899E16B009C; Thu, 11 Jul 2024 15:20:07 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 845BC6B009D; Thu, 11 Jul 2024 15:20:07 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6C0B06B009E; Thu, 11 Jul 2024 15:20:07 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 4C0A36B009C for ; Thu, 11 Jul 2024 15:20:07 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id F19111A05F1 for ; Thu, 11 Jul 2024 19:20:06 +0000 (UTC) X-FDA: 82328437212.19.4279B83 Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) by imf01.hostedemail.com (Postfix) with ESMTP id 3F9554002C for ; Thu, 11 Jul 2024 19:20:04 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=YEFHZ+Po; spf=pass (imf01.hostedemail.com: domain of 3YzCQZgYKCEA0w1jcqiqqing.eqonkpwz-oomxcem.qti@flex--yuzhao.bounces.google.com designates 209.85.128.202 as permitted sender) smtp.mailfrom=3YzCQZgYKCEA0w1jcqiqqing.eqonkpwz-oomxcem.qti@flex--yuzhao.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1720725560; 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-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=L5p4SaaO+7UoZgcm+e1C8dGPnGJXML0RCKN69AHh9/8=; b=m33cuV94DQyDMfKmzwUjYVXEsDcbU4CKc9kJQaFhicT6DMpnUjnGozicLI8Z3sHgHHnGcB rYv8DG9sS1JnGixv+vMWvhHMAJrtt/hcg4WgG2vmRjsYzxdVh1UkxOfCgWJltvsoFBsGyP D3L7T3NgR8wG5+x4VwbefKENK66YqXU= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=YEFHZ+Po; spf=pass (imf01.hostedemail.com: domain of 3YzCQZgYKCEA0w1jcqiqqing.eqonkpwz-oomxcem.qti@flex--yuzhao.bounces.google.com designates 209.85.128.202 as permitted sender) smtp.mailfrom=3YzCQZgYKCEA0w1jcqiqqing.eqonkpwz-oomxcem.qti@flex--yuzhao.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1720725560; a=rsa-sha256; cv=none; b=EPElRenHdLHdTL2QZmCb4kJdWIBmWl826x+Un3R7s7r4x6ChEvd9npO0MkmZbUtbZ9FrT0 TviHq5BKwbbTthufdTEfoabGdPBNd/0t4nUlAeArB3/yliZpv/du0WTOLF2O3N7TnsaxSa 3SSIWFW7c/l7ulff3DzzZdYPzDArA4w= Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-6522c6e5ed9so24308927b3.0 for ; Thu, 11 Jul 2024 12:20:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1720725603; x=1721330403; darn=kvack.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=L5p4SaaO+7UoZgcm+e1C8dGPnGJXML0RCKN69AHh9/8=; b=YEFHZ+Pojjl4RsHAJJSuJ2n4JCbWd7wfH4UsiTxKBTQ6nKajZYka0lFrQo50HFAFrX JITE8Hz0n7KfrNyvWbXuD1b9/AW0cIYfngTbRcaFAfUE5hV1DVIszGErsvhFKV3nDnS3 MID2RlSdVs+nFaSpTXacGyk0PtTcnsSkYQNF9QdDC8RTRRb5NiPWcltt3st7QVdR4bXC y40JDs+8t2RpaxXOSCvBl//3L8YM47JE3JY8FRdnsLDMuM+4+PMW5a6Rd6xTKvvhu8Fj wuw/FBZwPgVSO5Mk3DrfMfKzPqcwa7JLmRptoV3RvPQfaq3K6DoCeJnwq5OwH9iESUrF D/vw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720725603; x=1721330403; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=L5p4SaaO+7UoZgcm+e1C8dGPnGJXML0RCKN69AHh9/8=; b=u8CwZ8b01C+seCRohkjvZEm9kKfApABfvESVSjkmBUi2NOGrzRvX4+cd5s+iSSIkC3 fRWFGwM7ypzw5X2GBK2npKGqU3qvhram8EjxwLyVlybjfXgd3ftyN9NcnmsJaeuzUWAK UYVEQ4+s4cE2WaolsEjQ4hjawIiTN8RccUMRIdRlcXqBL99vll/lKgMwu4xzpFn+N3go 3ffGfJ7CydOpIpii0cZ7kD8yutEWevLkzV3rpb50cJwBVChDueVUETvCEACSN4DcdjXp 3NXolHfOXWtNortt27O5FdqhyL931k3IJoMtryDbXM/0hvRtsiPPg/lkMNtRX4pmuScN hlOQ== X-Gm-Message-State: AOJu0Yxo4w9ULKXrHpeQ91I+j3SWd9mHcbMXOSH34UVLp6hnb1RWTVg/ LgdXRa+TH8AkHdMibSHY0H+eZ4KvQXloY4oFLR6qNSGoy7Ea5sH/fIGVhRxgzHW1XdnIHZ3Jsc+ 8tw== X-Google-Smtp-Source: AGHT+IFwZuZdGnTKPExljm8Tw+4jIU2FhrH6S3OcLgO05bDExtd9/3IrHUiiKpVcYyY1Saivv4UkxyKDxXU= X-Received: from yuzhao2.bld.corp.google.com ([2a00:79e0:2e28:6:7f87:3390:5055:fce9]) (user=yuzhao job=sendgmr) by 2002:a05:6902:2e0d:b0:e03:2f90:e81d with SMTP id 3f1490d57ef6-e041b14c989mr615371276.11.1720725603316; Thu, 11 Jul 2024 12:20:03 -0700 (PDT) Date: Thu, 11 Jul 2024 13:19:57 -0600 In-Reply-To: <20240711191957.939105-1-yuzhao@google.com> Mime-Version: 1.0 References: <20240711191957.939105-1-yuzhao@google.com> X-Mailer: git-send-email 2.45.2.993.g49e7a77208-goog Message-ID: <20240711191957.939105-2-yuzhao@google.com> Subject: [PATCH mm-unstable v1 2/2] mm/mglru: fix overshooting shrinker memory From: Yu Zhao To: Andrew Morton Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Yu Zhao , Alexander Motin , stable@vger.kernel.org X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 3F9554002C X-Stat-Signature: 1w6woznqz6t1t8mmkk8yya8qgw13m73t X-Rspam-User: X-HE-Tag: 1720725604-157582 X-HE-Meta: U2FsdGVkX1/Cc/Nd8ZeUIkNNln25xkHPdAGQIDzY1cvzcddHnRaFAz2RELst1szDd/KYOupi/GQ+o0oAFSM2Tu9c+DcMGRR5M7JLP5ry9G9P/i6n82CrdMK10pjTieH597wV26TRRKLNXmDL9/qQuUkI+uQr5Zx1QsFSBK9y4HaIF238gM/NJcaNPirSvFeMjVxLKT8VcG4lc93d9xrYROQADqB/tffoxNtDOFz9IGTIAcrOFDSnMLvHaRwWTAvSx0gQv3tlNpflsh+uBjbeKMaFzUygXRgLYJLSPHhAfkLzdPDW67M1n/ZoxBo0yeFD63LA8gVR6i0tw73CZ5xqU+JuMUu91UryR25nf7PBrZt5Iw8h4G5rUniw2aNHL1sEVrqtC1f5eJLcoL1KoKQ4/bFqf0M3IeF3AjYASzwMp76t5M3X1vWhzM7mMwdDZaQDmql3ZeRxs9v3F5ug5e55akm8R6GCT33a9on1yl0YdU5EkZT2gZ00X/ProLqn389lb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qFZnItTQjCZ+bkCuuxk67GBjJqBITS6Xwf3pn9HPA== 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: set_initial_priority() tries to jump-start global reclaim by estimating the priority based on cold/hot LRU pages. The estimation does not account for shrinker objects, and it cannot do so because their sizes can be in different units other than page. If shrinker objects are the majority, e.g., on TrueNAS SCALE 24.04.0 where ZFS ARC can use almost all system memory, set_initial_priority() can vastly underestimate how much memory ARC shrinker can evict and assign extreme low values to scan_control->priority, resulting in overshoots of shrinker objects. To reproduce the problem, using TrueNAS SCALE 24.04.0 with 32GB DRAM, a test ZFS pool and the following commands: fio --name=mglru.file --numjobs=36 --ioengine=io_uring \ --directory=/root/test-zfs-pool/ --size=1024m --buffered=1 \ --rw=randread --random_distribution=random \ --time_based --runtime=1h & for ((i = 0; i < 20; i++)) do sleep 120 fio --name=mglru.anon --numjobs=16 --ioengine=mmap \ --filename=/dev/zero --size=1024m --fadvise_hint=0 \ --rw=randrw --random_distribution=random \ --time_based --runtime=1m done To fix the problem: 1. Cap scan_control->priority at or above DEF_PRIORITY/2, to prevent the jump-start from being overly aggressive. 2. Account for the progress from mm_account_reclaimed_pages(), to prevent kswapd_shrink_node() from raising the priority unnecessarily. Reported-by: Alexander Motin Fixes: e4dde56cd208 ("mm: multi-gen LRU: per-node lru_gen_folio lists") Cc: stable@vger.kernel.org Signed-off-by: Yu Zhao --- mm/vmscan.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/mm/vmscan.c b/mm/vmscan.c index 6403038c776e..6216d79edb7f 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -4930,7 +4930,11 @@ static void set_initial_priority(struct pglist_data *pgdat, struct scan_control /* round down reclaimable and round up sc->nr_to_reclaim */ priority = fls_long(reclaimable) - 1 - fls_long(sc->nr_to_reclaim - 1); - sc->priority = clamp(priority, 0, DEF_PRIORITY); + /* + * The estimation is based on LRU pages only, so cap it to prevent + * overshoots of shrinker objects by large margins. + */ + sc->priority = clamp(priority, DEF_PRIORITY / 2, DEF_PRIORITY); } static void lru_gen_shrink_node(struct pglist_data *pgdat, struct scan_control *sc) @@ -6754,6 +6758,7 @@ static bool kswapd_shrink_node(pg_data_t *pgdat, { struct zone *zone; int z; + unsigned long nr_reclaimed = sc->nr_reclaimed; /* Reclaim a number of pages proportional to the number of zones */ sc->nr_to_reclaim = 0; @@ -6781,7 +6786,8 @@ static bool kswapd_shrink_node(pg_data_t *pgdat, if (sc->order && sc->nr_reclaimed >= compact_gap(sc->order)) sc->order = 0; - return sc->nr_scanned >= sc->nr_to_reclaim; + /* account for progress from mm_account_reclaimed_pages() */ + return max(sc->nr_scanned, sc->nr_reclaimed - nr_reclaimed) >= sc->nr_to_reclaim; } /* Page allocator PCP high watermark is lowered if reclaim is active. */