Received: by 2002:a05:6a10:d5a5:0:0:0:0 with SMTP id gn37csp3132669pxb; Sat, 9 Oct 2021 02:40:11 -0700 (PDT) X-Google-Smtp-Source: ABdhPJycNDY2UlGMJCMK1U1bBE3+96UWZRL8vwL9Rnr79ELRdjJZ3ir4VQdps4UsSxgY9ZHd/tTC X-Received: by 2002:a63:1d53:: with SMTP id d19mr8645175pgm.85.1633772411358; Sat, 09 Oct 2021 02:40:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633772411; cv=none; d=google.com; s=arc-20160816; b=v896ZQEsYHFxucnphy6SlIC94U8NP076w3/wuEOCpu/v0pkx2BigvpFKrEyCx9JPDR E5NpU30gvfQY18yH4KJ5LNLxCptfl590dXdTXgrFpARr5yhbYgF0Y0fvGu2hmKehY8AU 4T9OrZxFjwVjmH8IOTFKbb3E9YvqhixnM+4lvbbfWQyQOYEfckUzYHkuTRgRXMo2fqhn dhS9l9qtMEOjABAThyQPFqMNmZGEz54YILoJluvafwj5DkvDSVex3nlkDtq0kCzSR5Ko j5EdvkoCsxh2nCQL3sw1z3r5eiGq9gYgVTAuoguCRGBzxKzyUy/swkroJJo0Ap9TuRBf fw2w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=SioM9xKmGN8vJ3DCRoUiyK7f3w1S9mmqTAeLqtqDDus=; b=OqYPgebAdlqsrfzGFn3dbjyt78MP4Bk7HGuiCpTG05UQhiaxMfY3B7M+SNuf4gQoSE /bP3R5XZWaJZ51Az/rA93XyJzrM/XhVeWMCPioJRsYRpOIAKAHLmuDnHQDSg438kBXZH NxHzOXOduAW4XdH7JoUknb0xdOLxdU3jdI0HSoW4RMguEZ8vp6QHwtIlF+s0flHPoQYI tm+Dj8StFOw6fEKh8b5G7es2n5NCoV9FDez72JFVlOye+mN/l58Kx+sX0nndhas4oloK Rnm4j5IAMhbsal+GvcOt0tRmeRp0/Sd5eZ9aRf4sDmEt73ykKiXUs82ZzDJRpaHZRooP CX3Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d17si2310343plh.259.2021.10.09.02.39.58; Sat, 09 Oct 2021 02:40:11 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244511AbhJIJlL (ORCPT + 99 others); Sat, 9 Oct 2021 05:41:11 -0400 Received: from szxga01-in.huawei.com ([45.249.212.187]:13716 "EHLO szxga01-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231598AbhJIJlF (ORCPT ); Sat, 9 Oct 2021 05:41:05 -0400 Received: from dggemv711-chm.china.huawei.com (unknown [172.30.72.57]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4HRKjB4krKzWjdh; Sat, 9 Oct 2021 17:37:34 +0800 (CST) Received: from dggpemm500005.china.huawei.com (7.185.36.74) by dggemv711-chm.china.huawei.com (10.1.198.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.8; Sat, 9 Oct 2021 17:39:06 +0800 Received: from localhost.localdomain (10.69.192.56) by dggpemm500005.china.huawei.com (7.185.36.74) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.8; Sat, 9 Oct 2021 17:39:06 +0800 From: Yunsheng Lin To: , CC: , , , , , , , , , , , , , , , , , , , , , , , , Subject: [PATCH net-next -v5 3/4] mm: introduce __get_page() and __put_page() Date: Sat, 9 Oct 2021 17:37:23 +0800 Message-ID: <20211009093724.10539-4-linyunsheng@huawei.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211009093724.10539-1-linyunsheng@huawei.com> References: <20211009093724.10539-1-linyunsheng@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.69.192.56] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To dggpemm500005.china.huawei.com (7.185.36.74) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Introduce __get_page() and __put_page() to operate on the base page or head of a compound page for the cases when a page is known to be a base page or head of a compound page. Signed-off-by: Yunsheng Lin --- include/linux/mm.h | 21 ++++++++++++++------- mm/swap.c | 6 +++--- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/include/linux/mm.h b/include/linux/mm.h index 73a52aba448f..5683313c3e9d 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -902,7 +902,7 @@ static inline struct page *virt_to_head_page(const void *x) return compound_head(page); } -void __put_page(struct page *page); +void __put_single_or_compound_page(struct page *page); void put_pages_list(struct list_head *pages); @@ -1203,9 +1203,8 @@ static inline bool is_pci_p2pdma_page(const struct page *page) #define page_ref_zero_or_close_to_overflow(page) \ ((unsigned int) page_ref_count(page) + 127u <= 127u) -static inline void get_page(struct page *page) +static inline void __get_page(struct page *page) { - page = compound_head(page); /* * Getting a normal page or the head of a compound page * requires to already have an elevated page->_refcount. @@ -1214,6 +1213,11 @@ static inline void get_page(struct page *page) page_ref_inc(page); } +static inline void get_page(struct page *page) +{ + __get_page(compound_head(page)); +} + bool __must_check try_grab_page(struct page *page, unsigned int flags); struct page *try_grab_compound_head(struct page *page, int refs, unsigned int flags); @@ -1228,10 +1232,8 @@ static inline __must_check bool try_get_page(struct page *page) return true; } -static inline void put_page(struct page *page) +static inline void __put_page(struct page *page) { - page = compound_head(page); - /* * For devmap managed pages we need to catch refcount transition from * 2 to 1, when refcount reach one it means the page is free and we @@ -1244,7 +1246,12 @@ static inline void put_page(struct page *page) } if (put_page_testzero(page)) - __put_page(page); + __put_single_or_compound_page(page); +} + +static inline void put_page(struct page *page) +{ + __put_page(compound_head(page)); } /* diff --git a/mm/swap.c b/mm/swap.c index af3cad4e5378..565cbde1caea 100644 --- a/mm/swap.c +++ b/mm/swap.c @@ -111,7 +111,7 @@ static void __put_compound_page(struct page *page) destroy_compound_page(page); } -void __put_page(struct page *page) +void __put_single_or_compound_page(struct page *page) { if (is_zone_device_page(page)) { put_dev_pagemap(page->pgmap); @@ -128,7 +128,7 @@ void __put_page(struct page *page) else __put_single_page(page); } -EXPORT_SYMBOL(__put_page); +EXPORT_SYMBOL(__put_single_or_compound_page); /** * put_pages_list() - release a list of pages @@ -1153,7 +1153,7 @@ void put_devmap_managed_page(struct page *page) if (count == 1) free_devmap_managed_page(page); else if (!count) - __put_page(page); + __put_single_or_compound_page(page); } EXPORT_SYMBOL(put_devmap_managed_page); #endif -- 2.33.0