From patchwork Thu Oct 10 09:58:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baolin Wang X-Patchwork-Id: 13829877 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 7424CCF11C5 for ; Thu, 10 Oct 2024 09:58:32 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6F5966B0089; Thu, 10 Oct 2024 05:58:28 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 67E036B008C; Thu, 10 Oct 2024 05:58:28 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4CFD26B0092; Thu, 10 Oct 2024 05:58:28 -0400 (EDT) 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 2AB336B0089 for ; Thu, 10 Oct 2024 05:58:28 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 12DE180CFD for ; Thu, 10 Oct 2024 09:58:25 +0000 (UTC) X-FDA: 82657242654.09.1043BD8 Received: from out30-110.freemail.mail.aliyun.com (out30-110.freemail.mail.aliyun.com [115.124.30.110]) by imf21.hostedemail.com (Postfix) with ESMTP id EC5F81C0014 for ; Thu, 10 Oct 2024 09:58:22 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=linux.alibaba.com header.s=default header.b=liuRLKXC; spf=pass (imf21.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.110 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=1728554236; 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=UsgmxRS9TKs/0ogcQ76wiAy1j6N7MLMM/FjqAS25YQo=; b=UW1EhzM73nvnU5cvBMFg6LRZBnxFpBwgaApia6z19aULkl/akO1VRMeLEuP27/sJyuLcjc 1m4eeNXDcZltG3kFjwGR5DE3a6bc1o8NoIwhhrd7LETX8FdqaxbT8yQixbHo5h5BPe8CEB SWQEJo2Py+BOdXp2Pel5FDfWyAgW3pk= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=pass header.d=linux.alibaba.com header.s=default header.b=liuRLKXC; spf=pass (imf21.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.110 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=1728554236; a=rsa-sha256; cv=none; b=dmOfrK7xdym2iqrGnpuwZkUOvqcXzX0BylbuslyzQ2cmAgWGcj1g8qiNCLX2WEPtLnH/WK cREHim+oqjk29KPhOFERAFmF/1mvTmy/+yquZ0shp3JtTOOmnNg4a79cV6nmI9Msd4u9k9 oQ3fDCPoq/0UGr17znaD375u35k/dlY= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1728554301; h=From:To:Subject:Date:Message-Id:MIME-Version; bh=UsgmxRS9TKs/0ogcQ76wiAy1j6N7MLMM/FjqAS25YQo=; b=liuRLKXCh3Z8VQnKAEfRp8eTtKweIxMqov8MQ5rrJWv7TfXTalyE5xxey29UzYimsMr+eh+44lKG5gfG3uLJqN6V5l3fEcuUW5wviI0GKw8+VQV/hGTZkN5IEwhRnEWls/AF18Kw5vFo0/gU3Ki7/VQ4WN6vgfG5R2Qla/AR28w= Received: from localhost(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0WGlzQXz_1728554299 cluster:ay36) by smtp.aliyun-inc.com; Thu, 10 Oct 2024 17:58:20 +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: [RFC PATCH v3 2/4] mm: shmem: change shmem_huge_global_enabled() to return huge order bitmap Date: Thu, 10 Oct 2024 17:58:12 +0800 Message-Id: X-Mailer: git-send-email 2.39.3 In-Reply-To: References: MIME-Version: 1.0 X-Rspamd-Server: rspam03 X-Rspam-User: X-Rspamd-Queue-Id: EC5F81C0014 X-Stat-Signature: dnzrgntk583qfhfr1uxm63bqo3funu1j X-HE-Tag: 1728554302-903780 X-HE-Meta: U2FsdGVkX187AJaVQW5/L7mU94WrZIY7AU7lF6jKJkGrPXVvS23jWAYpwlmg/8heroIZfOHZq41wn3dNroP1WCGWn8mDsnn5aeUlyd4mKQdlYFZc1qntcAm9xiDP+R5vEpD8xmAYdb2wvG9OfWWXfKMPivoOoyD1NyizQkxY9bYfvgFhhluR0zm/TwqBGRkS+0RuqoaDNHuV4wgOY05u3BfoYgyhuks50dhuVDCF5TW+jT8ZXPxqAJ7AWjfwDgMR1WyhEXB/suvd8TLCUW8GwXvp4x2DiOdxpbMEqdK1YJecbVzjdNs1MTjTUZOFNLg7Ln+4e/fGJanKWMwfA6RibNEjD9E7Wy9a3V2Aj6Bb480jmZmUNwAcBPkM51eoM06XjUMs1bd8YTABnta1fhRfmqZXl55JTTHIZbb1voHntfcwZQb2hm/O+VEdGff2ykXUUx8Is+PGtvih4945nimZ5r49at903IbxN3KfFWuI3IUvZh4VO41NbPP44hrtiZ76JSOgfB1gF+QEZzXIt+slvZCPKnFImipPElGJ9G5jbcssQHIeOrFSbdcPnsbyLlIK1xMVJoRqvLfMd4t3nbiZohnckJwUG52WxxyrhXSjDJVnMx7iBkbTCW0FUEFA+mFQghYBxIDE+Q/K3aLTgTw4MKZc0NLiHLwIg5+anA/Z5Dy48+pG95D3DR9yAluZ/YV+YucKBTuEkLzzPR/gjQrlpmxWCVdbemufxmHuOpFjyYmvOBnNYGycBXiEFUKZt9IuFt2GQMwnYlck9Zcp+A/RvGCo9enmpnnxn5j/bTV3D9dlE7XvHzgxazBfh/fkIu3188cED2Mzjpv1VeNOMV8PZeBGKxDSeao42t7NtsDo6ofqvs2HEcLtmdm+VeF158DjQ12AUwd7PCRLGzMyTGS/9N0fSN2FNR+UK0WDjigc4Zia1VFhynEkSnD6HNnVTdDcpn0OiHB71Y0CsUGI8bW 7jp5RBVx i0ST3m+fPL7Jj4KA7R1JwOguKGMw24ldFVLk0qRw9z39PU3JFf3RRJOex7NSsBUaiXFSoEGJD8KQ83KhfMvWtKaZGVPU8c4x6jGHwg2Q+jMD1BXg/XeNEKShNTgPsWX5ADT9kSZdYLrZKi3Vtufo8J9cYiCIzb5zjz2i1Mzb1YszZXmyuzUB8xhZYcIZM3G6du+nKin92Ebj+cYdjackLb/X/5nXRBjMBOOC9a5X4IzWXsTK1NhdiOKogzVF+LA3+6hSe8B1VWScbFEVcNfxTRZKQsw== 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 adding a new huge option to support various huge orders allocation in the following patch. No functional changes. Signed-off-by: Baolin Wang --- mm/shmem.c | 43 ++++++++++++++++++++++--------------------- 1 file changed, 22 insertions(+), 21 deletions(-) diff --git a/mm/shmem.c b/mm/shmem.c index 0613421e09e7..f04935722457 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -548,48 +548,48 @@ 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, - struct vm_area_struct *vma, - 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, + struct vm_area_struct *vma, + unsigned long vm_flags) { struct mm_struct *mm = vma ? vma->vm_mm : NULL; loff_t i_size; if (!S_ISREG(inode->i_mode)) - return false; + return 0; if (mm && ((vm_flags & VM_NOHUGEPAGE) || test_bit(MMF_DISABLE_THP, &mm->flags))) - 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 (mm && (vm_flags & VM_HUGEPAGE)) - return true; + return BIT(HPAGE_PMD_ORDER); fallthrough; default: - return false; + return 0; } } -static bool shmem_huge_global_enabled(struct inode *inode, pgoff_t index, +static unsigned int shmem_huge_global_enabled(struct inode *inode, pgoff_t index, loff_t write_end, bool shmem_huge_force, struct vm_area_struct *vma, unsigned long vm_flags) { if (HPAGE_PMD_ORDER > MAX_PAGECACHE_ORDER) - return false; + return 0; return __shmem_huge_global_enabled(inode, index, write_end, shmem_huge_force, vma, vm_flags); @@ -771,11 +771,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, +static unsigned int shmem_huge_global_enabled(struct inode *inode, pgoff_t index, loff_t write_end, bool shmem_huge_force, struct vm_area_struct *vma, unsigned long vm_flags) { - return false; + return 0; } #endif /* CONFIG_TRANSPARENT_HUGEPAGE */ @@ -1170,7 +1170,8 @@ static int shmem_getattr(struct mnt_idmap *idmap, generic_fillattr(idmap, request_mask, inode, stat); inode_unlock_shared(inode); - if (shmem_huge_global_enabled(inode, 0, 0, false, NULL, 0)) + if (shmem_huge_global_enabled(inode, 0, 0, false, NULL, 0) == + BIT(HPAGE_PMD_ORDER)) stat->blksize = HPAGE_PMD_SIZE; if (request_mask & STATX_BTIME) { @@ -1679,7 +1680,7 @@ 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_order; loff_t i_size; int order; @@ -1691,14 +1692,14 @@ unsigned long shmem_allowable_huge_orders(struct inode *inode, if (transparent_hugepage_flags & (1 << TRANSPARENT_HUGEPAGE_UNSUPPORTED)) return 0; - global_huge = shmem_huge_global_enabled(inode, index, write_end, + global_order = shmem_huge_global_enabled(inode, index, write_end, shmem_huge_force, vma, 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_order; } /* @@ -1731,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_order > 0) mask |= READ_ONCE(huge_shmem_orders_inherit); return THP_ORDERS_ALL_FILE_DEFAULT & mask;