From patchwork Wed Jan 11 14:29:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 13096762 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 2E6A3C54EBC for ; Wed, 11 Jan 2023 14:29:21 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 55A868E000C; Wed, 11 Jan 2023 09:29:11 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id F0A4D900003; Wed, 11 Jan 2023 09:29:10 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6913F900006; Wed, 11 Jan 2023 09:29:10 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 9CD54900005 for ; Wed, 11 Jan 2023 09:29:09 -0500 (EST) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 85E7FA0CE0 for ; Wed, 11 Jan 2023 14:29:09 +0000 (UTC) X-FDA: 80342750418.29.CC31F31 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf29.hostedemail.com (Postfix) with ESMTP id D7A02120011 for ; Wed, 11 Jan 2023 14:29:07 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=Ta7ihsCN; spf=none (imf29.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1673447347; 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=FxqAkPcytKuw5YjKq8uigj0qwlZCH6XVIp0l1lIOOVE=; b=iLs+GvcdocmFyIn9BKgpMDrZUNfDszEcbfPunvE4dtpR0iScl99mk8ohMjhJfFWAcy3Rle YIk5VJYQ2WX3MXJwlUOgIy5GnpkViCt1SfmoGxkOLNUWdhUiN5C9HA3qNwtx40FHpWyLCn lmiwDuVlza0wEB8FL/LRUwvVvwP5m0I= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=Ta7ihsCN; spf=none (imf29.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1673447348; a=rsa-sha256; cv=none; b=PDnfd2jMo94ztTIb7fDZT9emuhRB3mF8VCt5lE9wBYOHCDkx4oNdF4kON4ljn0bBGlQRo/ Lr98bXfemJUwRkIitwiqYRkt7I6Wa3twxa4B6X0xEjCY1zw+ZEAs7v1REV3chO4TKKkd8j UAfFUWv2YLC6NWwiG3XXxoj85R6DP1k= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=FxqAkPcytKuw5YjKq8uigj0qwlZCH6XVIp0l1lIOOVE=; b=Ta7ihsCNrkX1wy4/lB+0I83MRJ G32WLk8oRk3UMzkN+1L/gVFqSU5H2kFatCztXlnj1/FcGiN+Gy8WrpV3e34nrv2ZMH7ZrYY7kUmkc FrMI+7ItiyD/RDNbBjtjb8eC9HpJaA+Op2n0SA3JuroJ277CctaK+OJ/TXBTghR/CBVAW085wDuRc Z/Wbq9zzzWeTKUddNNYBP9NRjBOaY7hNQIesaUypXEMGDz5RSicPi9S8mFKBhve9rYjvQyTxeFpTn gogqGw0Z8kVK8CO1FGUV+Y4IRC7TZf7wsDyKRxEbC2Rf2vngOYkRcY6zcx+svF3AhdOJeKxsoEknQ 2etB8Xmw==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1pFc6Q-004CZV-TT; Wed, 11 Jan 2023 14:29:18 +0000 From: "Matthew Wilcox (Oracle)" To: Andrew Morton Cc: "Matthew Wilcox (Oracle)" , linux-mm@kvack.org, Hugh Dickins Subject: [PATCH 17/28] mm: Reimplement compound_nr() Date: Wed, 11 Jan 2023 14:29:03 +0000 Message-Id: <20230111142915.1001531-18-willy@infradead.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20230111142915.1001531-1-willy@infradead.org> References: <20230111142915.1001531-1-willy@infradead.org> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: D7A02120011 X-Stat-Signature: dz41ehb61bbgxohmqjjfz4ttwam3d77x X-HE-Tag: 1673447347-895213 X-HE-Meta: U2FsdGVkX19aUxs2WXrB9WEdexkALD4XdbvTjSJICxTvA0Xb0XfNTlS2utU1U453HlNLr/B6zfbLx8qKPW2voDP3pj6QmcKj32tKOnmM4ZcAvmzI582pLdg75GU2i5ZV9cnmybau32x+P7TSosX9YTkL8ZLbWr/etpry2kRNbMgbIdQWVNSziZsstA6KcC/rDu6lSTCsMzl1QdpT/e8+flPtiL0FXYKjn77mjW4gGv652kJqsTGWaHcNJYY8rNCLVkJZn12aAS6xJvOAQ7BrcMv8SHx/Il9m3RvVJ+F6ZADJd420tn33JabYc46E2Cw31J1MHLxOTM7AsYye0Mms7lXveVHUH5Oj9WzUUkfbM+xvDkyjSD6kahbXP9X1Fs1WYAy7+mskOj6ZHO3vB64mE7h9ao2qx4v0fIQivi7JaCKIGzHO1LED1Q/duPEIKLfiG6xnatDUvgPqK+N7Zt0H5AdJ5R3RNAoevQ2mLuPrYjlglBmPuJujifHXA3omaWnwzXftRs803/vWNke71tF4/X5bYP6iq2oADS/IcWNm9Z0K8fCcp4DuB0wz6THQrElyIM1D17LoNKLxHHkqQX4LP5YLZhrfnhIkqLpAwSNvqT1BHHuppeKI3GLytzsCkX2ITLsSuTTr/g7Hx77rFZUTed6AjGcMJhekL/IjZVK7YAMmtq9Uc9njGnGOurjnU1HLkdmxezRixGt35M52C0ZCSTqJLcpWYr1BLvMc9GnRMNiZbLEk+d3ZVmfBHNcuuZyJr1M6v8wJ193YttqbrQIB2rDp6nuwdFdFAvW568COu0VrfmlLifh7E2jsM4N66cQnpJr0x7e2jjQu+akk4uXrz17sqVRaMzsxK50OPwAOrAP0Vp03pzvydZPZjMdYe1AtMm20JQHLp+ebXB9WOMnZ8xIuqGD24zBcbrsu5ZHmNZeMzd1l1B5b8g== 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: Turn compound_nr() into a wrapper around folio_nr_pages(). Similarly to compound_order(), casting the struct page directly to struct folio preserves the existing behaviour, while calling page_folio() would change the behaviour. Move thp_nr_pages() down in the file so that compound_nr() can be after folio_nr_pages(). Signed-off-by: Matthew Wilcox (Oracle) --- include/linux/mm.h | 38 ++++++++++++++++---------------------- 1 file changed, 16 insertions(+), 22 deletions(-) diff --git a/include/linux/mm.h b/include/linux/mm.h index ddf09522c0d3..0b1cdaf0fa90 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -1005,18 +1005,6 @@ static inline void set_compound_order(struct page *page, unsigned int order) #endif } -/* Returns the number of pages in this potentially compound page. */ -static inline unsigned long compound_nr(struct page *page) -{ - if (!PageHead(page)) - return 1; -#ifdef CONFIG_64BIT - return page[1].compound_nr; -#else - return 1UL << compound_order(page); -#endif -} - /* Returns the number of bytes in this potentially compound page. */ static inline unsigned long page_size(struct page *page) { @@ -1039,16 +1027,6 @@ static inline unsigned int thp_order(struct page *page) return compound_order(page); } -/** - * thp_nr_pages - The number of regular pages in this huge page. - * @page: The head page of a huge page. - */ -static inline int thp_nr_pages(struct page *page) -{ - VM_BUG_ON_PGFLAGS(PageTail(page), page); - return compound_nr(page); -} - /** * thp_size - Size of a transparent huge page. * @page: Head page of a transparent huge page. @@ -1758,6 +1736,22 @@ static inline long folio_nr_pages(struct folio *folio) #endif } +/* Returns the number of pages in this potentially compound page. */ +static inline unsigned long compound_nr(struct page *page) +{ + return folio_nr_pages((struct folio *)page); +} + +/** + * thp_nr_pages - The number of regular pages in this huge page. + * @page: The head page of a huge page. + */ +static inline int thp_nr_pages(struct page *page) +{ + VM_BUG_ON_PGFLAGS(PageTail(page), page); + return compound_nr(page); +} + /** * folio_next - Move to the next physical folio. * @folio: The folio we're currently operating on.