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 78D27C54E41 for ; Tue, 5 Mar 2024 08:59:54 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C23936B0096; Tue, 5 Mar 2024 03:59:44 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id B0CC7940007; Tue, 5 Mar 2024 03:59:44 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 987F06B0099; Tue, 5 Mar 2024 03:59:44 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 845996B0096 for ; Tue, 5 Mar 2024 03:59:44 -0500 (EST) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 508F1140DB3 for ; Tue, 5 Mar 2024 08:59:44 +0000 (UTC) X-FDA: 81862387488.27.2D8DD4A Received: from mail-ej1-f54.google.com (mail-ej1-f54.google.com [209.85.218.54]) by imf24.hostedemail.com (Postfix) with ESMTP id 85564180011 for ; Tue, 5 Mar 2024 08:59:42 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=ionos.com header.s=google header.b=gCYA62bS; dmarc=pass (policy=quarantine) header.from=ionos.com; spf=pass (imf24.hostedemail.com: domain of max.kellermann@ionos.com designates 209.85.218.54 as permitted sender) smtp.mailfrom=max.kellermann@ionos.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1709629182; a=rsa-sha256; cv=none; b=bnub4sbnKmRtLkaJK+UBwvoWXPufhERHNfyY13bE1NOK1xePyhHaaHmH/r72LCc643Y1ed j3+NAdX1Ej1SPJmRBqzhJEmOT9uHNPturEv2vcVUjNhnSNfY0rYCt97tL/w/wvz1sJNBCP l0oQce4XStz76QmRYqaU9m1FWMlY9cs= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=ionos.com header.s=google header.b=gCYA62bS; dmarc=pass (policy=quarantine) header.from=ionos.com; spf=pass (imf24.hostedemail.com: domain of max.kellermann@ionos.com designates 209.85.218.54 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=1709629182; 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=vRU4ObWmTomh5k2VdOO2eLBqMu7PfT3tWOMggfY0/kgZX9rrR6tU259oAQOR/bY7oNcseY OI2LrrnndR2nGho6PxE2JpnbtflLXk86f8OeWKsLh5r35gqm6lwyDyJz9pWCeXwa/7P0bU Fjt7XS88nkWkghBvvfsLGrAtinMrT0o= Received: by mail-ej1-f54.google.com with SMTP id a640c23a62f3a-a26ed1e05c7so908069366b.2 for ; Tue, 05 Mar 2024 00:59:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ionos.com; s=google; t=1709629181; x=1710233981; 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=gCYA62bSrU5rOrEIKMg1Urm89GHk4Zj2lxoje7sJw8bDaoNtPt/xuJMyxDXMAYDaws kx+g3wdqPtWz1PLT93sdUVkbKufu/ue3ky4bd2EtfvReBQ6qWa9Pa83PqIYcwQh4mF31 KIye1Uvn4yqI3ASvsV6LGNd06w+/R8GvdDWJ/T55a6bWWQSo3itsRJJYm5ppV3ydvitd YMVU1+ol0/wqQilKqlYcE6CodWMc6jX07jdiGL2Ro+6pvP4fJO5cSqobJjmosuzEKws/ u1EsCerHeAZ9sB0bHtKg+QQV0T7zlY7i+9KGvmEa97C/V+ey7kuz2Hl/rywculQepKnG o6vw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709629181; x=1710233981; 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=tsIAREsSGHshSbk9GgUB1GGr8eQS7DckQ5TTulqmDdSOxSejKWkKAhqha9ZkIX58GZ i+ELz9UfKj4Vpkhu2s73Swsr4MjUUdL+mE8fPCx4srl6nTzKu2oI73Yg+dNzJi2eLQZP +1u6JcK81pgMPWJK2Pqshignz1rRBW9LaqNFLUHGZY2vDEvYDHDJvS39mZFh3NGRzrns cUK/g4v14l8JJ9EbV/x8NJ+BlvHriYt4zBZEC2A9cFoun4sSBxcNnm5uilGiX5KqV1Wh f5O3V0lVMB0+LFZUmx5YcJ0ih+B+oW3bnL00a2zHZGemmIMqtTP60HVKm13EHi7hb9i8 eSYQ== X-Forwarded-Encrypted: i=1; AJvYcCWV2Mqn53ipN+Yaij3csK4Kceeac5fBqnyfVTC3H0mG7/4Hvm2QqrVt3FRqKmCKhG16IgFDH73zcQZ07tLDqWKLVR0= X-Gm-Message-State: AOJu0Yx2K1f2s/c7gbLAuqmTPCabe1rMUUHhZ/UuAEHRumcJKCWsCgVV uvTT3OK1AK50UAb3ZNM2LvbiUbZ0ixv9i1baMgwCM6vJE7/oBKFVKyFqgm9/AuFslssK/Ms63T+ b X-Google-Smtp-Source: AGHT+IGqfqDUczGGo3QetAY7OAT6x3XRZvle5Qp1hnV3EYWTVeS5PH/gGnq4+ZcDT1bZzO9ng+chBA== X-Received: by 2002:a17:906:ca46:b0:a3f:2ef9:598a with SMTP id jx6-20020a170906ca4600b00a3f2ef9598amr7729507ejb.36.1709629180945; Tue, 05 Mar 2024 00:59:40 -0800 (PST) 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 gs4-20020a170906f18400b00a449d12cdc5sm4453005ejb.119.2024.03.05.00.59.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Mar 2024 00:59:40 -0800 (PST) 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 v3 06/14] linux/mm.h: move folio_size(), ... to mm/folio_size.h Date: Tue, 5 Mar 2024 09:59:11 +0100 Message-Id: <20240305085919.1601395-7-max.kellermann@ionos.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240305085919.1601395-1-max.kellermann@ionos.com> References: <20240305085919.1601395-1-max.kellermann@ionos.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 85564180011 X-Stat-Signature: c9wm4o9jz6y58n1jwerfcq7xgy41qbi1 X-HE-Tag: 1709629182-973564 X-HE-Meta: U2FsdGVkX18OMgsJLyNc2/T1NwSAjRiRrhw2oWM5KVIk58dntI1QL0N6bHsON9bFNc986Uy0Annhd6qFFPgDiQeFEascJkQHHmLZO0UBuNbG6SwOrrV9xA3ykoacaW7BDzm6jrYq7n1t+YA4GiX+ByUalrBdVUK75GZi25BRfyKTQzngFMO1z/pZXmIvw3mhkgNGXETjB7IA1zXWDJvGEzHNDw8bKr2Rn6rgYbu13O65n8I/ERXa4GDbFNPtCyXseN0LJwdPFRkMmU60F3NyICd10t5dDPoSnacdOVKVrKveQKYFJz3uZGv48mWBshUUcZucUppfQa3kgGHiIOdfYfO6dZ4f97YVevWtX2gwn142tcw4tdshEjbIYT/FzSJYsEPFy7N2jsyXVxmpf0/eEF/tz/GYkpIFHouqIAc0J7M1iE/6Gzu8eveaRCfVcdprfjXf9tvsx9DI4sFW3cYlv6nSEy4G+nlMNMkErVbQVJX+iqbd0rkORODpR8/vMN3IaGHinuykGyVV+tq2S1pfrxnl2cEoOQoyfUtTW/ZahtvfNVXSqGuxyDkNnPvqV3Rr5Tk68NMIrfsdGU8J0NR3ZyJQIYktLcP1X296sAfgvO0MB5ajFb66VwNlyLe0LIFIR3jjT27VyHc084OxU1d1ximWA/M5zhRNUouB9KvDWbjJBtKy31wLqKLxcu+XxBIBK24w9wpKutbnN9tqvblwARIBSdOqU3DoVs/txhJjWF6+EwvGxaMiP09/2QIAEnAMOPUmhSIxyTKZVvPMvb01WcJ+fyR6ZFZfXQ9ErrRtOjwiDwUYlZZILnFHNRz9ml4/zHy9jgMQtKueIqbj7QNb7LGpC0mNaQFGzp02K0dtxU56JaX4mQXm9Fx+U3NWtj5QLNIl7ij3S0YXfbJ/qNDapAzOAxf+Q8xZQUjFYZCGlToDEpJCvRCx1AKbesttuHPCHAwN67JX5fEHAYb4Vb1 6TG4rxOZ So6ettD6X8NMNLqviDJscEOdPHczGPNLkMTAEfq/HSbF+iSyAoOi8pqc1UmKjxXdKo4EaBSq9y4XLu736RSZcXg8D5nqvBN4MvTR8stIDGZnGtcE4TXtfiFPw2QZgUn2z0sKD5rZtz6RCdIXyQqFAJ5rkSfDjXhNOc8zm 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