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: 40216 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp945844wrt; Fri, 6 Jan 2023 09:46:39 -0800 (PST) X-Google-Smtp-Source: AMrXdXu6fLNpWtYJZ2WTD/bzfgYXnDtaCfvP5BKX9KtaHXQUloy2up5KafADGXOmMmRb6+p6sMbC X-Received: by 2002:a05:6402:33a:b0:46b:b750:3d2e with SMTP id q26-20020a056402033a00b0046bb7503d2emr47420611edw.26.1673027199191; Fri, 06 Jan 2023 09:46:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673027199; cv=none; d=google.com; s=arc-20160816; b=FxBfKIX6rJsbHSy+X2rnPpyVts5xP/n/9pP2a0qQNwNbXG/3/UPIKZ0u/VYVNPKi1r ysYAa6SQr+V0FODIkjfsH2sF5JyJd53J3yZSuq2v8IGyBHp3HRyhBnI3WQN0Bgn8ExLF yN/Oepyuw6MwKbW5YbLCz/6g7cKQRDzAbbB5/P89yzFxac8RAQ8n12wJiFYjglUwqdfK Gitn+y6douC53awFNVODFcG7FSp09UrF49AaTXNPb71gr4qG00CZb+TR0O22s4lroHr/ 6i5EWOW6mAqpVIz2nY6ZywYbAd0uN0uwof4jtNXUAyJOx3DLnYN9D8qeGjgjMlaYqyT0 rdLA== 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 :dkim-signature; bh=8M3pePemNop1p6sYijcJO/XCyrdzmIZrQcfJdfBbni0=; b=wQYLuZdqoylo+gsgMdLywU3hryVuwbOhBJXOLDNRACVQwWmPF2vNb3e46RU7CR5Dk6 QgT0pwqsm6qe1tB3E+AlOGNLAJtuGR7mfyzmWY1lsVG+TpwYTZ0la8j6HSBSTcgO2WJB I3S/hTncYPpCh2h682dk5MMQMkMP58aE4GHsaAiw6U0YqkCjLzeAD/IcyzEJoyAckxEU 2JvaABv3mfeg3lbiRjIVkrVV3eP2txTrXbbSOGqgcaSCK4A0ZSgPDFNXn5N2DTtj+t8N R2VPNJkyUV2Kejz0ebeqnKgNfCr5jrBrSxjoEKPGKOwBKaMr08SO4vSVqyyr962lb3VF 0VbQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="I9KaEMH/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l23-20020a056402029700b00486e2db6579si1997847edv.418.2023.01.06.09.46.13; Fri, 06 Jan 2023 09:46:39 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="I9KaEMH/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235738AbjAFRky (ORCPT + 99 others); Fri, 6 Jan 2023 12:40:54 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36496 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235727AbjAFRkt (ORCPT ); Fri, 6 Jan 2023 12:40:49 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B193F7DE18 for ; Fri, 6 Jan 2023 09:40:43 -0800 (PST) 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 6C6B9B810A7 for ; Fri, 6 Jan 2023 17:40:42 +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-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1754296168543135254?= X-GMAIL-MSGID: =?utf-8?q?1754296168543135254?= 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);