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 0F9E5C54E68 for ; Tue, 12 Mar 2024 09:42:08 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1F8C28D002D; Tue, 12 Mar 2024 05:42:00 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 15A608D000D; Tue, 12 Mar 2024 05:42:00 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EF19E8D002D; Tue, 12 Mar 2024 05:41:59 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id D90128D000D for ; Tue, 12 Mar 2024 05:41:59 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id B4BBEC0EBC for ; Tue, 12 Mar 2024 09:41:59 +0000 (UTC) X-FDA: 81887895558.09.12CDFD8 Received: from mail-ej1-f51.google.com (mail-ej1-f51.google.com [209.85.218.51]) by imf19.hostedemail.com (Postfix) with ESMTP id 04BA21A0015 for ; Tue, 12 Mar 2024 09:41:57 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=ionos.com header.s=google header.b=RZ243ZXe; dmarc=pass (policy=quarantine) header.from=ionos.com; spf=pass (imf19.hostedemail.com: domain of max.kellermann@ionos.com designates 209.85.218.51 as permitted sender) smtp.mailfrom=max.kellermann@ionos.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1710236518; a=rsa-sha256; cv=none; b=hcZtrFOQg3VAa7oeR/KEM14tdeUGfy79MAy7GGr19XKJMpM0WJQLUKnyayoJ3127PTa/1h sZLf35UJbumSHGkIHPXbrEIVPP2dsD2bq1ZhtZf0phqWMIBefT35IFwCtDrQGl6c2RDxhF BU8THffjFv3JN4QVj41ufE8zy4GLI3I= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=ionos.com header.s=google header.b=RZ243ZXe; dmarc=pass (policy=quarantine) header.from=ionos.com; spf=pass (imf19.hostedemail.com: domain of max.kellermann@ionos.com designates 209.85.218.51 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=1710236518; 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=pOCd08dVcNL3Vsd080U9IACgrN+4/kX0/WIiYLCuiY0=; b=sNrD8ahBVsuZuEaRaP4oW+Z/uHsa3OPtWDZIKMY5dE75E3tABoIPGNtJeFnAh63qnWO1M2 A1PY2rKgVaKCcbSY9YUq+rXuJNyBDfVV6ZPM50gpuTSMbVo7h9+0oLDTAFW+Sd40mWqY45 vJU3uGK/BE9ZlK2Gbtjqsy7wW8VGr04= Received: by mail-ej1-f51.google.com with SMTP id a640c23a62f3a-a4649c6f040so28048566b.0 for ; Tue, 12 Mar 2024 02:41:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ionos.com; s=google; t=1710236516; x=1710841316; 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=pOCd08dVcNL3Vsd080U9IACgrN+4/kX0/WIiYLCuiY0=; b=RZ243ZXerZxNny8mjCfBqusFiplIHTembsnIuV2hc9Ts0BritoUKxl8JpZGiEnMLa8 h81FIYC0UoBpDvOl5JGkIEAR/VNWFdGe8m+JObWjNJbbpObAPGHWqXht1eRDi0n8F+KO fgf+NDeU8uN/R8m0xHk1S/0ajYxTdN5IiXTONKZ2A/iFvs9VTy0hch6imVZmJaqoSfrE LWXNqIW1ej+PgdZcyy3l/gSRYWtxQyW0OM6rvDkIX3Ctnrrx8/3j4ERFn99Z4XFgS85m 9mvXkEoS0b9yx5kCEg8l9WfH1iuxIlwSGvKj0QNa4xEG8jhoWK5AuzXKMj+07lwt7nlG D4vg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710236516; x=1710841316; 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=pOCd08dVcNL3Vsd080U9IACgrN+4/kX0/WIiYLCuiY0=; b=tnYhc1WBFwReajsY17P3bKhF4nVtfdbd8PrzSds9tUUjFQXw34QNWy4MRqqa1HwUy8 /WC0smi4VFz0QX8M9U+6IF0N5nZ6KtYy2H8xjG58knH88rpmBtWlvCjkJli9PgwFVFWn OrTvLtw+20+LN+ZMm/LKbalpEC2rh6WauqjFabNGcLy7vLrqKD2l2kyyc1bNF9yFhDeQ M0Xdyw/JffcaiicbXikZ6CuqsF2Iji5E0NWo2Td3h2XUHXI/tsNLPegThdet82bq5Kd/ 8UccAe2t1i9c0XcKin3tOkA3fSD26oAmVbF2sypmSPRmkYmFb+aCaeMeR+E1eOIGVmNR WOTw== X-Forwarded-Encrypted: i=1; AJvYcCWEKOO26g5gb1HAadii8buBZxTpfPa+eTvLIAM3VLV3mlgh7OzDPYef6gc7dmRBpSPWXSd7cmW8pQIl7T4AZsD76CA= X-Gm-Message-State: AOJu0YyZNDpTXhSNFYjn0/I4PCwxzW96hXVrMEuOqpceCOXqXzzqbu4Z jLGhb7baKmJGHR2DOoBpMv4i7tf9tvwsgj9M431A7uVXorMWth/wU7FZWcrRynQ= X-Google-Smtp-Source: AGHT+IHjOIF4GXnxhEXYczDPqX+KWpyAlclam9FjYiLmhYYld2nrVA/ZGxZiKu/mMUbtJ1A/57F7ng== X-Received: by 2002:a17:906:9c87:b0:a45:ba06:e512 with SMTP id fj7-20020a1709069c8700b00a45ba06e512mr6914716ejc.6.1710236516574; Tue, 12 Mar 2024 02:41:56 -0700 (PDT) Received: from raven.blarg.de (p200300dc6f010900023064fffe740809.dip0.t-ipconnect.de. [2003:dc:6f01:900:230:64ff:fe74:809]) by smtp.gmail.com with ESMTPSA id jw22-20020a170906e95600b00a4623030893sm2091961ejb.126.2024.03.12.02.41.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Mar 2024 02:41:55 -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, Max Kellermann Subject: [PATCH v4 07/15] linux/mm.h: move folio_size(), ... to mm/folio_size.h Date: Tue, 12 Mar 2024 10:41:25 +0100 Message-Id: <20240312094133.2084996-8-max.kellermann@ionos.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240312094133.2084996-1-max.kellermann@ionos.com> References: <20240312094133.2084996-1-max.kellermann@ionos.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 04BA21A0015 X-Stat-Signature: chskrcrpr85gj51b4sd8fnz7ghiri3zi X-HE-Tag: 1710236517-300475 X-HE-Meta: U2FsdGVkX1+6XLDPRm1aHcLKQCHDstdnj6TNzOSS3x8VjP7tGbklXhXNqFZ20r24HqZOTvoC6wYpkpEOcL+zhlN0zGPdrhy4LOACcvKEIow4SN8BU4XQv/GWynF1RovHPnCFZXdFzZKkHUzHn2boY5cIJ290YToh83064iurGPbxDhHpJ2xpYGLge4Qh/VnmhmWKDsmJFj0Hs+oYhg9g7N6Z+lzodVGXu0oep4ZA+mIgpvDxzwpwO8d4EWt5jbzx5lljSp2PL4Ib6ANjbM+mzhhVSPzqW9cA3HdanCEEfEe5M8JGwNwKDLVte7wGUDsWW3qr7+jHkKTiYJccwhuzeQTvZh7jWWu6cIm+t9+WUCM1QZx5lqGGKGTez0JRU1Ej44Bx9TNrl3fmgqM0C8QI3x9VOxzVew0cu+4jALOna9hReEcj4ofPRf5o6nIZNhNSqnET46zozsd6ZoOnN3N6kcb6TAZevdyf6A1GJNI7ndrq65Q2cKNUX9QSdgoMoKRaL5m6zNrBbvQ/iHhbzwVnaKhkiNhKDMk/LbIf4gJ6163amHkV4PibJJ2IQ5hZFakwnPAl05ZidsTbxQVvleQX3m2610w8uDaOwNoDLSd/Jf8J8ZzdiHbnI2xe54elqWMHmF+u4BFBgHcLA4auavnYiHvxpV2wIq5bwXhXXoMVzPkRGFHBc2xxXXVyYbfVr/Hklk5o3TuRlIiCmYw4D4rcVONErjqOivptGv2c1j+qFaeRd9aNQWHXMee5ltDStNyH06DDKxepznhLlEA9eBvHmCAgMVn+Gxje71y9HuPNpauPa5iI9OeUe8yV19JnVfmepk8SQbkhqAf/46emRJMY1QoTZPzajfkFqj706L1Mt+/SzueuhaP8jU9GWZmtkEoKz41/yzFi5wQsvPHFBWlerKlLNgxSznRWZ741lJqaeKp9kovTuptueDEJtioKXzTxj5D6ysRI2FNj6apOViu /KRwJy4i opBkTqsKmZh7yjiPkij/AQowhAatCT2h+WGV5JhvNSglI/tLqlieyHDfvjwL4HJW9lYQvjlMOWOmGwUr6we19Yv4cBuitLb/Kzf0jvUlaw7kDXiKRZjI+PAqQvFVPzKSXAPGgsmRoMCg8dG2/LhqZn4bvEhF9nmnWq/IR 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 713cedc03b88..0d291ff61db3 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 @@ -1068,38 +1069,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 /* @@ -1306,39 +1275,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 @@ -1979,23 +1915,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 -} - /* Only hugetlbfs can allocate folios larger than MAX_ORDER */ #ifdef CONFIG_ARCH_HAS_GIGANTIC_PAGE #define MAX_FOLIO_NR_PAGES (1UL << PUD_ORDER) @@ -2003,33 +1922,6 @@ static inline long folio_nr_pages(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. @@ -2049,36 +1941,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