From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 106DF389E09 for ; Thu, 16 Apr 2026 08:57:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.135.223.130 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776329836; cv=none; b=k8Mi1r1aVzo2h1ra6AiDBUMV9lJrOjV7oo57/wkzOJ/qMJ7CjegkY/kOPtaRLIBvKzf1x2d2pGCmKwgguwNj6cAdf6Z0xlQxd4bRMsOVgoK5A4DFOxfp2IqLA3sOIb+vYF1KIzkpzeKNhB7cBJflUmWzvTAfsiYdA7MBBUje7gU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776329836; c=relaxed/simple; bh=5Vux+2P/Q5gL0bpx1sGAyS2QECs7lfADH85rQ46LwCI=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=lDmuE2NAHzj+RlctakwygiVNFdrKWDYIKojny4iWDvSFt3M0ZFuJ1XOpTUDadb8ggBuHWxtyDBT2ohCwDX/c08izN+qKuWIU+13G7SOVqqNlppGPTOEVFjyrd+cfJKJsEAU0fXlpOzzbxKPGpl1XbfmAyo3dkhEtZFnH7JVMN9o= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de; spf=pass smtp.mailfrom=suse.de; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=lNFk25tG; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=nWxDY/8W; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=lNFk25tG; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=nWxDY/8W; arc=none smtp.client-ip=195.135.223.130 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="lNFk25tG"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="nWxDY/8W"; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="lNFk25tG"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="nWxDY/8W" 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-out1.suse.de (Postfix) with ESMTPS id 2144A6A949; Thu, 16 Apr 2026 08:57:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1776329833; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=1Itbd4wP5e0LBwcEW8IWdSyTKJ027dOJH3Fuc12rHyM=; b=lNFk25tGutojyAp1e7mM30lClGPjPEeoPQ4bdnMvWgG9a+jHmZz/GyPLSD1xjNaGu9Pa1i k2nZtK6sGcYi+uiZcJC6eATVg073lFQXfer+YOPdgGfmJeFExKGBPdKyAQPOyZcQMw9mo9 9T/ramakBWoAF1+j7sKXLL39e0P4MXg= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1776329833; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=1Itbd4wP5e0LBwcEW8IWdSyTKJ027dOJH3Fuc12rHyM=; b=nWxDY/8W0F68feQUmmzLfvCsFjCSAPRe+F5q5K3ZOFN66+he3iRXvc6Mn67AD6OEzC2NBw X//6/abRMucOqzAQ== Authentication-Results: smtp-out1.suse.de; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=lNFk25tG; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b="nWxDY/8W" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1776329833; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=1Itbd4wP5e0LBwcEW8IWdSyTKJ027dOJH3Fuc12rHyM=; b=lNFk25tGutojyAp1e7mM30lClGPjPEeoPQ4bdnMvWgG9a+jHmZz/GyPLSD1xjNaGu9Pa1i k2nZtK6sGcYi+uiZcJC6eATVg073lFQXfer+YOPdgGfmJeFExKGBPdKyAQPOyZcQMw9mo9 9T/ramakBWoAF1+j7sKXLL39e0P4MXg= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1776329833; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=1Itbd4wP5e0LBwcEW8IWdSyTKJ027dOJH3Fuc12rHyM=; b=nWxDY/8W0F68feQUmmzLfvCsFjCSAPRe+F5q5K3ZOFN66+he3iRXvc6Mn67AD6OEzC2NBw X//6/abRMucOqzAQ== 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 AC0834BE97; Thu, 16 Apr 2026 08:57:12 +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 ptTbJ2ik4GmBSgAAD6G6ig (envelope-from ); Thu, 16 Apr 2026 08:57:12 +0000 Date: Thu, 16 Apr 2026 10:57:03 +0200 From: Oscar Salvador To: Usama Arif Cc: Andrew Morton , David Hildenbrand , Michal Hocko , Vlastimil Babka , Muchun Song , Lorenzo Stoakes , 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 Message-ID: References: <20260412174244.133715-6-osalvador@suse.de> <20260413141801.1465873-1-usama.arif@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spamd-Result: default: False [-4.51 / 50.00]; BAYES_HAM(-3.00)[100.00%]; NEURAL_HAM_LONG(-1.00)[-1.000]; R_DKIM_ALLOW(-0.20)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain]; MX_GOOD(-0.01)[]; ARC_NA(0.00)[]; ASN_FAIL(0.00)[7.9.0.0.4.6.0.0.0.5.1.0.0.1.0.0.4.0.1.0.1.8.2.b.0.4.e.d.7.0.a.2.asn6.rspamd.com:server fail]; MIME_TRACE(0.00)[0:+]; FUZZY_RATELIMITED(0.00)[rspamd.com]; RCPT_COUNT_SEVEN(0.00)[9]; MISSING_XM_UA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; RCVD_TLS_ALL(0.00)[]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; SPAMHAUS_XBL(0.00)[2a07:de40:b281:104:10:150:64:97:from]; FROM_EQ_ENVFROM(0.00)[]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; RCVD_COUNT_TWO(0.00)[2]; TO_MATCH_ENVRCPT_ALL(0.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[imap1.dmz-prg2.suse.org:helo,imap1.dmz-prg2.suse.org:rdns,suse.de:dkim]; URIBL_BLOCKED(0.00)[imap1.dmz-prg2.suse.org:helo,imap1.dmz-prg2.suse.org:rdns,suse.de:dkim]; DKIM_TRACE(0.00)[suse.de:+] X-Rspamd-Action: no action X-Spam-Flag: NO X-Spam-Score: -4.51 X-Spam-Level: X-Rspamd-Server: rspamd1.dmz-prg2.suse.org X-Rspamd-Queue-Id: 2144A6A949 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