From patchwork Sun Feb 4 03:06:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chengming Zhou X-Patchwork-Id: 13544433 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 E6BDAC48291 for ; Sun, 4 Feb 2024 03:06:26 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2C5996B007E; Sat, 3 Feb 2024 22:06:25 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 276AF6B0080; Sat, 3 Feb 2024 22:06:25 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0EF116B0081; Sat, 3 Feb 2024 22:06:25 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 029DB6B007E for ; Sat, 3 Feb 2024 22:06:25 -0500 (EST) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id BAA0980151 for ; Sun, 4 Feb 2024 03:06:24 +0000 (UTC) X-FDA: 81752633088.15.39CD1D0 Received: from out-179.mta1.migadu.com (out-179.mta1.migadu.com [95.215.58.179]) by imf02.hostedemail.com (Postfix) with ESMTP id E0CB28000A for ; Sun, 4 Feb 2024 03:06:22 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=none; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" header.from=bytedance.com (policy=quarantine); spf=pass (imf02.hostedemail.com: domain of chengming.zhou@linux.dev designates 95.215.58.179 as permitted sender) smtp.mailfrom=chengming.zhou@linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1707015983; 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:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=oehZngeZ2nrb2M/GFxupZyVJlDL4AGtR6M2RnEZZxsc=; b=e/Npf5InKAGIHLTmnMLiTC7JUVv4pqsAeHeInRTLKBJvxwz6ctb++xQt3kx5BnqbhsRhuY x8qWvwm8Hta+WSpdSoyjhheGGNNx2GoWV8ZnXQ4abVEiZVPbD4dUtwPFRo4x0k+PRxkp9h xqutBkNoPsitRxUEWPLmul44mCpAYL8= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=none; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" header.from=bytedance.com (policy=quarantine); spf=pass (imf02.hostedemail.com: domain of chengming.zhou@linux.dev designates 95.215.58.179 as permitted sender) smtp.mailfrom=chengming.zhou@linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1707015983; a=rsa-sha256; cv=none; b=3BmHDraDc/4f1EWFFbj/Kllg7ZnMR06Utefr2dD+vKKXo81S7rh7azIeyvGBPANZK7NRUQ 9L3+UI14YZjDoACc4d8lRiS8TeInW7jXhPq8yjs7Yr9DfuoUttUzcCVgRYzrBne4SCH8SV 1BJKnNorL8NXDeFSNxHgRXA4ZUY2V6o= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Chengming Zhou Date: Sun, 04 Feb 2024 03:06:01 +0000 Subject: [PATCH v2 3/6] mm/zswap: stop lru list shrinking when encounter warm region MIME-Version: 1.0 Message-Id: <20240201-b4-zswap-invalidate-entry-v2-3-99d4084260a0@bytedance.com> References: <20240201-b4-zswap-invalidate-entry-v2-0-99d4084260a0@bytedance.com> In-Reply-To: <20240201-b4-zswap-invalidate-entry-v2-0-99d4084260a0@bytedance.com> To: Nhat Pham , Yosry Ahmed , Andrew Morton , Johannes Weiner Cc: linux-mm@kvack.org, Nhat Pham , Chengming Zhou , linux-kernel@vger.kernel.org, Yosry Ahmed , Johannes Weiner X-Migadu-Flow: FLOW_OUT X-Rspam-User: X-Rspamd-Queue-Id: E0CB28000A X-Rspamd-Server: rspam12 X-Stat-Signature: thz6x1jef3cq39rcjwp4u837er1pqi9j X-Rspamd-Pre-Result: action=add header; module=dmarc; Action set by DMARC X-Rspam: Yes X-HE-Tag: 1707015982-652375 X-HE-Meta: U2FsdGVkX198cINser+BLonNTLZdIxB5SgSuMFDrTj3VtGYhoHTJ8R9DGc+kN7ZaiGNh/9z8c66TVh2v3pcqQAclJkQ0s3V2vd90givAJWfIVfEFdDXxV5hGmVW46meXRN9b94QScnpZC+opj+sw4bG4HgGJhpLb4/mejI5dsFJGXaCMhAspaUEQzG9iSr6HPAGZl054iUv9KomtzpbQbAeeRNbQERaw66eblOjullnm0gB5t2Z0tq3L0iGHVIx0i7wkTC8r78sEcheG8LRYVUg8KUDahF7U6e4VYjBZJttALzOHBDkfbO6UiJ8pm17Y8r/mAmLFM33+OvHy1i3SRsrc1It0aNXoIE1ep+afYccPvOdI83nVfcRtCADx0IotWZ67tNTW4o1Ck28DxRrFBS3jZ+RnbxEnfV4E7pr/HnGZFpGSu1B/uLt1ULNfIeNoZRnTZNewMNB4XLT3/koFjDAcJ9B8zSkKniPLvrdBTeeSYnnvus3wWPEoin4zz3kXCEXiw3KcttF7j1itT/x0c+BPCHZJHDHwRvq5/7rhOSi5zZjh9yax+aXcZAAIrs12YYlEwFfT2jxnyaox4iPKDZchq4dTI5oLRTP6ryC8UEuAERebYlJHSjU8j81KPplxfxnu/6RXb4PdDVODgHoAfHRfs3+gcAL0MnzPO/sHx2n+3FMnGfBc5x00a3/PgLppIvG7GAMZak5RZXOzpaN/L4Fmb85s2qRQwQpWUkbqZm5mqwMZMWAuoRPGKLx/MgEtPGLTZJDVQbbwBoBvDskLeGFgt6lNm5/wp019muyJ7jy96iwd0fZ5zwoV8/d9HMuFWcexQgvzHlFAKmq9y3RRFamBUhnKs5xKJ+xJnfygM7SyZVT2OFRd1LqQNsmzZhTYGIYdAIwg6Rt8/4OIonQzhCOla87p03LK1wr2wULQYv6nz7VyUk2yQpzK6tYiEdcpDdSC+NqUlJRflVcp+ch RVbuJfqz acmG2EDjiM1pHLfhqdOk/G9fgYZPE+d2+DOpjikdyHGctlhkhZ217oEUL5qcwblGG5JYzcVJHgum5qd9TdEdDiXwlsIthhHAs/5tPBnZ6j/N8NpNG0xrAcxDvubkP3FFLU2SKanFFGLL0sqiWi0im35qkH+jjTfBwZjq/LRGfd5l7LIhqycaOmx2o5YK9VeBY3uQaPyU4ClkrFfCUXOxAMKkZDDjNt2wEiQccY3sGJsmxQn70EkpB6UJMRKQ9azWR2DJz2TQ01LrXsZpYraqHadW6+Urno+/dkF5uutNVaO9d2doiM2DvVJiQqOTArIrTUXjkFVlfOtyKHg0twnzDUSCpFCoUXN4WHGaHL8K/OauASwlk+rCVpldmusC/gxs2Mz5GKZ93XRmcZgNO5fHjrF2jAjzRYg0jQb3Bw7EHMfr3AnLIh+PZ3iGd9XcI11hrRpduWY/6F89sL9HAOt4Y95WhIQ== 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: When the shrinker encounter an existing folio in swap cache, it means we are shrinking into the warmer region. We should terminate shrinking if we're in the dynamic shrinker context. This patch add LRU_STOP to support this, to avoid overshrinking. Acked-by: Johannes Weiner Acked-by: Nhat Pham Reviewed-by: Yosry Ahmed Signed-off-by: Chengming Zhou --- include/linux/list_lru.h | 2 ++ mm/list_lru.c | 3 +++ mm/zswap.c | 4 +++- 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/include/linux/list_lru.h b/include/linux/list_lru.h index f2882a820690..792b67ceb631 100644 --- a/include/linux/list_lru.h +++ b/include/linux/list_lru.h @@ -24,6 +24,8 @@ enum lru_status { LRU_SKIP, /* item cannot be locked, skip */ LRU_RETRY, /* item not freeable. May drop the lock internally, but has to return locked. */ + LRU_STOP, /* stop lru list walking. May drop the lock + internally, but has to return locked. */ }; struct list_lru_one { diff --git a/mm/list_lru.c b/mm/list_lru.c index 61f3b6b1134f..3fd64736bc45 100644 --- a/mm/list_lru.c +++ b/mm/list_lru.c @@ -243,6 +243,9 @@ __list_lru_walk_one(struct list_lru *lru, int nid, int memcg_idx, */ assert_spin_locked(&nlru->lock); goto restart; + case LRU_STOP: + assert_spin_locked(&nlru->lock); + goto out; default: BUG(); } diff --git a/mm/zswap.c b/mm/zswap.c index d8bb0e06e2b0..4381b7a2d4d6 100644 --- a/mm/zswap.c +++ b/mm/zswap.c @@ -1315,8 +1315,10 @@ static enum lru_status shrink_memcg_cb(struct list_head *item, struct list_lru_o * into the warmer region. We should terminate shrinking (if we're in the dynamic * shrinker context). */ - if (writeback_result == -EEXIST && encountered_page_in_swapcache) + if (writeback_result == -EEXIST && encountered_page_in_swapcache) { + ret = LRU_STOP; *encountered_page_in_swapcache = true; + } } else { zswap_written_back_pages++; }