From patchwork Thu Aug 29 14:54:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kefeng Wang X-Patchwork-Id: 13783355 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 B995CC83F2F for ; Thu, 29 Aug 2024 14:55:10 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6B7E66B0089; Thu, 29 Aug 2024 10:55:07 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 640466B008A; Thu, 29 Aug 2024 10:55:07 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4E2796B008C; Thu, 29 Aug 2024 10:55:07 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 1EB456B008A for ; Thu, 29 Aug 2024 10:55:07 -0400 (EDT) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id AE782140B8C for ; Thu, 29 Aug 2024 14:55:06 +0000 (UTC) X-FDA: 82505580612.02.67A4A49 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by imf30.hostedemail.com (Postfix) with ESMTP id 1945680010 for ; Thu, 29 Aug 2024 14:55:02 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=none; spf=pass (imf30.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.187 as permitted sender) smtp.mailfrom=wangkefeng.wang@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1724943185; 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=WtBKDhXYu95JY5c7tiHXMhZnGiWWXdEXj9Mq8yW03Pg=; b=YzMlLiA6MgMMvFuEPpzoW0+L3w27AUS4PitusQZs0J270ev4brRHSnscK+7U9caUK0tw3A JRMTCgOPjrMAhd3ChD/jstL5skDF+aDc5fskh5jI4U3E6Rgv+qU0IBabOf0+85akCx7GeU 70RzvpuEb7OCB3RC2CsFfYeIrL07pvo= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=none; spf=pass (imf30.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.187 as permitted sender) smtp.mailfrom=wangkefeng.wang@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1724943185; a=rsa-sha256; cv=none; b=jn34F0eFYP1Hapwx+h7TYGx0tB288t0K/G9u9DbJEcdrCBiostbi2OzrYXkobKrUZAPupg LDwxAztaovMo3gYL2lCM7FwIjdDVLvytYZ5EZSA2sI6Ao8KXTQZgcNz1RjJyU37l/Aalb0 eNfakKzuvmTfvkBZ1ReWOyNl7Vx4MYg= Received: from mail.maildlp.com (unknown [172.19.163.174]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4WvknX6hxVzyQmk; Thu, 29 Aug 2024 22:54:08 +0800 (CST) Received: from dggpemf100008.china.huawei.com (unknown [7.185.36.138]) by mail.maildlp.com (Postfix) with ESMTPS id EBA0E1402CA; Thu, 29 Aug 2024 22:54:58 +0800 (CST) Received: from localhost.localdomain (10.175.112.125) by dggpemf100008.china.huawei.com (7.185.36.138) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Thu, 29 Aug 2024 22:54:58 +0800 From: Kefeng Wang To: Andrew Morton CC: David Hildenbrand , Matthew Wilcox , Baolin Wang , Zi Yan , Vishal Moola , , Kefeng Wang Subject: [PATCH v2 1/5] mm: compaction: get reference before non LRU movable folio isolation Date: Thu, 29 Aug 2024 22:54:52 +0800 Message-ID: <20240829145456.2591719-2-wangkefeng.wang@huawei.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20240829145456.2591719-1-wangkefeng.wang@huawei.com> References: <20240829145456.2591719-1-wangkefeng.wang@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.112.125] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To dggpemf100008.china.huawei.com (7.185.36.138) X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 1945680010 X-Stat-Signature: 4kiwjamqfawape559u58me9mdmxuxhsq X-Rspam-User: X-HE-Tag: 1724943302-311423 X-HE-Meta: U2FsdGVkX18oYOpN0Dr6FUh6vebgzs1YLebSy2zyZ1AdT0/bHeTqlQICA0l5mHd5FXL1BsMuKRoz53xrhwonYVznsGPxnfmNTb+ErAkHgQXcVkKM7NohnjZYJicmPYQz/7NHZUGvQCR3j7ELxK9It36F6TFhTN8UOT9hSAJzexKLYnQZQRMCIt+2BmOaLoLIv8FdfLj8u24iGgI+H/Q+r7vTYmOW9/OmEUM76pbu2CYV14Cj+P9pHiVYIpEa9M/RtNp06U0hUpI7H9/3QuChwaSRcQF6oeacHSIaqINJ5aZ6/wCzxI+uMsZ/6C8zjBrvXydPoozyFkFrKhnAywh51yl67/h2q2FYWS3MIU+ltMYjfq0Oil27BnoiuhDyrpqzMaskaa43/gHViSfthEXsARsM12ji7NAKkpYggFrmBRMvZj7M4m7jOB22PUWKRjrFi5dMEAtLEQct35FO9AwGEp79xecF1CVclPLqoZKaxQC5sHYhzu+ycs3+iE72dT6fcivlEK66C4gxaHGiy2K6COYrqdbZz3gnX2NCYUS6wZwcb4FjplE+czq65NTj0yv8FPNCza4JoJj7A9zIqaH+a1aELASyz7ihgu8lDmbSbbiqRNWHekkskSv2UkZmwgcAlrx46uIe0drDc7C/+DT9dq7xxfrk/sXaUqSWhJSZS4ZG8bwev+UNaGP5ltIIfzDZY+qClIuFXJuJZW/wjrS3+AiMyziPkhAyN6n4/pz1XOwScA6cS+57dMatwFLdPWQLmlx8kA84dI5I/kp/ENAA/xR5cZVNemOYYFEzZgB3bs42R5nKrQmFprtS7/diCSCyBzgt48A/s92hVH9xtQqVwBdHwkkCmYwZA1RSWgZulUpgnQNd/NDq59/NcHS2aYlWdB1TEEgD3De9MwpkZqWagkRsXwgEQCwWItaZUgrpFBskEr0DybDJa7CMJcxAjCJijaaoze+AgvrlqMdSG+n yW8SFa4W cPZffJAN3ucXK+HYfgVnHXQ18LOJKzRDaU2eoN4SFRNU+Mmls6kl7lAli4slfBiII0ecUG2aGxodsjvIYocqI0TqnzvmwNLPzUn85g3qAE8VrmgQRgmG3CRywS25KumcgEYwcSddCRajLmmVTV7z/2tNO297Ln8lOqNadSTdlrFRHwgw985uv5vrEUM3yVS0XzXCk1kHE3D8lWkBNA6fPDUjrVg== 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: Non-LRU movable folio isolation will fail if it can't grab a reference in isolate_movable_page(), so folio_get_nontail_page() could be called ahead to unify the handling of non-LRU movable/LRU folio isolation a bit, this is also prepare to convert isolate_movable_page() to take a folio. Since the reference count of the non-LRU movable folio is increased, a folio_put() is needed whether the folio is isolated or not. Signed-off-by: Kefeng Wang --- mm/compaction.c | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/mm/compaction.c b/mm/compaction.c index a2b16b08cbbf..8998574da065 100644 --- a/mm/compaction.c +++ b/mm/compaction.c @@ -1074,41 +1074,41 @@ isolate_migratepages_block(struct compact_control *cc, unsigned long low_pfn, } } + /* + * Be careful not to clear lru flag until after we're + * sure the folio is not being freed elsewhere -- the + * folio release code relies on it. + */ + folio = folio_get_nontail_page(page); + if (unlikely(!folio)) + goto isolate_fail; + /* * Check may be lockless but that's ok as we recheck later. - * It's possible to migrate LRU and non-lru movable pages. - * Skip any other type of page + * It's possible to migrate LRU and non-lru movable folioss. + * Skip any other type of folios. */ - if (!PageLRU(page)) { + if (!folio_test_lru(folio)) { /* - * __PageMovable can return false positive so we need - * to verify it under page_lock. + * __folio_test_movable can return false positive so + * we need to verify it under page_lock. */ - if (unlikely(__PageMovable(page)) && - !PageIsolated(page)) { + if (unlikely(__folio_test_movable(folio)) && + !folio_test_isolated(folio)) { if (locked) { unlock_page_lruvec_irqrestore(locked, flags); locked = NULL; } - if (isolate_movable_page(page, mode)) { - folio = page_folio(page); + if (isolate_movable_page(&folio->page, mode)) { + folio_put(folio); goto isolate_success; } } - goto isolate_fail; + goto isolate_fail_put; } - /* - * Be careful not to clear PageLRU until after we're - * sure the page is not being freed elsewhere -- the - * page release code relies on it. - */ - folio = folio_get_nontail_page(page); - if (unlikely(!folio)) - goto isolate_fail; - /* * Migration will fail if an anonymous page is pinned in memory, * so avoid taking lru_lock and isolating it unnecessarily in an