From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 819F9611E for ; Wed, 4 Mar 2026 12:38:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772627911; cv=none; b=nNkTs0uUIPI+jlUJrcd1ceLUWTfPTbMDoz9VC9MLya357mklKnlPuYeOk94O4lRyG2X2SGM9K9L4O3dwfgom0+kdGu1RHOUOoABhv2GC/d13UymGzXDebw1vthlJwx8SLaO3S79QRvMkhSKdGt7SzSOFX+5pWPHWQp5uR+AOHBw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772627911; c=relaxed/simple; bh=j4dICI8IopsxSKAMiVL12nDcoFM4FwiGToHiOpfGt9s=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=atK27yJk+I8lW6GFV7hpQoHuXHspms9zUIYfg772qw0kbe9/V2CRLj7Qo27tQTWeF59XFDgike+0szZPfNSEMEQh8N8FRXINo9j7kAt/7lAGX8Yawm53Cu/CkhkXffooLkbiWUbR6CoRzL1yLJyzijVLLXdhZU5OgEqhYhGPcmU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=TCSI/Duv; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="TCSI/Duv" Received: by smtp.kernel.org (Postfix) with ESMTPSA id BA3D6C19423; Wed, 4 Mar 2026 12:38:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1772627911; bh=j4dICI8IopsxSKAMiVL12nDcoFM4FwiGToHiOpfGt9s=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=TCSI/DuvnUfvGpbtoRBBP8x/4H+2EL6WoZrurZ9E8NApYlUSfmW3x7TH7z6qsevfG h13K7NreUgrTW69D8fMHsj5lOoWfyMB6OQ/azSAbRRQNtxasO2FiotnNop8hR4k0yL 6wak+WWaKF5kHoxj+npl83Fcbjq3qOl1jnOFT6pdfRZoAZZMR/mJRdfdyUwg3iPIhE qn+odKsKpWNyKMwdOCLnmteJj2NkoEfQ5Y2dSsIso36GBwY5H62+bgIxhBZsLXhTQN jGimJub/qF1WRtavwhhmtGsHadsL7JkCcncw2RugmtVWze9lKxqij8p/J3DuvFtHso Je3BUg4C8EiVA== Message-ID: Date: Wed, 4 Mar 2026 13:38:27 +0100 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] mm/vmstat: reject zero vm.stat_interval to prevent busy-loop To: Michal Hocko , maximilianpezzullo@gmail.com Cc: Andrew Morton , David Hildenbrand , Lorenzo Stoakes , "Liam R. Howlett" , Mike Rapoport , Suren Baghdasaryan , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Terry M References: <20260304-mm-vmstat-reject-zero-vm-stat_interval-to-prevent-busy-loop-v1-1-c03c9555ff15@gmail.com> From: "Vlastimil Babka (SUSE)" Content-Language: en-US In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit On 3/4/26 10:27 AM, Michal Hocko wrote: > On Wed 04-03-26 08:27:38, Maximilian Pezzullo via B4 Relay wrote: >> From: Maximilian Pezzullo >> >> Setting vm.stat_interval to 0 causes excessive kworker CPU usage >> because vmstat_shepherd() and vmstat_update() reschedule themselves >> with round_jiffies_relative(0), which resolves to an immediate >> reschedule and creates a busy-loop. >> >> Add a custom sysctl handler that rejects 0 and restores the previous >> value, similar to how dirtytime_interval_handler() handles >> vm.dirtytime_expire_seconds. >> >> Reported-by: Terry M >> Closes: https://bugzilla.kernel.org/show_bug.cgi?id=220226 >> Signed-off-by: Maximilian Pezzullo >> --- >> mm/vmstat.c | 14 +++++++++++++- >> 1 file changed, 13 insertions(+), 1 deletion(-) >> >> diff --git a/mm/vmstat.c b/mm/vmstat.c >> index 86b14b0f77b5..6eeb4341b215 100644 >> --- a/mm/vmstat.c >> +++ b/mm/vmstat.c >> @@ -2114,6 +2114,18 @@ void vmstat_flush_workqueue(void) >> flush_workqueue(mm_percpu_wq); >> } >> >> +static int vmstat_interval_handler(const struct ctl_table *table, int write, >> + void *buffer, size_t *lenp, loff_t *ppos) >> +{ >> + int ret = proc_dointvec_jiffies(table, write, buffer, lenp, ppos); >> + >> + if (ret == 0 && write && sysctl_stat_interval == 0) { >> + sysctl_stat_interval = HZ; >> + return -EINVAL; > > So you update the value and report the failure. Nope, this is not > correct way to handle that. Either tou check the value and fail before > any side effects or you correct the value, report that to the log and > return success. > > I would preffer to not do that at all. Setting any arbitrary small value > will have some side effects. This is admin only interface and we expect > those do know what they are doing. I think it would make some sense to reject a value that leads to unrecoverable situation due to something in the kernel looping endlessly with no preemption, causing e.g. softlockups, and making it impossible to set a new sane value again. I don't know if that's the case here for value 0. If it only leads to 20-30% cpu utilization (per the bugzilla) and the admin can recover by setting a sane value again, we can indeed leave it that way. > NAK to the patch