Received: by 2002:ab2:710b:0:b0:1ef:a325:1205 with SMTP id z11csp942787lql; Tue, 12 Mar 2024 02:44:50 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCV/vfonnxb7915gUqB39B06RiyKiSHh3NP4tzBTGSPShjUXTmtLNdxBUiMXFqTOxHa/j1ja7+zrN0GK4ZZDmKgcJxZat0Xdy0WrwHCYZA== X-Google-Smtp-Source: AGHT+IHaD7ppbOjkBx7I7cbWElOPx9fEHbv5b18NYWuzN6jjhsZWzE0E34Pn6nQEiZI8VKI3KTkD X-Received: by 2002:a05:6830:1497:b0:6e5:dda:1a26 with SMTP id s23-20020a056830149700b006e50dda1a26mr9919822otq.33.1710236689775; Tue, 12 Mar 2024 02:44:49 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1710236689; cv=pass; d=google.com; s=arc-20160816; b=XUqMkY7aC/1TOv0fLPE2vbFj3P0MJYbJLjeZpzTAi30PzwuehSJ5hT2BUz68ggbbE8 QvKyeZw0MoNRk4pFRuMlmVg9CGlPw3ApxDii0H3gAt8fmmNSGTpxrvM/xzRj2VH3zYH/ GvaR305wvOe1MD4z2zFZbwFphar/OWk7vfoXQeqFzUkTIcKXodvtjiHOYRX22xbYL4nH mapQVagLg1j6ewviylgzeSHDl5Pv9dR3SG2qekjxcTFV0qXOjp2Mh8AYSDLMoeJRgbG5 NPnPlnlMYDUKnIr+++yD9zQjklvXK0yCaOR2vyJ+dxrxAdAVR10FViyNZSYWVFqx/NPI 7yLw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=pOCd08dVcNL3Vsd080U9IACgrN+4/kX0/WIiYLCuiY0=; fh=6GAc6seBccqhFF1y7MqxaJKFgObQytjviHEZhuNeXos=; b=U5I2dKikkKrtFC1PbLtVKam8HMrKbwGXmq4rEqOSMyZ0mC0ASdfiZYJG5ELSx05KQt oLJ6HxuomJglOIUILY7II85YyyFw7BUmuliefQcMsrwLPGGYhCyCQKRao9/yvDMvr7ns q1GQbypM6l8Gqc8NSQ7F4+eieIQtwAb19oakRd2Eezcm2dmkjJUC9KF+XMWsD76NcglM 9Ad5554jVSh1ZE+0OkRj5esV05ofc/cBP4nC5RsO08qaodxlbdsUUJ91A0/JhZnrLZRD L4xZopie3hBjrBlWed2wWtBKAL1UWYElT+40mE6p7fgH2dzc+2Nlp5mdffyPYDzPKMqC Lucg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@ionos.com header.s=google header.b=BMj+d4Qm; arc=pass (i=1 spf=pass spfdomain=ionos.com dkim=pass dkdomain=ionos.com dmarc=pass fromdomain=ionos.com); spf=pass (google.com: domain of linux-kernel+bounces-100047-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-100047-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=ionos.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id 14-20020a63144e000000b005d8badaa0c8si6676472pgu.621.2024.03.12.02.44.49 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Mar 2024 02:44:49 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-100047-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@ionos.com header.s=google header.b=BMj+d4Qm; arc=pass (i=1 spf=pass spfdomain=ionos.com dkim=pass dkdomain=ionos.com dmarc=pass fromdomain=ionos.com); spf=pass (google.com: domain of linux-kernel+bounces-100047-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-100047-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=ionos.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 6ADD2281255 for ; Tue, 12 Mar 2024 09:44:49 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4B2B47B3D7; Tue, 12 Mar 2024 09:42:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ionos.com header.i=@ionos.com header.b="BMj+d4Qm" Received: from mail-ej1-f52.google.com (mail-ej1-f52.google.com [209.85.218.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4EB817A713 for ; Tue, 12 Mar 2024 09:41:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.52 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710236520; cv=none; b=Pc/+yQDRI6yGFCzyI+DkBEmJPR4rsm54arU6cKc82uBb2ri/o0Xe6qnMO4Gzc5tMnUFX+uptjVFxTxOtN0CP9ktIUBvxTD2eHfQIllqHFBtcGpp7Gpw9tdsQk4FN7rKi78FZOSHtwgYMH0aVTAdgB93979qaqlRK5Ynfkcd3x44= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710236520; c=relaxed/simple; bh=oP7Nqn8yuoYUkUvIrSzyGSI4sXVkm22lBDg3rwCJ9kE=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Q6bV8RbyRi8RaP3P2D1Ygf9JV1SChO6DMvtg7acus+pDzo2xkI/aBc2tXLLDD7sEC91att2kYWtQNAcRa/QolyidTfoYoQ3cDWnRDuE6y1FZyN56k19VX0JEMih3P0Q0DDBBsP2VtB11tuQwfd28UFIhaicMrnjoTLO7BMjA634= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=ionos.com; spf=pass smtp.mailfrom=ionos.com; dkim=pass (2048-bit key) header.d=ionos.com header.i=@ionos.com header.b=BMj+d4Qm; arc=none smtp.client-ip=209.85.218.52 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=ionos.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ionos.com Received: by mail-ej1-f52.google.com with SMTP id a640c23a62f3a-a4645485da6so50087666b.1 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=vger.kernel.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=BMj+d4QmPEnzhOwOq9YE5bayC4vLqgzgcHTK8aKg1rAc4VGv++O7UDu+C2jjFyXBIz TMx2P51+tG9wCPtlInMWXcwp0mLTX6qlMUZnohy6tJ5afOzRxfmW0kkc7mqsqJY9nRJ9 VyPAH63+GlkXX7UHbbMF8Yxt+qlbJ+U1KqCtC1lyiF+6+6T6vwkDPI1kZHeF6UyxIsku pZPxgSjH6KGiZo0QNevsP69aZKeLktWL9F3BztT8MRTYF+nKFU+4lsZyxWRpu3R5rnFu ASslpqG7u9wGx9siaNHmnnCyMWugS+CENrdBA3AfhNgYtPzMRh9782/mYJGLkagNdEWE 0P9g== 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=qh6lKlFcRS2HKtPh7V/XTeWoM4uAAE3Xz2NfrGkmHRVyZCDpcr5+XT5uUnu/fglT3r sXkMEL8daSN3TkiqoJkIOdqtnHehH7ZQILiVxJaYrDgAOR4hLiqgELyBlW2w1kkSY2Fa dcwVIoqzYCg6XdztrBN6e4yxoDOzpoIqrk/SuaLjWNQjNrNZF45sVEMvpUPnYe56Gn3R eKcRfcTaWssM9YXTwUqRqPmeoOtjOlbUzH8oAjx63/6vTHcv2QQthQrW1p+4IdntJyDq jqnadSVFHwRnSyfNq3r/fA8NVKnOUVgGKDxbve2PC1McPqt88EnfnCnxR9fdghIAHyJK w1zg== X-Forwarded-Encrypted: i=1; AJvYcCWmI78RjoSeFtcDX2cid7NjAcTNC8DO/CPOzzyaNSPGYgltOqJlYgdP4To0JU2NYpo1wyrQfV8ALTLkZAyXZ4dUrdenXEq+iPL+9aFW X-Gm-Message-State: AOJu0Yw1mEoA/vDmS1XXwpXx9WbjDUyvORn8cX7c2M+KMXOBjl/jKLUk qPUISvAmnl2bUQqoYL7wiLAZP21bKrIfYRi45sw3e7FYwzAPvJZczS4bkY3WtFw= 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> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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