From patchwork Thu Nov 28 07:40:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baolin Wang X-Patchwork-Id: 13887734 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 C6912D690E2 for ; Thu, 28 Nov 2024 07:41:06 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D15796B008C; Thu, 28 Nov 2024 02:41:04 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id C9E2E6B0089; Thu, 28 Nov 2024 02:41:04 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A7A986B0093; Thu, 28 Nov 2024 02:41:04 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 6F3476B0085 for ; Thu, 28 Nov 2024 02:41:04 -0500 (EST) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 1F98B121465 for ; Thu, 28 Nov 2024 07:41:04 +0000 (UTC) X-FDA: 82834707564.14.213B147 Received: from out30-130.freemail.mail.aliyun.com (out30-130.freemail.mail.aliyun.com [115.124.30.130]) by imf12.hostedemail.com (Postfix) with ESMTP id 274674000C for ; Thu, 28 Nov 2024 07:40:58 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=linux.alibaba.com header.s=default header.b=pSVpRjf6; spf=pass (imf12.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.130 as permitted sender) smtp.mailfrom=baolin.wang@linux.alibaba.com; dmarc=pass (policy=none) header.from=linux.alibaba.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1732779655; 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=6HM6mcd3kWqgluzVJQFUY15MBVLtFMN3usvJqqfXf8k=; b=yF0lW8AXY0ajoFbahK+DptOHr6mYOtAs3c3PlS6PB044ppsQLO7H3Fw9mYiRF5HacDG3xz XVnkYC5WzkG2kKAm5KK7A5++iJHBR6ipdjYbn/SK/uGiksk0nSkgfQWhsYchAJA3ZmrcXs vckDqd1PHcPOhLwnibiar/+MlUrC+XU= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1732779655; a=rsa-sha256; cv=none; b=lu9TAA8TeW0YL/3n7J7KKWxx1VasUdPTQTO6zEuIs9DmH8QRY+lG7oO7ZAP+dQH/CXyYti JMjUOx9BAbgJsEQW7HfKyHLNTECxJyRVZRu2As7o3CC1H8t4qT83VyAyHgiA6wCB0LtC/Y 5QYkkQUE2OKFGpEYcrKNImoi0kB/wyM= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=linux.alibaba.com header.s=default header.b=pSVpRjf6; spf=pass (imf12.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.130 as permitted sender) smtp.mailfrom=baolin.wang@linux.alibaba.com; dmarc=pass (policy=none) header.from=linux.alibaba.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1732779657; h=From:To:Subject:Date:Message-Id:MIME-Version; bh=6HM6mcd3kWqgluzVJQFUY15MBVLtFMN3usvJqqfXf8k=; b=pSVpRjf64qYcay/O+uKnEs9ZlLACDcC3LJ/+o5h7ijQCETZ8TBByQgskk5qbrGobVExRpxL2AcZ2z1A5ggVHoSpqaHtbeP5MODLw1c18NJ38SxutNGbVILbgbp81k7NvZDnOu8cAdx3LlNMgy7oUDUTqFTZZzXoL+UnxU/veC7A= Received: from localhost(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0WKP.Wk0_1732779655 cluster:ay36) by smtp.aliyun-inc.com; Thu, 28 Nov 2024 15:40:56 +0800 From: Baolin Wang To: akpm@linux-foundation.org, hughd@google.com Cc: willy@infradead.org, david@redhat.com, wangkefeng.wang@huawei.com, 21cnbao@gmail.com, ryan.roberts@arm.com, ioworker0@gmail.com, da.gomez@samsung.com, baolin.wang@linux.alibaba.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 2/6] mm: shmem: change shmem_huge_global_enabled() to return huge order bitmap Date: Thu, 28 Nov 2024 15:40:40 +0800 Message-Id: <9dce1cfad3e9c1587cf1a0ea782ddbebd0e92984.1732779148.git.baolin.wang@linux.alibaba.com> X-Mailer: git-send-email 2.39.3 In-Reply-To: References: MIME-Version: 1.0 X-Rspamd-Queue-Id: 274674000C X-Rspam-User: X-Rspamd-Server: rspam07 X-Stat-Signature: r9uq9rcymdnrassejtoqkmcm3rxmt8jo X-HE-Tag: 1732779658-323765 X-HE-Meta: U2FsdGVkX19uYaNg/Mzafa+2knDCqG1N5ksv/BQ/wNEWiGkftajH6UzXIOmluJqa9OUjPZtrE8nuFGk2kST5Cb1lOYlJEf5nY/6+DGc9gfpVoJ5ItQ/v/qe2ZO7VbZ3Q+tdsxTEcWcOJ6rO0S/udbiBvxSmO+ZwwmzXoe9lza/I71lC6nYQlIGMaUPLgG1nNXapFCw/SgbCf+Rr56IY4R+W7ObHqXRw25vmaVwLJIV+HWbEGv+QO0KcDKcl8+5NwU+bXoLlLV25mx5SVBvGb/msdH8He5pS/X01LafZN55A/wZlxE4Lo0D8OtZr8ajz0RubnbFYXbIVuJex+iQ8/Mkdg89dTIUSnb3PQGuVvF8fO6wHuy4eguIjyYIE4bA8OS5rUALFKIvxT/RDx/qbetgjs1GNna/7VdBPATRLZT2NmUSQol+TE9cf7PNnIcfm9me0K8IPUlLTKVPXkt+Gg+L70W328cNlfWiTWBcIGttauFl3RUxA+n/SY9MrXiyu8HioZ2sd4edcxetmjvKled/35bVYGGkoAGkH1F8zG1be3EOBHl5U5Kjc8XwIdhsKa2hJkn2TmPzM5c30UKgCCu2PR+Wbb+pe3t9hok7okclZfRXklr9BrKltsFuQy3fV+6nqVzN91Yh/16MpEPAkeZQncWnW6bs6Nzm52SgoPgrtu0uzfMVENeCVqTJ6t4w/d+I6/3AB5VQYXWJG3NoVz4Tmmm1H9jmCAJJDL64QmzvPru/E7A7yy9j0cBJkIToP8MuJivbhbwVdZh6AwRjTIyOKxGj+4hFIiJ7VBzH1eq95/bpp34DxzCDKI5ie+9vYfEFTiERYfJT06iKA8oSi9fEpkwVD3QLNktE7qlOtjMZNbfIZangGyBr4L0FVfRK3AntF7i4OkcW/w3dG3az7XikIjCN+OulP81kE/jUkWizS2FFOxJtaKPTz6FYLuAhr/DOhKEcEJHpnmjFw5Xn2 7iCze3cg hhmlykvrL60+TFjfDP+wRQTbtdjqPZZ5iKRJ3tLlKeWn9HfhsRsZKD6xjEjDweoPbqgeCvDZUKWRThC6v5ZRS3qBwA0X7cHPZ08TShuDjiVd1YH7rqvyM0/7SYwghCojWuHa2JfCtjqkjjwfwNglibj6EEbzNuvxGmXtVQqPfwLdo52gvsszlUFgoI7nC3jOzUKrDuOrJd+zJ2KGpsNxd0So+wALtK6ds1c/SVM2twJAssD9PVomNev4fI+vy26021V9jq076WgOcQbw6NStzDZ0uyLt+um5oT83kgLT1nA1EFuw= 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: Change the shmem_huge_global_enabled() to return the suitable huge order bitmap, and return 0 if huge pages are not allowed. This is a preparation for supporting various huge orders allocation of tmpfs in the following patches. No functional changes. Signed-off-by: Baolin Wang Acked-by: David Hildenbrand --- mm/shmem.c | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/mm/shmem.c b/mm/shmem.c index ccb9629a0f70..7595c3db4c1c 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -554,37 +554,37 @@ static bool shmem_confirm_swap(struct address_space *mapping, static int shmem_huge __read_mostly = SHMEM_HUGE_NEVER; -static bool shmem_huge_global_enabled(struct inode *inode, pgoff_t index, - loff_t write_end, bool shmem_huge_force, - unsigned long vm_flags) +static unsigned int shmem_huge_global_enabled(struct inode *inode, pgoff_t index, + loff_t write_end, bool shmem_huge_force, + unsigned long vm_flags) { loff_t i_size; if (HPAGE_PMD_ORDER > MAX_PAGECACHE_ORDER) - return false; + return 0; if (!S_ISREG(inode->i_mode)) - return false; + return 0; if (shmem_huge == SHMEM_HUGE_DENY) - return false; + return 0; if (shmem_huge_force || shmem_huge == SHMEM_HUGE_FORCE) - return true; + return BIT(HPAGE_PMD_ORDER); switch (SHMEM_SB(inode->i_sb)->huge) { case SHMEM_HUGE_ALWAYS: - return true; + return BIT(HPAGE_PMD_ORDER); case SHMEM_HUGE_WITHIN_SIZE: index = round_up(index + 1, HPAGE_PMD_NR); i_size = max(write_end, i_size_read(inode)); i_size = round_up(i_size, PAGE_SIZE); if (i_size >> PAGE_SHIFT >= index) - return true; + return BIT(HPAGE_PMD_ORDER); fallthrough; case SHMEM_HUGE_ADVISE: if (vm_flags & VM_HUGEPAGE) - return true; + return BIT(HPAGE_PMD_ORDER); fallthrough; default: - return false; + return 0; } } @@ -779,11 +779,11 @@ static unsigned long shmem_unused_huge_shrink(struct shmem_sb_info *sbinfo, return 0; } -static bool shmem_huge_global_enabled(struct inode *inode, pgoff_t index, - loff_t write_end, bool shmem_huge_force, - unsigned long vm_flags) +static unsigned int shmem_huge_global_enabled(struct inode *inode, pgoff_t index, + loff_t write_end, bool shmem_huge_force, + unsigned long vm_flags) { - return false; + return 0; } #endif /* CONFIG_TRANSPARENT_HUGEPAGE */ @@ -1685,21 +1685,21 @@ unsigned long shmem_allowable_huge_orders(struct inode *inode, unsigned long mask = READ_ONCE(huge_shmem_orders_always); unsigned long within_size_orders = READ_ONCE(huge_shmem_orders_within_size); unsigned long vm_flags = vma ? vma->vm_flags : 0; - bool global_huge; + unsigned int global_orders; loff_t i_size; int order; if (thp_disabled_by_hw() || (vma && vma_thp_disabled(vma, vm_flags))) return 0; - global_huge = shmem_huge_global_enabled(inode, index, write_end, - shmem_huge_force, vm_flags); + global_orders = shmem_huge_global_enabled(inode, index, write_end, + shmem_huge_force, vm_flags); if (!vma || !vma_is_anon_shmem(vma)) { /* * For tmpfs, we now only support PMD sized THP if huge page * is enabled, otherwise fallback to order 0. */ - return global_huge ? BIT(HPAGE_PMD_ORDER) : 0; + return global_orders; } /* @@ -1732,7 +1732,7 @@ unsigned long shmem_allowable_huge_orders(struct inode *inode, if (vm_flags & VM_HUGEPAGE) mask |= READ_ONCE(huge_shmem_orders_madvise); - if (global_huge) + if (global_orders > 0) mask |= READ_ONCE(huge_shmem_orders_inherit); return THP_ORDERS_ALL_FILE_DEFAULT & mask;