From patchwork Mon Feb 5 23:24:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nhat Pham X-Patchwork-Id: 13546423 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 0D9FAC4828D for ; Mon, 5 Feb 2024 23:24:46 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6294E6B0083; Mon, 5 Feb 2024 18:24:46 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 5D9676B0085; Mon, 5 Feb 2024 18:24:46 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4A0B96B0087; Mon, 5 Feb 2024 18:24:46 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 3B3156B0083 for ; Mon, 5 Feb 2024 18:24:46 -0500 (EST) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id EED901A0B2A for ; Mon, 5 Feb 2024 23:24:45 +0000 (UTC) X-FDA: 81759332130.09.3403915 Received: from mail-qk1-f177.google.com (mail-qk1-f177.google.com [209.85.222.177]) by imf26.hostedemail.com (Postfix) with ESMTP id 40C86140003 for ; Mon, 5 Feb 2024 23:24:44 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=ifsi3qPq; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf26.hostedemail.com: domain of nphamcs@gmail.com designates 209.85.222.177 as permitted sender) smtp.mailfrom=nphamcs@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1707175484; a=rsa-sha256; cv=none; b=bzfayYdihYZL32IOjvo7MKSYTtffw8sNE29y05EQ+v52ZLldpG+oc1T2lfGE24rnKPTQ1f XVQc5HG+awWGmZc5Rary54PQ6xINeVI51Xigr7scM6Og2NFgZ+4k24YwBeQYCAtOQq/smJ GPVUEHH8+VoBPJfydpFlYPRcREDiA60= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=ifsi3qPq; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf26.hostedemail.com: domain of nphamcs@gmail.com designates 209.85.222.177 as permitted sender) smtp.mailfrom=nphamcs@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1707175484; 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-transfer-encoding:content-transfer-encoding: in-reply-to:references:dkim-signature; bh=Y64gFmrSep8Jb0vFEjY7ZG/bOjun6eItlr5gW+o3hIQ=; b=aUpROtllFYh+P4c1JAM3ypBCdUlI7XES/4cQAyv8+xn2g0cs0M+y2cc8C3LlwhgyFwrP7v pQ5TINRgw0rtAU6kIV4Ae74cl5UfLO1j5/Q1+iWsmUyvo7zn17j6ppbISYIkXHobnqAT9v pF/pG9b3TIBKONCVfQf8pPZBw49to6c= Received: by mail-qk1-f177.google.com with SMTP id af79cd13be357-783da8920e5so311775285a.1 for ; Mon, 05 Feb 2024 15:24:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1707175483; x=1707780283; darn=kvack.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=Y64gFmrSep8Jb0vFEjY7ZG/bOjun6eItlr5gW+o3hIQ=; b=ifsi3qPqZ2Y+YRZLDd/BYmYoXK4BnrTfs+zVUMdQFuRBvysq317TdQNIY43pIh+b6n lFBZJBEkDkIkTveizK2ogveNHl4I7NrSKzPFF8Hvoq9fcT9SpUGwQVceFra4AwJbfs+O smJb/IuqS2bVVwY+pKwGs/pZOx3eW0rMf1PCRMzZ+FfhgTH7Fj+KZj13yZT29bdNuI26 Gco7t816mP2GUtxZd51VgBSKu+1tvEs6PX0iinAcUTFC8qp/l0LUqWc81GiKGipnHL/X OKQ7QIMORo+7Mck3+iZFcXo/Hj+qleD9aX+LgJIGYmIMekMi3JEE31YXaggTTBTZQIKj IrDw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707175483; x=1707780283; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=Y64gFmrSep8Jb0vFEjY7ZG/bOjun6eItlr5gW+o3hIQ=; b=cIEbWBYNXEe1vX0YYyyqX3wVUddxcpyv78n/vuIIqqM+s9UTK9t/yqHZZvLcdcI8/I 2Ishm28vIm3o6vIJHH0fhs8p9fRsyLyjG3lj6PjD4octDlY+QZcr8T8Ms7lmvIV/v/iZ npXxgChWjFF2puwfbf67kyrM0zIMoakyRCzuK9cvjFt3YiWgLBQ8YldJhci03hglipeY bbLS5f91a4XbPX6ydI1PHZN+7iqbpVx3qrztQzwmiiOOTWBShr3j8L3xtc2fuF3CeHqP IK0Rrg95YZ18j/Y9e9JxHQOOlSe6FHcsvMX4k0Z6OKErOf/P146IiA1YrkbKNMjeg1ti 3ZXw== X-Gm-Message-State: AOJu0YzDjSOfI4lZ+k3JBrIEIeFkCkpz0iYJFQDJdJNhZYh7HbKEmq+s pzOPv6B7AwPWK1PKKKgFX8xlpvx8qCU2u3oRBR4loYxxevE6+IQM X-Google-Smtp-Source: AGHT+IH/EtuMqGFyfpQGNw+Sk+j1APJiECASWsMkSGapslq+bKPOrPjwErrzftRMZZugX15IhqfMBw== X-Received: by 2002:ad4:5bc9:0:b0:68c:50cf:9e1a with SMTP id t9-20020ad45bc9000000b0068c50cf9e1amr976939qvt.33.1707175483242; Mon, 05 Feb 2024 15:24:43 -0800 (PST) X-Forwarded-Encrypted: i=0; AJvYcCWFKPVGcaS7HRKV0boBMfOmKjCW6tYNmFzg3u1JcmUEjLeIbHUyDogSKn7EluFN0t5C8SgnfrdebJwyRZUBb3CStDUa4OCd8qvp8yMqqlX225LnoD1qrv1v30hXz0dGAwozwbNerq9TY5TFF3ZMOhBFGMx5rwEXiea7buzcsk3XqX90hNYi2S7oufD+hxgx3UD1VF2OlGBDt/Cx+Wg5OSicWCiY/vq6DA== Received: from localhost (fwdproxy-nao-009.fbsv.net. [2a03:2880:23ff:9::face:b00c]) by smtp.gmail.com with ESMTPSA id n8-20020a05620a222800b007840c63ad70sm389447qkh.15.2024.02.05.15.24.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Feb 2024 15:24:43 -0800 (PST) From: Nhat Pham To: akpm@linux-foundation.org Cc: hannes@cmpxchg.org, chengming.zhou@linux.dev, yosryahmed@google.com, linux-mm@kvack.org, kernel-team@meta.com, linux-kernel@vger.kernel.org Subject: [PATCH] mm/swap_state: update zswap LRU's protection range with the folio locked Date: Mon, 5 Feb 2024 15:24:42 -0800 Message-Id: <20240205232442.3240571-1-nphamcs@gmail.com> X-Mailer: git-send-email 2.39.3 MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 40C86140003 X-Stat-Signature: 1t8cnd5gbm7nfh561qhmccdmk83dr5t8 X-HE-Tag: 1707175484-821590 X-HE-Meta: U2FsdGVkX19RBhboN9uPhue0haR/Q9A2G/NsYXpRmV/CaFIBFgrhnGRuLOL/rxLNcLotyng4W2Hgd1tCGs7oTUiaFgjuXRXaPx9aQnKb6LNvzE0M4oXY/arcjyWlA6yBGJota7cgqy3X/2E8QGxYD/4Xyrz+WnqRbPXuYI5A6DFV4rEEV6JzJsd76o/WtYU+zioAy9JXNczh7tDv043r+RGHDZGfZLak5ga/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pz6pWiONIEv7syHBARkAThNoUlfeCM0b/PpOtXTmLsxAYfbjjGb45CV2B+T6sQd5xe8+8nwBO8eOY87LDNr0i2e2JQyI6yvqY4N8GBQg92tI+IzJPwM8Vapg9A3JqW58AiPNO3hRb4a7uJSdwKTKCsB8nda+jm2hp0r65dwsTeKXBKg+5VJO1ktQnNlzdBm8B2VDFpW78B5kZCICeFgQR06Omaogesg2frspiBzQHpupZJvAXT0mnHav14mJvF17xyLpJoKM45t+X7qDZfa3FmE6X+BkwNJlRRPE9DsotmHhs= X-Bogosity: Ham, tests=bogofilter, spamicity=0.022617, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Move the zswap LRU protection range update above the swap_read_folio() call, and only when a new page is allocated. This is the case where (z)swapin could happen, which is a signal that the zswap shrinker should be more conservative with its reclaiming action. It also prevents a race, in which folio migration can clear the memcg_data of the now unlocked folio, resulting in a warning in the inlined folio_lruvec() call. Reported-by: syzbot+17a611d10af7d18a7092@syzkaller.appspotmail.com Closes: https://lore.kernel.org/all/000000000000ae47f90610803260@google.com/ Fixes: b5ba474f3f51 ("zswap: shrink zswap pool based on memory pressure") Signed-off-by: Nhat Pham Reviewed-by: Chengming Zhou --- mm/swap_state.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) base-commit: 91f3daa1765ee4e0c89987dc25f72c40f07af34d diff --git a/mm/swap_state.c b/mm/swap_state.c index e671266ad772..7255c01a1e4e 100644 --- a/mm/swap_state.c +++ b/mm/swap_state.c @@ -680,9 +680,10 @@ struct folio *swap_cluster_readahead(swp_entry_t entry, gfp_t gfp_mask, /* The page was likely read above, so no need for plugging here */ folio = __read_swap_cache_async(entry, gfp_mask, mpol, ilx, &page_allocated, false); - if (unlikely(page_allocated)) + if (unlikely(page_allocated)) { + zswap_folio_swapin(folio); swap_read_folio(folio, false, NULL); - zswap_folio_swapin(folio); + } return folio; } @@ -855,9 +856,10 @@ static struct folio *swap_vma_readahead(swp_entry_t targ_entry, gfp_t gfp_mask, /* The folio was likely read above, so no need for plugging here */ folio = __read_swap_cache_async(targ_entry, gfp_mask, mpol, targ_ilx, &page_allocated, false); - if (unlikely(page_allocated)) + if (unlikely(page_allocated)) { + zswap_folio_swapin(folio); swap_read_folio(folio, false, NULL); - zswap_folio_swapin(folio); + } return folio; }