From patchwork Tue Jun 4 09:08:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max Kellermann X-Patchwork-Id: 13684919 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 C1618C25B78 for ; Tue, 4 Jun 2024 09:09:30 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 22FF26B009F; Tue, 4 Jun 2024 05:09:19 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1DCEE6B00A1; Tue, 4 Jun 2024 05:09:19 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EB1076B00A0; Tue, 4 Jun 2024 05:09:18 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id CB27C6B009C for ; Tue, 4 Jun 2024 05:09:18 -0400 (EDT) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 8B2ABA0429 for ; Tue, 4 Jun 2024 09:09:18 +0000 (UTC) X-FDA: 82192632396.28.E1EC956 Received: from mail-ed1-f48.google.com (mail-ed1-f48.google.com [209.85.208.48]) by imf25.hostedemail.com (Postfix) with ESMTP id 9CF8FA000A for ; Tue, 4 Jun 2024 09:09:16 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=ionos.com header.s=google header.b=YZKGsk12; spf=pass (imf25.hostedemail.com: domain of max.kellermann@ionos.com designates 209.85.208.48 as permitted sender) smtp.mailfrom=max.kellermann@ionos.com; dmarc=pass (policy=quarantine) header.from=ionos.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1717492156; 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=LGA97Ct+cPd+7V/cTW+dx47R1ZSFkzyCh6qF0w1u/vk=; b=XlE7tmh/xkvcRTZAy9bALYFfFTYJFyljK8bdFz+3QW0orm18ExmVAndcma3TM4P1Z+c92/ hqN7UA8uaEK3ENxFqkJCZToI7pNnPlVPfUZxXGZC6Z1lEfeXrk4ejtB8bCZdGyLrlTE6Ok Q4ch80JeYO6oT70teyIqU6a0+o9JM6I= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1717492156; a=rsa-sha256; cv=none; b=DhlVfU2wAXzqUkLrQs5P8yeIU2+TMaWR9Mxlip3uAoc80IWGL01ofw1JyCNBZkdG2QtEIe cQL//2swmsGYdXhFjw/ZNpTL2Xt/nIxNuQmqpx9YrR4xe+rO/rafbjch+TE7TQ81ufTfjd fzjO4l/sXXrYsvjzG5uChWmYNbKus00= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=pass header.d=ionos.com header.s=google header.b=YZKGsk12; spf=pass (imf25.hostedemail.com: domain of max.kellermann@ionos.com designates 209.85.208.48 as permitted sender) smtp.mailfrom=max.kellermann@ionos.com; dmarc=pass (policy=quarantine) header.from=ionos.com Received: by mail-ed1-f48.google.com with SMTP id 4fb4d7f45d1cf-57a1fe6392eso6069684a12.0 for ; Tue, 04 Jun 2024 02:09:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ionos.com; s=google; t=1717492155; x=1718096955; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=LGA97Ct+cPd+7V/cTW+dx47R1ZSFkzyCh6qF0w1u/vk=; b=YZKGsk12FCd2iweR7moqgXmnQSORo7YPTLo95KCB2SSIvpq2t+FEgFJtkMu83I487O THluunTPmyRvpQWOXDtigzRuI+JbXESY/ijaYIjgsCf8nDSas9BYq6iN4TxKJ+2c+OS9 bobv/cYrDOSPer1Qyat6oNN3ttrE5ASHvfJqO3Iq8/lFICKy71lsmpGnJm8ImH9qeRYe Uf37n4p2NviM7DSZDo9GZBEiHL0JVMW/59oyAecWvTUtcvoJqMn8zXa5vXw5u3FRB1VO 4Y9Jkb++TclTd4vOFFsIpS/aZPyMMQ5mkoG+9ImVVVupSSF51uAeFM+EfzpKVDvHCbsE N+xQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717492155; x=1718096955; 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=LGA97Ct+cPd+7V/cTW+dx47R1ZSFkzyCh6qF0w1u/vk=; b=OqnTlXg/967RuGPsoqqZC0aDZnBUY/nHdVqTO3PHD1XMZFBXTOL+f0JLHGlgTaydWQ Q5FlvualZFYkr45fcgsgMgvUH78BxSBGOgvuNDTbhFSsfUTh+lm51RCDd/Cyr3YLE9CA RHlrbEZuO1pGr7ptz+O74XwS6iXXypXP7B1LcKNzplOB85PvSRyNUY+/AzJZEskTczSb CNl/KHZ0MAcnMHde8gQ8dS4+XsUXHo2BAAJwU9l5WWxEyirDxOPfggOXYAVNQCbYrf9a P0VZccQiuKmQPRtKJUADA7azFbN3jMX6Cozj/vCCBucdxAGHBSBd/BADpI1fWCJR9qcD vYEQ== X-Forwarded-Encrypted: i=1; AJvYcCUYYLoKgWwoR/XYmxHrtpqme8/+4byAdb40nLGILAf9CFMOZlVJPWMF/KeckGosXV/XkFGdIZstqSfOkRIk/ga/q0I= X-Gm-Message-State: AOJu0YxC4antk7IIPqOe3joDwW8dm3xBwM5Q64pfQ6qku2vm6o3QoSCm QLnKMFxvGwOKPKIRC5w+EupU7tqGjDmXO48LX7mzAXnQXs5D13aV1wxB3aFNH36kmYDeqHZz386 HjvY= X-Google-Smtp-Source: AGHT+IEsb+sDgUGZexqUFY3hraRHpEBznY4zG62l35w3uux2zbvBuWOtU9Ps2+jctDU3Yl2qZVDwFQ== X-Received: by 2002:a17:907:516:b0:a59:b88c:2b2a with SMTP id a640c23a62f3a-a6821b71cdemr586561966b.50.1717492155201; Tue, 04 Jun 2024 02:09:15 -0700 (PDT) Received: from raven.blarg.de (p200300dc6f4f9200023064fffe740809.dip0.t-ipconnect.de. [2003:dc:6f4f:9200:230:64ff:fe74:809]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a68fa49e66fsm328376766b.129.2024.06.04.02.09.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Jun 2024 02:09:14 -0700 (PDT) From: Max Kellermann To: akpm@linux-foundation.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: willy@infradead.org, sfr@canb.auug.org.au, david@redhat.com, Max Kellermann Subject: [PATCH v6 07/15] linux/mm.h: move folio_size(), ... to mm/folio_size.h Date: Tue, 4 Jun 2024 11:08:37 +0200 Message-Id: <20240604090845.2182265-8-max.kellermann@ionos.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240604090845.2182265-1-max.kellermann@ionos.com> References: <20240604090845.2182265-1-max.kellermann@ionos.com> MIME-Version: 1.0 X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 9CF8FA000A X-Rspam-User: X-Stat-Signature: b6x4x8zwwpieds58usij8f5twbso3a5j X-HE-Tag: 1717492156-37669 X-HE-Meta: U2FsdGVkX1/F/4gPFba8W5LzzN1UaFBvyp0BdHIOsOKgfNnk/ywENg25POgdXr8b80TKV500TfwnUvGvlZT4K92kTk+Yp7carVhkrEeX5/xa4vJYiV4j8B4l35fn3O+LCrfke5TKShlt0rORWJjjPV7A/+KrNidPQP5oMRpkHtSvyujGjB/w3hj2G3gAUlHra6uIbe3yMFWUP6lwzTa6S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1qrZDL14tnkVg5T4vT+W9taJWhLlD0eVSw7kkqZvkMUfq4HKMLeSXbSafoId3PRamn1MNTxqHaVOF3kH+v2vL+ShnXk/MrIe7KZwkMqCqGvV6OergNe6w8I9TUZK7a+HJQleg05nWA= 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: List-Subscribe: List-Unsubscribe: Prepare to reduce dependencies on linux/mm.h. folio_size()/page_size() are used by the following popular headers: - linux/highmem.h - linux/iov_iter.h - linux/pagemap.h Moving them to a separate lean header will allow us to avoid the dependency on linux/mm.h. Additionally, it allows us to move folio_next() to a separate header, because it needs folio_nr_pages() which is also moved to folio_size.h. Signed-off-by: Max Kellermann --- include/linux/mm.h | 140 +------------------------------ include/linux/mm/folio_size.h | 150 ++++++++++++++++++++++++++++++++++ 2 files changed, 151 insertions(+), 139 deletions(-) create mode 100644 include/linux/mm/folio_size.h diff --git a/include/linux/mm.h b/include/linux/mm.h index 014db2b39c16..b11bbbdd2754 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -2,6 +2,7 @@ #ifndef _LINUX_MM_H #define _LINUX_MM_H +#include #include #include #include @@ -1069,38 +1070,6 @@ int vma_is_stack_for_current(struct vm_area_struct *vma); struct mmu_gather; struct inode; -/* - * compound_order() can be called without holding a reference, which means - * that niceties like page_folio() don't work. These callers should be - * prepared to handle wild return values. For example, PG_head may be - * set before the order is initialised, or this may be a tail page. - * See compaction.c for some good examples. - */ -static inline unsigned int compound_order(struct page *page) -{ - struct folio *folio = (struct folio *)page; - - if (!test_bit(PG_head, &folio->flags)) - return 0; - return folio->_flags_1 & 0xff; -} - -/** - * folio_order - The allocation order of a folio. - * @folio: The folio. - * - * A folio is composed of 2^order pages. See get_order() for the definition - * of order. - * - * Return: The order of the folio. - */ -static inline unsigned int folio_order(struct folio *folio) -{ - if (!folio_test_large(folio)) - return 0; - return folio->_flags_1 & 0xff; -} - #include /* @@ -1303,39 +1272,6 @@ void folio_copy(struct folio *dst, struct folio *src); unsigned long nr_free_buffer_pages(void); -/* Returns the number of bytes in this potentially compound page. */ -static inline unsigned long page_size(struct page *page) -{ - return PAGE_SIZE << compound_order(page); -} - -/* Returns the number of bits needed for the number of bytes in a page */ -static inline unsigned int page_shift(struct page *page) -{ - return PAGE_SHIFT + compound_order(page); -} - -/** - * thp_order - Order of a transparent huge page. - * @page: Head page of a transparent huge page. - */ -static inline unsigned int thp_order(struct page *page) -{ - VM_BUG_ON_PGFLAGS(PageTail(page), page); - return compound_order(page); -} - -/** - * thp_size - Size of a transparent huge page. - * @page: Head page of a transparent huge page. - * - * Return: Number of bytes in this page. - */ -static inline unsigned long thp_size(struct page *page) -{ - return PAGE_SIZE << thp_order(page); -} - #ifdef CONFIG_MMU /* * Do pte_mkwrite, but only if the vma says VM_WRITE. We do this when @@ -1973,23 +1909,6 @@ static inline void set_page_links(struct page *page, enum zone_type zone, #endif } -/** - * folio_nr_pages - The number of pages in the folio. - * @folio: The folio. - * - * Return: A positive power of two. - */ -static inline long folio_nr_pages(const struct folio *folio) -{ - if (!folio_test_large(folio)) - return 1; -#ifdef CONFIG_64BIT - return folio->_folio_nr_pages; -#else - return 1L << (folio->_flags_1 & 0xff); -#endif -} - /* Only hugetlbfs can allocate folios larger than MAX_ORDER */ #ifdef CONFIG_ARCH_HAS_GIGANTIC_PAGE #define MAX_FOLIO_NR_PAGES (1UL << PUD_ORDER) @@ -1997,33 +1916,6 @@ static inline long folio_nr_pages(const struct folio *folio) #define MAX_FOLIO_NR_PAGES MAX_ORDER_NR_PAGES #endif -/* - * compound_nr() returns the number of pages in this potentially compound - * page. compound_nr() can be called on a tail page, and is defined to - * return 1 in that case. - */ -static inline unsigned long compound_nr(struct page *page) -{ - struct folio *folio = (struct folio *)page; - - if (!test_bit(PG_head, &folio->flags)) - return 1; -#ifdef CONFIG_64BIT - return folio->_folio_nr_pages; -#else - return 1L << (folio->_flags_1 & 0xff); -#endif -} - -/** - * 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) -{ - return folio_nr_pages((struct folio *)page); -} - /** * folio_next - Move to the next physical folio. * @folio: The folio we're currently operating on. @@ -2043,36 +1935,6 @@ static inline struct folio *folio_next(struct folio *folio) return (struct folio *)folio_page(folio, folio_nr_pages(folio)); } -/** - * folio_shift - The size of the memory described by this folio. - * @folio: The folio. - * - * A folio represents a number of bytes which is a power-of-two in size. - * This function tells you which power-of-two the folio is. See also - * folio_size() and folio_order(). - * - * Context: The caller should have a reference on the folio to prevent - * it from being split. It is not necessary for the folio to be locked. - * Return: The base-2 logarithm of the size of this folio. - */ -static inline unsigned int folio_shift(struct folio *folio) -{ - return PAGE_SHIFT + folio_order(folio); -} - -/** - * folio_size - The number of bytes in a folio. - * @folio: The folio. - * - * Context: The caller should have a reference on the folio to prevent - * it from being split. It is not necessary for the folio to be locked. - * Return: The number of bytes in this folio. - */ -static inline size_t folio_size(struct folio *folio) -{ - return PAGE_SIZE << folio_order(folio); -} - /** * folio_likely_mapped_shared - Estimate if the folio is mapped into the page * tables of more than one MM diff --git a/include/linux/mm/folio_size.h b/include/linux/mm/folio_size.h new file mode 100644 index 000000000000..e7cd567cf069 --- /dev/null +++ b/include/linux/mm/folio_size.h @@ -0,0 +1,150 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _LINUX_MM_FOLIO_SIZE_H +#define _LINUX_MM_FOLIO_SIZE_H + +#include // for test_bit() +#include // for VM_BUG_ON_PGFLAGS() +#include // for struct page +#include // for folio_test_large() +#include // for PAGE_SIZE, PAGE_SHIFT + +/* + * compound_order() can be called without holding a reference, which means + * that niceties like page_folio() don't work. These callers should be + * prepared to handle wild return values. For example, PG_head may be + * set before the order is initialised, or this may be a tail page. + * See compaction.c for some good examples. + */ +static inline unsigned int compound_order(struct page *page) +{ + struct folio *folio = (struct folio *)page; + + if (!test_bit(PG_head, &folio->flags)) + return 0; + return folio->_flags_1 & 0xff; +} + +/** + * folio_order - The allocation order of a folio. + * @folio: The folio. + * + * A folio is composed of 2^order pages. See get_order() for the definition + * of order. + * + * Return: The order of the folio. + */ +static inline unsigned int folio_order(struct folio *folio) +{ + if (!folio_test_large(folio)) + return 0; + return folio->_flags_1 & 0xff; +} + +/* Returns the number of bytes in this potentially compound page. */ +static inline unsigned long page_size(struct page *page) +{ + return PAGE_SIZE << compound_order(page); +} + +/* Returns the number of bits needed for the number of bytes in a page */ +static inline unsigned int page_shift(struct page *page) +{ + return PAGE_SHIFT + compound_order(page); +} + +/** + * thp_order - Order of a transparent huge page. + * @page: Head page of a transparent huge page. + */ +static inline unsigned int thp_order(struct page *page) +{ + VM_BUG_ON_PGFLAGS(PageTail(page), page); + return compound_order(page); +} + +/** + * thp_size - Size of a transparent huge page. + * @page: Head page of a transparent huge page. + * + * Return: Number of bytes in this page. + */ +static inline unsigned long thp_size(struct page *page) +{ + return PAGE_SIZE << thp_order(page); +} + +/** + * folio_nr_pages - The number of pages in the folio. + * @folio: The folio. + * + * Return: A positive power of two. + */ +static inline long folio_nr_pages(const struct folio *folio) +{ + if (!folio_test_large(folio)) + return 1; +#ifdef CONFIG_64BIT + return folio->_folio_nr_pages; +#else + return 1L << (folio->_flags_1 & 0xff); +#endif +} + +/* + * compound_nr() returns the number of pages in this potentially compound + * page. compound_nr() can be called on a tail page, and is defined to + * return 1 in that case. + */ +static inline unsigned long compound_nr(struct page *page) +{ + struct folio *folio = (struct folio *)page; + + if (!test_bit(PG_head, &folio->flags)) + return 1; +#ifdef CONFIG_64BIT + return folio->_folio_nr_pages; +#else + return 1L << (folio->_flags_1 & 0xff); +#endif +} + +/** + * 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) +{ + return folio_nr_pages((struct folio *)page); +} + +/** + * folio_shift - The size of the memory described by this folio. + * @folio: The folio. + * + * A folio represents a number of bytes which is a power-of-two in size. + * This function tells you which power-of-two the folio is. See also + * folio_size() and folio_order(). + * + * Context: The caller should have a reference on the folio to prevent + * it from being split. It is not necessary for the folio to be locked. + * Return: The base-2 logarithm of the size of this folio. + */ +static inline unsigned int folio_shift(struct folio *folio) +{ + return PAGE_SHIFT + folio_order(folio); +} + +/** + * folio_size - The number of bytes in a folio. + * @folio: The folio. + * + * Context: The caller should have a reference on the folio to prevent + * it from being split. It is not necessary for the folio to be locked. + * Return: The number of bytes in this folio. + */ +static inline size_t folio_size(struct folio *folio) +{ + return PAGE_SIZE << folio_order(folio); +} + +#endif /* _LINUX_MM_FOLIO_SIZE_H_H */