From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 51D9D352072 for ; Thu, 21 Aug 2025 20:07:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755806871; cv=none; b=C+u3Afme949Mm2+TGKoNQiGGLp1rsajPkVHtpDgV46Szv3cTVGOVALuV9UIF20W9q6wB/ShsoSZAh9yUNpHxFrAeOdyH5fYI6XjL3e0pSc8p15l8y83wzKs+OG4IZ7YyxBgLxvwPmwudLiRKtaqrxXT/ypdFz3BGgEEjIHGjxTk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755806871; c=relaxed/simple; bh=KQhGj4yMV2JJyYTphSuwtYusktgVAWzYxv4GDdmnyDY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:content-type; b=u7bjVkJmeCvS7XPjAzHFNS5mmEfwnxoqMJc9rGTD97QMODHf8Dc6E8OvhiDfmE1Zjl8rxvEKSqFzWZ4dK+QYYoCFI8L+UNJ0PlCScgJUwQ197Nc0IYncWnPe3QzV03ex5QZKCR6v2TODmUoPTT7hulngdL38BaFLd6NFhr9j+qI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=SyYTfZbu; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="SyYTfZbu" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1755806866; h=from:from: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=PkrXh5PHMEq3NY5i+0892fbAshOERsmwyMLhbVIa0Cc=; b=SyYTfZbuLDjRLeVEASoNNlrJO8iu+FMJsS61MAfef62rsTA54jfinhZ2Ej15mkcMUKY3of 8OQce9iU41kpATn1T0j8qRkpMTH4parQNIs65gYoYcrgj2R7RBYbWmsw+WSdGtZkvT9hhe lvoZhhvzh3D5UPfAOd+aDROv/cVlIFY= Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-628-BVF3Efi8Ok2SpxfyvrBx6Q-1; Thu, 21 Aug 2025 16:07:45 -0400 X-MC-Unique: BVF3Efi8Ok2SpxfyvrBx6Q-1 X-Mimecast-MFC-AGG-ID: BVF3Efi8Ok2SpxfyvrBx6Q_1755806864 Received: by mail-wm1-f72.google.com with SMTP id 5b1f17b1804b1-45a1ba17bbcso7095945e9.0 for ; Thu, 21 Aug 2025 13:07:44 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1755806864; x=1756411664; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=PkrXh5PHMEq3NY5i+0892fbAshOERsmwyMLhbVIa0Cc=; b=dTWXOjD2SjnUGETnVWFjXjM+M6Q60WMaoGOaKotG8VuQ0q8dx/tfEPx/Cb3v/UaHD3 giQpaxpW7mP3gh//OV8oK2EV1g/yLr/pFBcvv0sx+yvryD3FVUNipFhv27RkfhyxEGfV GCdpIalXMO+SVDRYmwdGaqek3sLroqrSX8RrYO5mv2SYsx6RqRlh0oR+JNzfvuvybVP/ IAI2YlzlukWbl98th4T3kr41vt+1wTiCWpi6OUfmF0CdlusUrM9oM2g4JoPQrCH5XznP D6DI+XLKsTBD5t7m26zlSUYDQWyc65C+2qESYR28c695pk0fD13kpoUQEIEL4in0Errq FqJQ== X-Forwarded-Encrypted: i=1; AJvYcCUCkTwxqfbX3FUW8bTGZwqHM21DV+TbADgRiVKlfA9yML6eUTR2d0xHp3PzSvLU7+mmha5q3Pyjpd/0ahAFcQ==@lists.linux.dev X-Gm-Message-State: AOJu0Yzf2pBxOdp9BvrAK/fOoDrdVVBt8TxjPnjEq4ga75AnGpe+PZhR YeU/QXiHx/RWv/C4PYOHSJDuYcH5rHkF9Rudl2yA12zGHzvzHwVebkZZ5zWGjamV4PrfDCdTVJ2 qR8zd71pttqjw/4zIH5j/Q/IJwVb4xeduUf6tKh89XIXacE0J1sHW8H0Plo92JZTDH2cs X-Gm-Gg: ASbGnculQMK5psfUN3xPS+cskCNRU5jwmIQ6YlG10THylQuGv35E+utBMYcaTMhwBuF obwYICGC9jPvfjRWOBfi24biVnVT9LMINtl1wtOsdKryXW0D+VCHBDUPbV6ToxPK66hYpfT0K8N w6QXstm8L/Kl4olqKuN5U3H6mQY2embUzC96RljDEL947si5Pajxu61VYGBpL7GOeEqNJOn9i/x NUBy/TPRAVdQgebevH9GyhQMjsIyiDS8UcYltmGHhwfddpG/kfXOxjw26IU3iAr9EIIBIpEcSqm o56m9essYndZWK0MAIn1L1N8xH8AHQU4lIgU1J1R0MmI9mkMIc+I/uXuRZVen7+puEsos0T4Qns L8zwvkduD/FVs93X7ohOBew== X-Received: by 2002:a5d:5d0a:0:b0:3b9:14f2:7eea with SMTP id ffacd0b85a97d-3c5daefc2a3mr192576f8f.18.1755806863499; Thu, 21 Aug 2025 13:07:43 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFB28V/U3gI+p1afMr2c1HujEN1g59N1A45YIj+RBO5vrtdOMlsNhrN6BtrkE7YShkW7nBB8Q== X-Received: by 2002:a5d:5d0a:0:b0:3b9:14f2:7eea with SMTP id ffacd0b85a97d-3c5daefc2a3mr192518f8f.18.1755806862961; Thu, 21 Aug 2025 13:07:42 -0700 (PDT) Received: from localhost (p200300d82f26ba0008036ec5991806fd.dip0.t-ipconnect.de. [2003:d8:2f26:ba00:803:6ec5:9918:6fd]) by smtp.gmail.com with UTF8SMTPSA id 5b1f17b1804b1-45b51b61256sm1742995e9.3.2025.08.21.13.07.40 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 21 Aug 2025 13:07:42 -0700 (PDT) From: David Hildenbrand To: linux-kernel@vger.kernel.org Cc: David Hildenbrand , Alexander Potapenko , Andrew Morton , Brendan Jackman , Christoph Lameter , Dennis Zhou , Dmitry Vyukov , dri-devel@lists.freedesktop.org, intel-gfx@lists.freedesktop.org, iommu@lists.linux.dev, io-uring@vger.kernel.org, Jason Gunthorpe , Jens Axboe , Johannes Weiner , John Hubbard , kasan-dev@googlegroups.com, kvm@vger.kernel.org, "Liam R. Howlett" , Linus Torvalds , linux-arm-kernel@axis.com, linux-arm-kernel@lists.infradead.org, linux-crypto@vger.kernel.org, linux-ide@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-mips@vger.kernel.org, linux-mmc@vger.kernel.org, linux-mm@kvack.org, linux-riscv@lists.infradead.org, linux-s390@vger.kernel.org, linux-scsi@vger.kernel.org, Lorenzo Stoakes , Marco Elver , Marek Szyprowski , Michal Hocko , Mike Rapoport , Muchun Song , netdev@vger.kernel.org, Oscar Salvador , Peter Xu , Robin Murphy , Suren Baghdasaryan , Tejun Heo , virtualization@lists.linux.dev, Vlastimil Babka , wireguard@lists.zx2c4.com, x86@kernel.org, Zi Yan Subject: [PATCH RFC 13/35] mm: simplify folio_page() and folio_page_idx() Date: Thu, 21 Aug 2025 22:06:39 +0200 Message-ID: <20250821200701.1329277-14-david@redhat.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20250821200701.1329277-1-david@redhat.com> References: <20250821200701.1329277-1-david@redhat.com> Precedence: bulk X-Mailing-List: virtualization@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: eeLrBtvk6gHLahTAr5B-fIAFTqbUV2heffbO8wRqH08_1755806864 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit content-type: text/plain; charset="US-ASCII"; x-default=true Now that a single folio/compound page can no longer span memory sections in problematic kernel configurations, we can stop using nth_page(). While at it, turn both macros into static inline functions and add kernel doc for folio_page_idx(). Signed-off-by: David Hildenbrand --- include/linux/mm.h | 16 ++++++++++++++-- include/linux/page-flags.h | 5 ++++- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/include/linux/mm.h b/include/linux/mm.h index 48a985e17ef4e..ef360b72cb05c 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -210,10 +210,8 @@ extern unsigned long sysctl_admin_reserve_kbytes; #if defined(CONFIG_SPARSEMEM) && !defined(CONFIG_SPARSEMEM_VMEMMAP) #define nth_page(page,n) pfn_to_page(page_to_pfn((page)) + (n)) -#define folio_page_idx(folio, p) (page_to_pfn(p) - folio_pfn(folio)) #else #define nth_page(page,n) ((page) + (n)) -#define folio_page_idx(folio, p) ((p) - &(folio)->page) #endif /* to align the pointer to the (next) page boundary */ @@ -225,6 +223,20 @@ extern unsigned long sysctl_admin_reserve_kbytes; /* test whether an address (unsigned long or pointer) is aligned to PAGE_SIZE */ #define PAGE_ALIGNED(addr) IS_ALIGNED((unsigned long)(addr), PAGE_SIZE) +/** + * folio_page_idx - Return the number of a page in a folio. + * @folio: The folio. + * @page: The folio page. + * + * This function expects that the page is actually part of the folio. + * The returned number is relative to the start of the folio. + */ +static inline unsigned long folio_page_idx(const struct folio *folio, + const struct page *page) +{ + return page - &folio->page; +} + static inline struct folio *lru_to_folio(struct list_head *head) { return list_entry((head)->prev, struct folio, lru); diff --git a/include/linux/page-flags.h b/include/linux/page-flags.h index d53a86e68c89b..080ad10c0defc 100644 --- a/include/linux/page-flags.h +++ b/include/linux/page-flags.h @@ -316,7 +316,10 @@ static __always_inline unsigned long _compound_head(const struct page *page) * check that the page number lies within @folio; the caller is presumed * to have a reference to the page. */ -#define folio_page(folio, n) nth_page(&(folio)->page, n) +static inline struct page *folio_page(struct folio *folio, unsigned long nr) +{ + return &folio->page + nr; +} static __always_inline int PageTail(const struct page *page) { -- 2.50.1