From patchwork Thu Apr 25 08:40:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kefeng Wang X-Patchwork-Id: 13642968 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 E92B0C19F4E for ; Thu, 25 Apr 2024 08:41:02 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EEBD46B0087; Thu, 25 Apr 2024 04:40:56 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A5F636B0093; Thu, 25 Apr 2024 04:40:56 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6DC776B0096; Thu, 25 Apr 2024 04:40:56 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 15AF56B008A for ; Thu, 25 Apr 2024 04:40:56 -0400 (EDT) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id C4C97A041C for ; Thu, 25 Apr 2024 08:40:55 +0000 (UTC) X-FDA: 82047408870.27.2240708 Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) by imf05.hostedemail.com (Postfix) with ESMTP id 7C8BB100007 for ; Thu, 25 Apr 2024 08:40:53 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf05.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.189 as permitted sender) smtp.mailfrom=wangkefeng.wang@huawei.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1714034454; 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=9/bUAZGbcia7hUeDGEA76soBivbT09Wey2IhVaRzpcE=; b=h9Y9RhNY7eCoaTJDENSeB0ct4tKE7NNUfCxvEBQy0Kq3WexgiX7nYTuNjLNkkxTcxbd5wD npCBvq7hDJApAncL7sMbKLMXxzSLiYrifoCz1YNLmn9s/u2fW0yeQQ54bHqXShTLizTIXL LmIwym5w8Z/lOhqOMw/O1htzwgBJ9Vc= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf05.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.189 as permitted sender) smtp.mailfrom=wangkefeng.wang@huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1714034454; a=rsa-sha256; cv=none; b=MfFNCPs4vwLeMktRC6ZKegtLvECCqZYnENYfHdPbX1nC+mg0SYaGYEQfMg1mxlEw4EbfR0 0fZwVnIfb+GMy6bU5wDtRavX2A8WieJE4Ov6WuU3zcM37kwoQswz8DY2RLeGxBfzuYHiYH HswB2gkQ1DUB0tX4gGGIhWCHJaRcb5I= Received: from mail.maildlp.com (unknown [172.19.163.174]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4VQ8Q16zCHzNtHh; Thu, 25 Apr 2024 16:38:17 +0800 (CST) Received: from dggpemm100001.china.huawei.com (unknown [7.185.36.93]) by mail.maildlp.com (Postfix) with ESMTPS id 64357140257; Thu, 25 Apr 2024 16:40:50 +0800 (CST) Received: from localhost.localdomain (10.175.112.125) by dggpemm100001.china.huawei.com (7.185.36.93) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.35; Thu, 25 Apr 2024 16:40:49 +0800 From: Kefeng Wang To: Andrew Morton CC: , David Hildenbrand , Miaohe Lin , Naoya Horiguchi , Oscar Salvador , Zi Yan , Hugh Dickins , Jonathan Corbet , , Vishal Moola , Kefeng Wang Subject: [PATCH v2 04/10] mm: compaction: try get reference before non-lru movable folio migration Date: Thu, 25 Apr 2024 16:40:22 +0800 Message-ID: <20240425084028.3888403-5-wangkefeng.wang@huawei.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20240425084028.3888403-1-wangkefeng.wang@huawei.com> References: <20240425084028.3888403-1-wangkefeng.wang@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.112.125] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) To dggpemm100001.china.huawei.com (7.185.36.93) X-Rspam-User: X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 7C8BB100007 X-Stat-Signature: m7pa5g79wdeb5yrce1m8szych7kw9jt1 X-HE-Tag: 1714034453-755605 X-HE-Meta: U2FsdGVkX1/lA5Og18/LoBtn9DA9J2TMazq9wWwM0cw5m0QQ+dVGMgjlUnoAlgI9BsyOTbhUB8xRNiA9Qr9jhfQZRDvNodkZAiOUQ5NafhijGbyMLCcx2tU+UObRRPdhQc49TyYep4oYHFocOlMxxZIjnqNxAcqaZ+FlN/XY0kHsMeVqsRhSj80+NF67pO8Z6Vjc0EPFF+9X7UWQBp8DwjWK6ex8x1+ryyPC5PCOdr6I4ivSvZr3xM/UYpIbyJ0DgugdCFktNtphwZiLGTt+Ca+Ae1XJwvOWUj4cnunq2YAHC/4m9BlePansVACE75jf3l6vCAOgpQPTJGIjzNUf2Fg2Vn1faw98GHExvAplnnQ3U23PlPyxVW2y82I0SeFlhosqOK+krEqUq2K/AAcgejzEq0qYw4UuPWdnnpymKrowNm4iCkNUtUIR7pdnKTvME/b/roIWrxINda9w/FEmSw5kIraVoquR0o1uvG/OK5rV3Kr1DkD9h/uNlsyRUZJz6q+Fwi6hf+73Etbb5i9vWQ52N4fyjavTk8GUKU/9mgbQmSzEF4xD6WUboq6Q1tSddlppdJRIWTvk4x4Xhki6kv47hlF9o3O9e6EdE/1o1ZRMxLFHJom7iqlB2oUka1FarVv5p4hvJVQapZgX9WGhu5LIrzbXbCubjwdj3GSvvNHUoETgnw+1xCw+g4h4tzS4yh1QY8GFd49Z5uko13lAnmF2PrQLZhehTWnqMhbkIHAmLuXYybWRcefgytPw63aMUz5MqRuPmvWx4OKVBLwAc0V2DZU48hitIDJ6m/+lSENmLAEwqpYKFuATyJhtpU89a0Eki7vOOMxgSC7rfYXC254+0bQ8ViZOqA5lBPz15EmGNNqcjjCjMaZCErI3Su3Pfr3qz3UY59yXPMfwpU+c7AeZ5pueiaFVMcIzrfgH/So= 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 migration will fail if !folio_get_nontail_page(), see isolate_movable_page(), so does lru folio, so folio_get_nontail_page() could be called firstly to unify the handling of non-lru movable/lru folios migration a bit, this is also to 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 e731d45befc7..4fc5a19b06ad 100644 --- a/mm/compaction.c +++ b/mm/compaction.c @@ -1097,41 +1097,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 folios. + * Skip any other type of folio */ - 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 folio 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