From patchwork Thu Jul 4 04:30:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oscar Salvador X-Patchwork-Id: 13723186 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 18E8AC30653 for ; Thu, 4 Jul 2024 04:32:14 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 689486B009B; Thu, 4 Jul 2024 00:32:03 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 574266B009C; Thu, 4 Jul 2024 00:32:03 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3C38B6B009D; Thu, 4 Jul 2024 00:32:03 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 15E4F6B009B for ; Thu, 4 Jul 2024 00:32:03 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id C8CFCA0835 for ; Thu, 4 Jul 2024 04:32:02 +0000 (UTC) X-FDA: 82300797684.09.E90A489 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) by imf20.hostedemail.com (Postfix) with ESMTP id B6D841C0013 for ; Thu, 4 Jul 2024 04:32:00 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=suse.de; spf=pass (imf20.hostedemail.com: domain of osalvador@suse.de designates 195.135.223.131 as permitted sender) smtp.mailfrom=osalvador@suse.de ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1720067501; a=rsa-sha256; cv=none; b=6c9tHDrLDVlxMS7ZzbqfgMzvONyRzosBpelOzzQFbGD4beutU9o3YPG5AB1XAaOt7OpRpM fu70nJoWcg3d1+Ohf4O2KI6GHLL5Jid0Y4K7YP1rHkCPB6TlK3MGemLnnOx3/hFBBMlk/l 4e1DrygaSHr6lECNDq33XcZ9WB5f+1Y= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=suse.de; spf=pass (imf20.hostedemail.com: domain of osalvador@suse.de designates 195.135.223.131 as permitted sender) smtp.mailfrom=osalvador@suse.de ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1720067501; 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; bh=3qKedk2fwycHSnQhhuoHW6DxwcyT9yK5ZC/WZBJG70E=; b=isI7webdiuwjJJaVR4117aEIG2WZvBOYKXR/P+wl+yrXDfBmuRhw6znMAaCQLxUIejGnyc 55Wds5JJvkCeAaZukZDpDbpUhLuZ3fmnR3aEiL4PtOvs+7FEfQ6ED59lkmewQK260VwLtR IowhV/f8Unx5F7+JX6OF/K843uZc9LE= Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 824D71FCF7; Thu, 4 Jul 2024 04:31:59 +0000 (UTC) Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 5F5B113889; Thu, 4 Jul 2024 04:31:58 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id AKLwEr4lhmbnDAAAD6G6ig (envelope-from ); Thu, 04 Jul 2024 04:31:58 +0000 From: Oscar Salvador To: Andrew Morton Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, Peter Xu , Muchun Song , David Hildenbrand , SeongJae Park , Miaohe Lin , Michal Hocko , Matthew Wilcox , Christophe Leroy , Oscar Salvador Subject: [PATCH 08/45] fs/proc: Enable smaps_pmd_entry to handle PMD-mapped hugetlb vmas Date: Thu, 4 Jul 2024 06:30:55 +0200 Message-ID: <20240704043132.28501-9-osalvador@suse.de> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240704043132.28501-1-osalvador@suse.de> References: <20240704043132.28501-1-osalvador@suse.de> MIME-Version: 1.0 X-Rspamd-Pre-Result: action=no action; module=replies; Message is reply to one we originated X-Rspamd-Pre-Result: action=no action; module=replies; Message is reply to one we originated X-Rspamd-Action: no action X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: B6D841C0013 X-Stat-Signature: 3ebizy9rjyjn1hm7oy6sh4o5asw6bdrz X-Rspam-User: X-HE-Tag: 1720067520-869317 X-HE-Meta: U2FsdGVkX1+/IgMzZcOgHHDL6W5VfPrNvxEvte7ACZeXZDXaPw5VYQScDVYpyse39hun+Jn0HrUJjyBxGQ1Tzpj1T1PZgqojAgYKf2PPCUeLyO1iM5cYhbo1/+kpCRGZGs8PsOoc3Aolt75WGle/lUA49w9PZtolbGUAVvIge2iCCmTqpraCR94CICwU1P/6VuzyIK5A3LdmaN3KLZCf3LhRRt/HFRDCr9Dgyu+FaBGyQl5za+kotlenErlthTZy1jufqwLAVTJt1zYhYpDloeYyNvGHNuwvZmR1Oho9ke2J29imzeid5lIJBjB+G8F3qkCIzZPEK03QSJ9bMcC+TA5xkJF0nnAUZpXbh8cfIEKdlqJHalJqCQkR8beLdssX+KcXneejDTXEIlTVuzNtJXDz/C7EQc1wJ1FCQgtm63nYJGF3X8cE6TnJgm4q1ff4hOuSFgJbtmEFI01/cwwLdmgTx6I1/FW2QWjrcQfWGJbF60tJOJYPDHol1Ey/L054TuyITQpbZqb9Z+nz5iPyy620DyNrX/cBV7bwx7haQWP7HMrAn8UY414LR01buYNm4OuKcRgDGMAjcvdSWWBHgwgNnUBFls582CuLprpB4EJJgumMzodzIu3P6wS16LoUmrrDtY6jyNQ6QG0d2u2en3cBHPV4tuiWxtV8NgCmmxBt+5X4+l7fMPU50gVzHtVVEGKyW31q+UCPCplV4qv6UNFNOI1+vLQI4Db41woZpi/NN9WkZo/KiPSUyWBUxBP2wO2WIS3+NWQO3wJFpT9cJRTXFzkC33k1yygVR1qFavcs+H/of7SW+bSEkdPfPEcWSKfzDaKWn7nfiI/pWv7ETkbz2tKrMdhCHRrL3Haqrn042Pbi2eKfxhF92WZy5lVYQiI2VYiq2kq/ss3dQL3jZsW07Wmg08QfXrqLBugkV6akRJr0xjyqWtnPCvTs3vBEtbXRgQsuVgExNyRaSKY /yDDuEAj hX24o0ol2eWyzwkBkh0SD8AN+5bUlNnW+ywh7m7r+9leodZor/WcqZmlfC8dAYubBx6XxFQMsm4G87uMQMIYdX4ZVD1W6IJQaCzgSBRKE9+O2XVwZ0TSJm9E5KAImTAUgQyWzeUR2IPD1FluCTKSWpemDb6ZdcejCjmrMUVlM2Kf8TPQ= 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: PMD-mapped hugetlb vmas will also reach smaps_pmd_entry. Add the required code so it knows how to handle those there. Signed-off-by: Oscar Salvador --- fs/proc/task_mmu.c | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c index 775a2e8d600c..78d84d7e2353 100644 --- a/fs/proc/task_mmu.c +++ b/fs/proc/task_mmu.c @@ -804,6 +804,18 @@ static void smaps_pte_hole_lookup(unsigned long addr, struct mm_walk *walk) #endif } +#ifdef CONFIG_HUGETLB_PAGE +static void mss_hugetlb_update(struct mem_size_stats *mss, struct folio *folio, + struct vm_area_struct *vma, pte_t *pte) +{ + if (folio_likely_mapped_shared(folio) || + hugetlb_pmd_shared(pte)) + mss->shared_hugetlb += huge_page_size(hstate_vma(vma)); + else + mss->private_hugetlb += huge_page_size(hstate_vma(vma)); +} +#endif + static void smaps_pte_entry(pte_t *pte, unsigned long addr, struct mm_walk *walk) { @@ -851,12 +863,13 @@ static void smaps_pte_entry(pte_t *pte, unsigned long addr, smaps_account(mss, page, false, young, dirty, locked, present); } -#ifdef CONFIG_TRANSPARENT_HUGEPAGE +#ifdef CONFIG_PGTABLE_HAS_HUGE_LEAVES static void smaps_pmd_entry(pmd_t *pmd, unsigned long addr, struct mm_walk *walk) { struct mem_size_stats *mss = walk->private; struct vm_area_struct *vma = walk->vma; + bool hugetlb = is_vm_hugetlb_page(vma); bool locked = !!(vma->vm_flags & VM_LOCKED); struct page *page = NULL; bool present = false; @@ -865,7 +878,7 @@ static void smaps_pmd_entry(pmd_t *pmd, unsigned long addr, if (pmd_present(*pmd)) { page = vm_normal_page_pmd(vma, addr, *pmd); present = true; - } else if (unlikely(thp_migration_supported() && is_swap_pmd(*pmd))) { + } else if (is_swap_pmd(*pmd)) { swp_entry_t entry = pmd_to_swp_entry(*pmd); if (is_pfn_swap_entry(entry)) @@ -874,6 +887,12 @@ static void smaps_pmd_entry(pmd_t *pmd, unsigned long addr, if (IS_ERR_OR_NULL(page)) return; folio = page_folio(page); + + if (hugetlb) { + mss_hugetlb_update(mss, folio, vma, (pte_t *)pmd); + return; + } + if (folio_test_anon(folio)) mss->anonymous_thp += HPAGE_PMD_SIZE; else if (folio_test_swapbacked(folio)) @@ -900,7 +919,7 @@ static int smaps_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end, pte_t *pte; spinlock_t *ptl; - ptl = pmd_trans_huge_lock(pmd, vma); + ptl = pmd_huge_lock(pmd, vma); if (ptl) { smaps_pmd_entry(pmd, addr, walk); spin_unlock(ptl);