From mboxrd@z Thu Jan 1 00:00:00 1970 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 DD480C54788 for ; Thu, 22 Feb 2024 11:51:21 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AD1576B007E; Thu, 22 Feb 2024 06:51:11 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id A5ACA6B0080; Thu, 22 Feb 2024 06:51:11 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8125F6B0081; Thu, 22 Feb 2024 06:51:11 -0500 (EST) 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 67D886B007E for ; Thu, 22 Feb 2024 06:51:11 -0500 (EST) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 474AF1C0427 for ; Thu, 22 Feb 2024 11:51:11 +0000 (UTC) X-FDA: 81819273942.28.0D60B77 Received: from mail-wr1-f41.google.com (mail-wr1-f41.google.com [209.85.221.41]) by imf17.hostedemail.com (Postfix) with ESMTP id 58BF84000C for ; Thu, 22 Feb 2024 11:51:09 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=ionos.com header.s=google header.b=Y3N0noEb; dmarc=pass (policy=quarantine) header.from=ionos.com; spf=pass (imf17.hostedemail.com: domain of max.kellermann@ionos.com designates 209.85.221.41 as permitted sender) smtp.mailfrom=max.kellermann@ionos.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1708602669; 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=zrzkS3Jr9rDGJgnZMZCc9dS49bV9O/AFecbIWIE3ZsM=; b=nDY6JcevV1Ud0vb2wtsKYM0w/K/uRMEWfQ0i1tXiXAwIn1kewjcMcnUV6FsnXns1e7Euvd KQ7t4qhHg8mJT5T0YsRogoVu5Bq3P4C1n+AC1QzCLuNrT4/JtVEiwe10JJZEaHtUaB3lNP HBbS2D9D8EJbY+zPahQMDWEp4okSTXs= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=ionos.com header.s=google header.b=Y3N0noEb; dmarc=pass (policy=quarantine) header.from=ionos.com; spf=pass (imf17.hostedemail.com: domain of max.kellermann@ionos.com designates 209.85.221.41 as permitted sender) smtp.mailfrom=max.kellermann@ionos.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1708602669; a=rsa-sha256; cv=none; b=0wrx70oCOKDKcIEzPlFUZn/V0XtWpM5yrZ8kpV7Iwt24j53QZnYWqj4rrXJFriKg68uyel KLFiVUt/D+1W6q6N6c6LQTgP0Q01YBOMM39L6rZtt2kTZl17ex1mSa4VR3lgUMFr2HnqU4 BQEDQiHf088RpAz4E0GdrVoyC0TFEnY= Received: by mail-wr1-f41.google.com with SMTP id ffacd0b85a97d-33d6f1f17e5so1753755f8f.3 for ; Thu, 22 Feb 2024 03:51:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ionos.com; s=google; t=1708602668; x=1709207468; 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=zrzkS3Jr9rDGJgnZMZCc9dS49bV9O/AFecbIWIE3ZsM=; b=Y3N0noEbXgUoT0rTEbwsfiTe5wzsq/yPPPybxdoc2zjVFITxO0ynwi45YOIiJf4q02 5PasvsteQCqLYRD6a+X3Z6kpfvyMT7CEQNt52YjjoK2UK6aPFKoP+lynn57JhnuKB0aw iiNq70r0EZtRv5N4plbCRTcz4d5Md8He21lZ/s4rXOwiRehcpDLMZN24lGB9Q1SFgdMZ 58sv8wc6yY0NaHVDEbUAPoEEU+5N8r0/c6DZfK7J/VVGc76C+GEB4EFrVLs+LC2S2kyp zKUKNNRnzsqMlsfuzp18LIKcRjcyImnIFrQUQoXg9T4NPdRHmlh0mwMBL7hDav8mo3t+ V6ig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708602668; x=1709207468; 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=zrzkS3Jr9rDGJgnZMZCc9dS49bV9O/AFecbIWIE3ZsM=; b=rBMQZPK1eEjmoyTCYOTtcFoBNSQPFp1X6atfB+WnBV2CMXFLmD6qefLVDWT1hFYnCJ CBTLmCQMI9H53FTP2GKaKWpsQS0Wmpa+GLOuBQtq2kDtMBsJKUHR7t7A9kik/lXlXXqm +R/O7kMt876OkkrpHW6z6NOvwQ9fg8abtqJdXjavY9fJBIVvL8vPju3/9lq6hjP9dHo6 K7ipZpxUCgMcdx4JIpxKmcwRqVzHDBuPlap9RQHDU88mMLhu7OLLh66ePXoJWx28zfqp kmqiCW0dVtbfJ/dKZ7kcuVUpjG3DHXdgiJ9Z64gqKhzvHirH55nLd71etnInsT/n+qvm Xw9Q== X-Forwarded-Encrypted: i=1; AJvYcCVg7uVcw+n4k4tDePaRI4Yg62D0ixkWKqAiNk9Z6aM9n0kdnTxp7KxoEBpBTcqtPznroFHlp9J5WH2edKix2D+snb0= X-Gm-Message-State: AOJu0YwZyAgs9swJezZ/4sLnxQvleIJsa5M1y9ppXpAnQTzxIamqJNPg UBSthV+Pv5HNt0i8bxqtthOKC20V5vQSsBAgayV0jh5E0765l30GtSYhEeejZDI= X-Google-Smtp-Source: AGHT+IEf30oKm3SvDXvZCjTXb955DQvutxWXp0IjhfwewVF9FwEP1ddQHLarxc6WQx8FTmkpa5t7tA== X-Received: by 2002:a5d:54c4:0:b0:33d:887c:fe04 with SMTP id x4-20020a5d54c4000000b0033d887cfe04mr1569315wrv.19.1708602667899; Thu, 22 Feb 2024 03:51:07 -0800 (PST) Received: from raven.intern.cm-ag (p200300dc6f010900023064fffe740809.dip0.t-ipconnect.de. [2003:dc:6f01:900:230:64ff:fe74:809]) by smtp.gmail.com with ESMTPSA id co18-20020a0560000a1200b0033d4c3b0beesm15044920wrb.19.2024.02.22.03.51.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Feb 2024 03:51:07 -0800 (PST) From: Max Kellermann To: akpm@linux-foundation.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: willy@infradead.org, Max Kellermann Subject: [PATCH v2 06/14] linux/mm.h: move folio_size(), ... to mm/folio_size.h Date: Thu, 22 Feb 2024 12:50:47 +0100 Message-Id: <20240222115055.1172877-7-max.kellermann@ionos.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240222115055.1172877-1-max.kellermann@ionos.com> References: <20240222115055.1172877-1-max.kellermann@ionos.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: 58BF84000C X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: t155rmk7cdswz77fr9ref63hghxc7ou8 X-HE-Tag: 1708602669-501197 X-HE-Meta: U2FsdGVkX1/CuaoK1AzK+fjYDE3F/q2WRp0Xd3IzQh4tH219UlUZJ1V4fUYYI70ptvKvwvLcbJrF7VuloKBWk9pePRviZMBo1vkO+o8Cdpmkk4TKEDZm+9rqKWl4miyWzpmhoz3Kt5s648ESBYWw9HU8ADiD2D0fdXqZ7QD0LqS0cEA/pTDqGVQihaGd/lpAwjId/PkowkdL1t3pp0cT7P8lYHTUzBWa7a+xV42r+YCtjq2wbtixdh0vgblqzyYEOf+Poa9srXlZgnhG9/z5VwXS+WteDfdGYrVfcmayAh5qk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MYxr1B2juYqGNJDUz6UB4EFIHm/OEpYHPtN0moZGuE= 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 57c091e7579e..9dea6477b4ac 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 @@ -1054,38 +1055,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 /* @@ -1299,39 +1268,6 @@ unsigned long nr_free_buffer_pages(void); void destroy_large_folio(struct folio *folio); -/* 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 @@ -1971,50 +1907,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(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_next - Move to the next physical folio. * @folio: The folio we're currently operating on. @@ -2034,36 +1926,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_estimated_sharers - Estimate the number of sharers of a folio. * @folio: The folio. diff --git a/include/linux/mm/folio_size.h b/include/linux/mm/folio_size.h new file mode 100644 index 000000000000..dd8af39ef572 --- /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(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 */ -- 2.39.2