public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Oscar Salvador <osalvador@suse.de>
To: Usama Arif <usama.arif@linux.dev>
Cc: Andrew Morton <akpm@linux-foundation.org>,
	David Hildenbrand <david@kernel.org>,
	Michal Hocko <mhocko@suse.com>,
	Vlastimil Babka <vbabka@kernel.org>,
	Muchun Song <muchun.song@linux.dev>,
	Lorenzo Stoakes <lorenzo.stoakes@oracle.com>,
	linux-kernel@vger.kernel.org, linux-mm@kvack.org
Subject: Re: [RFC PATCH 5/7] mm: Make /proc/pid/smaps use the new generic pagewalk API
Date: Thu, 16 Apr 2026 10:57:03 +0200	[thread overview]
Message-ID: <aeCkX5gT5akiQnE0@localhost.localdomain> (raw)
In-Reply-To: <adz-SRhS7H50fWXY@localhost.localdomain>

On Mon, Apr 13, 2026 at 04:31:37PM +0200, Oscar Salvador wrote:
> On Mon, Apr 13, 2026 at 07:18:00AM -0700, Usama Arif wrote:
>  
> > The old smap_gather_stats had special handling for shmem swap
> > accounting.  For shared or readonly shmem mappings it used
> > shmem_swap_usage() to efficiently account swapped-out shmem pages.
> > For private writable shmem mappings it used smaps_pte_hole() via
> > smaps_shmem_walk_ops to call shmem_partial_swap_usage() for each
> > PTE hole.
> > 
> > The new code removes all of this.  The pt_range_walk API does not
> > have pte_hole callbacks, so shmem pages that are swapped out (and
> > thus have no PTE) would not be counted in the Swap field of smaps?
> 
> Yes, sorry, that is one of those parts which is incomplete.
> I am already working on that offline, but did not have the time to
> prepare it for this one.

So, I implemented it, quick test show it works:

--- fs/proc/task_mmu.c	2026-04-16 10:54:54.440974482 +0200
+++ task_mmu.c	2026-04-16 10:53:36.465147406 +0200
@@ -1105,13 +1105,38 @@
 	enum pt_range_walk_type type;
 	pt_type_flags_t flags = PT_TYPE_ALL;

-	if (!start)
-		start = vma->vm_start;
+	if (start >= vma->vm_end)
+		return;

 	flags &= ~(PT_TYPE_NONE|PT_TYPE_PFN);

+	if (vma->vm_file && shmem_mapping(vma->vm_file->f_mapping)) {
+		/*
+		 * For shared or readonly shmem mappings we know that all
+		 * swapped out pages belong to the shmem object, and we can
+		 * obtain the swap value much more efficiently. For private
+		 * writable mappings, we might have COW pages that are
+		 * not affected by the parent swapped out pages of the shmem
+		 * object, so we have to distinguish them during the page walk.
+		 * Unless we know that the shmem object (or the part mapped by
+		 * our VMA) has no swapped out pages at all.
+		 */
+		unsigned long shmem_swapped = shmem_swap_usage(vma);
+
+		if (!start && (!shmem_swapped || (vma->vm_flags & VM_SHARED) ||
+		    !(vma->vm_flags & VM_WRITE))) {
+			mss->swap += shmem_swapped;
+		} else {
+			flags |= PT_TYPE_NONE;
+		}
+	}
+
+	if (!start)
+		start = vma->vm_start;
+
 	type = pt_range_walk_start(&ptw, vma, start, vma->vm_end, flags);
 	while (type != PTW_DONE) {
+		unsigned long curr_addr = ptw.curr_addr;
 		bool locked = !!(vma->vm_flags & VM_LOCKED);
 		bool compound = false, account = false;
 		unsigned long swap_size;
@@ -1168,6 +1193,17 @@
 				mss->swap_pss += (u64)swap_size << PSS_SHIFT;
 			}
 			break;
+		case PTW_NONE:
+#ifdef CONFIG_SHMEM
+			unsigned long addr = ptw.curr_addr;
+			unsigned long end = ptw.next_addr;
+
+			if (ptw.level == PTW_PMD_LEVEL || ptw.level PTW_PTE_LEVEL)
+				mss->swap += shmem_partial_swap_usage(vma->vm_file->f_mapping,
+							      linear_page_index(vma, addr),
+							      linear_page_index(vma, end));
+#endif
+			break;
 		default:
 			/* Ooops */
 			break;

 

-- 
Oscar Salvador
SUSE Labs

  reply	other threads:[~2026-04-16  8:57 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-12 17:42 [RFC PATCH 0/7] Implement a new generic pagewalk API Oscar Salvador
2026-04-12 17:42 ` [RFC PATCH 1/7] mm: Add softleaf_from_pud Oscar Salvador
2026-04-12 17:42 ` [RFC PATCH 2/7] mm: Add {pmd,pud}_huge_lock helper Oscar Salvador
2026-04-12 17:42 ` [RFC PATCH 3/7] mm: Implement folio_pmd_batch Oscar Salvador
2026-04-12 17:42 ` [RFC PATCH 4/7] mm: Implement pt_range_walk Oscar Salvador
2026-04-12 17:42 ` [RFC PATCH 5/7] mm: Make /proc/pid/smaps use the new generic pagewalk API Oscar Salvador
2026-04-13 14:18   ` Usama Arif
2026-04-13 14:31     ` Oscar Salvador
2026-04-16  8:57       ` Oscar Salvador [this message]
2026-04-12 17:42 ` [RFC PATCH 6/7] mm: Make /proc/pid/numa_maps " Oscar Salvador
2026-04-12 17:42 ` [RFC PATCH 7/7] mm: Make /proc/pid/pagemap " Oscar Salvador
2026-04-13  7:38 ` [syzbot ci] Re: Implement a " syzbot ci

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=aeCkX5gT5akiQnE0@localhost.localdomain \
    --to=osalvador@suse.de \
    --cc=akpm@linux-foundation.org \
    --cc=david@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=lorenzo.stoakes@oracle.com \
    --cc=mhocko@suse.com \
    --cc=muchun.song@linux.dev \
    --cc=usama.arif@linux.dev \
    --cc=vbabka@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox