From patchwork Fri Dec 30 07:08:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kefeng Wang X-Patchwork-Id: 13084135 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 AAF35C3DA7C for ; Fri, 30 Dec 2022 06:53:15 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C836F8E0003; Fri, 30 Dec 2022 01:53:11 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id BD6868E000B; Fri, 30 Dec 2022 01:53:11 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9186E8E0006; Fri, 30 Dec 2022 01:53:11 -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 7132F8E0008 for ; Fri, 30 Dec 2022 01:53:11 -0500 (EST) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 47B24A048B for ; Fri, 30 Dec 2022 06:53:11 +0000 (UTC) X-FDA: 80298055782.13.6714661 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by imf25.hostedemail.com (Postfix) with ESMTP id 44C62A000B for ; Fri, 30 Dec 2022 06:53:08 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf25.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.188 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=1672383189; 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=8dmIvNeYv2WzwsuX+phCpp3DT1r6ESPMuw4tfvgMB+A=; b=QtBdZ7ZW3muT9ZZ3/6g6os4MXnGGXes2ScC/2jAab5qxu03025oHbPFVrZgHvCjWFRznUw r6ujPEE+VdLfBX1VuaxuVaGwrQWjoJB5Ds6UN+yaL7HlZHWLY4O2uRYtHpAXWzPo2EfmwN O/FUgoDDa2fAQE8TxG2jsLfy20u69bE= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf25.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.188 as permitted sender) smtp.mailfrom=wangkefeng.wang@huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1672383189; a=rsa-sha256; cv=none; b=djn/U8+MjSQpf8XE9EEtzwJ2icXSuma/ZtNYOzC/Tb4DJwsov2PVQAGZAUmOWFO/qVQxKs YgcXp7Mx41ZT7Kty+GGWXqqBDHXG3i8poHn1uDrExQRl2WiwJ8nj5T7ld/dXZsTBP1ByFK g3ftHJop8BC8aAlhXE6jorhQqX1z19Q= Received: from dggpemm500001.china.huawei.com (unknown [172.30.72.55]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4NjwsR5CFBzRqPX; Fri, 30 Dec 2022 14:51:39 +0800 (CST) Received: from localhost.localdomain.localdomain (10.175.113.25) by dggpemm500001.china.huawei.com (7.185.36.107) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Fri, 30 Dec 2022 14:53:03 +0800 From: Kefeng Wang To: Andrew Morton , SeongJae Park CC: , , , , , Kefeng Wang Subject: [PATCH -next v4 3/8] mm/damon: introduce damon_get_folio() Date: Fri, 30 Dec 2022 15:08:44 +0800 Message-ID: <20221230070849.63358-4-wangkefeng.wang@huawei.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20221230070849.63358-1-wangkefeng.wang@huawei.com> References: <20221230070849.63358-1-wangkefeng.wang@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.113.25] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) To dggpemm500001.china.huawei.com (7.185.36.107) X-CFilter-Loop: Reflected X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 44C62A000B X-Stat-Signature: e8gxcueb8mxizd7ysim7cbfn491jrrx9 X-HE-Tag: 1672383188-485863 X-HE-Meta: U2FsdGVkX19Tl4RNRCkJcDfK65NhOVP5mxpwFUAq8FLRCGDIRc+4d1pwR0vblwK9uPmDWHoQjen4Riw9ySEBO+ZOH9wKDBJ0K1lHh0WFdMEg+8vZmWMqj++B3VK7eyzpZwWM3nMdVkU0Jgr1qbrBJUSVKVZyQoFI64ENwBYGW8oHpaKhXEJ8BA0GvaV2cFnsR+blqomWXli0TejV5XNGNE2MTy+buvhRG8WIU63+aF2cSt5zxkVLyzLD5h3qL+DTA9P1vR7AItFhCYrqZqTpb2a0vrBzcC6LNj4wM3H6sUDph92nZhEMS5Ysudtq+rSQuMvC+Dpm804otDTBXagNh5pDzCnvmHLETvTE5m5MMvDeJG3EHFpLB2R3S1lgnZbew5dglu1sh1lw83YQ8H+Zrk/sM0a90sM0+SlvksnxQuqG1BZYqkyEVfNtT6bBr8xOLM6i8GkjO+XE+nhmW7Jplrm7NVSTFPQ6ylu6aFDvCTWvOJAtF5eD3CBedBQRADhGfAU83w4w9+hEmIT4W7VlrpevYCr5OVwjl+c5U1l4qtsI6hCq0L2dz8pH0FPcxfbUIUV5dBnmx6Hj3gTh53VeTkzCPDYWGns5+MyQfczoxuT3SC+OWtdjA7gdLkHxwVQFZB7liWh4iQ+IyB3ZAEhoITP9oIUQxFiNQ0o2NxXMz3C4zdI9wwQwhOlvdLBXfao8B7RHqcUlHPHAH0LWVA3Eww/WDkVN8R1osnteZhoHB/q8kgiXwDkP0CTUEamSskkVG3vATYz1fL9gal3zNy174npucgRE2dZJjeav99sLvnyYs7l+4G948SaOqI6jqUEZ9R4m6tu061RxGqKEde+DLg2150PfgEy3BbgDiHdq5R8iM62nTdjgdthbADy0IeyMTxNHJopqH1uHL/5EtRvyC2H+jR3kewSOmrGEdcNybL911K/OzGTJO4tXYK/nLsB12kRCbpEwNpFJ1EHTHZF rHZ0hMQV D1e/W2K3wlDiIZB4= 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: Introduce damon_get_folio(), and the temporary wrapper function damon_get_page(), which help us to convert damon related functions to use folios, and it will be dropped once the conversion is completed. Reviewed-by: SeongJae Park Signed-off-by: Kefeng Wang --- mm/damon/ops-common.c | 18 +++++++++++------- mm/damon/ops-common.h | 9 ++++++++- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/mm/damon/ops-common.c b/mm/damon/ops-common.c index 75409601f934..1294a256a87c 100644 --- a/mm/damon/ops-common.c +++ b/mm/damon/ops-common.c @@ -16,21 +16,25 @@ * Get an online page for a pfn if it's in the LRU list. Otherwise, returns * NULL. * - * The body of this function is stolen from the 'page_idle_get_page()'. We + * The body of this function is stolen from the 'page_idle_get_folio()'. We * steal rather than reuse it because the code is quite simple. */ -struct page *damon_get_page(unsigned long pfn) +struct folio *damon_get_folio(unsigned long pfn) { struct page *page = pfn_to_online_page(pfn); + struct folio *folio; - if (!page || !PageLRU(page) || !get_page_unless_zero(page)) + if (!page || PageTail(page)) return NULL; - if (unlikely(!PageLRU(page))) { - put_page(page); - page = NULL; + folio = page_folio(page); + if (!folio_test_lru(folio) || !folio_try_get(folio)) + return NULL; + if (unlikely(page_folio(page) != folio || !folio_test_lru(folio))) { + folio_put(folio); + folio = NULL; } - return page; + return folio; } void damon_ptep_mkold(pte_t *pte, struct mm_struct *mm, unsigned long addr) diff --git a/mm/damon/ops-common.h b/mm/damon/ops-common.h index 8d82d3722204..65f290f0a9d6 100644 --- a/mm/damon/ops-common.h +++ b/mm/damon/ops-common.h @@ -7,7 +7,14 @@ #include -struct page *damon_get_page(unsigned long pfn); +struct folio *damon_get_folio(unsigned long pfn); +static inline struct page *damon_get_page(unsigned long pfn) +{ + struct folio *folio = damon_get_folio(pfn); + + /* when folio is NULL, return &(0->page) mean return NULL */ + return &folio->page; +} void damon_ptep_mkold(pte_t *pte, struct mm_struct *mm, unsigned long addr); void damon_pmdp_mkold(pmd_t *pmd, struct mm_struct *mm, unsigned long addr);