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 80D81C4345F for ; Tue, 30 Apr 2024 15:30:17 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 53B0E6B009E; Tue, 30 Apr 2024 11:29:56 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4C1FC6B009F; Tue, 30 Apr 2024 11:29:56 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2EFB76B00A0; Tue, 30 Apr 2024 11:29:56 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 028CB6B009F for ; Tue, 30 Apr 2024 11:29:55 -0400 (EDT) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id AE66140850 for ; Tue, 30 Apr 2024 15:29:55 +0000 (UTC) X-FDA: 82066583550.22.87D5E15 Received: from mail-ej1-f54.google.com (mail-ej1-f54.google.com [209.85.218.54]) by imf14.hostedemail.com (Postfix) with ESMTP id E9CDE100002 for ; Tue, 30 Apr 2024 15:29:53 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=ionos.com header.s=google header.b=akt2T+DU; spf=pass (imf14.hostedemail.com: domain of max.kellermann@ionos.com designates 209.85.218.54 as permitted sender) smtp.mailfrom=max.kellermann@ionos.com; dmarc=pass (policy=quarantine) header.from=ionos.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1714490994; 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=bHEADXESNKyxsQ8fI0BRJ8jQ2HgpWucDU2RQJfn4Qzg=; b=Y8sQfdCs264pZGYndsFjB6BNRp2pWBbV+tqp1nztiK9Ekmcac9IS/bQttlD4EK8BHKW66u 8CqHRY02o1SMEmm2SfIMf6pNurmrEP9eqIrkuY84HnV4HAveAjDBrLuK2ivAsMlhk2ml0K Z+zwmfEG7vzvR+qlic4E8oe8Qw+9EmM= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1714490994; a=rsa-sha256; cv=none; b=SCaR71abJ80ljeNMiUL9xfCMOSQ7s43qgdBW4HA31rQKKyy9vjW0IRSYw36zEuFwytMvdx X4FmT5LDGfJo5oHXod3Xa4zWUorBigX/UrbVdPwywY8tYopxeshdPvFvzr4QYcWE8PboXR 4dwIz3RIBiQ5y5HlVKBdUrqMg5HoOd4= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=ionos.com header.s=google header.b=akt2T+DU; spf=pass (imf14.hostedemail.com: domain of max.kellermann@ionos.com designates 209.85.218.54 as permitted sender) smtp.mailfrom=max.kellermann@ionos.com; dmarc=pass (policy=quarantine) header.from=ionos.com Received: by mail-ej1-f54.google.com with SMTP id a640c23a62f3a-a58fc650f8fso303012066b.1 for ; Tue, 30 Apr 2024 08:29:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ionos.com; s=google; t=1714490992; x=1715095792; 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=bHEADXESNKyxsQ8fI0BRJ8jQ2HgpWucDU2RQJfn4Qzg=; b=akt2T+DUsJJlXwxB6TX3qZFGURGy9jYjn9sdxKD+yMV4qa/kv0xyE5Pd31A7qJJ2EK bVYbfvr2K/zdm9Kz3xduNz0d4lHqzJ5099ymzfik/jQLRb9eE/yEIomyFXRZq7SyTtHy StRUygRPPVqzmoC9JuqacYHpOH00t520q+JYr3OzoStUATAp2i5Ydu5YzDlUXX8NroiG 9KD9aAntGOg0FHpzy9/a7r7HK23WLuVVU1rPwpXv66LdrCb1cQFkCXoVSv/0BvOd4bi1 6emu/sQXwvy3uC3+wKdprnuQa3sUAYItuMYYp9cKh9DriA2hrl7UG1TxXU3EMxOM3HJ0 yvaA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714490992; x=1715095792; 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=bHEADXESNKyxsQ8fI0BRJ8jQ2HgpWucDU2RQJfn4Qzg=; b=uUDtPOGW7kyqLu+h4ekcniO5KOzJ3O2NWFzbXVB+cToMXHodlUOZkrN6rxQiaPK/i5 V4vj3lYiJzV7OO/orxvpnjFA16VvRSK/ejKNKybodpaX00xja+O6y7kAURncxfiNo3Ow 3kg4sBqcVmfK4U9UCcLn//uFXkVI9Qqm/hRAMyjvANGU7t+J0XOx4l6+lej0bwlREnyM 88L9GSZLsryF7/isad2GyHq+pW2tnOK3EcpMmigtgE/v9jTUVL/IPnG9fY16Aw/EZ9RR kmpVPp06eoYVklUGEsHys4VP/4wsAQKlOF1GQtyt490E4OsQgWV9Ej3hL2gxZd6HpfjC RlCg== X-Forwarded-Encrypted: i=1; AJvYcCWU23CRZm1A3MhpFNbAHcMKHqmvfAiiyeDUVBC97JGy3HTMy6x3mLvAJhw3GQeTHKUBeMncc28WmHCazSeXiIxMRvo= X-Gm-Message-State: AOJu0YwXne3pQ42TtG1K19SB/YJKG+9kynOYmu08sPkeG0ncWgEHNTSJ dyu2hsufuUgE2+/s1kV5Fu/vJZ4ebNUsVkphIEyWq75Gp/SwwUbbptx1tzmc5BgniD3AaEcdxDe f X-Google-Smtp-Source: AGHT+IEPd6SpriBO596E3GI2OlGUcDV6KYMIlhq1sjz10czfW10eudXFYEG0ggW+HoSOpXol/hrTag== X-Received: by 2002:a17:906:90c:b0:a52:10c8:c4e2 with SMTP id i12-20020a170906090c00b00a5210c8c4e2mr31595ejd.66.1714490992531; Tue, 30 Apr 2024 08:29:52 -0700 (PDT) Received: from raven.intern.cm-ag (p200300dc6f06e100023064fffe740809.dip0.t-ipconnect.de. [2003:dc:6f06:e100:230:64ff:fe74:809]) by smtp.gmail.com with ESMTPSA id a10-20020a1709066d4a00b00a52567ca1b6sm15278137ejt.94.2024.04.30.08.29.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Apr 2024 08:29:52 -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, david@redhat.com.au, Max Kellermann Subject: [PATCH v5 07/15] linux/mm.h: move folio_size(), ... to mm/folio_size.h Date: Tue, 30 Apr 2024 17:29:23 +0200 Message-Id: <20240430152931.1137975-8-max.kellermann@ionos.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240430152931.1137975-1-max.kellermann@ionos.com> References: <20240430152931.1137975-1-max.kellermann@ionos.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Rspam-User: X-Stat-Signature: pdnaaj9pncqcrx1h9s8pzgsjn838fh8b X-Rspamd-Server: rspam11 X-Rspamd-Queue-Id: E9CDE100002 X-HE-Tag: 1714490993-857686 X-HE-Meta: U2FsdGVkX19lWWeHgS0l7gG4mSITekfjUEtzaBL+HndWCvV0LOwxb/DtP2lsYo1tc6ACk+OkzP0/zvTKtEaZQmeI365Z8f27YPaaXzGfVQuinvCkjQAqKMEkUHCpKC+VhdSkulzNQTBjKB/ckZ45FBQ9siQSpIwK/MzKgeYbmhToC4ChbIzRAdGzKENtJWfLaKUade11yuDlAjT/SRu9Ogr+lhhTZ5+k2KMEEasZ0zIrJQp4f20qoJshBgbLu5sqVa5spVnE2Is3qwfGrW6nqu1VRSrU0MjT/WRPjkRHA+CPhiPQZNIrC61r+0bmlMzBa8EcvkahEDK2l5ulZ9rHNLY4kohZWGxTWZQ8Wfy/bNZjJv/bPzmWr6pHCrqpKgDHKWhJryziYc+KoRe0E3CNjaNXuP3zkd/dywutiyLyuMN5gF0nipuSQeRlKlFy5yJtrJacrG997p4I+aWnMqyYvWpmz6Oj8bXlPgr3Hh/weOe0FRECyey7CjtSZCOKsdzRAh9fXlxPoK+Iw2v7wR7FaHJ3BpDwESLlbFpoRtLn61NyaK9ZDIbvzMpnkoDBpaoeTbpXQYJ9ybMXMpzPi3gadKTuO6XvyCuz6LBWZvsffFBWVIFJtScnbFR4FSvpWZgJTGw11pstFU3Z85Jtt60qex9vqLE3cGpE3wOX95P/5jTCH91s7JFT9FglSWCezmsTwS/oqJ/Ij7gn2Lh7IYv/jiadDOA825+6nAO/Ud1obEHssrW098YU1HSvMyvj9B/979kk/vsmYeoqylpo6aPHYI2bRarGFd0qFjA8og4z4FpbCRnVx4hEPXSWqNGJmOczJn6ZP0Muhic9lLa+14ykmJ/omPxvJUt98UBkBj8cKsKXLT6KPOnZu2oqGmUwH0A21oxD0kTmw/nbBdNhgKyOIZYQb3Y36MS+vS+0w5gte03GuwFXXZ3ZyY8AkxgY8dAIsTHRa8alaEnZHo8y6LF 8ysDEorU GOP6itgapR1p2UWpPMZNbj8OwhXkdWKPS+YAmueBz4D4PEwvui81hhxV/1SfWcJUGJRtRDOs91ZzBET4bd+oMNr0BgxjjZKvgdnW22/H0GyV1rBPa1O+FCuCSVCLKYkYFVVmGxBAlkQd6g3dNpafPJq5BZZWFOC/gQUp2 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 0dea734194aa..d5019aed8330 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 @@ -1069,38 +1070,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 /* @@ -1313,39 +1282,6 @@ void folio_copy(struct folio *dst, struct folio *src); unsigned long nr_free_buffer_pages(void); -/* 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 @@ -1981,23 +1917,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(const 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) @@ -2005,33 +1924,6 @@ static inline long folio_nr_pages(const 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. @@ -2051,36 +1943,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_likely_mapped_shared - Estimate if the folio is mapped into the page * tables of more than one MM diff --git a/include/linux/mm/folio_size.h b/include/linux/mm/folio_size.h new file mode 100644 index 000000000000..e7cd567cf069 --- /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(const 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