From patchwork Thu Jul 4 04:30:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oscar Salvador X-Patchwork-Id: 13723189 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 40C1AC30653 for ; Thu, 4 Jul 2024 04:32:23 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7476A6B009E; Thu, 4 Jul 2024 00:32:07 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6A9426B009F; Thu, 4 Jul 2024 00:32:07 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4FB3A6B00A0; Thu, 4 Jul 2024 00:32:07 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 271EF6B009E for ; Thu, 4 Jul 2024 00:32:07 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id E235A140A92 for ; Thu, 4 Jul 2024 04:32:06 +0000 (UTC) X-FDA: 82300797852.09.82CB443 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) by imf27.hostedemail.com (Postfix) with ESMTP id BEBCA40004 for ; Thu, 4 Jul 2024 04:32:04 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=suse.de; spf=pass (imf27.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=1720067506; a=rsa-sha256; cv=none; b=qSiYCjrQwuHbz/FYuAStcGz+cVo/pthgA1qXHo4gLJhYA9GfA9Zj/0b1d6FFrRChy40n78 Jb16kb3WZu72AXvIMGbKj7AwB0dBWEko0jsPYKkS4jO9qVvMd5OQw0/WI1K/q+8otPo0Ge y3ScCE17XBljt3x4tunWY8XMBkmCEzw= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=suse.de; spf=pass (imf27.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=1720067506; 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=F9LfBkIVdTUBVSN3j07vFwBTlJlTYHksIUd3RDOpre8=; b=bM3rzVzkZj4bGsG6MH91BXMeJKLMxM6jm6CfHnMwK7bRh3gg5ex0pUN7dU5L++3B5HVHvx s+icyzYOKy5aNdFAXSZthVBvtNBMZPz63wU7eiJ9xKwaXvriiz19D9mRTkN46v28WpY9NK 9sfzsReedgsowDnSH6xCFhrAglbApCg= 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 770A51FCFD; Thu, 4 Jul 2024 04:32:03 +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 4D9D013889; Thu, 4 Jul 2024 04:32:02 +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 IPAUDcIlhmbnDAAAD6G6ig (envelope-from ); Thu, 04 Jul 2024 04:32:02 +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 11/45] fs/proc: Enable smaps_pte_entry to handle cont-pte mapped hugetlb vmas Date: Thu, 4 Jul 2024 06:30:58 +0200 Message-ID: <20240704043132.28501-12-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-Queue-Id: BEBCA40004 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: j7bj9wuzomahe5c5ddmy3dysnm7rumhz X-HE-Tag: 1720067524-538987 X-HE-Meta: U2FsdGVkX18XemCUbwJbGnHWavJ59ny4OjS+60jStNMln1rG6g0d9exl5jMIYymWRz/jbax/ruRetAC2ICNhLwQvH5yk0a5hWWSJEQs42IlKyKHwfGrwBBIQIyhF+LrNaGQ+JAkNfeDmKWMz124pXo67d6i4O4+5NgQqeizBR/mYt4pTSCnn0iy/EYwXDiQ6rn9hJeVfbTIuakV+NLxEMBM/bv8QpF85l1RNxV0ttb2KrWcDmvLgKyh4fdDTvIA/n0+4m56bC9A9pme6tev/uYuUXhU3y5V0eZzAErDVZhxc+/qSgE8tMjhIHozfytiGO7JwQJLoHCgQkYWcWAoA2z+GcJcYajcVgtF3WNtdc+GjvQ2+C5tiH69YQXC8Om5qICAFlNMoR7KpwV5HTWu6mXEgrOyNNKA579v9jmyXBrtSQO3COFHD34FvHI/ZZ10uGFMYwLGvbslo9kTG1t+3F02Fkg6LJV6IzIVd7DkWIveYST2Otf5RCYhqwpy5M3yg+eh+IfqBLZQMu60SZu6GSsAr6FIS2LVvpXjfvDwn4HM+szDkXhTuRfNMLThSGiQbRZW4YNvpsvCX7a+cVHItZGnBlZDhFD7OSW8FtExp8rLalSMsi582u5E2GWJ6ee+YNw5Ki4LpYFS8U2w/ec7AFuQu/GDIScel2IQ3sSLDVFER1H3GVFWCaEBJSzpz85A6oFAw2mT4TbDaGEBlArmAHnzuyePfB14xJAYoqnT32Il541k2I6bgWvFckEOV5BlunFdPctzmjrrljXNJqXu4lk6tPk2qc5CFEO05LL1RgnkGcZzb5LYvcw2w2y0ZFQHpJFIU8M3xgLkBovQGcKNxs92t5ENEQanGwVwm72EyULz6gxSgQzQVvkxD2QbXfoDRUbUoAGZBfe9zY83v+7IVHeW/HWcLcjhGIIfwgRzcRhNW0CjRUQDEP4HHIjnQj5aPkNAO8FZR3KTjJ25gl1E xYvl6mNn nVpZQWe8j2UVeGnjmGkXSPTeMIuPSM8X1vnsskARtClDK5g5zpNzwCNTCo0lu0UvhqSxRAV1kQhxy+1ugxxF2+r8YQ0QVUbbJE0zAi4pF+hNzWHJiPdblD4OVCs/s8lSjkfteEK42DYUci0x023I/ltw1TLz1bpBgAivJfavjiwYw/0M= 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: HugeTLB pages can be cont-pte mapped, so teach smaps_pte_entry to handle them. Signed-off-by: Oscar Salvador --- fs/proc/task_mmu.c | 19 +++++++++++++------ include/linux/pgtable.h | 12 ++++++++++++ 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c index 3f3460ff03b0..4d94b6ce58dd 100644 --- a/fs/proc/task_mmu.c +++ b/fs/proc/task_mmu.c @@ -825,6 +825,7 @@ static void smaps_pte_entry(pte_t *pte, unsigned long addr, struct page *page = NULL; bool present = false, young = false, dirty = false; pte_t ptent = ptep_get(pte); + unsigned long size = pte_cont(ptent) ? PAGE_SIZE * CONT_PTES : PAGE_SIZE; if (pte_present(ptent)) { page = vm_normal_page(vma, addr, ptent); @@ -834,18 +835,18 @@ static void smaps_pte_entry(pte_t *pte, unsigned long addr, } else if (is_swap_pte(ptent)) { swp_entry_t swpent = pte_to_swp_entry(ptent); - if (!non_swap_entry(swpent)) { + if (!is_vm_hugetlb_page(vma) && !non_swap_entry(swpent)) { int mapcount; - mss->swap += PAGE_SIZE; + mss->swap += size; mapcount = swp_swapcount(swpent); if (mapcount >= 2) { - u64 pss_delta = (u64)PAGE_SIZE << PSS_SHIFT; + u64 pss_delta = (u64)size << PSS_SHIFT; do_div(pss_delta, mapcount); mss->swap_pss += pss_delta; } else { - mss->swap_pss += (u64)PAGE_SIZE << PSS_SHIFT; + mss->swap_pss += (u64)size << PSS_SHIFT; } } else if (is_pfn_swap_entry(swpent)) { if (is_device_private_entry(swpent)) @@ -860,7 +861,10 @@ static void smaps_pte_entry(pte_t *pte, unsigned long addr, if (!page) return; - smaps_account(mss, page, false, young, dirty, locked, present); + if (is_vm_hugetlb_page(vma)) + mss_hugetlb_update(mss, page_folio(page), vma, pte); + else + smaps_account(mss, page, false, young, dirty, locked, present); } #ifdef CONFIG_PGTABLE_HAS_HUGE_LEAVES @@ -952,6 +956,7 @@ static int smaps_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end, struct vm_area_struct *vma = walk->vma; pte_t *pte; spinlock_t *ptl; + unsigned long size, cont_ptes; ptl = pmd_huge_lock(pmd, vma); if (ptl) { @@ -965,7 +970,9 @@ static int smaps_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end, walk->action = ACTION_AGAIN; return 0; } - for (; addr != end; pte++, addr += PAGE_SIZE) + size = pte_cont(ptep_get(pte)) ? PAGE_SIZE * CONT_PTES : PAGE_SIZE; + cont_ptes = pte_cont(ptep_get(pte)) ? CONT_PTES : 1; + for (; addr != end; pte += cont_ptes, addr += size) smaps_pte_entry(pte, addr, walk); pte_unmap_unlock(pte - 1, ptl); out: diff --git a/include/linux/pgtable.h b/include/linux/pgtable.h index a9edeb86b7fe..991137dab87e 100644 --- a/include/linux/pgtable.h +++ b/include/linux/pgtable.h @@ -1926,6 +1926,18 @@ typedef unsigned int pgtbl_mod_mask; #define CONT_PMDS 0 #endif +#ifndef pte_cont +#define pte_cont(x) false +#endif + +#ifndef CONT_PTE_SIZE +#define CONT_PTE_SIZE 0 +#endif + +#ifndef CONT_PTES +#define CONT_PTES 0 +#endif + /* * We always define pmd_pfn for all archs as it's used in lots of generic * code. Now it happens too for pud_pfn (and can happen for larger