From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B70DA606A32D for ; Fri, 4 Dec 2026 16:49:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=aYFUoH88 Received: by kanga.kvack.org (Postfix) id 1260F6B05BF; Fri, 4 Dec 2026 11:48:32 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 0FDDB6B05C0; Fri, 4 Dec 2026 11:48:32 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F2E6A6B05C1; Fri, 4 Dec 2026 11:48:31 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id BA96F6B05BF for ; Fri, 4 Dec 2026 11:48:31 -0500 (EST) Received: from smtpin06.hostedemail.com (lb01a-stub [10.200.18.249]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 4114EC0522 for ; Fri, 4 Dec 2026 16:48:31 +0000 (UTC) X-FDA: 85506884022.06.F9B2620 Received: from tor.source.kernel.org (tor.source.kernel.org [172.105.4.254]) by imf03.hostedemail.com (Postfix) with ESMTP id A305B20014 for ; Fri, 4 Dec 2026 16:48:29 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20260515 header.b=aYFUoH88; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf03.hostedemail.com: domain of sashiko-bot@kernel.org designates 172.105.4.254 as permitted sender) smtp.mailfrom=sashiko-bot@kernel.org ARC-Seal: i=1; a=rsa-sha256; d=hostedemail.com; s=arc-20220608; cv=none; t=1796402909; b=bMjy7MEyrtwFhNPntK9BMJJ0yD649lDH27TeJYrEwIMuye5rmmUMJVfCcODFUl1SfSpOMt sLBMkiMtWXMu8w7X/23DMqLefW8a1sHYewU25fTzCfRGOd4SfSxBZ9Z8mmJ9cVjnmZl5vZ t+vR5qxHtUsF8zSbphfgMnsUzqm2gqU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1796402909; h=from:from:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=iZX0AfnT/EXN9XdXabow4AXhRITqb/kcbcRYrcK/4DU=; b=yZl2FzjN1/QcxeQ1Zc2begaF5SJ2zk7aCHDJSUIiF7wdIsyPsuaRuBWm8duOIG2q7HXSBe WP4zz5RPHmCxNHV0JmKEHOtuNEB2k62PVRgQ3QFOf4uz0RqaqZA4vEYcFOHTOu0QZXv9GC wvgHPpu9i85VGZkKdGZ6ivHzi1T4kcc= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20260515 header.b=aYFUoH88; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf03.hostedemail.com: domain of sashiko-bot@kernel.org designates 172.105.4.254 as permitted sender) smtp.mailfrom=sashiko-bot@kernel.org Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by tor.source.kernel.org (Postfix) with ESMTP id 482F461754; Fri, 4 Dec 2026 16:48:29 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 03BB01F00939; Fri, 4 Dec 2026 16:48:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796402908; bh=iZX0AfnT/EXN9XdXabow4AXhRITqb/kcbcRYrcK/4DU=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=aYFUoH880tpPDxbTar1dgaAaafk6sWXjpox4Ua1cMWyGgN5Xcd+vsrA8TSymdngnh bXOspCI/dTtdMcNkj6zXVkiLeIcXPxEsOEiUxvIQHOq6hsubn5lpbouqYhWz1abQAc o9LdPw5zcbu014VF1Wfn8zwQJy9mdMwSl+KNF7COh9yuBnVsXlwIkNhS9ZsEPXZSIh orp/C1xv5/DdRS3Sp9CFwjgJOZ2nrEEoHdYm9CMV55OVQQHSHVJJgxdfQXLUMlEDS+ Sb7lyqmd3oYskaLjDNV1O947JZ8DZwTl8tcwkYRb93MHjnumQGB5Jwq0idjDxQKxwt JVCkL90ftG96w== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v8 12/14] mm, swap: add debugfs counters for xswap Reply-To: sashiko-reviews@lists.linux.dev To: "Baoquan He" , linux-mm@kvack.org Cc: akpm@linux-foundation.org, david@kernel.org, corbet@lwn.net, chrisl@kernel.org, kasong@tencent.com, urezki@gmail.com, hannes@cmpxchg.org, yosry@kernel.org, nphamcs@gmail.com, baohua@kernel.org, youngjun.park@lge.com, kunwu.chan@gmail.com, klarasmodin@gmail.com, "Baoquan He" In-Reply-To: <20261203164336.864691-13-baoquan.he@linux.dev> References: <20261203164336.864691-1-baoquan.he@linux.dev> <20261203164336.864691-13-baoquan.he@linux.dev> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Fri, 04 Dec 2026 16:48:27 +0000 X-Rspamd-Queue-Id: A305B20014 X-Stat-Signature: 9mqgdtz6u4ouothaau4he6cquq9mwxq5 X-Rspam-User: X-Spam-Status: No, score=-11.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_PASS,SPF_PASS autolearn=ham autolearn_force=no version=4.0.1 X-Rspamd-Server: rspam08 X-HE-Tag: 1796402909-94451 X-HE-Meta: U2FsdGVkX1+AQvJ6Z3N403ChjahVLD60zC31mC878rpjdAQtq/FvWQ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ON1hjAiDDqQUz3y8TlaRhED2NOc+bF0q5sMYB0cTw+klrpvRWAWOYKvO2Ht6SF1xbzm3E6ibqzeyK7xBv5zTSWr1fQEHfstnckvc7gIdk9wpqdX1do/lC5qZY2qOwhQYQ0q4UOxPu4rparUyHtownktZW0QFghEPrPWKqIVmUh64lcBogIKS725whcLQFNWQEd0aGpHB6x/bhV+8EL537LqohBMlOcGYxbLXvEYgFTw4b9sxY/WGjTDfxl5Gc7zPkp2UgurAIHQySB5mgEC8zcVzRDa4j/Mxm+rGraCnsCZoOLce5ZVT5eNMGr5T2b1nkUmyUNc6gfVDChxvJpbT799zKvmPOy02Cd+nOgw9GHvRP5XMGr1MaiUU2qbMn2qFmZNEh0xc90QhgJv1jJqeUUqHNMHMBJKkTAjgdnHz67mE+Em1YRjTDOTvaApHFaAKCoDt83SIOXCMFS9KsPqS6aWFhThHhjHddor44/tE4LrOYRZcZTX7YGnrRzNjVhZT3q6LDajZQ/7vtDx0JTFIKgaoO/mltJQcqKYUQZKL9d5PDiyFFcjfeEVBcYaqPbJ9mPM/hB/KdnD+ZbYvmj4u6OjzYkWqWUJK3136arkJoN9mXg6Q00y6j6RzPX0J9Y3L9yD15qGw7j3SfRGkL++5+Eg+++o/69ji91GBwrkhGfB/+ukunM5QnRapxMG5LbB/wF3jlihLAZt13Cr2YypPG5cI= Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 X-Archived-By: Thank you for your contribution! Sashiko AI review found 3 potential issues to consider: - [Medium] mm: xswap_debugfs_read() corrupts output on multi-read with live stats - [Medium] mm: xswap_debugfs_read() scans under xswap_lock without cond_resched() - [Low] mm: xswap_debugfs_add() permanently caches ERR_PTR in xswap_debugfs_root -- commit 661117d24147f38fb85952116650fbeb71a65516 Author: Baoquan He mm, swap: add debugfs counters for xswap This commit exposes xswap mapped cluster counts, free tail length, usage, and grow statistics through /sys/kernel/debug/xswap/xswap.stats. > diff --git a/mm/swapfile.c b/mm/swapfile.c > index 4d6a46346b935..b2d24e1a24f08 100644 > --- a/mm/swapfile.c > +++ b/mm/swapfile.c [ ... ] > @@ -4156,6 +4161,68 @@ static unsigned long xswap_grow(struct swap_info_s= truct *si, bool force) > return nr_new; > } > =20 > +static ssize_t xswap_debugfs_read(struct file *file, char __user *buf, > + size_t count, loff_t *ppos) > +{ > + struct swap_info_struct *si =3D file->private_data; > + struct swap_cluster_info *ci; > + unsigned long mapped, tail =3D 0; > + char tmp[192]; > + int len; > + > + /* > + * Count the free clusters at the end of the mapped range. The > + * xswap_lock keeps the range from moving under the scan. > + */ > + mutex_lock(&si->xswap_lock); > + mapped =3D READ_ONCE(si->nr_clusters_mapped); > + if (si->cluster_info) { > + while (mapped - tail > 1) { > + ci =3D &si->cluster_info[mapped - tail - 1]; > + if (READ_ONCE(ci->count) || > + READ_ONCE(ci->flags) !=3D CLUSTER_FLAG_FREE) > + break; > + tail++; > + } > + } [Severity: Medium] Could this loop cause scheduling stalls on large xswap devices without a cond_resched()? Once nr_clusters_mapped has grown large and trailing clusters are freed, reading xswap.stats walks millions of vmalloc-backed swap_cluster_info entries in a tight loop. On CONFIG_PREEMPT_NONE or CONFIG_PREEMPT_VOLUNTARY kernels this causes non-preemptible stalls. Holding si->xswap_lock across the scan also blocks swap-out growth in cluster_alloc_swap_entry() -> xswap_grow() -> xswap_map_clusters(). Calling cond_resched() periodically inside the loop would avoid the scheduling stall. > + len =3D scnprintf(tmp, sizeof(tmp), > + "type %d\nclusters_max %lu\nclusters_mapped %lu\nusage_pages %lu\ntai= l_free %lu\ngrows %lu\n", > + si->type, READ_ONCE(si->nr_clusters_max), mapped, > + swap_usage_in_pages(si), tail, > + atomic_long_read(&si->xswap_grows)); > + mutex_unlock(&si->xswap_lock); > + > + return simple_read_from_buffer(buf, count, ppos, tmp, len); > +} [Severity: Medium] Can reformatting live counters on every read() corrupt output on the follow-up EOF read? Standard readers such as cat issue a second read() at *ppos =3D=3D len to check for EOF. If any counter grows in decimal width between the two calls, len increases, so simple_read_from_buffer() copies trailing bytes from tmp instead of returning 0 and appends garbled output. This also re-acquires si->xswap_lock and rescans the tail on every EOF check. Using DEFINE_SHOW_ATTRIBUTE() would snapshot the stats once per open and avoid both issues. [ ... ] > +static void xswap_debugfs_add(struct swap_info_struct *si) > +{ > + if (!xswap_debugfs_root) > + xswap_debugfs_root =3D debugfs_create_dir("xswap", NULL); > + if (IS_ERR_OR_NULL(xswap_debugfs_root)) > + return; [Severity: Low] Does this permanently cache an ERR_PTR in xswap_debugfs_root if debugfs_create_dir() fails? debugfs_create_dir() returns a non-NULL ERR_PTR on failure such as -ENOMEM. On later swapoff/swapon cycles, !xswap_debugfs_root is false and IS_ERR_OR_NULL() returns early, leaving xswap.stats unavailable until reboot. Resetting xswap_debugfs_root to NULL on error, as done for si->xswap_debugfs below, would allow subsequent xswap_create() calls to retry. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261203164336.8646= 91-1-baoquan.he@linux.dev?part=3D12