* + shmem-clamp-negative-used-block-samples-in-statfs.patch added to mm-nonmm-unstable branch
@ 2026-11-02 5:33 Andrew Morton
0 siblings, 0 replies; only message in thread
From: Andrew Morton @ 2026-11-02 5:33 UTC (permalink / raw)
To: mm-commits, tim.c.chen, stable, hughd, david, baolin.wang,
dennylin0707, akpm
The patch titled
Subject: shmem: clamp negative used-block samples in statfs
has been added to the -mm mm-nonmm-unstable branch. Its filename is
shmem-clamp-negative-used-block-samples-in-statfs.patch
This patch will shortly appear at
https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patches/shmem-clamp-negative-used-block-samples-in-statfs.patch
This patch will later appear in the mm-nonmm-unstable branch at
git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
Before you just go and hit "reply", please:
a) Consider who else should be cc'ed
b) Prefer to cc a suitable mailing list as well
c) Ideally: find the original patch on the mailing list and do a
reply-to-all to that, adding suitable additional cc's
*** Remember to use Documentation/process/submit-checklist.rst when testing your code ***
The -mm tree is included into linux-next via various
branches at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
and is updated there most days
------------------------------------------------------
From: Hungyu Lin <dennylin0707@gmail.com>
Subject: shmem: clamp negative used-block samples in statfs
Date: Wed, 28 Oct 2026 05:18:26 +0000
percpu_counter_sum() holds the counter lock while scanning the per-CPU
values, but local updates can still proceed. Concurrent allocation and
freeing on different CPUs can therefore produce a negative sample even
though the number of used tmpfs blocks cannot be negative.
shmem_statfs() subtracts this sample from max_blocks, reporting more free
blocks than the filesystem's total. With a one-page file being written
and truncated on separate CPUs, GNU df reports negative used space, for
example 67108864 total bytes, -28672 used and 67137536 available.
Use percpu_counter_sum_positive() to clamp a negative sample to zero.
This keeps the existing best-effort accounting in statfs and does not
change allocation or limit enforcement.
Link: https://lore.kernel.org/20261028051826.23058-1-dennylin0707@gmail.com
Fixes: 7e496299d4d2 ("tmpfs: make tmpfs scalable with percpu_counter for used blocks")
Signed-off-by: Hungyu Lin <dennylin0707@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Reviewed-by: Tim Chen <tim.c.chen@linux.intel.com>
Reviewed-by: Baolin Wang <baolin.wang@linux.alibaba.com>
Cc: Hugh Dickins <hughd@google.com>
Cc: David Hildenbrand <david@kernel.org>
Cc: <stable@vger.kernel.org>
---
mm/shmem.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
--- a/mm/shmem.c~shmem-clamp-negative-used-block-samples-in-statfs
+++ a/mm/shmem.c
@@ -4018,7 +4018,7 @@ static int shmem_statfs(struct dentry *d
buf->f_blocks = sbinfo->max_blocks;
buf->f_bavail =
buf->f_bfree = sbinfo->max_blocks -
- percpu_counter_sum(&sbinfo->used_blocks);
+ percpu_counter_sum_positive(&sbinfo->used_blocks);
}
if (sbinfo->max_inodes) {
buf->f_files = sbinfo->max_inodes;
_
Patches currently in -mm which might be from dennylin0707@gmail.com are
mm-page-writeback-avoid-32-bit-overflow-in-dirty-threshold-shares.patch
mm-migrate-untag-addresses-when-querying-page-nodes.patch
fat-fix-parent-link-count-when-replacing-a-sibling-directory.patch
delayacct-preserve-delay-extrema-when-aggregating-taskstats.patch
shmem-clamp-negative-used-block-samples-in-statfs.patch
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2026-11-02 5:33 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-02 5:33 + shmem-clamp-negative-used-block-samples-in-statfs.patch added to mm-nonmm-unstable branch Andrew Morton
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox