From patchwork Tue Nov 12 07:45:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baolin Wang X-Patchwork-Id: 13871827 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 2ED96D41D66 for ; Tue, 12 Nov 2024 07:46:07 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C69BB6B00E1; Tue, 12 Nov 2024 02:46:03 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id BF1836B00E3; Tue, 12 Nov 2024 02:46:03 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A6B0B6B00E7; Tue, 12 Nov 2024 02:46:03 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 877926B00E1 for ; Tue, 12 Nov 2024 02:46:03 -0500 (EST) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 3AC08161110 for ; Tue, 12 Nov 2024 07:46:03 +0000 (UTC) X-FDA: 82776657516.19.FDD63FA Received: from out30-97.freemail.mail.aliyun.com (out30-97.freemail.mail.aliyun.com [115.124.30.97]) by imf03.hostedemail.com (Postfix) with ESMTP id 292512000C for ; Tue, 12 Nov 2024 07:45:41 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=linux.alibaba.com header.s=default header.b=MLzIlkAI; spf=pass (imf03.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.97 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=1731397328; 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=qou3qX2PAau4l6WamHoD3ilZA9HxOfUZL7Pa/oatbLM=; b=d64LURdAmwRUQYGHMPqTaj5g+nBmayRx/hJwore89B6fyr4pxsdkk2/g/myGUA2BCHIcyl 9P7ivNkuQpHx+Hhyp2R2YNm8LbduZehlg1swNA8gBcIa+4enwnyVtuOW1DBYTuywM+KDX4 Gf+zKtxmoJooAZOEvJpPbTpjSv024wE= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=linux.alibaba.com header.s=default header.b=MLzIlkAI; spf=pass (imf03.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.97 as permitted sender) smtp.mailfrom=baolin.wang@linux.alibaba.com; dmarc=pass (policy=none) header.from=linux.alibaba.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1731397328; a=rsa-sha256; cv=none; b=1aj+f2I/uceXJDrTJ/Vd98ksETtxNBtzrFW0rTUFYtQuR7smY6XE84YPZ0iovi1B48fhAX ta7hZNC74X0jMKqPVkLZSirvycZbzxsi/kXi5frJkty3rylDJgwrgHFOV3nWV+ZOXbNMqR 1MB/218HK5x+sCcC1Iwi4lcnQnhqOig= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1731397558; h=From:To:Subject:Date:Message-Id:MIME-Version; bh=qou3qX2PAau4l6WamHoD3ilZA9HxOfUZL7Pa/oatbLM=; b=MLzIlkAIRVM3Pg/F0BKbIPGMCk/ZC5/YkSYTQZ1w450AVs+9Lof/+a1wdSFCm/uMvBl5floqLX7D0Y7GFGrEJZVURXd/IxKS3u+YaqCMajXq5cY+mzgLSdSen4nWe4VZKzm6IxqjAKflzIQqwa51na5nRC6G3KifPiQnNjFhwrY= Received: from localhost(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0WJG9pLG_1731397556 cluster:ay36) by smtp.aliyun-inc.com; Tue, 12 Nov 2024 15:45:57 +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 v2 2/5] mm: shmem: change shmem_huge_global_enabled() to return huge order bitmap Date: Tue, 12 Nov 2024 15:45:49 +0800 Message-Id: X-Mailer: git-send-email 2.39.3 In-Reply-To: References: MIME-Version: 1.0 X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 292512000C X-Stat-Signature: 1b653xwntrwzt98pg4a5y8797hgz59by X-Rspam-User: X-HE-Tag: 1731397541-201926 X-HE-Meta: U2FsdGVkX1+z27S7r9m/PX/e5qUrXB0IPLQXRUP5a8j26BVGTxRTo18KgvCVF/jsfVx1IxAhkLASYy3KbnjNydrJ6Ae80uGDOiKuoiln13FvM+jAq+y9B7JCrpXiLflFfVS9vFKxG362wECCppSAPNvxcjQeMlAtUF/drcITXRRHtizfITasa3AQuQRX+zqY4jYKfKNkqd1Ns79Vll3G4CgDXJsxCOGWIiGDkgsHG/YrNx9+PoeYc1ByTN3nADAi3818t3WPxMQ1rB0db3GWCVMn6UrQIjTr4G3eiQHcvOcDPdDlW/VkuV8BgA18fSynI55MH2QFQr0x07AxY+ZtHLnrKvvF9wJa2C3L5vLL/tJ+rEmFVQQ7qQN6Ya+rlAH5Re0Gtg7FhxyvzmUYf4CGnGF5/qLqKjWb1IQaux0oFAdRFCqIEfursrjNE6UAr5/XT7eIGy+hJ6oyD66FE9pGfwmEWXbSAyztqObkXefQv54VmsMyqiFI1JwU6u8MPLu+nC9BqAb8WKEzY/HG6u58cGRmlR4DHpuxT1QBxwDkch5ifhc3V7RuLZ4VSX8OJLve7MIfb7n68l1zWl9peBn0kXj90f58QD4INxpTQLINvMjxcHGyTCe1oigFcvpRtIDf99IaZ3hRLrQD43iMkLZg0szahfG1lB+LnPyQMewGlo24rQvZLk65RWXy1l/2ByyM55JpZEauTBcDiecBm8ZncrbYa9+BhOs9overrjYK8oiydztqBAPwsXSkenCdZv2Xbs0/TnpSmVbETvUnGLlkyRCB7WEXvQ+EPzkdcvXl+g/4bReSBwOoQ0vrSXRKIgrr0hxmL2Jnr5gCFJb76uEXod3zdj4NcevviaJWt6qATk7IYgpO3/39d50wVHvbhp+dNSv7lCSICK8XCzsXRJweZKCH2KniW2KVJTOH9v3o0Fxr91otmGDZWhvVJYXKfFVl5lb7EPhTlNs+gZZKL+m mu/1504h E7koO2O2CCT9SjidiZdQCjSl0UCi1u+NcvDra3JuZHb2rc0R3/RMRPRfjw6U7rqBKAxPE7Ap54qoUTkoOZZEKJzs6IrJaHnVvHZGn/K0gEwPf+qcP6e9KT3sQRCqDEkramB7SOOLlrDi1NRVzumQFlD05sO/CUjWv99KqeoSlHQMjL06MV+UK3yMV88cEu5b7EE34trCZkqk2rVzaf888lScCmejBsKnbSe8vgu4WgUO3rc0q8wN/sDLttSbKuvJJdIv+FRnjePP61RY9iwNOsU4aCQ== 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 579e58cb3262..86b2e417dc6f 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -549,37 +549,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; } } @@ -774,11 +774,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 */ @@ -1682,21 +1682,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; } /* @@ -1729,7 +1729,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;