From patchwork Thu Oct 10 06:10:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kefeng Wang X-Patchwork-Id: 13829517 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 2C768CF07AA for ; Thu, 10 Oct 2024 06:10:39 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9322E6B0093; Thu, 10 Oct 2024 02:10:38 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8B84E6B008A; Thu, 10 Oct 2024 02:10:38 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 730CF6B0092; Thu, 10 Oct 2024 02:10:38 -0400 (EDT) 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 530956B008A for ; Thu, 10 Oct 2024 02:10:38 -0400 (EDT) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id F4136140C1C for ; Thu, 10 Oct 2024 06:10:34 +0000 (UTC) X-FDA: 82656668514.25.AC00D7C Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by imf12.hostedemail.com (Postfix) with ESMTP id 9876A40002 for ; Thu, 10 Oct 2024 06:10:34 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf12.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.187 as permitted sender) smtp.mailfrom=wangkefeng.wang@huawei.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1728540485; 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-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=vbxzBkF71Jj6QrOZLI0tKHBjDkIXQOuyWDX88kTEaQM=; b=idMy3BtFRqHyqkqEVyny2nvJtXt7a4RgITXisBQZtzi916636zUWCmS/95AM64lJxgdO0K B49K3z6X6y4VslzWfn6Ns+QVVPdpuW/ZYPCnAC/nvTu1EYLKMTfNEOmOk3jmHUf0CZYT0v mSQR2CpK/+OTtOZso9HQ286zPsYtfr4= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1728540485; a=rsa-sha256; cv=none; b=t1LC+OzcmV1f5SDhcvfyD5EMI4cO2Kka3eAJ+ey1NNrfS5PN3CYBXlO+1kDopYU3lNPAkE 14NI+wcfiLGQ+zyug+93vLofZJanoyTaFtiq9Sh0xe9F7Pa+lWGFeLXV7ss0zSiTzASqr9 PnpHMYSxHM173BhpxCG7FLgQc25J5N0= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf12.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.187 as permitted sender) smtp.mailfrom=wangkefeng.wang@huawei.com Received: from mail.maildlp.com (unknown [172.19.162.254]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4XPK7z1M3Jz10N4N; Thu, 10 Oct 2024 14:08:47 +0800 (CST) Received: from dggpemf100008.china.huawei.com (unknown [7.185.36.138]) by mail.maildlp.com (Postfix) with ESMTPS id D5FD218010F; Thu, 10 Oct 2024 14:10:31 +0800 (CST) Received: from localhost.localdomain (10.175.112.125) by dggpemf100008.china.huawei.com (7.185.36.138) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Thu, 10 Oct 2024 14:10:31 +0800 From: Kefeng Wang To: Andrew Morton CC: Hugh Dickins , David Hildenbrand , Barry Song , Ryan Roberts , Baolin Wang , Matthew Wilcox , , Kefeng Wang Subject: [PATCH 2/3] mm: huge_memory: add thp_vma_disabled() Date: Thu, 10 Oct 2024 14:10:23 +0800 Message-ID: <20241010061024.1846220-3-wangkefeng.wang@huawei.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20241010061024.1846220-1-wangkefeng.wang@huawei.com> References: <20241010061024.1846220-1-wangkefeng.wang@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.112.125] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To dggpemf100008.china.huawei.com (7.185.36.138) X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 9876A40002 X-Stat-Signature: itx1owf5q8m6fch7fpewc4okydiwao9s X-Rspam-User: X-HE-Tag: 1728540634-915115 X-HE-Meta: U2FsdGVkX1+uyd80Tke9KiFZu5/MTPSnBs85EdpaaHHyB8+dg9TqGguK8b1IEhM9Ix9CfbQ+RFpvCc/KOi0eFNBupaSJ8YhtSVmaJr+3LNMN4dfJHQ211ZWknH2V7262d+uWRdGCmUMe6a9a7VkY6633uSR70EELgjeapFkWf5y57hlWTdRd2Y1dXIPUS9JUlde6y5zU1ElxDm/8x8g9ukI+KO7sV2MFHNCY4gNNLPMXXvIr0NVsc5F+aqljLd7GODTcFUfu3k3pN9Qe6RqQi3skHmyyWJuIKkdajwzFpT9SMZSFQ3LAIqcjfXilyZQylF6NpQUJnQiUoikcMNPH6uy57amVWjZmTL26fwKwkhb17VnFbzHloS88aWfuIcMA4KSGKcb+KkOObjBV7H1270Cxosri1lf4c4MU6S103InHrr1XOBNUieXwAIVGtIO8mrU+s8R7gIGFvPgEDCEL60LdAioIttJPsNe/Bw/W24nSqh5pUae+HiyVSZAYzrZtTptTgMo6C1JGc8fFjsDpNZvrRQnvqAI1ZR2X7eVcFVIoAsAdGEtZgVlXt1h7UpUAcyAdcfRj2tnlu7BwMjnbbVDXf65JUW+b4aR04Gf1zbI87mEEGjP+YlPROrVaQdvRjl44DosAJepUAGxc9Cp2RncPlPNgCzlWdh0RvanfjENki558wGlBP24wv87gs1nFKACUQ6siADM87miNcTqnB8GufhuGyQjG/p/kUqlgN+GxugIO36X4UFo/jUh/UFBobfjhCPjIJpLpnYuE/Hi+w6Vdc1y6hW/lPNXofoPBIsigWDqOgg6wtJU8IXIdCx5JRLYc7BBd/lP1BeOWLdLOYViUrZMI4ZcVA8pvgo0DAqK0BIfcFKax8HfjDgWB3uTaxFB2Wdcf6jr7mpmt5wgjdJbtuOvMD8sbgDXUZWAgbtLDI/elUNDPsUN4v3j/op6uPxBK+JoLwOD/KCWR53W VIPh6kyN D/e2St5cZhz9uDcZMrV4Diy7GIjcvq4IEhbH4SJCW5IVIvftJRTMLn5h8yTdYd1ODh2vjEaqCZWluBJRV9N3CfKsMiIBUDxdjpwaWh7vDVhRVcHGR7OQL1e12ipXkG2BzWvOJfMz9niSsS+E2BXpq/Rd+cw233RwJD66A1Ae4flTPi8tu/MmQT42YwUMKxGxq8V13 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: Add thp_vma_disabled() helper to shared by shmem_allowable_huge_orders() and __thp_vma_allowable_orders(). Signed-off-by: Kefeng Wang Signed-off-by: Kefeng Wang Signed-off-by: David Hildenbrand --- include/linux/huge_mm.h | 19 +++++++++++++++++++ mm/huge_memory.c | 13 +------------ mm/shmem.c | 7 +------ 3 files changed, 21 insertions(+), 18 deletions(-) diff --git a/include/linux/huge_mm.h b/include/linux/huge_mm.h index 795df660efa5..d77891332b35 100644 --- a/include/linux/huge_mm.h +++ b/include/linux/huge_mm.h @@ -309,6 +309,25 @@ struct thpsize { (transparent_hugepage_flags & \ (1<vm_mm->flags))) + return true; + + /* If the hardware/firmware marked hugepage support disabled. */ + if (transparent_hugepage_flags & (1 << TRANSPARENT_HUGEPAGE_UNSUPPORTED)) + return true; + + return false; +} + unsigned long thp_get_unmapped_area(struct file *filp, unsigned long addr, unsigned long len, unsigned long pgoff, unsigned long flags); unsigned long thp_get_unmapped_area_vmflags(struct file *filp, unsigned long addr, diff --git a/mm/huge_memory.c b/mm/huge_memory.c index d23e4aab7511..30912a93f7dc 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -123,18 +123,7 @@ unsigned long __thp_vma_allowable_orders(struct vm_area_struct *vma, if (!vma->vm_mm) /* vdso */ return 0; - /* - * Explicitly disabled through madvise or prctl, or some - * architectures may disable THP for some mappings, for - * example, s390 kvm. - * */ - if ((vm_flags & VM_NOHUGEPAGE) || - test_bit(MMF_DISABLE_THP, &vma->vm_mm->flags)) - return 0; - /* - * If the hardware/firmware marked hugepage support disabled. - */ - if (transparent_hugepage_flags & (1 << TRANSPARENT_HUGEPAGE_UNSUPPORTED)) + if (thp_vma_disabled(vma, vm_flags)) return 0; /* khugepaged doesn't collapse DAX vma, but page fault is fine. */ diff --git a/mm/shmem.c b/mm/shmem.c index 0a2f78c2b919..34a31e7e527c 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -1683,12 +1683,7 @@ unsigned long shmem_allowable_huge_orders(struct inode *inode, loff_t i_size; int order; - if (vma && ((vm_flags & VM_NOHUGEPAGE) || - test_bit(MMF_DISABLE_THP, &vma->vm_mm->flags))) - return 0; - - /* If the hardware/firmware marked hugepage support disabled. */ - if (transparent_hugepage_flags & (1 << TRANSPARENT_HUGEPAGE_UNSUPPORTED)) + if (thp_vma_disabled(vma, vm_flags)) return 0; global_huge = shmem_huge_global_enabled(inode, index, write_end,