From patchwork Fri Jan 6 17:40:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 13091657 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 240B0C54E76 for ; Fri, 6 Jan 2023 17:40:45 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B6511900002; Fri, 6 Jan 2023 12:40:44 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id B130D8E0001; Fri, 6 Jan 2023 12:40:44 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9DB8D900002; Fri, 6 Jan 2023 12:40:44 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 8BC938E0001 for ; Fri, 6 Jan 2023 12:40:44 -0500 (EST) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 699511C6069 for ; Fri, 6 Jan 2023 17:40:44 +0000 (UTC) X-FDA: 80325089208.21.41B0F56 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by imf27.hostedemail.com (Postfix) with ESMTP id D6C6040014 for ; Fri, 6 Jan 2023 17:40:42 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b="I9KaEMH/"; spf=pass (imf27.hostedemail.com: domain of sj@kernel.org designates 145.40.68.75 as permitted sender) smtp.mailfrom=sj@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1673026843; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=8M3pePemNop1p6sYijcJO/XCyrdzmIZrQcfJdfBbni0=; b=QwXZih9qna3PqOBVpuH7WnFkqqEcwec7JU0EME0siCvs5cc2+qopjcuXEc377MU2G4fv9w rKJy9F/upnnwoaPIvakYgZffRoNaYD17kipd7fow0UjurmLiz0YWRLGxjSnzx2uotH83C2 wpvp6/L/2yfGRAKtunc9OG7VE7zGhSY= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b="I9KaEMH/"; spf=pass (imf27.hostedemail.com: domain of sj@kernel.org designates 145.40.68.75 as permitted sender) smtp.mailfrom=sj@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1673026843; a=rsa-sha256; cv=none; b=jPYjAjfE+NEKPjOKY+7dXxi0LLFuhOgKfXIy1e8Qjizsgw1XQXnJoIShFOotz9dCCR12l6 EE0ikrmhDpQGgTbWJg7oVvUDbbem4Yg2pvCz2rwD1wiu+oTSZS3iW8+6T1sb91KbNoZ1Tq XhWO51JdgHjGSx+6kq2C+O7IIvGporU= Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 6E32DB81E2D; Fri, 6 Jan 2023 17:40:41 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B1883C433EF; Fri, 6 Jan 2023 17:40:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1673026841; bh=lehRB+fMwqiaN+fsr24vSBnpbQfHVQHTL6mnxILFBts=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=I9KaEMH/AY3GqDnRRYPEJoBMGtwMgv+AjV6t5PTvgm/xPvax0GyXmcoFTaHIKYUjf E6+10Gx0Zsd3ZLs+NLFgwS6jfv3WprcOXJAUpeKODNOiYxXGlzbJ+5gtviSQ/zQ8o6 ut4slaiJsNbgznopHReIdiJCcNZwMTHrzgCk0fASbBaE85Is4fM5Jmhoz5/lK8fj1L TwD7ZQf+YCAL1yAuzJf4hVtWNxw6IZwiskQti0MUj3BdeQ9DYPAIe1NcZ8Kk8bWjH/ Uo5K3kBHkNHUZ4bFa8hnobyxxNGOl+jzr23GcfFp4lVDXzWA7KrH4BYXkilwLnG4C5 /AJpyeph2OkoA== From: SeongJae Park To: Andrew Morton Cc: SeongJae Park , willy@infradead.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/3] include/linux/page-flags: add folio_headpage() Date: Fri, 6 Jan 2023 17:40:26 +0000 Message-Id: <20230106174028.151384-2-sj@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230106174028.151384-1-sj@kernel.org> References: <20230106174028.151384-1-sj@kernel.org> MIME-Version: 1.0 X-Stat-Signature: 1hq7zfb4ena14zqsuzty15dgosfi5gjd X-Rspam-User: X-Rspamd-Queue-Id: D6C6040014 X-Rspamd-Server: rspam06 X-HE-Tag: 1673026842-69514 X-HE-Meta: U2FsdGVkX18xemTlXMbkuOQjSDGyeJsBX59QL51Znoo5VgShVtfcukXu7r1kMakXSrNlS9SnxEXUXsEN8EQbQpghwlu7GcXTtY4pUoFu9kNBhM4p0+svX7YX4mBBqljigp8NjB0jA+BeG2+a6AXYhdf2KkveWOFE42qnU6PnOAnt9FnzV4aWv+WGCEHzFH217T+CQtjVhN7ppgeeQurmf7tjhzmxpdFrHV73IdlaNe5NMROkOAM65DpFDNe/q2A+fCaGrPiQE44TPeAfKhLlGwGtI9QYZKRIH0yBlYfUpNRAcJt/o2rV4RMKKfkkftYcYMEgMZ0kNRYKcOA1PZ58Bxqdau6D+OQZbUKjomTGAM1odmKCESt4v51Mhb4c6/cNgw59rW5R5N8EbebWE63m3nZqY8pR9lUEkRUgtvIY962Wwhqq9RNITdkfjXFMGSx4fW4NpIzr27bKEL3QVpd7LCW74uQ2bVBPji0GPNfCfIPfRQQvUjZUnBs+ClEPLra1JdYQcwXMoUNWjXfiST74ZU/op3HQwZWUJyWV170+o1NaawsBzZhfNSWgKlLuBLjWMjAqOpAm0m1VWYql5J9/HSdwfc/+ztFofbw/RfHnUkKReqQah2gpFO6VyQ0nyNRRCiBgsRDmYVqiBfySRNyYol3WDvfCx28YVNHjypmu55EwxK4oVey23dA9AIYu4cNnWGnBv8c+d8HTO01YOCTEaS9mIYCStK0vwiKorrNiti+a5c5MZLduhLCvO1HlOQkOB1FDrBPk5iK/OfTedH2x8oYv+yR0U4bLxyBs9apv+bIVAZFwZ20KoyLrBL93qqTO+l6ettMaXzmccQPDarthBq4jBt9k2ZZjkxx7dF7ap9MlYwCC7T1Fad6qF6BBNo1D4mjiAx1n4CVVMf655KKnpLaNQh4HU2yGwqWU6ofzUg1++q8G6nj67iG1smC8fHwhkf4P6aBzO4Qc4Z1Eaiz xp3xaTj2 ZAh5NuoQ4q8xhfAz660Fey47ZZNxX0hEOHswSFogkGeL/XHODBk+8sBxIIgfJGTw+5gIQaZBt9cdYfQB4gIGa/C5YKFWYqDEMpTQLsyFY50hLYWR+ahczcskYeA== 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: The standard idiom for getting head page of a given folio is '&folio->page'. It is efficient and safe even if the folio is NULL, because the offset of page field in folio is zero. However, it makes the code not that easy to understand at the first glance, especially the NULL safety. Also, sometimes people forget the idiom and use 'folio_page(folio, 0)' instead. To make it easier to read and remember, add a new macro function called 'folio_headpage()' with the NULL case explanation. Signed-off-by: SeongJae Park --- include/linux/page-flags.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/include/linux/page-flags.h b/include/linux/page-flags.h index 69e93a0c1277..5a22bd823a5d 100644 --- a/include/linux/page-flags.h +++ b/include/linux/page-flags.h @@ -285,6 +285,14 @@ static inline unsigned long _compound_head(const struct page *page) */ #define folio_page(folio, n) nth_page(&(folio)->page, n) +/** + * folio_headpage - Return the head page from a folio. + * @folio: The pointer to the folio. + * + * Return: The head page of the folio, or NULL if the folio is NULL. + */ +#define folio_headpage(folio) (&(folio)->page) + static __always_inline int PageTail(struct page *page) { return READ_ONCE(page->compound_head) & 1 || page_is_fake_head(page);