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 282F93FD4; Mon, 23 Jun 2025 21:47:47 +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=1750715267; cv=none; b=LnUnrCDfW2HvY6IJyF6ZmQzVB3frfUewx48hcXM7CrMlP2FWq+JBkwqc/QNSJj+i5q9uHjF63/9ZLRetH6+3QDdM9D0boOAfxM6ezucdz4tRwLyZgCWWhVDNRRQLi2kM541jHQDW/+CC7z+JxGG7pVGK6IuewMEVMVpW9cyCnK4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750715267; c=relaxed/simple; bh=tsTxpbkua1dis2UO7r07S+wcJd91kJa7/huLbMiuVdM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=FcVBOIp8S2VWcZbLfPLhrm4tB22jtUK9wdk1JuTzXZCnzAZ/bn+afhRcEuQjd25nfI9r/VwcUD/fSf3t9NLF2Zy4SFcDyH6VZFO9/tWIU7D5DQsElzx0KryZnktMPEqUiZ4LYqjb+bMQ9xPbiXaFaLZTQ6Ufw1ToI9LpNEir4pc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=CaRfKzEN; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="CaRfKzEN" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B257AC4CEEA; Mon, 23 Jun 2025 21:47:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1750715267; bh=tsTxpbkua1dis2UO7r07S+wcJd91kJa7/huLbMiuVdM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CaRfKzENt5TEIKdsL3KJFI/2vu9gM0q0RuB0osjNw8i0yK/vyhCM6L/SI8UT6srDC p46WiJzg2zObpzmneUKJRTLStyENCq4m1XYzCNWrR88ATrFU7rIuxRjMpembYJ/OvW rJZkH1QwVY7J/tdCx4FD819mml7cbrBRUVf19P3Y= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Jinliang Zheng , MengEn Sun , Andrea Righi , Fenggaung Wu , "Matthew Wilcox (Oracle)" , Andrew Morton Subject: [PATCH 5.15 242/411] mm: fix ratelimit_pages update error in dirty_ratio_handler() Date: Mon, 23 Jun 2025 15:06:26 +0200 Message-ID: <20250623130639.745106004@linuxfoundation.org> X-Mailer: git-send-email 2.50.0 In-Reply-To: <20250623130632.993849527@linuxfoundation.org> References: <20250623130632.993849527@linuxfoundation.org> User-Agent: quilt/0.68 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 5.15-stable review patch. If anyone has any objections, please let me know. ------------------ From: Jinliang Zheng commit f83f362d40ccceb647f7d80eb92206733d76a36b upstream. In dirty_ratio_handler(), vm_dirty_bytes must be set to zero before calling writeback_set_ratelimit(), as global_dirty_limits() always prioritizes the value of vm_dirty_bytes. It's domain_dirty_limits() that's relevant here, not node_dirty_ok: dirty_ratio_handler writeback_set_ratelimit global_dirty_limits(&dirty_thresh) <- ratelimit_pages based on dirty_thresh domain_dirty_limits if (bytes) <- bytes = vm_dirty_bytes <--------+ thresh = f1(bytes) <- prioritizes vm_dirty_bytes | else | thresh = f2(ratio) | ratelimit_pages = f3(dirty_thresh) | vm_dirty_bytes = 0 <- it's late! ---------------------+ This causes ratelimit_pages to still use the value calculated based on vm_dirty_bytes, which is wrong now. The impact visible to userspace is difficult to capture directly because there is no procfs/sysfs interface exported to user space. However, it will have a real impact on the balance of dirty pages. For example: 1. On default, we have vm_dirty_ratio=40, vm_dirty_bytes=0 2. echo 8192 > dirty_bytes, then vm_dirty_bytes=8192, vm_dirty_ratio=0, and ratelimit_pages is calculated based on vm_dirty_bytes now. 3. echo 20 > dirty_ratio, then since vm_dirty_bytes is not reset to zero when writeback_set_ratelimit() -> global_dirty_limits() -> domain_dirty_limits() is called, reallimit_pages is still calculated based on vm_dirty_bytes instead of vm_dirty_ratio. This does not conform to the actual intent of the user. Link: https://lkml.kernel.org/r/20250415090232.7544-1-alexjlzheng@tencent.com Fixes: 9d823e8f6b1b ("writeback: per task dirty rate limit") Signed-off-by: Jinliang Zheng Reviewed-by: MengEn Sun Cc: Andrea Righi Cc: Fenggaung Wu Cc: Jinliang Zheng Cc: Matthew Wilcox (Oracle) Cc: Signed-off-by: Andrew Morton Signed-off-by: Greg Kroah-Hartman --- mm/page-writeback.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) --- a/mm/page-writeback.c +++ b/mm/page-writeback.c @@ -551,8 +551,8 @@ int dirty_ratio_handler(struct ctl_table ret = proc_dointvec_minmax(table, write, buffer, lenp, ppos); if (ret == 0 && write && vm_dirty_ratio != old_ratio) { - writeback_set_ratelimit(); vm_dirty_bytes = 0; + writeback_set_ratelimit(); } return ret; }