From patchwork Fri Jun 28 10:49:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bang Li X-Patchwork-Id: 13715948 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 3B281C3064D for ; Fri, 28 Jun 2024 10:49:58 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 425FE6B0085; Fri, 28 Jun 2024 06:49:57 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3D6306B0088; Fri, 28 Jun 2024 06:49:57 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 29E076B0089; Fri, 28 Jun 2024 06:49:57 -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 0AD9A6B0085 for ; Fri, 28 Jun 2024 06:49:57 -0400 (EDT) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 60888C1A14 for ; Fri, 28 Jun 2024 10:49:56 +0000 (UTC) X-FDA: 82279977192.02.EF15C40 Received: from out0-218.mail.aliyun.com (out0-218.mail.aliyun.com [140.205.0.218]) by imf02.hostedemail.com (Postfix) with ESMTP id 40EAB8001C for ; Fri, 28 Jun 2024 10:49:52 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=antgroup.com header.s=default header.b=SmAnbNva; dmarc=pass (policy=quarantine) header.from=antgroup.com; spf=pass (imf02.hostedemail.com: domain of libang.li@antgroup.com designates 140.205.0.218 as permitted sender) smtp.mailfrom=libang.li@antgroup.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1719571781; a=rsa-sha256; cv=none; b=dw0KpMJ183Vr+JF+nnPzlSwzCqLP2iRJl4R6ZWCrkk83agKWsiBuWUCTxioPgj/lNKDI5n OSDwemMvZ0XKnGYp3Onx6w1vaWzPnprausUcKVdfLT3q1BHCrKGGSwm4/5024BwPciYJEK wZ6xVxsKocc4co5uaKq1QaCTa6B3MkA= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=antgroup.com header.s=default header.b=SmAnbNva; dmarc=pass (policy=quarantine) header.from=antgroup.com; spf=pass (imf02.hostedemail.com: domain of libang.li@antgroup.com designates 140.205.0.218 as permitted sender) smtp.mailfrom=libang.li@antgroup.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1719571781; 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:references:dkim-signature; bh=PmC6WY0awgsY9XoqlRu++2CjZX1SiBFOFYun5TXen0I=; b=hgTufrnPLZMH34FCpEPhuTSeJgEmGNmnE/SnRyyYEYeXFkzfQEsuHGaPngfWlo6S39TkDU noM/3z7sm7KgOWexE8VNboibIQpwb01+lbOtAhdzgjZ8yyKWTLkXlf7tUuclQigOLL7J4k ZfaW6PWKRfe8+5Y1hd5IdWrJS734ULQ= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=antgroup.com; s=default; t=1719571790; h=From:To:Subject:Date:Message-Id:MIME-Version; bh=PmC6WY0awgsY9XoqlRu++2CjZX1SiBFOFYun5TXen0I=; b=SmAnbNvaj9CZJZJj+OjSxTdLlnUHwid8/4CsOaIV6kvlJyxwZYRNJMBZrGhicegfBT4hVtEolLghby/Z6CIeLPET+FuDyMc1M+6QhzTtHqE9Cf4x58rxHxe/E04EUiERZK334Pt+A6ZrLvkD2TxGx3dF/FdhsS9YnrgAcd8sFso= X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R121e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=maildocker-contentspam033023108233;MF=libang.li@antgroup.com;NM=1;PH=DS;RN=10;SR=0;TI=SMTPD_---.YCQ5T17_1719571788; Received: from localhost(mailfrom:libang.li@antgroup.com fp:SMTPD_---.YCQ5T17_1719571788) by smtp.aliyun-inc.com; Fri, 28 Jun 2024 18:49:48 +0800 From: "Bang Li" To: hughd@google.com, akpm@linux-foundation.org Cc: , , , , , , , "Bang Li" Subject: [PATCH] support "THPeligible" semantics for mTHP with anonymous shmem Date: Fri, 28 Jun 2024 18:49:26 +0800 Message-Id: <20240628104926.34209-1-libang.li@antgroup.com> X-Mailer: git-send-email 2.19.1.6.gb485710b MIME-Version: 1.0 X-Rspamd-Queue-Id: 40EAB8001C X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: qeu6pew8kppczj6wrwrsojrr8rfhzk7k X-HE-Tag: 1719571792-585081 X-HE-Meta: U2FsdGVkX1+ZfnX35N4IZ3G9NagYI5fM80gJ3IAfKr8wZ/6gSMWkFTgXxJvlU7/aIWDLsIhSAXQQMjlI99oeBcgmPU4Xukx+JCbCyP6s7MxeXtNIui4xER8okz+U0Hc1OXtkEPw6o3yH1gqW5zSGOI+6eVCY2H+qfCnbWDiMcD/A6HbBrpVcIZtZLeHUwOepvEHU3/5p+6c8anElL5woE12XtUOgcrVB/Ijf1c7KXIB4VpQ4ZhTSSy79aQ3s7VQW+svIe8WnKUfg5Otfh5z3zQ+yQBMrtcqArdNEsbWMIxV/3qWDhMx7PCoCwRpdu46QYbuHtEovMw1NlT3z1yxPBtDcA33+nOsxTih8V3YEJNT7F98xOyYkO5iZUtzAYV+ADQcTvQJM8G9E8jx3RM43v8MT84pLNAFDDZaUG+J/QIL5iWrgnHspQaVlogDnWEbpZ+/7pK/dqVSyh8Sg3Cv4EH0B6fRn6H0Xg7rwiCeb3/OR+1giHAObg1wQ7gUJK2zbOH0+wWN+O+kJssvItsURRP7Ki8dTfsLNUtFMDp5aK3SDWuWh3qnGvJVKtn8AakpNpg9UJ2tzQLAZRW0ltLgrTtvXZvz1soe21ZrU/1uIlvv/WuEGssHoEJHDl0BzJbgcYjsNpf1VsrEqeoK4BjT0BszqMmLVbWVoNxFPrRNlrIHSIdUKqEdpTSGwYhazuP9ecj5GTgYUiQOMa266D9PLyX4NnBHP6jr/X37iVnbN0qqRYxCqBrmk40TCUB2trilir5aZ4SZUuQ7OE2jjwbgOqFOgz/GTlxTMFHrUyzvfQ9NRlv0za2KNsvrIy9N/g55eK+scmmPtfLZoPmBQKUYSSHcFdnzAGadHtqoEN+IEMjJIXRSPv4RM5kJVXpGWJwzDtbZNEhchUZndSoUqNUYW5SJ7kXnWB7fUWMge1IOvFa/y9QahBBKiZoMAC5EWKGPsXmT8feldcoY9T91rg/G 5iSsNLrr liEzyykfunUayqJRgmgVI0tO25ZlMtO3SSFuhkXDqQb5LHWW+fwsEIJbOsgdveqlwyWMRpERMewUosfYZSgswkVQ4TaV8IhS05739ov3wgEzR3FNAYBDYri4pmr+YjThIsXtSK+M873Nc6VEe7GK2dlzN8xVBBGN/qzwZNrejxxSXVMwKKiXWh7FtCTfmDjFtr4OQKt0risxwR6jUG8wmbCQmNBe6+Ggnhjj2l0T8y8A4UxgGQnGLvuBI0Q== 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: After the commit 7fb1b252afb5 ("mm: shmem: add mTHP support for anonymous shmem"), we can configure different policies through the multi-size THP sysfs interface for anonymous shmem. But currently "THPeligible" indicates only whether the mapping is eligible for allocating THP-pages as well as the THP is PMD mappable or not for anonymous shmem, we need to support semantics for mTHP with anonymous shmem similar to those for mTHP with anonymous memory. Signed-off-by: Bang Li --- fs/proc/task_mmu.c | 10 +++++++--- include/linux/huge_mm.h | 11 +++++++++++ mm/shmem.c | 9 +-------- 3 files changed, 19 insertions(+), 11 deletions(-) diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c index 93fb2c61b154..09b5db356886 100644 --- a/fs/proc/task_mmu.c +++ b/fs/proc/task_mmu.c @@ -870,6 +870,7 @@ static int show_smap(struct seq_file *m, void *v) { struct vm_area_struct *vma = v; struct mem_size_stats mss = {}; + bool thp_eligible; smap_gather_stats(vma, &mss, 0); @@ -882,9 +883,12 @@ static int show_smap(struct seq_file *m, void *v) __show_smap(m, &mss, false); - seq_printf(m, "THPeligible: %8u\n", - !!thp_vma_allowable_orders(vma, vma->vm_flags, - TVA_SMAPS | TVA_ENFORCE_SYSFS, THP_ORDERS_ALL)); + thp_eligible = !!thp_vma_allowable_orders(vma, vma->vm_flags, + TVA_SMAPS | TVA_ENFORCE_SYSFS, THP_ORDERS_ALL); + if (vma_is_anon_shmem(vma)) + thp_eligible = !!shmem_allowable_huge_orders(file_inode(vma->vm_file), + vma, vma->vm_pgoff, thp_eligible); + seq_printf(m, "THPeligible: %8u\n", thp_eligible); if (arch_pkeys_enabled()) seq_printf(m, "ProtectionKey: %8u\n", vma_pkey(vma)); diff --git a/include/linux/huge_mm.h b/include/linux/huge_mm.h index 212cca384d7e..f87136f38aa1 100644 --- a/include/linux/huge_mm.h +++ b/include/linux/huge_mm.h @@ -267,6 +267,10 @@ unsigned long thp_vma_allowable_orders(struct vm_area_struct *vma, return __thp_vma_allowable_orders(vma, vm_flags, tva_flags, orders); } +unsigned long shmem_allowable_huge_orders(struct inode *inode, + struct vm_area_struct *vma, pgoff_t index, + bool global_huge); + struct thpsize { struct kobject kobj; struct list_head node; @@ -460,6 +464,13 @@ static inline unsigned long thp_vma_allowable_orders(struct vm_area_struct *vma, return 0; } +static inline unsigned long shmem_allowable_huge_orders(struct inode *inode, + struct vm_area_struct *vma, pgoff_t index, + bool global_huge) +{ + return 0; +} + #define transparent_hugepage_flags 0UL #define thp_get_unmapped_area NULL diff --git a/mm/shmem.c b/mm/shmem.c index d495c0701a83..aa85df9c662a 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -1622,7 +1622,7 @@ static gfp_t limit_gfp_mask(gfp_t huge_gfp, gfp_t limit_gfp) } #ifdef CONFIG_TRANSPARENT_HUGEPAGE -static unsigned long shmem_allowable_huge_orders(struct inode *inode, +unsigned long shmem_allowable_huge_orders(struct inode *inode, struct vm_area_struct *vma, pgoff_t index, bool global_huge) { @@ -1707,13 +1707,6 @@ static unsigned long shmem_suitable_orders(struct inode *inode, struct vm_fault return orders; } #else -static unsigned long shmem_allowable_huge_orders(struct inode *inode, - struct vm_area_struct *vma, pgoff_t index, - bool global_huge) -{ - return 0; -} - static unsigned long shmem_suitable_orders(struct inode *inode, struct vm_fault *vmf, struct address_space *mapping, pgoff_t index, unsigned long orders)