From patchwork Thu Feb 15 14:55:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max Kellermann X-Patchwork-Id: 13558586 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 B734BC4829E for ; Thu, 15 Feb 2024 14:56:30 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CD52D8D0026; Thu, 15 Feb 2024 09:56:20 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id C5DBC8D0022; Thu, 15 Feb 2024 09:56:20 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AAFEB8D0026; Thu, 15 Feb 2024 09:56:20 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 8EE008D0022 for ; Thu, 15 Feb 2024 09:56:20 -0500 (EST) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 69204C0F93 for ; Thu, 15 Feb 2024 14:56:20 +0000 (UTC) X-FDA: 81794338920.09.647EA2D Received: from mail-ej1-f41.google.com (mail-ej1-f41.google.com [209.85.218.41]) by imf22.hostedemail.com (Postfix) with ESMTP id 64A67C0009 for ; Thu, 15 Feb 2024 14:56:18 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=ionos.com header.s=google header.b=L3hurrd3; dmarc=pass (policy=quarantine) header.from=ionos.com; spf=pass (imf22.hostedemail.com: domain of max.kellermann@ionos.com designates 209.85.218.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=1708008978; 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=eRdb10/lfp5UXJT3tHF43SuGZ47dFW6seynzctgmvuM=; b=ZWxXG6lHpYoAPFAFVZ8NIZft6UkJhMe8gIE/E+kH+3dKfo5Fm4UGCRgauNQzXWxMzZRwXh ii01PNVi97LRyxmolWlIW3zAnz9BzR6zZENh/fP7WyUtcUMFYZcHx4RjiPccn2hXvu/zHZ yZPKmQmzyLfwFQWj5rMsVnCzSO3zC18= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=ionos.com header.s=google header.b=L3hurrd3; dmarc=pass (policy=quarantine) header.from=ionos.com; spf=pass (imf22.hostedemail.com: domain of max.kellermann@ionos.com designates 209.85.218.41 as permitted sender) smtp.mailfrom=max.kellermann@ionos.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1708008978; a=rsa-sha256; cv=none; b=lS8oCQQvNTo2WyTX2yfCljuLCgbsBgyx1uEY58glV1U92tC6J083OyxV65syDemK1MiAd1 xvVADbtnAXXm76oAR38106IsK3pcpYtTRKyAkx4+EOZwOn4Cu2WSNe8k2W3FNBBmFeNSnS Lynr46cDr+iaVWpIc+kAaQeojO9Zeb4= Received: by mail-ej1-f41.google.com with SMTP id a640c23a62f3a-a3d5e77cfbeso177475766b.0 for ; Thu, 15 Feb 2024 06:56:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ionos.com; s=google; t=1708008977; x=1708613777; 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=eRdb10/lfp5UXJT3tHF43SuGZ47dFW6seynzctgmvuM=; b=L3hurrd3og6EXdSkGAxJd3j+uF6wtY1C/wAL7RZTQkRk/cBm1AiYjeSYOwAEZfhI10 D+iTgoM0jXj2+vsXrRU+O75MDPcxOi2YashV2xcI73cd2TbVDK9gPeTGljq/RuDZxPhV L+/Z79/s13/D6yWSFBWm3I0S3ylq6u9eLYWEFXLVfMi1IjKDhlArwvjqxhidgg1WFXnM wGEbVRy5A4IxkTYPLKpniWLWgIg67LawXcXrDzXsPVbuaj30BS9viGGuv7RVgtFjiwkY 4yB+NohquA8ac4B5ava1vQapKu7l/7Ju29xDy3q+MmLQo8EZYIBw8aP5qcld6wLN9wyA sFjw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708008977; x=1708613777; 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=eRdb10/lfp5UXJT3tHF43SuGZ47dFW6seynzctgmvuM=; b=ZWyqcWFOrsU6RGdETIx+fomj6ucr7qLqvBfPRoVGLwXSZ9FoiXt22HEIGsuuVj8/dj xC0qbd7ijyOkUQaNVpeFLvFbrnF3CGKVLTMuhARa3UG2QjA0MAjuKWY46QC/dDwypvoB powpTiYATeyPMT9Z/vkpQ6JecipyhMduStecRk95pCiYZae1Ctp/D1JkyDw+Pbtu+KTW oIfGpinaYkiId6q76Xkg67zm5fgqSiNxCaqZF+F6fNdXE+ppiJrYs25ngY1VIE6LkPDT C9pUsUHuplA82vSTLufS7ExoxjLClZ8s5J53QajIADBLaxravTOWgrpICY1ouAn3b2Kl iIog== X-Forwarded-Encrypted: i=1; AJvYcCUKolr6pi+4UbOi63nOQIBSu/B4tX9v0xjIrbtghKGBxJ7oeHTZzGVm75g0+7/Boe6nC7a64S8DvsKKr5vh9HEtorM= X-Gm-Message-State: AOJu0YwosIPTh6DhyyrJtlAftmMRMa3+qcuLxvnAvbzlyRW7Y+eUn4Ll g5HAsvhTjW96EHeciKVXgS9rE7iorqUftJpQDAWoeUWhTV4V5plG5dHk4WJ7r0Q= X-Google-Smtp-Source: AGHT+IH0v9QIPzh4mLYGVGUXnX6SaEOib6O3Cyl6trEGIAKPjF0auWYf6zoGD9rvUxlVXqLI+vIGaA== X-Received: by 2002:a17:906:22d8:b0:a38:4f6a:4e7e with SMTP id q24-20020a17090622d800b00a384f6a4e7emr1940730eja.32.1708008976994; Thu, 15 Feb 2024 06:56:16 -0800 (PST) Received: from raven.intern.cm-ag (p200300dc6f267100023064fffe740809.dip0.t-ipconnect.de. [2003:dc:6f26:7100:230:64ff:fe74:809]) by smtp.gmail.com with ESMTPSA id s18-20020a170906169200b00a3d1897ab68sm631175ejd.113.2024.02.15.06.56.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Feb 2024 06:56:16 -0800 (PST) From: Max Kellermann To: akpm@linux-foundation.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Max Kellermann Subject: [PATCH v1 06/14] linux/mm.h: move page_size() to mm/page_size.h Date: Thu, 15 Feb 2024 15:55:54 +0100 Message-Id: <20240215145602.1371274-7-max.kellermann@ionos.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240215145602.1371274-1-max.kellermann@ionos.com> References: <20240215145602.1371274-1-max.kellermann@ionos.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: 64A67C0009 X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: s6przinfqyb8edtwgi754tnuk8zcg48p X-HE-Tag: 1708008978-144076 X-HE-Meta: U2FsdGVkX181eHmsH6fZWWvQPgC2eg+vIqXMiVyeGhk77QDM/V09S4b45e8THFRs/BBmpKkpjAA61oqKtbFW76VhNjD0zSBVqFRmWulwFZg0gLGUQjI2pdl96qRmb/AVGr2x9nMTQfHo0B00JJDUggrJ5yMsRimMx0KJSfpEBdj79xYwqWP8+mPzUVcmDEXMnRQ3HqkSqFpTtXsLAZXKJvWaFZKlicGpD9UYAT76pXracanXvPAMYLNy1Yb63ajbTE/MCfLeByWlaLG3s6o+Hz7DovmnacxPF6oK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kQbGvmw0U/yQzsFdQNtAFj/9SwwC5EwHFVmF6n/054VlgLDlc= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000202, 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 in linux/mm.h. Signed-off-by: Max Kellermann --- include/linux/mm.h | 140 +------------------------------- include/linux/mm/page_size.h | 150 +++++++++++++++++++++++++++++++++++ 2 files changed, 151 insertions(+), 139 deletions(-) create mode 100644 include/linux/mm/page_size.h diff --git a/include/linux/mm.h b/include/linux/mm.h index 2cc39916cf04..778f8aebb45c 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -4,6 +4,7 @@ #include #include +#include #include #include #include @@ -1049,38 +1050,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 /* @@ -1294,39 +1263,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 @@ -1966,50 +1902,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. @@ -2029,36 +1921,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/page_size.h b/include/linux/mm/page_size.h new file mode 100644 index 000000000000..0f8ee3dab6d0 --- /dev/null +++ b/include/linux/mm/page_size.h @@ -0,0 +1,150 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _LINUX_MM_PAGE_SIZE_H +#define _LINUX_MM_PAGE_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_PAGE_SIZE_H */