From patchwork Sat Aug 10 06:15:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ge Yang X-Patchwork-Id: 13759430 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 8F51DC3DA7F for ; Sat, 10 Aug 2024 06:16:23 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B15DC6B008A; Sat, 10 Aug 2024 02:16:22 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id AC6686B0092; Sat, 10 Aug 2024 02:16:22 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9B44F6B0095; Sat, 10 Aug 2024 02:16:22 -0400 (EDT) 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 82B006B008A for ; Sat, 10 Aug 2024 02:16:22 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id D56DE12013B for ; Sat, 10 Aug 2024 06:16:21 +0000 (UTC) X-FDA: 82435326162.09.0C53C27 Received: from m16.mail.126.com (m16.mail.126.com [117.135.210.7]) by imf12.hostedemail.com (Postfix) with ESMTP id E5AA340014 for ; Sat, 10 Aug 2024 06:16:18 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=126.com header.s=s110527 header.b=OgsJwxET; dmarc=pass (policy=none) header.from=126.com; spf=pass (imf12.hostedemail.com: domain of yangge1116@126.com designates 117.135.210.7 as permitted sender) smtp.mailfrom=yangge1116@126.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1723270530; a=rsa-sha256; cv=none; b=Vh8IcmLLCdQ2Qy/kTJbjnwz5nEdZbC4LlliBeJ4TjvnQp36WEp7vGVwaopE5WmF4XgIG2O 4GD94oacLja2D201sgpPP1hcn+UGSDVVBp5Uj2DOEGaDp4L9iFMtphVuAUYPoD+73awuqH gX0pmdeDIJmICMf4cJx5+nJJMqWmV64= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=126.com header.s=s110527 header.b=OgsJwxET; dmarc=pass (policy=none) header.from=126.com; spf=pass (imf12.hostedemail.com: domain of yangge1116@126.com designates 117.135.210.7 as permitted sender) smtp.mailfrom=yangge1116@126.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1723270530; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:content-type: content-transfer-encoding:in-reply-to:references:dkim-signature; bh=LIGLXSFjNXiP5pR+2/To2QWyASHDuTsautJcNOBg/+o=; b=3eQ+b86i9bhf0x58uwxAF6RdDhLi8+dxcanH+cIuNiYbxttfQ8u0mc//52440tRI+h3Scd AqmOpkWc1tvBqS72Vx5tIhrDzmd6KZdabdnYu0xv06uu4mJk29UWta+8jjeLt24oLzoagR xvNSyWRc6dQbuGYZ3vkpNajnD/Ano6s= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=126.com; s=s110527; h=From:Subject:Date:Message-Id; bh=LIGLXSFjNXiP5pR+2/ To2QWyASHDuTsautJcNOBg/+o=; b=OgsJwxETnr4hrNrtWZOUEs6O1nbmQKOuEU qhmyz/8lukp2YwFFLaITKX7m5NA98vIjr8k8q4dU5X4pZNk55yMfrJcnbX+OSKOs RilSt8l2RLkGH/jXfL8i7M9udsaAEQzFuCa0UW5bLiKDSzT/UVLnuYz1kg9V9I0J a2iSqKLfo= Received: from hg-OptiPlex-7040.hygon.cn (unknown [118.242.3.34]) by gzga-smtp-mta-g0-0 (Coremail) with SMTP id _____wDnrzWiBbdmdazfAA--.16456S2; Sat, 10 Aug 2024 14:16:03 +0800 (CST) From: yangge1116@126.com To: akpm@linux-foundation.org Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, 21cnbao@gmail.com, david@redhat.com, baolin.wang@linux.alibaba.com, liuzixing@hygon.cn, yangge Subject: [PATCH] mm/swap: take folio refcount after testing the LRU flag Date: Sat, 10 Aug 2024 14:15:58 +0800 Message-Id: <1723270558-31674-1-git-send-email-yangge1116@126.com> X-Mailer: git-send-email 2.7.4 X-CM-TRANSID: _____wDnrzWiBbdmdazfAA--.16456S2 X-Coremail-Antispam: 1Uf129KBjvdXoW7Xw4UArWfWw4rWw47uw4DJwb_yoWkGrg_Kr 48tas5Wayrtrn3KF1ft347Xr92va93Cr1j9F4xtF43Ary5t3Z7AF4kKF13uryxWF4rCrs5 Z3yDAws8AwnxCjkaLaAFLSUrUUUUjb8apTn2vfkv8UJUUUU8Yxn0WfASr-VFAUDa7-sFnT 9fnUUvcSsGvfC2KfnxnUUI43ZEXa7xRi2Nt3UUUUU== X-Originating-IP: [118.242.3.34] X-CM-SenderInfo: 51dqwwjhrrila6rslhhfrp/1tbiGAY3G2VLdFPbZgAAsG X-Rspamd-Queue-Id: E5AA340014 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: bmq9ta43dc7orky4farhkihadmx1csi3 X-HE-Tag: 1723270578-129718 X-HE-Meta: U2FsdGVkX1/DkNvzZXtmYbHkBX/N5F/5s2egoCQ+VHCthVvRGS25dsVC1RF3VOD4WEZxlKEVMfUhXqzfeumhbGg93Jpg0NTnfADluuJQRQl7+M5skPhnGlgQwFApqkeSYW8p7O8f+rEl3pl7wiS8J0NJlYiQhwM1mfDCmRWeRg4JAP+w19ZkHIBe0I10MKOaXEjY1PJvKY9WkEogHZNpZPNP+y835eIlXQ7Y8HHH/l3lggQbiIeuuuPutr+STFDDQsSZuqS4Vv8gL4Q5vEpNeT5vVaeSP9DFYk4owgY+iEW57Sd3KHVps3S6phkhWpePL1kp8kSY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kmgrlL49mbC34Ucg0z0kqngzK8= 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: From: yangge Whoever passes a folio to __folio_batch_add_and_move() must hold a reference, otherwise something else would already be messed up. If the folio is referenced, it will not be freed elsewhere, so we can safely clear the folio's lru flag. As discussed with David in [1], we should take the reference after testing the LRU flag, not before. Link: https://lore.kernel.org/lkml/d41865b4-d6fa-49ba-890a-921eefad27dd@redhat.com/ [1] Signed-off-by: yangge Acked-by: David Hildenbrand --- mm/swap.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/mm/swap.c b/mm/swap.c index 67a2467..6b83898 100644 --- a/mm/swap.c +++ b/mm/swap.c @@ -226,12 +226,10 @@ static void __folio_batch_add_and_move(struct folio_batch __percpu *fbatch, { unsigned long flags; - folio_get(folio); - - if (on_lru && !folio_test_clear_lru(folio)) { - folio_put(folio); + if (on_lru && !folio_test_clear_lru(folio)) return; - } + + folio_get(folio); if (disable_irq) local_lock_irqsave(&cpu_fbatches.lock_irq, flags);