From nobody Fri Sep 25 13:54:14 2026 Received: from mail-pj1-f71.google.com (mail-pj1-f71.google.com [209.85.216.71]) (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 BD8F9552955 for ; Fri, 11 Sep 2026 19:42:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.71 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789155745; cv=none; b=PjdaSvjurbospPD5JRQegVuQCEbyYwJ8P/i2tsHQrXk1v1x6riZQNaLxM0AsYJoEk1+i7LQHKVXV8Zo67sfT7PZdgR9dGX5KpEMQYgWDZkDufYJVOTeNExjTsbtsHEWngDl2PPbL48UI9bfy0PNuCeIg7fcw3DidbthAOUg0JPI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789155745; c=relaxed/simple; bh=hTFVKt75D71OvdXG4pzTXlqYcjNqksLPxYYyQHAZ+yc=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=YqjqZDTcMSR3U7ELho7W0yZ4APXfHYEEJT6oXCky6t9DBY1rv3YjpyKLaUQqM/jnTgOraETkI62ITepPTiWXkLsd6uyPdlpLChIceHwf074fXtVVTCSm/YXTi9TitfMMsz7pFfV5X4wb27YEfbUOmthqiaY1itk5cuWo1h7uCTU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--surenb.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=TKzVZYg/; arc=none smtp.client-ip=209.85.216.71 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--surenb.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="TKzVZYg/" Received: by mail-pj1-f71.google.com with SMTP id 98e67ed59e1d1-398fe469aa0so2186099a91.2 for ; Fri, 11 Sep 2026 12:42:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1789155711; x=1789760511; darn=vger.kernel.org; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:from:to:cc:subject:date:message-id:reply-to :content-type; bh=xOFXyMArwtdLkzPinOADoZdNqvQDYiollRghSoVraI0=; b=TKzVZYg/gyRfvrb8NxOkX1XIF1P1agFnWHyxoh5rRuo6tSeM2vVdSPkjPRNitv/TpL ob9I8NrAPC0O+0cI6Zq/aEUUcicoTI46iqErviIkBY7IPPzLq0RP9EH6vQ4i5T+nOg+L mTtNfkIec4DHdNiYPrscu6Fo7LzDgSqi8vPE84Qd2SC5cCqFdT6EymKpAaCpNmlipCfK tPTppqRYIiSMyKhWKh6MlgggIMNSbc/cl6AgpuAHG1Q5zjgdOHDpjkmcjVndDva8vEgu p0aVfYeMMuKDEGMXt8/+9x1nZQ2V4HWLJihWa27LZeHQwImc+phLknGPo34UUCYbBeQR retQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1789155711; x=1789760511; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=xOFXyMArwtdLkzPinOADoZdNqvQDYiollRghSoVraI0=; b=X2vWVZQVHpuckUsdMKRlOvIB9YLoBIwl1YqlruyDiNbiNl/HgBJ+knpLCTvqNXhMLQ PZ0AtvCtY9pG+i2Xm94Lmgb42W7Y4RiGcc/02DFk7P2TSICmyTgn2alUCzqUaCRUC+pO S6vKYgE6wI208P3pl/kr82+J0qjVOS7ZQwugo1wwNKECGvYrtTgs6Convf3BGOIraYrl kv8Q87idCJClURGhk+gWvct1I8epBrEqA9H/M7ftGDw67yo4geYj1epCJu0QLF12oyLq VocuykIHPpG6PtMmyrq5RkTaSIm2GkLopv2eXO1UaRl9+eF3nRK2S2n4qH4Un/Muls35 joiQ== X-Forwarded-Encrypted: i=1; AKwUvBz8uwsujd+/Q+kekZFHCUu/EDdHM3NL/T8lC13ASI3N7GEbQViL02DK8YLdCFxE4nIcznoQiHRgUsoz91s=@vger.kernel.org X-Gm-Message-State: AFuF++lEHda5ShARwaGpvAfoWHXeIx0t11y5Y3TI2CKZjXJu1yf3chhX XmFYXTQPxlTiAW1m3PYgyhEeKZQwzP6waETHwkywYzlqtZFkg7rV273ouTa42a1Ufv6F2P+Jh1J ulhs7QQ== X-Received: from dlbrj7.prod.google.com ([2002:a05:7022:f407:b0:143:5fe6:4e1a]) (user=surenb job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:5246:b0:398:d2a0:87ff with SMTP id 98e67ed59e1d1-39d9bc67660mr10045684a91.1.1789155711065; Fri, 11 Sep 2026 12:41:51 -0700 (PDT) Date: Fri, 11 Sep 2026 12:41:39 -0700 In-Reply-To: <20260911194145.1781926-1-surenb@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260911194145.1781926-1-surenb@google.com> X-Mailer: git-send-email 2.55.0.1007.g17ff1f9808-goog Message-ID: <20260911194145.1781926-2-surenb@google.com> Subject: [PATCH v4 1/7] proc/task_mmu: remove unnecessary helpers From: Suren Baghdasaryan To: akpm@linux-foundation.org Cc: liam@infradead.org, ljs@kernel.org, vbabka@kernel.org, david@kernel.org, willy@infradead.org, jannh@google.com, paulmck@kernel.org, pfalcato@suse.de, xueyuan.chen21@gmail.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, surenb@google.com, Usama Arif Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" When per-vma locks were behind a config option, a number of helper functions were needed to simplify the locking code. Now that these locks are universally available, we can do a little cleanup. Remove lock_vma_range(), unlock_vma_range(), query_vma_setup(), query_vma_teardown() helpers. No functional change intended. Signed-off-by: Suren Baghdasaryan Reviewed-by: Liam R. Howlett (Oracle) Reviewed-by: Lorenzo Stoakes (ARM) Acked-by: Usama Arif Acked-by: David Hildenbrand (Arm) --- fs/proc/task_mmu.c | 67 ++++++++++++---------------------------------- 1 file changed, 17 insertions(+), 50 deletions(-) diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c index e671b4fd8ded..2f500d639db5 100644 --- a/fs/proc/task_mmu.c +++ b/fs/proc/task_mmu.c @@ -160,25 +160,6 @@ static void unlock_ctx_vma(struct proc_maps_locking_ct= x *lock_ctx) } } =20 -static inline bool lock_vma_range(struct seq_file *m, - struct proc_maps_locking_ctx *lock_ctx) -{ - rcu_read_lock(); - reset_lock_ctx(lock_ctx); - - return true; -} - -static inline void unlock_vma_range(struct proc_maps_locking_ctx *lock_ctx) -{ - if (lock_ctx->mmap_locked) { - unlock_ctx_mm(lock_ctx); - } else { - unlock_ctx_vma(lock_ctx); - rcu_read_unlock(); - } -} - static struct vm_area_struct *get_next_vma(struct proc_maps_private *priv, loff_t last_pos) { @@ -286,13 +267,8 @@ static void *m_start(struct seq_file *m, loff_t *ppos) return NULL; } =20 - if (!lock_vma_range(m, lock_ctx)) { - mmput(mm); - put_task_struct(priv->task); - priv->task =3D NULL; - return ERR_PTR(-EINTR); - } - + rcu_read_lock(); + reset_lock_ctx(lock_ctx); /* * Reset current position if last_addr was set before * and it's not a sentinel. @@ -325,7 +301,12 @@ static void m_stop(struct seq_file *m, void *v) return; =20 release_task_mempolicy(priv); - unlock_vma_range(&priv->lock_ctx); + if (priv->lock_ctx.mmap_locked) { + unlock_ctx_mm(&priv->lock_ctx); + } else { + unlock_ctx_vma(&priv->lock_ctx); + rcu_read_unlock(); + } mmput(mm); put_task_struct(priv->task); priv->task =3D NULL; @@ -518,21 +499,6 @@ static int pid_maps_open(struct inode *inode, struct f= ile *file) PROCMAP_QUERY_VMA_FLAGS \ ) =20 -static int query_vma_setup(struct proc_maps_locking_ctx *lock_ctx) -{ - reset_lock_ctx(lock_ctx); - - return 0; -} - -static void query_vma_teardown(struct proc_maps_locking_ctx *lock_ctx) -{ - if (lock_ctx->mmap_locked) - unlock_ctx_mm(lock_ctx); - else - unlock_ctx_vma(lock_ctx); -} - static struct vm_area_struct *query_vma_find_by_addr(struct proc_maps_lock= ing_ctx *lock_ctx, unsigned long addr) { @@ -653,12 +619,7 @@ static int do_procmap_query(struct mm_struct *mm, void= __user *uarg) if (!mm || !mmget_not_zero(mm)) return -ESRCH; =20 - err =3D query_vma_setup(&lock_ctx); - if (err) { - mmput(mm); - return err; - } - + reset_lock_ctx(&lock_ctx); vma =3D query_matching_vma(&lock_ctx, karg.query_addr, karg.query_flags); if (IS_ERR(vma)) { err =3D PTR_ERR(vma); @@ -732,7 +693,10 @@ static int do_procmap_query(struct mm_struct *mm, void= __user *uarg) vm_file =3D get_file(vma->vm_file); =20 /* unlock vma or mmap_lock, and put mm_struct before copying data to user= */ - query_vma_teardown(&lock_ctx); + if (lock_ctx.mmap_locked) + unlock_ctx_mm(&lock_ctx); + else + unlock_ctx_vma(&lock_ctx); mmput(mm); =20 if (karg.build_id_size) { @@ -773,7 +737,10 @@ static int do_procmap_query(struct mm_struct *mm, void= __user *uarg) return 0; =20 out: - query_vma_teardown(&lock_ctx); + if (lock_ctx.mmap_locked) + unlock_ctx_mm(&lock_ctx); + else + unlock_ctx_vma(&lock_ctx); mmput(mm); out_file: if (vm_file) --=20 2.55.0.1007.g17ff1f9808-goog From nobody Fri Sep 25 13:54:14 2026 Received: from mail-pl1-f197.google.com (mail-pl1-f197.google.com [209.85.214.197]) (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 AF96F38E8A8 for ; Fri, 11 Sep 2026 19:42:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.197 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789155729; cv=none; b=hdJX/Dn3f83Cj8/GArAwsucNlZrtA9MIbKoXafm4u32P/lCMwG+SlVY5fGXlhIhgjoZ8VKhYE2IIpQ38otXji7Uu0pzGIRrEMMXTCcLqGXeqEKMrXlJHpQsHLNhs1KL18udYLlXMLY4s3RcFRxDIH0cSuEd5ZLBkR+1b2uqV6mM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789155729; c=relaxed/simple; bh=fUxXDYw3T1gUirTrhaVtgZWtvxsAdhHi4+wohdyk030=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=lcXa2ARJgQQ7AJbFKgdPTLdcMhKgGMo37B0WRiChFZR+Z18R3yE5+p/P8d14jQVCbWLJBDGuNO/0ivtr+6sVkF5ppCODEmbn2WeeF9r+MhlrlpkBw0BFs/T4K7stWQBCnytFRK4qMDjsGdDRusP7vDqgGvyF7X5Wxc9WRs/JcaY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--surenb.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=YX9IOoyD; arc=none smtp.client-ip=209.85.214.197 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--surenb.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="YX9IOoyD" Received: by mail-pl1-f197.google.com with SMTP id d9443c01a7336-2db050d469fso34567805ad.0 for ; Fri, 11 Sep 2026 12:41:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1789155713; x=1789760513; darn=vger.kernel.org; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:from:to:cc:subject:date:message-id:reply-to :content-type; bh=YI2R/SdoKPqweMYYzjbXGeDWKwn1DHCKfjSC8BU4ikg=; b=YX9IOoyDHCtVX5kYiuXg61qs2GEN+0EzGzp3ouuKpfKmmSFdCKlxir45/tB6dvV+oQ bfo2KoZQh9rwm5mkEKJwmGh8oQbhQJpo6I7sxEDzbxzrEUeFTZNCTRzWVmmhb4WHaiMm UKo9Sv/2ErmESr2us9G9G9ak5hVORfhdF1U53U4ulYfK6mDuLQdFexKnACiHg1IRkib1 VvcCs/psqtcoOZHBCMr24cm6kYZyg7LcSabhxGKjTIl3bSKJtmmy1zLetid30OEMGsCM IvLZ9pf/+rxokGKXyaIqjSGO0wEQ5+RiL/L1VLNwS0itW27H7hUfXQXaB7AS0Ax9YqsC EYjA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1789155713; x=1789760513; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=YI2R/SdoKPqweMYYzjbXGeDWKwn1DHCKfjSC8BU4ikg=; b=iiNmC9fnFGXCGGSDoqojgemQRXYrtlP4wfYo3QzjC03SFBya1BovsoeU6mTjDbtG5S 5YZKmVyIhX0jB+Xea7Gbw+4RM/6M5pclR7AT+oRHcrbMgGvPKmY18X8Q9o0XYAkma9cj Wr7p57wref+ULKc7LISF50u7lvtkH8aExdU9WQAVVqrK1rIogPJEgUL+L4s+YCE7aBO2 F7mP4vCWX01f+YsfCefI0UP9MEfAxKl+2DL4pUs0Q7HGlZgQ7p2g0kE0rTQg5YF1s43/ pgDm5i0lJK9tYXwXp8L+/Z5pDMcl4Brdn8SCP+TErWpScK9xnU/px7uDXopamyfsAJHo Flig== X-Forwarded-Encrypted: i=1; AKwUvBwFQiKHfumo3gjRvORotsxA2dn1GnZYON2+hpVP/wSz0QxrebX92HwZzd4qRCDSrbMCO31raebAZ/c4jvk=@vger.kernel.org X-Gm-Message-State: AFuF++l4Yxrw9Uc+MiqaUeljyPMgoOu5E/l5l63s1RvSv5Ltc4kNyMSF iB4DUo1V5wkDVHNLcRLDcuvGhovkFFvgLkJL7qJS0fgOX0Y2u+qmgKkENQ7SDCk7RS10Mi5rqFD 8Lz7OHg== X-Received: from dybrp10.prod.google.com ([2002:a05:7301:460a:b0:339:7bd3:e896]) (user=surenb job=prod-delivery.src-stubby-dispatcher) by 2002:a17:903:38cc:b0:2db:3734:cfa4 with SMTP id d9443c01a7336-2dd0e8a0ef6mr117429835ad.5.1789155713246; Fri, 11 Sep 2026 12:41:53 -0700 (PDT) Date: Fri, 11 Sep 2026 12:41:40 -0700 In-Reply-To: <20260911194145.1781926-1-surenb@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260911194145.1781926-1-surenb@google.com> X-Mailer: git-send-email 2.55.0.1007.g17ff1f9808-goog Message-ID: <20260911194145.1781926-3-surenb@google.com> Subject: [PATCH v4 2/7] proc/task_mmu: remove unnecessary inlines in function definitions From: Suren Baghdasaryan To: akpm@linux-foundation.org Cc: liam@infradead.org, ljs@kernel.org, vbabka@kernel.org, david@kernel.org, willy@infradead.org, jannh@google.com, paulmck@kernel.org, pfalcato@suse.de, xueyuan.chen21@gmail.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, surenb@google.com, Usama Arif Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" It was pointed out in the previous reviews of this code that many functions are specified as inline, which is unnecessary as the compile can make that decision by itself. Cleanup these definitions. No change in the resulting binary file size with gcc v15.2.0. No functional change intended. Signed-off-by: Suren Baghdasaryan Reviewed-by: Liam R. Howlett (Oracle) Reviewed-by: Lorenzo Stoakes (ARM) Acked-by: Usama Arif Acked-by: David Hildenbrand (Arm) --- fs/proc/task_mmu.c | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c index 2f500d639db5..cfc7af1b551d 100644 --- a/fs/proc/task_mmu.c +++ b/fs/proc/task_mmu.c @@ -130,7 +130,7 @@ static void release_task_mempolicy(struct proc_maps_pri= vate *priv) } #endif =20 -static inline int lock_ctx_mm(struct proc_maps_locking_ctx *lock_ctx) +static int lock_ctx_mm(struct proc_maps_locking_ctx *lock_ctx) { int ret =3D mmap_read_lock_killable(lock_ctx->mm); =20 @@ -140,7 +140,7 @@ static inline int lock_ctx_mm(struct proc_maps_locking_= ctx *lock_ctx) return ret; } =20 -static inline void unlock_ctx_mm(struct proc_maps_locking_ctx *lock_ctx) +static void unlock_ctx_mm(struct proc_maps_locking_ctx *lock_ctx) { mmap_read_unlock(lock_ctx->mm); lock_ctx->mmap_locked =3D false; @@ -177,8 +177,8 @@ static struct vm_area_struct *get_next_vma(struct proc_= maps_private *priv, return vma; } =20 -static inline bool fallback_to_mmap_lock(struct proc_maps_private *priv, - loff_t pos) +static bool fallback_to_mmap_lock(struct proc_maps_private *priv, + loff_t pos) { struct proc_maps_locking_ctx *lock_ctx =3D &priv->lock_ctx; =20 @@ -194,7 +194,7 @@ static inline bool fallback_to_mmap_lock(struct proc_ma= ps_private *priv, return true; } =20 -static inline void drop_rcu(struct proc_maps_private *priv) +static void drop_rcu(struct proc_maps_private *priv) { if (priv->lock_ctx.mmap_locked) return; @@ -202,7 +202,7 @@ static inline void drop_rcu(struct proc_maps_private *p= riv) rcu_read_unlock(); } =20 -static inline void reacquire_rcu(struct proc_maps_private *priv) +static void reacquire_rcu(struct proc_maps_private *priv) { if (priv->lock_ctx.mmap_locked) return; @@ -1230,7 +1230,7 @@ static const struct mm_walk_ops smaps_shmem_walk_vma_= lock_ops =3D { .walk_lock =3D PGWALK_VMA_RDLOCK_VERIFY, }; =20 -static inline const struct mm_walk_ops * +static const struct mm_walk_ops * get_smaps_walk_ops(struct proc_maps_private *priv) { if (priv->lock_ctx.mmap_locked) @@ -1238,7 +1238,7 @@ get_smaps_walk_ops(struct proc_maps_private *priv) return &smaps_walk_vma_lock_ops; } =20 -static inline const struct mm_walk_ops * +static const struct mm_walk_ops * get_smaps_shmem_walk_ops(struct proc_maps_private *priv) { if (priv->lock_ctx.mmap_locked) @@ -1572,7 +1572,7 @@ struct clear_refs_private { enum clear_refs_types type; }; =20 -static inline bool pte_is_pinned(struct vm_area_struct *vma, unsigned long= addr, pte_t pte) +static bool pte_is_pinned(struct vm_area_struct *vma, unsigned long addr, = pte_t pte) { struct folio *folio; =20 @@ -1588,8 +1588,8 @@ static inline bool pte_is_pinned(struct vm_area_struc= t *vma, unsigned long addr, return folio_maybe_dma_pinned(folio); } =20 -static inline void clear_soft_dirty(struct vm_area_struct *vma, - unsigned long addr, pte_t *pte) +static void clear_soft_dirty(struct vm_area_struct *vma, unsigned long add= r, + pte_t *pte) { if (!pgtable_supports_soft_dirty()) return; @@ -1620,7 +1620,7 @@ static inline void clear_soft_dirty(struct vm_area_st= ruct *vma, } =20 #if defined(CONFIG_TRANSPARENT_HUGEPAGE) -static inline void clear_soft_dirty_pmd(struct vm_area_struct *vma, +static void clear_soft_dirty_pmd(struct vm_area_struct *vma, unsigned long addr, pmd_t *pmdp) { pmd_t old, pmd =3D *pmdp; @@ -1646,7 +1646,7 @@ static inline void clear_soft_dirty_pmd(struct vm_are= a_struct *vma, } } #else -static inline void clear_soft_dirty_pmd(struct vm_area_struct *vma, +static void clear_soft_dirty_pmd(struct vm_area_struct *vma, unsigned long addr, pmd_t *pmdp) { } @@ -1846,7 +1846,7 @@ struct pagemapread { =20 #define PM_END_OF_BUFFER 1 =20 -static inline pagemap_entry_t make_pme(u64 frame, u64 flags) +static pagemap_entry_t make_pme(u64 frame, u64 flags) { return (pagemap_entry_t) { .pme =3D (frame & PM_PFRAME_MASK) | flags }; } @@ -3388,7 +3388,7 @@ static const struct mm_walk_ops show_numa_vma_lock_op= s =3D { .walk_lock =3D PGWALK_VMA_RDLOCK_VERIFY, }; =20 -static inline const struct mm_walk_ops * +static const struct mm_walk_ops * get_show_numa_ops(struct proc_maps_private *priv) { if (priv->lock_ctx.mmap_locked) --=20 2.55.0.1007.g17ff1f9808-goog From nobody Fri Sep 25 13:54:14 2026 Received: from mail-pg1-f198.google.com (mail-pg1-f198.google.com [209.85.215.198]) (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 33E1357269C for ; Fri, 11 Sep 2026 19:42:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.198 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789155734; cv=none; b=uYjxcXAoGPrHVQ6eK5cP7wn53u+jESn4vPJdM8evAMcFgdgzrz9qOyXl3KO6hSmMJsZBZD933eOhxeF2EgCJGxOeURmmdI0PfAa4Qui7ynkwDBwZ7nfYyBfZRXGauC5xkT7PDAVvHoRsITJau/Qs6reEVTK2gDQ8m4mfVe59i9g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789155734; c=relaxed/simple; bh=xC/1m/ZNc5aD6WbXVRq3B46Q8Q9ABXZzcNxtVqCNRYM=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=FbDVM5+P9BXAuMke662TByCaYPAvEoakXbndru2KFpmNrMXsRtErDu0qT3mpCArrhcZccL1iI/GgJ6MZ7dXUwiA6U71JnjJ8j5I9CP0MBM6RNnZbBGkZiNnF/Zs1PO9tcJh8ibJ2t4YtNd5do6p70dEKf83AOq1tcOBMdWmIvVE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--surenb.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=lUdWkD9z; arc=none smtp.client-ip=209.85.215.198 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--surenb.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="lUdWkD9z" Received: by mail-pg1-f198.google.com with SMTP id 41be03b00d2f7-cc1eb205d31so1844510a12.2 for ; Fri, 11 Sep 2026 12:41:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1789155715; x=1789760515; darn=vger.kernel.org; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:from:to:cc:subject:date:message-id:reply-to :content-type; bh=7FgSt6854K565EW8hKNAIrNpKO8xQPyDCjbWGmWWQzU=; b=lUdWkD9zD1CLXJmIp/rKKVNq9jD2Oh2GRnSOKy96DciTzX7LLO/Hz2EibEOUL+s1e/ Myr//Mdj7dpXKnvsz/kjzig/YClgO5RELer+dbpP3Qe0bQOzTjKMejwrfDbQb56q0n6Q ctvo5WfMqrvxHhLM7RRvaY9ONHb5YzMjk6yu/Id5ipWhnNnN3gdNCmT1ptHYZAFbDH0O nHEVV25Resjyu7i3cCWFH9z7UVAdYCrNxjIytKUy2JYqkYJ+68m7AP7nFUHQzrU+soec TdIDfjf9QsFqAMEOMoZtw3vsb4+OgHgAHdf4l2l4gGj3A6ojjcRx5YhBbv0vxitAVHlA FvUA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1789155715; x=1789760515; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=7FgSt6854K565EW8hKNAIrNpKO8xQPyDCjbWGmWWQzU=; b=LoBoftcoR/oNVEd2VQxDe+8fqWTTKVet0pDtiu50DKUpazzh8lwM36+/3yf6NwPwuy WfBs/1FSPSauu4mncQVS4eiBf+C+kC7eec+dNMGLHA79RFte6LNtWp5YaN2h0WrCrhZ4 2vIfEcQ4mOmmgtJWwBSSiQ5ghQRGSvk+H+/XI9AezvBmaLpNmWWaMlem21INhOQd7g0O g0reftNYjjMYGt54tyA9YwQnmda6pg8x1vdUbovZbp3lnXVt+p97jEVy1w9cjXHGuETk W3aH16+yK40+/Xom5ko0iC+pZwlVAkCRQ4LlelOF2bUNA+zYY/CeJwxtqUpnNupGNw16 axRg== X-Forwarded-Encrypted: i=1; AKwUvBwUoSlLWyPZqLT0RxIJGexKuafdep2g4SDX25BxA3oFqtYWaAxrYFi6mXiVW08r++dedOIpjtbG2/Em8Ss=@vger.kernel.org X-Gm-Message-State: AFuF++nHTum5zIHqlRZxINiMiUkNQ1uvm7g7hI1DprSHymzLLuEziTVP DUKC4lJSUjvmi8jj+UE4ZrAvJYIWA/LygfPC375uwqwl/fR92Kqfex4kd38ihhXujnvqGfgW80t 5NY7/Lw== X-Received: from dyaz19-n1.prod.google.com ([2002:a05:693c:6393:10b0:339:7d9d:9439]) (user=surenb job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a20:3c8f:b0:3da:b8b4:91d7 with SMTP id adf61e73a8af0-3daed100006mr10905880637.2.1789155715225; Fri, 11 Sep 2026 12:41:55 -0700 (PDT) Date: Fri, 11 Sep 2026 12:41:41 -0700 In-Reply-To: <20260911194145.1781926-1-surenb@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260911194145.1781926-1-surenb@google.com> X-Mailer: git-send-email 2.55.0.1007.g17ff1f9808-goog Message-ID: <20260911194145.1781926-4-surenb@google.com> Subject: [PATCH v4 3/7] proc/task_mmu: clarify shmem mapping walk conditions in smap_gather_stats() From: Suren Baghdasaryan To: akpm@linux-foundation.org Cc: liam@infradead.org, ljs@kernel.org, vbabka@kernel.org, david@kernel.org, willy@infradead.org, jannh@google.com, paulmck@kernel.org, pfalcato@suse.de, xueyuan.chen21@gmail.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, surenb@google.com Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" smap_gather_stats() optimizes stats gathering by skipping the walk for shmem mappings in certain conditions. Update the comment to clarify these conditions and use vma_is_cow_mapping() for CoW identification instead of open-coding it. No functional change intended. Suggested by: David Hildenbrand (Arm) Signed-off-by: Suren Baghdasaryan Acked-by: David Hildenbrand (Arm) Reviewed-by: Lorenzo Stoakes (ARM) --- fs/proc/task_mmu.c | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c index cfc7af1b551d..0e53eb065a3e 100644 --- a/fs/proc/task_mmu.c +++ b/fs/proc/task_mmu.c @@ -1270,23 +1270,18 @@ static void smap_gather_stats(struct proc_maps_priv= ate *priv, =20 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. + * CoW mappings might map anon folios that do not belong to + * shmem. Perform a less efficient page table walk in this + * situation, 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 =3D shmem_swap_usage(vma); + const unsigned long shmem_swapped =3D shmem_swap_usage(vma); + const bool is_cow =3D vma_is_cow_mapping(vma); =20 - if (!start && (!shmem_swapped || (vma->vm_flags & VM_SHARED) || - !(vma->vm_flags & VM_WRITE))) { - mss->swap +=3D shmem_swapped; - } else { + if (start || (shmem_swapped && is_cow)) ops =3D get_smaps_shmem_walk_ops(priv); - } + else + mss->swap +=3D shmem_swapped; } =20 if (!start) --=20 2.55.0.1007.g17ff1f9808-goog From nobody Fri Sep 25 13:54:14 2026 Received: from mail-pg1-f198.google.com (mail-pg1-f198.google.com [209.85.215.198]) (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 326964A8432 for ; Fri, 11 Sep 2026 19:42:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.198 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789155734; cv=none; b=rIQM70z5sA5j6oehjc6pv4jDbOa1pUjrr4wpZNugMOlT5bHC1FBfY8bUaptsoldaCRv110Dgu3WFrXJt6nh8VhxWaQqNDJqwT/EYIwik5SnYlzuT7scNQTLlZmwTxiu7JFXekpeRqRozfkCwxMJgRZjjxqc5VMZQ31T1RIqVXJQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789155734; c=relaxed/simple; bh=PJrURw2ZScHR+KM9E/4Wk02npY3TbSNhd0d/aZXjmKg=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=XI+uLrZ8E/gfNkPxV8+hh8tmKZZHAPv5sKMsJuVcAGx8dBxzTf/a/gOR26JGqtAwCSnz8cMVES4gkExU+LXHNH5h9z7nKMppeliDfFmbN2DFs+m0I+nAp+7KsnRcA6TIQNQdHtJJqAtVJoKprCTAcYjl3uUb/+NAtFSbBFVgE1s= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--surenb.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=AlQZ8PaI; arc=none smtp.client-ip=209.85.215.198 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--surenb.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="AlQZ8PaI" Received: by mail-pg1-f198.google.com with SMTP id 41be03b00d2f7-cbe77d6864dso1775071a12.2 for ; Fri, 11 Sep 2026 12:42:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1789155717; x=1789760517; darn=vger.kernel.org; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:from:to:cc:subject:date:message-id:reply-to :content-type; bh=oS2GLdH94EngI/E4RH9yM/bXq5HOqmtDA5Og7xd7+N8=; b=AlQZ8PaIA2eokAZkqSfOakzQO9hh8ftHCIoxT4DQKbogYfDB+PR/WokRbE3u9j5pkS 8aRa+htZwNK32tVcuGFh7ObERnPvYktrYRRhEColye5NJdGN1U9aY8XGgI2+mmebnZQq jSPLj8xzTF6cHQZ5IO14jjB91tmUeN2JDZ2uPgksO6zrZ4ea8dk4BBF3EXcaWhxJVPTK eUnziBl0jQGp8TnKjVEa7MJ1ZjTkPv1j2rLtBR0nf7DjdsKybV/hnEjH1w2JvLR7hvDv ZJoFYCO3uZp9AwUqUD+ldW2nVx3YMna52EiEtxoBBrs4grmf7iGr85bpOEvuFVw04AcL OUgw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1789155717; x=1789760517; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=oS2GLdH94EngI/E4RH9yM/bXq5HOqmtDA5Og7xd7+N8=; b=RHBAahbcHjCd9g9QR63ypPF85txNWfTTa/rikLlQb3AU9JKDMucMtUrUcveb9+cXak TKQCtbtfZfaBRp5y7jCLEVi9fz+7MgRhy2nsTCUvgEUeRA+sWYkDjgoCZHTNP8OaFce5 g5HiQnnP0IAahLUP44Y5+H1ekN6c9+NmjRFioy6oTcIPfF8kAN/F/9RTiPNpboP6UjrF qEFWVjTvCESChMNDTMoDVk5y98cEWgCTbYENMREQbOYvOEXqdxxm92eJHKGWDyj2kxTJ RzqoD+XICa6ih3ZktUUFBJAP3ViisDLvOgVT+aty50GylwS5wvibbOwzFhzqBT9nXQZ2 c6/A== X-Forwarded-Encrypted: i=1; AKwUvBw4APUiRVpm1H+H3kophRYefEWJQZPzm+BugqvYmrSYIZC1JbJeHWGkg1RQ4CMrsIHlLHHFgpi/SweCkh4=@vger.kernel.org X-Gm-Message-State: AFuF++mlU1w0kbmF2OQO27mumInlBLrGeAVK57scc/UBKo8pO6nEF8IO 6aloq2dS8m1Kna/QewJAluf0sXKm7Au3gb6AvzWJQzUwAYISTITMgf5guwj++MEuhH4rRzwAPgH 7xh2qPA== X-Received: from dyvn14-n2.prod.google.com ([2002:a05:693c:864e:20b0:313:fb09:e2c0]) (user=surenb job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a20:be8f:b0:3d1:7238:33d9 with SMTP id adf61e73a8af0-3daed559065mr10930453637.3.1789155717279; Fri, 11 Sep 2026 12:41:57 -0700 (PDT) Date: Fri, 11 Sep 2026 12:41:42 -0700 In-Reply-To: <20260911194145.1781926-1-surenb@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260911194145.1781926-1-surenb@google.com> X-Mailer: git-send-email 2.55.0.1007.g17ff1f9808-goog Message-ID: <20260911194145.1781926-5-surenb@google.com> Subject: [PATCH v4 4/7] proc/task_mmu: remove special-casing of smap_gather_stats() start parameter From: Suren Baghdasaryan To: akpm@linux-foundation.org Cc: liam@infradead.org, ljs@kernel.org, vbabka@kernel.org, david@kernel.org, willy@infradead.org, jannh@google.com, paulmck@kernel.org, pfalcato@suse.de, xueyuan.chen21@gmail.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, surenb@google.com Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" smap_gather_stats() interprets its start parameter to mean vma->vm_start when it's set to 0. Eliminate this special interpretation and provide two separate functions for a partial and complete VMA walk. Since smap_gather_stats() operates within a single VMA, we can replace walk_page_vma()/walk_page_range() calls with walk_page_range_vma() which is simpler and also can be called while holding per-VMA lock. No functional change intended. Suggested by: Lorenzo Stoakes Signed-off-by: Suren Baghdasaryan Acked-by: David Hildenbrand (Arm) Reviewed-by: Lorenzo Stoakes (ARM) --- fs/proc/task_mmu.c | 52 +++++++++++++++++++++++++++++++--------------- 1 file changed, 35 insertions(+), 17 deletions(-) diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c index 0e53eb065a3e..a6026ffd07f1 100644 --- a/fs/proc/task_mmu.c +++ b/fs/proc/task_mmu.c @@ -1246,20 +1246,26 @@ get_smaps_shmem_walk_ops(struct proc_maps_private *= priv) return &smaps_shmem_walk_vma_lock_ops; } =20 -/* - * Gather mem stats from @vma with the indicated beginning - * address @start, and keep them in @mss. +/** + * smap_gather_stats_range() - Gather mem stats from a portion of the @vma. + * @priv: proc maps private state. + * @vma: The VMA to gather stats for. + * @mss: The accumulated stats. + * @start: The address from which to start. * - * Use vm_start of @vma as the beginning address if @start is 0. + * This gathers stats for the portion of the VMA starting at the @start + * address. */ -static void smap_gather_stats(struct proc_maps_private *priv, - struct vm_area_struct *vma, - struct mem_size_stats *mss, unsigned long start) +static void smap_gather_stats_range(struct proc_maps_private *priv, + struct vm_area_struct *vma, + struct mem_size_stats *mss, + unsigned long start) { const struct mm_walk_ops *ops =3D get_smaps_walk_ops(priv); + const bool is_partial =3D start > vma->vm_start; =20 /* Invalid start */ - if (start >=3D vma->vm_end) + if (start < vma->vm_start || start >=3D vma->vm_end) return; =20 if (vma =3D=3D get_gate_vma(priv->lock_ctx.mm)) @@ -1278,20 +1284,31 @@ static void smap_gather_stats(struct proc_maps_priv= ate *priv, const unsigned long shmem_swapped =3D shmem_swap_usage(vma); const bool is_cow =3D vma_is_cow_mapping(vma); =20 - if (start || (shmem_swapped && is_cow)) + if (is_partial || (shmem_swapped && is_cow)) ops =3D get_smaps_shmem_walk_ops(priv); else mss->swap +=3D shmem_swapped; } =20 - if (!start) - walk_page_vma(vma, ops, mss); - else - walk_page_range(vma->vm_mm, start, vma->vm_end, ops, mss); + walk_page_range_vma(vma, start, vma->vm_end, ops, mss); =20 reacquire_rcu(priv); } =20 +/** + * smap_gather_stats() - Gather mem stats from the entire @vma. + * @priv: proc maps private state. + * @vma: The VMA to gather stats for. + * @mss: The accumulated stats. + * + * This gathers stats for the whole of the VMA. + */ +static void smap_gather_stats(struct proc_maps_private *priv, + struct vm_area_struct *vma, struct mem_size_stats *mss) +{ + smap_gather_stats_range(priv, vma, mss, vma->vm_start); +} + #define SEQ_PUT_DEC(str, val) \ seq_put_decimal_ull_width(m, str, (val) >> 10, 8) =20 @@ -1342,7 +1359,7 @@ static int show_smap(struct seq_file *m, void *v) struct vm_area_struct *vma =3D v; struct mem_size_stats mss =3D {}; =20 - smap_gather_stats(priv, vma, &mss, 0); + smap_gather_stats(priv, vma, &mss); =20 show_map_vma(m, vma); =20 @@ -1395,7 +1412,7 @@ static int show_smaps_rollup(struct seq_file *m, void= *v) =20 vma_start =3D vma->vm_start; do { - smap_gather_stats(priv, vma, &mss, 0); + smap_gather_stats(priv, vma, &mss); last_vma_end =3D vma->vm_end; =20 /* @@ -1454,14 +1471,15 @@ static int show_smaps_rollup(struct seq_file *m, vo= id *v) =20 /* Case 1 and 2 above */ if (vma->vm_start >=3D last_vma_end) { - smap_gather_stats(priv, vma, &mss, 0); + smap_gather_stats(priv, vma, &mss); last_vma_end =3D vma->vm_end; continue; } =20 /* Case 4 above */ if (vma->vm_end > last_vma_end) { - smap_gather_stats(priv, vma, &mss, last_vma_end); + smap_gather_stats_range(priv, vma, &mss, + last_vma_end); last_vma_end =3D vma->vm_end; } } --=20 2.55.0.1007.g17ff1f9808-goog From nobody Fri Sep 25 13:54:14 2026 Received: from mail-pj1-f71.google.com (mail-pj1-f71.google.com [209.85.216.71]) (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 BAEEF563FB5 for ; Fri, 11 Sep 2026 19:42:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.71 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789155737; cv=none; b=KFJpr2EVl+V3xKHQtEou4DCf/KWxtkooQ84xrYhGRimxGCx5jZNcTrtoKDaAKkrBd9slYre0lKkWHBRyQIWaBWwP4JiqnzuWwtYMOwQAB5SnaD8r9VODlPRLli2alsX8w8OI/n31VFqT6+CsiaJWmvm5fN3mMskSxrBNf8a2EQQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789155737; c=relaxed/simple; bh=iwNq5uu3Zcz820eD4nEDR07scSxQngOrG28BzpUpX0I=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=KTub4DwXYWxaAnQOlBChuQXLLeEXQN4IHLNb4zBe8VH4dnJjzTgb+SInwRITliuEC9myoXrAdNlpKGTc1O5ZkMC9asgImfHlmDTvrbxelYqYJTDi4EfnWuUXU8OxVKqoAWJ2GH9Mp1+uPgR7kLKFwfy+vxljcybDX5TgLZ/jqSM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--surenb.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=Jf4B3KNd; arc=none smtp.client-ip=209.85.216.71 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--surenb.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="Jf4B3KNd" Received: by mail-pj1-f71.google.com with SMTP id 98e67ed59e1d1-38ec0f510a9so2400883a91.2 for ; Fri, 11 Sep 2026 12:42:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1789155719; x=1789760519; darn=vger.kernel.org; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:from:to:cc:subject:date:message-id:reply-to :content-type; bh=Zej03whk2f8tlO07T6d+N4M+kS17EX2Qpuy0D1YVEz0=; b=Jf4B3KNdcYS2cJ041SfVt58lvY0wH/q3scN26lfyaeVDfEIuzE6c+Mn6ZR7Zpz1jjN CspqNzHq0NGSsmoa7znJwL+iA+qMhzmO5cGHMBvOgGELq6q1K8DOUGPSO11xfrEGeLin d9zVxr1EfINgxw+hoc7Q2qkNCVAfPApQZwZ46RV5SX0SEqEjr3jev9PBA1U6alKvXu6l 1+I50XofIBZ9Wn56ICyZBs3mWEBPEy8iOKIpGqejGvsOz4ARu+Dh0OxA4ku5jbuhRmNF 3xOkfVOOBGtRwS0PMhRsW2R+Pisxk8frgFwIO301CF+bBs6WL52w33DLoDpne9YLqubW E6tw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1789155719; x=1789760519; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=Zej03whk2f8tlO07T6d+N4M+kS17EX2Qpuy0D1YVEz0=; b=Aiv24L0weuyx4giaYzQkN+L0QfmRnAMljjxQcbIfAj01AU74csqT4V81XxF0OrCEEM F8mXqXQ1brHltvNBsW8IJzeDXAD+MHdqgfb4bVYdgLd8K78IYshmBbYPnjU7l/Y/Rd5F ULAvtw2Wl1y3n+QyFN7ZpJW7HDsXFPtXRq0X4clxggcfsp4qc9ROpWxuvupDv88jH0pe 3/OyBrMw3CsTRPrlBfXifdlQR39RWidLAMlbI4mMITOszU7ufcjsG7bUv+2NlRWo9ae/ AFSWIgHpJUoxUavfKrE3I7BqeFTN8lV5+HCfj9f4AujHSumUKQ3WpUJF1KQ8heQRX5TA KQgQ== X-Forwarded-Encrypted: i=1; AKwUvBzOcXK42UCB4PWXLT+Fh60Dwy2QBwYc15ozWp0TPCzZAzzw5TUcQYwqlFh++KMqJuRwzmpea2e6RtG9CM4=@vger.kernel.org X-Gm-Message-State: AFuF++ncZ2a+fTB4mL8A4Mlt3ybinLmP3Bw/PELBl8rbQby/OIOSdqGA ENYeF6eCbzaRscBBQZyNMji6SeriSeu9eTU4XBii3hEMIshE7ZvffQB/Q6+15C3LWGkSMcAmymq vYnPQTA== X-Received: from dlzz14.prod.google.com ([2002:a05:7022:48e:b0:143:5477:e9f]) (user=surenb job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:280e:b0:395:5eec:b932 with SMTP id 98e67ed59e1d1-39d9beb7248mr9867936a91.11.1789155719169; Fri, 11 Sep 2026 12:41:59 -0700 (PDT) Date: Fri, 11 Sep 2026 12:41:43 -0700 In-Reply-To: <20260911194145.1781926-1-surenb@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260911194145.1781926-1-surenb@google.com> X-Mailer: git-send-email 2.55.0.1007.g17ff1f9808-goog Message-ID: <20260911194145.1781926-6-surenb@google.com> Subject: [PATCH v4 5/7] proc/task_mmu: change proc_get_vma() to stop returning gate VMA at the end From: Suren Baghdasaryan To: akpm@linux-foundation.org Cc: liam@infradead.org, ljs@kernel.org, vbabka@kernel.org, david@kernel.org, willy@infradead.org, jannh@google.com, paulmck@kernel.org, pfalcato@suse.de, xueyuan.chen21@gmail.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, surenb@google.com Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" proc_get_vma() returning gate VMA at the end is desirable for the its current m_start/m_next callers, as they need to report a gate VMA at the end of the address space. This behavior is very specific to these callers and makes proc_get_vma() hard to use for other purposes. Move this usage-specific behavior into the callers themselves so that proc_get_vma() returns either a valid VMA, an error or a NULL when no more VMAs are available. This makes it more generic, simpler and usable in the later patches. Signed-off-by: Suren Baghdasaryan Reviewed-by: Lorenzo Stoakes (ARM) Acked-by: David Hildenbrand (Arm) --- fs/proc/task_mmu.c | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c index a6026ffd07f1..aef7ce659889 100644 --- a/fs/proc/task_mmu.c +++ b/fs/proc/task_mmu.c @@ -236,9 +236,6 @@ static struct vm_area_struct *proc_get_vma(struct seq_f= ile *m, loff_t *ppos) * found the extended vma with the same vm_start. */ *ppos =3D vma->vm_end; - } else { - *ppos =3D SENTINEL_VMA_GATE; - vma =3D get_gate_vma(priv->lock_ctx.mm); } =20 return vma; @@ -248,6 +245,7 @@ static void *m_start(struct seq_file *m, loff_t *ppos) { struct proc_maps_private *priv =3D m->private; struct proc_maps_locking_ctx *lock_ctx; + struct vm_area_struct *vma; loff_t last_addr =3D *ppos; struct mm_struct *mm; =20 @@ -277,19 +275,39 @@ static void *m_start(struct seq_file *m, loff_t *ppos) *ppos =3D last_addr =3D priv->last_pos; vma_iter_init(&priv->iter, mm, (unsigned long)last_addr); hold_task_mempolicy(priv); + /* + * If seq_file had to flush its collected data right after m_next() set + * position to SENTINEL_VMA_GATE, m_start() will get that sentinel and + * should return gate_vma without calling proc_get_vma(). + */ if (last_addr =3D=3D SENTINEL_VMA_GATE) return get_gate_vma(mm); =20 - return proc_get_vma(m, ppos); + vma =3D proc_get_vma(m, ppos); + if (vma) + return vma; + + /* Return gate VMA at the end */ + *ppos =3D SENTINEL_VMA_GATE; + return get_gate_vma(mm); } =20 static void *m_next(struct seq_file *m, void *v, loff_t *ppos) { + struct proc_maps_private *priv =3D m->private; + struct vm_area_struct *vma; + if (*ppos =3D=3D SENTINEL_VMA_GATE) { *ppos =3D SENTINEL_VMA_END; return NULL; } - return proc_get_vma(m, ppos); + vma =3D proc_get_vma(m, ppos); + if (vma) + return vma; + + /* Return gate VMA at the end */ + *ppos =3D SENTINEL_VMA_GATE; + return get_gate_vma(priv->lock_ctx.mm); } =20 static void m_stop(struct seq_file *m, void *v) --=20 2.55.0.1007.g17ff1f9808-goog From nobody Fri Sep 25 13:54:14 2026 Received: from mail-pj1-f71.google.com (mail-pj1-f71.google.com [209.85.216.71]) (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 7E015559CB5 for ; Fri, 11 Sep 2026 19:42:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.71 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789155777; cv=none; b=ghuJKiQzagGmgszOAe4RecGkEkz0y1BSNGCIoUIaOHGsNpVvJp9qkNZcESIVj1+nhL0Zhqi8yuKUqrJVNfzWj95WZ+PNAUlbDt/mkSCI+HJFJmt48E1PJiJ5/iK7aAIfFVuNc5kyVEgffy8ov3bFaykluOKAbzXLademdxoc/To= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789155777; c=relaxed/simple; bh=wH7jj5R4Ra5IKGbThxfzLUVFqszHkay6XVq0oM2vaXA=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=CGVGkUEhpAa0VFB6HVCuSpMgZj2ijvKLfABP9fyzJv39FcQp5jNxUFYm3zIAYVTERmEBhNbcjQmZGhHK8ioODVvCQg96nxAEkoIsJnsByGcZTgEuemg/2RSCPrcGqzRkLfi/QiKnBo+B6QYmqcs1ztP8QIJh7WqjJhif+yrEi2k= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--surenb.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=lkdvPrxb; arc=none smtp.client-ip=209.85.216.71 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--surenb.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="lkdvPrxb" Received: by mail-pj1-f71.google.com with SMTP id 98e67ed59e1d1-38ecc48b3c2so1937588a91.1 for ; Fri, 11 Sep 2026 12:42:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1789155750; x=1789760550; darn=vger.kernel.org; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:from:to:cc:subject:date:message-id:reply-to :content-type; bh=G3NQAYtt8jxExfRNC6GxDvVWEx4uiZRxod+0H4r29Lo=; b=lkdvPrxbLKnVf9+vGpwiPhnvNuETyLIFPpTJ4tfJ3mfr1ay0x5wTUZm4YoTzcIlBUg cI/arDlZf0HIBQwlE00MWwVTB8f4Qv0xBVGLGRZad1m2Jha08t1xCl0zzS//7BF/4SEO MZMmY9EB6alikHkrJ3ikoP2v/eBYrj1hEY/rRyPlQVuuPVLMUrzrZ6DXi9vdq7ws6hS4 XLgG1rfdqYFwq1r/OUSfqbNhz6xrp2oF2WSp16U+v9xsipaDxMRrGOxbyY29XUCp6f5A P+BU7UnoOx3GAVu+ccmB870u3YK32vCQ2OwiNggkR9uRYLnl3vSRXxUgwDL5nempPS7o Fb2g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1789155750; x=1789760550; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=G3NQAYtt8jxExfRNC6GxDvVWEx4uiZRxod+0H4r29Lo=; b=Adn2u5myeRnLakLO7FF4gl/ksIbwmf/BQCukyFqkKnAUGCAZ5uaeo1nYxqh/zLgPWB +d4l3is1MIIBxJ7DEWSjUlB24TOHw92D3L0QEz+KHyAWf1uXMAofebZ5PMKgdv++n3eX CjAUmSNw5nC3FH86o4o22PQzxZULT4Tj0J21nMVvduktnnXSqLODG1KEOpXaMXx+gtsc S2GozoB8cHHP+FpaBczHI0oRYrUokDKiWB4MTAI06Y3k+xx3SScY4P1rQfSaa013NoYK jydMn8wTOgoF438NNIlvSmWnezb80MjylysBbpvLu7NlBwloLcp6/ZCcins+AUEQ67yh BevA== X-Forwarded-Encrypted: i=1; AKwUvBwwK+TPdrK+Wx+hYCLX78793/ZWnW0cpjxNf1zFZRbc6s09SE7dKMWCWXLi4JvKRPmRBgz9vQLYXxA1mMk=@vger.kernel.org X-Gm-Message-State: AFuF++lmTSISwkqC6XIYYr8LW6x/xqVoJHh97uTnO4HlbZLZ+ae4YLmh dic97XocXUwROOBiUQ/dcr+Q2RHgJ8dzoioYxL+/k+YUBHhzl3QM+yfCHV6Hx5exAZyyhmnij70 pQpAZRg== X-Received: from dlbrl17.prod.google.com ([2002:a05:7022:f511:b0:13c:fe05:89a3]) (user=surenb job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:558c:b0:39b:29ca:3d23 with SMTP id 98e67ed59e1d1-39d9c345ddfmr10081715a91.17.1789155721097; Fri, 11 Sep 2026 12:42:01 -0700 (PDT) Date: Fri, 11 Sep 2026 12:41:44 -0700 In-Reply-To: <20260911194145.1781926-1-surenb@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260911194145.1781926-1-surenb@google.com> X-Mailer: git-send-email 2.55.0.1007.g17ff1f9808-goog Message-ID: <20260911194145.1781926-7-surenb@google.com> Subject: [PATCH v4 6/7] proc/task_mmu: read proc/pid/smaps_rollup under per-vma lock From: Suren Baghdasaryan To: akpm@linux-foundation.org Cc: liam@infradead.org, ljs@kernel.org, vbabka@kernel.org, david@kernel.org, willy@infradead.org, jannh@google.com, paulmck@kernel.org, pfalcato@suse.de, xueyuan.chen21@gmail.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, surenb@google.com Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" proc/pid/smaps_rollup can be read using the combination of RCU and VMA read locks, similar to proc/pid/{maps|smaps|numa_maps}. RCU is required to safely traverse the VMA tree and VMA lock stabilizes the VMA being processed and the pagetable walk. Note that we have to keep the logic to drop mmap_lock on contention because even when using per-VMA locks we might have to fall back to holding the mmap_lock. Running Paul's contention benchmark [1] shows considerable improvement both in median and in the worst case latencies: Execution command: run-proc-vs-map.sh --nsamples 20 --rawdata -- \ --busyduration 2 --procfile smaps_rollup Baseline: Median Minimum Maximum 0.174 0.161 2.553 0.174 0.164 2.663 0.174 0.165 2.664 0.174 0.166 2.679 0.174 0.167 2.691 0.174 0.168 2.704 0.174 0.169 2.729 0.174 0.172 2.741 0.174 0.174 2.745 0.174 0.174 2.755 0.174 0.175 2.790 0.174 0.177 2.809 0.174 0.179 3.096 0.174 0.183 3.144 0.174 0.184 3.158 0.174 0.185 3.175 0.174 0.185 4.568 0.174 0.198 4.821 0.174 0.214 5.143 0.174 0.251 5.220 Patched: Median Minimum Maximum 0.007 0.007 1.952 0.007 0.007 1.955 0.007 0.007 1.955 0.007 0.007 1.955 0.007 0.007 1.957 0.007 0.007 1.969 0.007 0.007 2.065 0.007 0.007 2.075 0.007 0.007 2.146 0.007 0.007 2.195 0.007 0.007 2.223 0.007 0.007 2.259 0.007 0.007 2.488 0.007 0.007 2.562 0.007 0.007 2.599 0.007 0.007 2.697 0.007 0.007 3.030 0.007 0.007 3.075 0.007 0.007 3.145 0.007 0.007 3.225 Remove now unused lock_ctx_mm() and move unlock_ctx_vma() next to unlock_ctx_mm() as they are logically related. Remove a long comment about 4 cases that we handle when dropping the mmap lock in the middle of VMA walk due to contention. The first 3 cases explained there are handled naturally and only case 4 needs to be handled in a special way, which is done in smap_gather_stats() by gathering stats from the portion of the VMA that has not yet been processed. For posterity, moving this comment here: After dropping the lock, there are four cases to consider. See the following example for explanation. +------+------+-----------+ | VMA1 | VMA2 | VMA3 | +------+------+-----------+ | | | | 4k 8k 16k 400k Suppose we drop the lock after reading VMA2 due to contention, then we get: last_vma_end =3D 16k 1) VMA2 is freed, but VMA3 exists: vma_next(vmi) will return VMA3. In this case, just continue from VMA3. 2) VMA2 still exists: vma_next(vmi) will return VMA3. In this case, just continue from VMA3. 3) No more VMAs can be found: vma_next(vmi) will return NULL. No more things to do, just break. 4) (last_vma_end - 1) is the middle of a vma (VMA'): vma_next(vmi) will return VMA' whose range contains last_vma_end. Iterate VMA' from last_vma_end. [1] https://github.com/paulmckrcu/proc-mmap_sem-test Signed-off-by: Suren Baghdasaryan Reviewed-by: Lorenzo Stoakes (ARM) --- fs/proc/task_mmu.c | 157 ++++++++++++++++++--------------------------- 1 file changed, 63 insertions(+), 94 deletions(-) diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c index aef7ce659889..24425e230895 100644 --- a/fs/proc/task_mmu.c +++ b/fs/proc/task_mmu.c @@ -130,28 +130,12 @@ static void release_task_mempolicy(struct proc_maps_p= rivate *priv) } #endif =20 -static int lock_ctx_mm(struct proc_maps_locking_ctx *lock_ctx) -{ - int ret =3D mmap_read_lock_killable(lock_ctx->mm); - - if (!ret) - lock_ctx->mmap_locked =3D true; - - return ret; -} - static void unlock_ctx_mm(struct proc_maps_locking_ctx *lock_ctx) { mmap_read_unlock(lock_ctx->mm); lock_ctx->mmap_locked =3D false; } =20 -static void reset_lock_ctx(struct proc_maps_locking_ctx *lock_ctx) -{ - lock_ctx->locked_vma =3D NULL; - lock_ctx->mmap_locked =3D false; -} - static void unlock_ctx_vma(struct proc_maps_locking_ctx *lock_ctx) { if (lock_ctx->locked_vma) { @@ -160,6 +144,12 @@ static void unlock_ctx_vma(struct proc_maps_locking_ct= x *lock_ctx) } } =20 +static void reset_lock_ctx(struct proc_maps_locking_ctx *lock_ctx) +{ + lock_ctx->locked_vma =3D NULL; + lock_ctx->mmap_locked =3D false; +} + static struct vm_area_struct *get_next_vma(struct proc_maps_private *priv, loff_t last_pos) { @@ -1402,12 +1392,14 @@ static int show_smap(struct seq_file *m, void *v) static int show_smaps_rollup(struct seq_file *m, void *v) { struct proc_maps_private *priv =3D m->private; + struct proc_maps_locking_ctx *lock_ctx =3D &priv->lock_ctx; + struct mm_struct *mm =3D lock_ctx->mm; struct mem_size_stats mss =3D {}; - struct mm_struct *mm =3D priv->lock_ctx.mm; + unsigned long last_vma_end =3D 0; + unsigned long vma_start =3D 0; struct vm_area_struct *vma; - unsigned long vma_start =3D 0, last_vma_end =3D 0; + loff_t pos =3D 0; int ret =3D 0; - VMA_ITERATOR(vmi, mm, 0); =20 priv->task =3D get_proc_task(priv->inode); if (!priv->task) @@ -1418,90 +1410,63 @@ static int show_smaps_rollup(struct seq_file *m, vo= id *v) goto out_put_task; } =20 - ret =3D lock_ctx_mm(&priv->lock_ctx); - if (ret) - goto out_put_mm; - hold_task_mempolicy(priv); - vma =3D vma_next(&vmi); + rcu_read_lock(); + reset_lock_ctx(lock_ctx); =20 + vma_iter_init(&priv->iter, mm, 0); + vma =3D proc_get_vma(m, &pos); if (unlikely(!vma)) goto empty_set; =20 - vma_start =3D vma->vm_start; - do { - smap_gather_stats(priv, vma, &mss); + if (!IS_ERR(vma)) + vma_start =3D vma->vm_start; + + while (vma) { + if (IS_ERR(vma)) { + ret =3D PTR_ERR(vma); + goto out_unlock; + } + + if (vma->vm_start < last_vma_end) { + /* + * After retaking the lock, already reported VMA grew + * or got merged with the next one and we found it + * again. Gather stats for the remaining portion by + * starting at last_vma_end. + */ + smap_gather_stats_range(priv, vma, &mss, last_vma_end); + } else { + /* Found next unreported VMA, start from its beginning */ + smap_gather_stats(priv, vma, &mss); + } last_vma_end =3D vma->vm_end; =20 /* - * Release mmap_lock temporarily if someone wants to - * access it for write request. + * If the VMA lock is not taken, we hold the often contended + * mmap lock. This can happen if we had to fall back to the + * mmap lock. + * + * To relieve pressure, check if it is indeed contended, then + * temporarily release it. */ - if (mmap_lock_is_contended(mm)) { - vma_iter_invalidate(&vmi); - unlock_ctx_mm(&priv->lock_ctx); - ret =3D lock_ctx_mm(&priv->lock_ctx); - if (ret) { - release_task_mempolicy(priv); - goto out_put_mm; - } - + if (lock_ctx->mmap_locked && + mmap_lock_is_contended(lock_ctx->mm)) { + unlock_ctx_mm(lock_ctx); /* - * After dropping the lock, there are four cases to - * consider. See the following example for explanation. - * - * +------+------+-----------+ - * | VMA1 | VMA2 | VMA3 | - * +------+------+-----------+ - * | | | | - * 4k 8k 16k 400k - * - * Suppose we drop the lock after reading VMA2 due to - * contention, then we get: - * - * last_vma_end =3D 16k - * - * 1) VMA2 is freed, but VMA3 exists: - * - * vma_next(vmi) will return VMA3. - * In this case, just continue from VMA3. - * - * 2) VMA2 still exists: - * - * vma_next(vmi) will return VMA3. - * In this case, just continue from VMA3. - * - * 3) No more VMAs can be found: - * - * vma_next(vmi) will return NULL. - * No more things to do, just break. - * - * 4) (last_vma_end - 1) is the middle of a vma (VMA'): - * - * vma_next(vmi) will return VMA' whose range - * contains last_vma_end. - * Iterate VMA' from last_vma_end. + * Even though we previously fell back to mmap lock, + * we try taking VMA lock for the next VMA, since it + * might not be under modification. In the worst case + * we will fall back to mmap lock again. */ - vma =3D vma_next(&vmi); - /* Case 3 above */ - if (!vma) - break; - - /* Case 1 and 2 above */ - if (vma->vm_start >=3D last_vma_end) { - smap_gather_stats(priv, vma, &mss); - last_vma_end =3D vma->vm_end; - continue; - } - - /* Case 4 above */ - if (vma->vm_end > last_vma_end) { - smap_gather_stats_range(priv, vma, &mss, - last_vma_end); - last_vma_end =3D vma->vm_end; - } + rcu_read_lock(); + reset_lock_ctx(lock_ctx); + /* Resume from the last position. */ + pos =3D last_vma_end; + vma_iter_init(&priv->iter, mm, pos); } - } for_each_vma(vmi, vma); + vma =3D proc_get_vma(m, &pos); + } =20 empty_set: show_vma_header_prefix(m, vma_start, last_vma_end, 0, 0, 0, 0); @@ -1510,10 +1475,14 @@ static int show_smaps_rollup(struct seq_file *m, vo= id *v) =20 __show_smap(m, &mss, true); =20 +out_unlock: + if (lock_ctx->mmap_locked) { + unlock_ctx_mm(lock_ctx); + } else { + unlock_ctx_vma(lock_ctx); + rcu_read_unlock(); + } release_task_mempolicy(priv); - unlock_ctx_mm(&priv->lock_ctx); - -out_put_mm: mmput(mm); out_put_task: put_task_struct(priv->task); --=20 2.55.0.1007.g17ff1f9808-goog From nobody Fri Sep 25 13:54:14 2026 Received: from mail-pg1-f198.google.com (mail-pg1-f198.google.com [209.85.215.198]) (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 C310F55D86A for ; Fri, 11 Sep 2026 19:42:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.198 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789155768; cv=none; b=Wh6TxFICI7Pe7blweyObe4BJM10tMsw3W13Pv0ZG3rKLblHIN5nottgMCU1u+RrJNo5ZzoqNfgtMLag8UUWAO3+KxdFBgqG5HaQsvKspjs8GKBuUM7bJ/dirXK2kX7zJDfG6ZIO8Um+TDF7guej2YyBmwcRCdN+60gujVV95uT4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789155768; c=relaxed/simple; bh=2EZtmyVe/AuhVx1mOL6EAXpHVMVAsAonFKy96SvaHE4=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=YlUMCbju/yWFsLrWZ4nzxcYPK3t1xy5hQdQanxGG6nHyikmXa0Ozl0Blwo063Mn7J93qQ7EuV5fr4up1BPG4+n4QpU52WAlukcsueanJyKKC6KKFEOP4MvtJx1cnDjR1pckxCQN2ags/DFVJyOM9C/BfLE25hkdIXcEtI9j+b0w= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--surenb.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=Nr97ep4F; arc=none smtp.client-ip=209.85.215.198 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--surenb.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="Nr97ep4F" Received: by mail-pg1-f198.google.com with SMTP id 41be03b00d2f7-cc1ca15334cso1710836a12.1 for ; Fri, 11 Sep 2026 12:42:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1789155752; x=1789760552; darn=vger.kernel.org; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:from:to:cc:subject:date:message-id:reply-to :content-type; bh=7ohbs4z+CUsr70I4edsl15jnnhRHi6ax7ubJItL9lr8=; b=Nr97ep4FkMpq4exfYlI15UqtbbFG8rM0/ZF0x5VyudplTybL0MZ8C5tTM9shMa3z+B 4qBdnoEqxkFSesOkue82MLOX6iujuOvQhIGbWSodtA6mI+tQ0dqhCJrPROXq2tMyLvQQ gN6OuSJi6VtXM+Lq6iIi29W6ypY+VVS9pFTSojnUAGzIHMllP6NUqdbZw74MEMh48PU4 FhsT488NVQlFdRg8ZGg7N64OGYZAG4JdaqBy3N1v2vaj6G3/w1705XIVNvVo67UeDeaP oDhcUlJo15zH8zXIkeiT8aU77gYncdfpc48KXrYBqLR8pPpdBeRawMBy0w14Vuxm0anG mRFg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1789155752; x=1789760552; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=7ohbs4z+CUsr70I4edsl15jnnhRHi6ax7ubJItL9lr8=; b=duxauKmJL84txWb3g4YoQ8jw6lRrsFJjCOERqSorfy6msa3aQACjJyp7my+PZ54ZVk nTLfQO5gSTPChoN+vt9+LHoluqa8GxR1h74oZTCPE0FeDFdrWqOqUPPbsh8oaW/q5HYy dF+6Qh/pjZlE3dW+6ekBSuQ+N1tF91AQx+wkprlmN6OoBAUX3TAJMv0aHZQcLpShuAlX Bmz9uQ/FSnIf/VE15IBbL5J0WIw2KX0I4XDR7GXdW0a83b9afpKao0qG8W+fucydbb44 ineH8Jqt+BjLAuO2dJKu6vYXxqUEoPkSfFnoJYYXJwBqqQoleNSdIi0GJBO3xa8Yqysx e4yA== X-Forwarded-Encrypted: i=1; AKwUvBxGmEJhx8rpZUeJ1+wIwBWmQ8VcYZOs6nC+oXN+7iWctt691kDtJjY0XjJD7jMWWBpIMxgvOkpiCCt6PhI=@vger.kernel.org X-Gm-Message-State: AFuF++mCx572zSjbTreuOG2WASMhD3ZS2qOoa9Koj7FakvjnizING8bB UlO+yJ7Ewz1O035ZH/WsK7kWtGwFQFer0V7/gG0pNwYYfvkWY9/lJwaagDpeW0t0+7fQ/bqCArs ZdNB0lQ== X-Received: from dybdn25.prod.google.com ([2002:a05:7300:bc99:b0:31c:55a5:e131]) (user=surenb job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a20:72aa:b0:3da:bea4:6215 with SMTP id adf61e73a8af0-3daed38c5f8mr10656354637.19.1789155751652; Fri, 11 Sep 2026 12:42:31 -0700 (PDT) Date: Fri, 11 Sep 2026 12:41:45 -0700 In-Reply-To: <20260911194145.1781926-1-surenb@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260911194145.1781926-1-surenb@google.com> X-Mailer: git-send-email 2.55.0.1007.g17ff1f9808-goog Message-ID: <20260911194145.1781926-8-surenb@google.com> Subject: [PATCH v4 7/7] selftests/proc: add /proc/pid/smaps_rollup tearing tests From: Suren Baghdasaryan To: akpm@linux-foundation.org Cc: liam@infradead.org, ljs@kernel.org, vbabka@kernel.org, david@kernel.org, willy@infradead.org, jannh@google.com, paulmck@kernel.org, pfalcato@suse.de, xueyuan.chen21@gmail.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, surenb@google.com Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" During tearing tests, smaps_rollup Pss* metrics should stay constant. Extend /proc/pid/smaps tearing tests to also check for smaps_rollup consistency. Signed-off-by: Suren Baghdasaryan Acked-by: Lorenzo Stoakes (ARM) --- tools/testing/selftests/proc/proc-maps-race.c | 186 +++++++++++++++++- 1 file changed, 181 insertions(+), 5 deletions(-) diff --git a/tools/testing/selftests/proc/proc-maps-race.c b/tools/testing/= selftests/proc/proc-maps-race.c index 415eccb70468..bf4c5073f6fc 100644 --- a/tools/testing/selftests/proc/proc-maps-race.c +++ b/tools/testing/selftests/proc/proc-maps-race.c @@ -80,6 +80,61 @@ enum maps_file { =20 struct vma_modifier_info; =20 +enum smaps_rollup_stat { + Rss, + Pss, + Pss_Dirty, + Pss_Anon, + Pss_File, + Pss_Shmem, + Shared_Clean, + Shared_Dirty, + Private_Clean, + Private_Dirty, + Referenced, + Anonymous, + KSM, + LazyFree, + AnonHugePages, + ShmemPmdMapped, + FilePmdMapped, + Shared_Hugetlb, + Private_Hugetlb, + Swap, + SwapPss, + Locked, + RollupFieldCount +}; + +static const char *smaps_rollup_stat_names[RollupFieldCount] =3D { + "Rss", + "Pss", + "Pss_Dirty", + "Pss_Anon", + "Pss_File", + "Pss_Shmem", + "Shared_Clean", + "Shared_Dirty", + "Private_Clean", + "Private_Dirty", + "Referenced", + "Anonymous", + "KSM", + "LazyFree", + "AnonHugePages", + "ShmemPmdMapped", + "FilePmdMapped", + "Shared_Hugetlb", + "Private_Hugetlb", + "Swap", + "SwapPss", + "Locked", +}; + +struct smaps_rollup_stats { + unsigned long values[RollupFieldCount]; +}; + FIXTURE(proc_maps_race) { struct vma_modifier_info *mod_info; @@ -91,6 +146,7 @@ FIXTURE(proc_maps_race) enum maps_file maps_file; int shared_mem_size; int skip_pages; + int rollup_fd; int page_size; int vma_count; bool verbose; @@ -132,12 +188,12 @@ struct vma_modifier_info { void *child_mapped_addr[]; }; =20 -static bool read_page(FIXTURE_DATA(proc_maps_race) *self, +static bool read_page(FIXTURE_DATA(proc_maps_race) *self, int fd, struct page_content *page) { ssize_t bytes_read; =20 - bytes_read =3D read(self->maps_fd, page->data, self->page_size); + bytes_read =3D read(fd, page->data, self->page_size); if (bytes_read <=3D 0) return false; =20 @@ -175,7 +231,7 @@ static int locate_containing_page(FIXTURE_DATA(proc_map= s_race) *self, char *curr_pos; char *end_pos; =20 - if (!read_page(self, &self->page1)) + if (!read_page(self, self->maps_fd, &self->page1)) return -1; =20 curr_pos =3D self->page1.data; @@ -205,10 +261,11 @@ static bool read_two_pages(FIXTURE_DATA(proc_maps_rac= e) *self) return false; =20 for (int i =3D 0; i < self->skip_pages; i++) - if (!read_page(self, &self->page1)) + if (!read_page(self, self->maps_fd, &self->page1)) return false; =20 - return read_page(self, &self->page1) && read_page(self, &self->page2); + return read_page(self, self->maps_fd, &self->page1) && + read_page(self, self->maps_fd, &self->page2); } =20 static void copy_line(const char *line_start, const char *line_end, @@ -317,6 +374,61 @@ static bool read_boundary_lines(FIXTURE_DATA(proc_maps= _race) *self, &first_line->end_addr) =3D=3D 2; } =20 +static bool parse_smaps_rollup(FIXTURE_DATA(proc_maps_race) *self, + struct smaps_rollup_stats *stats) +{ + unsigned int dev_maj, dev_min, inode; + unsigned long start, end, offs; + unsigned long value; + char name[32], perm[5]; + char *curr_pos; + char *end_pos; + char *line_end; + + if (lseek(self->rollup_fd, 0, SEEK_SET) < 0) + return false; + + if (!read_page(self, self->rollup_fd, &self->page1)) + return false; + + curr_pos =3D self->page1.data; + end_pos =3D self->page1.data + self->page1.size; + + line_end =3D strchr(curr_pos, '\n'); + if (!line_end) + return false; + + if (sscanf(curr_pos, "%lx-%lx %4s %lx %u:%u %u %31s", + &start, &end, perm, &offs, &dev_maj, &dev_min, &inode, name) !=3D 8) + return false; + + if (strcmp(name, "[rollup]")) + return false; + + for (int stat =3D 0; stat < ARRAY_SIZE(smaps_rollup_stat_names); stat++) { + int len; + + curr_pos =3D line_end + 1; + if (curr_pos >=3D end_pos) + return false; + + line_end =3D strchr(curr_pos, '\n'); + if (!line_end) + return false; + + if (sscanf(curr_pos, "%31s %lu kB", name, &value) !=3D 2) + return false; + + len =3D strlen(name); + if (name[len - 1] !=3D ':' || strncmp(name, smaps_rollup_stat_names[stat= ], len - 1)) + return false; + + stats->values[stat] =3D value; + } + + return true; +} + /* Thread synchronization routines */ static void wait_for_state(struct vma_modifier_info *mod_info, enum test_s= tate state) { @@ -397,6 +509,40 @@ static bool print_boundaries_on(bool condition, const = char *title, return condition; } =20 +static void print_smaps_rollup_stats(const char *title, FIXTURE_DATA(proc_= maps_race) *self, + struct smaps_rollup_stats *stats) +{ + printf("%s", title); + for (int stat =3D 0; stat < ARRAY_SIZE(smaps_rollup_stat_names); stat++) + printf("%64s %lu kB\n", smaps_rollup_stat_names[stat], stats->values[sta= t]); +} + +static bool cmp_smaps_rollup_stat(struct smaps_rollup_stats *s1, + struct smaps_rollup_stats *s2, enum smaps_rollup_stat stat) +{ + return s1->values[stat] =3D=3D s2->values[stat]; +} + +static bool compare_smaps_rollup(FIXTURE_DATA(proc_maps_race) *self, + struct smaps_rollup_stats *expected, + struct smaps_rollup_stats *actual) +{ + /* + * Clean/dirty metrics might change but Pss-related ones + * should stay constant. + */ + if (cmp_smaps_rollup_stat(expected, actual, Pss) && + cmp_smaps_rollup_stat(expected, actual, Pss_Anon) && + cmp_smaps_rollup_stat(expected, actual, Pss_File) && + cmp_smaps_rollup_stat(expected, actual, Pss_Shmem)) + return true; + + print_smaps_rollup_stats("Expected stats:", self, expected); + print_smaps_rollup_stats("Actual stats:", self, actual); + + return false; +} + static void report_test_start(const char *name, bool verbose) { if (verbose) @@ -572,6 +718,7 @@ FIXTURE_SETUP(proc_maps_race) unsigned long first_map_addr; unsigned long last_map_addr; unsigned long duration_sec; + char rollup_fname[32]; char fname[32]; =20 self->page_size =3D (unsigned long)sysconf(_SC_PAGESIZE); @@ -649,6 +796,9 @@ FIXTURE_SETUP(proc_maps_race) break; case SMAPS: sprintf(fname, "/proc/%d/smaps", self->pid); + sprintf(rollup_fname, "/proc/%d/smaps_rollup", self->pid); + self->rollup_fd =3D open(rollup_fname, O_RDONLY); + ASSERT_NE(self->rollup_fd, -1); break; default: ksft_exit_fail(); @@ -711,6 +861,8 @@ FIXTURE_TEARDOWN(proc_maps_race) for (int i =3D 0; i < self->vma_count; i++) munmap(self->mod_info->child_mapped_addr[i], self->page_size); close(self->maps_fd); + if (self->maps_file =3D=3D SMAPS) + close(self->rollup_fd); waitpid(self->pid, &status, 0); munmap(self->mod_info, self->shared_mem_size); } @@ -723,6 +875,7 @@ TEST_F(proc_maps_race, test_maps_tearing_from_split) struct line_content split_first_line; struct line_content restored_last_line; struct line_content restored_first_line; + struct smaps_rollup_stats orig_stats; =20 wait_for_state(mod_info, SETUP_READY); =20 @@ -736,6 +889,8 @@ TEST_F(proc_maps_race, test_maps_tearing_from_split) report_test_start("Tearing from split", self->verbose); ASSERT_TRUE(capture_mod_pattern(self, &split_last_line, &split_first_line, &restored_last_line, &restored_first_line)); + if (self->maps_file =3D=3D SMAPS) + ASSERT_TRUE(parse_smaps_rollup(self, &orig_stats)); =20 /* Now start concurrent modifications for self->duration_sec */ signal_state(mod_info, TEST_READY); @@ -799,6 +954,11 @@ TEST_F(proc_maps_race, test_maps_tearing_from_split) vma_end =3D=3D self->last_line.end_addr) || (vma_start =3D=3D split_first_line.start_addr && vma_end =3D=3D split_first_line.end_addr)); + } else { + struct smaps_rollup_stats stats; + + ASSERT_TRUE(parse_smaps_rollup(self, &stats)); + ASSERT_TRUE(compare_smaps_rollup(self, &orig_stats, &stats)); } clock_gettime(CLOCK_MONOTONIC_COARSE, &end_ts); end_test_iteration(&end_ts, self->verbose); @@ -817,6 +977,7 @@ TEST_F(proc_maps_race, test_maps_tearing_from_resize) struct line_content shrunk_first_line; struct line_content restored_last_line; struct line_content restored_first_line; + struct smaps_rollup_stats orig_stats; =20 wait_for_state(mod_info, SETUP_READY); =20 @@ -830,6 +991,8 @@ TEST_F(proc_maps_race, test_maps_tearing_from_resize) report_test_start("Tearing from resize", self->verbose); ASSERT_TRUE(capture_mod_pattern(self, &shrunk_last_line, &shrunk_first_li= ne, &restored_last_line, &restored_first_line)); + if (self->maps_file =3D=3D SMAPS) + ASSERT_TRUE(parse_smaps_rollup(self, &orig_stats)); =20 /* Now start concurrent modifications for self->duration_sec */ signal_state(mod_info, TEST_READY); @@ -880,6 +1043,11 @@ TEST_F(proc_maps_race, test_maps_tearing_from_resize) ASSERT_TRUE(vma_start =3D=3D self->last_line.start_addr && (vma_end - vma_start =3D=3D self->page_size * 3 || vma_end - vma_start =3D=3D self->page_size)); + } else { + struct smaps_rollup_stats stats; + + ASSERT_TRUE(parse_smaps_rollup(self, &stats)); + ASSERT_TRUE(compare_smaps_rollup(self, &orig_stats, &stats)); } clock_gettime(CLOCK_MONOTONIC_COARSE, &end_ts); end_test_iteration(&end_ts, self->verbose); @@ -898,6 +1066,7 @@ TEST_F(proc_maps_race, test_maps_tearing_from_remap) struct line_content remapped_first_line; struct line_content restored_last_line; struct line_content restored_first_line; + struct smaps_rollup_stats orig_stats; =20 wait_for_state(mod_info, SETUP_READY); =20 @@ -911,6 +1080,8 @@ TEST_F(proc_maps_race, test_maps_tearing_from_remap) report_test_start("Tearing from remap", self->verbose); ASSERT_TRUE(capture_mod_pattern(self, &remapped_last_line, &remapped_firs= t_line, &restored_last_line, &restored_first_line)); + if (self->maps_file =3D=3D SMAPS) + ASSERT_TRUE(parse_smaps_rollup(self, &orig_stats)); =20 /* Now start concurrent modifications for self->duration_sec */ signal_state(mod_info, TEST_READY); @@ -963,6 +1134,11 @@ TEST_F(proc_maps_race, test_maps_tearing_from_remap) vma_end - vma_start =3D=3D self->page_size * 3) || (vma_start =3D=3D self->last_line.start_addr + self->page_size && vma_end - vma_start =3D=3D self->page_size)); + } else { + struct smaps_rollup_stats stats; + + ASSERT_TRUE(parse_smaps_rollup(self, &stats)); + ASSERT_TRUE(compare_smaps_rollup(self, &orig_stats, &stats)); } clock_gettime(CLOCK_MONOTONIC_COARSE, &end_ts); end_test_iteration(&end_ts, self->verbose); --=20 2.55.0.1007.g17ff1f9808-goog