From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pf1-f181.google.com (mail-pf1-f181.google.com [209.85.210.181]) (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 1CA371A9FA4 for ; Sun, 10 May 2026 12:10:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.181 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778415038; cv=none; b=F8OPHd2TFEc9ob5UZochYLE58V6MNNtqxMimnUxFyH/76n9eVnx5RxFDnF3c2sN4hnHvd/RxpZ1QqsCzg7nJJSbGXSZ3OUvkp0AMky7lr3KALjtyq98oLEtdj64Lo+VRau/HvyYKgNhtU/K7zoFw/eY5FPPCdmK4lD29PUjdS4w= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778415038; c=relaxed/simple; bh=l4nDan9AutZWuY0Xh6vvvwpRnjhFjuZVx1S/mbvg3y4=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=dY0rMGxL/sXYDVcBOFWkYta24lHpB+8Fn9gQdHhM2vKMvInHPqNqJKUBIjLOX8lM0OjLOt/NRUuhx1VCfopGdxXiWBIPNOajnIcZR/H9/hQVJwdaHyrvkmBPt/m0IH8aqTFPUN6s54BQNQmawP0nTTwOB+Avag7hzVK2ly3UBqY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Qn3wbXll; arc=none smtp.client-ip=209.85.210.181 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Qn3wbXll" Received: by mail-pf1-f181.google.com with SMTP id d2e1a72fcca58-839dc688d6cso1370753b3a.2 for ; Sun, 10 May 2026 05:10:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1778415036; x=1779019836; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=pADTMwgHLZcS8M9nw2OxNMnlL/QBZWV74vfUPzWUFmY=; b=Qn3wbXllCvbSvfFloUMt0WwccP85hjwi4NIbgUNVsjdO/64yhD9+OqbRMAS7hFwbcm cfJL4TfGcTt5mX/9xI1nYG+i73pHL8fktV4tNTrEjs9izK4nAOtznuWFmgkjRSQ4TVU3 5+V71lZJsI92FF0X/7EFxVkhiJUIjdrHm6r9Tcn4oAlXdVJohw0U3plwV8eQZpHdNMR6 ELro57aZ+nQaPrjGYc4dBwaLqTHM8DbXOOnS06QTv+szDwDbcJ4rjMvH0nnXDiAkvhNm Q5RtOn5Laaz8834TAq6oIS2Ew6fSCIXR/4mpbvAgiFCI7+bIik/6P1FmR1HzYxnlHu8+ V20w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778415036; x=1779019836; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=pADTMwgHLZcS8M9nw2OxNMnlL/QBZWV74vfUPzWUFmY=; b=KNrHrNx7qB8zFPoqCxK4EyVBpgVcWkUiD9/OZDl2nonpT16QEvf94U+53Mc2V2v9W4 A8K18yQ7FLL+4eD2fQRQZNDl7HALo6nQlgUWHQrh583vnGMoiurrO6D60UJ7hq77QNMR hQdPRhYSRTGxwgS6OOSIJOe5By68JVDc3TJBPWE6BU7JTOkz2kAU8rx0gXPeLeRgt5Pz wFhuTpYY3yXOteovVNGmI0WKF52Jw5V0f0qtQsJO6EXJdRemjXHzlS/+0AS+A+uuuVbz cU9yXSWfLRNr845FA5VXxERoRvyY/Nul+Bo263FHwUQWPKcdzAz1shKFDHyjg3BVLELl o1Zg== X-Forwarded-Encrypted: i=1; AFNElJ+RIppbCOwbUxSIKPOQan1Mv2iCGqQaGVr1gJNxYNCkcgWtpbxHhC6jz3zkcqt1ZFjLPURxQT/9vmujuDg=@vger.kernel.org X-Gm-Message-State: AOJu0YzhRmyATdr7mocsZJZiKvp3PVPJYu0XJkTydk0Hg7dWJbGHkpPM Vi87XlEmxy4kfcgC70zZGOqIfNmu8tO9ZSW1koNJxiC8XldxUNZR3PmV X-Gm-Gg: Acq92OEsDvm/cYcHXMiWMh31LsMwBbrzU+RmF31T1i3J4ypG6qZZMAVIxpzswb+0JDk fJZWr0QICxj5Ut2tQy/2a/s0O9p2qYYuO37cfDOLdwohEv45RSGX5OKisiXVl5KlW4pYxFAXLM9 88nsplgQBGGDfjD4CGbP2X2x2s/I+D5NOZXS88D+YP9HgT3Fg5FxADbFYxvCx0GbESpQJL4wVCg K9Z8bx+Rft5j0XfCJWPis7E4CIK1BsNqq96jIgp0RMh5841x5OpNv1Z34mrxKvEoexvFoqdUuDg PAFaAPZ/Q5HWkjCQTJHsqFKJGOCaroGXIkvVl/2Z3/UB0u5fQnEfxkBoymJzeKwhen2q57wEFZm N1uNR9b77NWBhtioFcD7BkspM5bZdTfJu55M2EVj5PcizkPXbr6torA4XQQyKjpSFgybdnH36fa QMLYaSen9xUQwdQv8O4q02jl+11lNpQZWCqlRLPYjSU36d2yOq X-Received: by 2002:a05:6a00:124c:b0:834:df57:9d67 with SMTP id d2e1a72fcca58-83a5d285356mr20691784b3a.32.1778415036255; Sun, 10 May 2026 05:10:36 -0700 (PDT) Received: from [10.121.80.58] ([210.184.73.204]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-83967dbee14sm23091785b3a.48.2026.05.10.05.10.34 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 10 May 2026 05:10:35 -0700 (PDT) Message-ID: <23d6a85e-7314-4a56-ba15-fa6727446f21@gmail.com> Date: Sun, 10 May 2026 20:10:31 +0800 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 v3] f2fs: fix potential deadlock in f2fs_balance_fs() To: Chao Yu , jaegeuk@kernel.org Cc: linux-f2fs-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org References: <20260502124157.3406780-1-ruipengqi3@gmail.com> Content-Language: en-US From: Ruipeng Qi In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit On 5/3/2026 5:47 PM, Chao Yu wrote: > On 5/2/26 20:41, ruipengqi wrote: >> From: Ruipeng Qi >> >> When the f2fs filesystem space is nearly exhausted, we encounter >> deadlock >> issues as below: >> >> INFO: task A:1890 blocked for more than 120 seconds. >>        Tainted: G           O       6.12.41-g3fe07ddf05ab #1 >> "echo 0 > /proc/sys/kernel/hung_task_timeout_secs" disables this >> message. >> task:A    state:D stack:0     pid:1890  tgid:1626  ppid:1153 >> flags:0x00000204 >> Call trace: >>   __switch_to+0xf4/0x158 >>   __schedule+0x27c/0x908 >>   schedule+0x3c/0x118 >>   io_schedule+0x44/0x68 >>   folio_wait_bit_common+0x174/0x370 >>   folio_wait_bit+0x20/0x38 >>   folio_wait_writeback+0x54/0xc8 >>   truncate_inode_partial_folio+0x70/0x1e0 >>   truncate_inode_pages_range+0x1b0/0x450 >>   truncate_pagecache+0x54/0x88 >>   f2fs_file_write_iter+0x3e8/0xb80 >>   do_iter_readv_writev+0xf0/0x1e0 >>   vfs_writev+0x138/0x2c8 >>   do_writev+0x88/0x130 >>   __arm64_sys_writev+0x28/0x40 >>   invoke_syscall+0x50/0x120 >>   el0_svc_common.constprop.0+0xc8/0xf0 >>   do_el0_svc+0x24/0x38 >>   el0_svc+0x30/0xf8 >>   el0t_64_sync_handler+0x120/0x130 >>   el0t_64_sync+0x190/0x198 >> >> INFO: task kworker/u8:11:2680853 blocked for more than 120 seconds. >>        Tainted: G           O       6.12.41-g3fe07ddf05ab #1 >> "echo 0 > /proc/sys/kernel/hung_task_timeout_secs" disables this >> message. >> task:kworker/u8:11   state:D stack:0     pid:2680853 tgid:2680853 >> ppid:2      flags:0x00000208 >> Workqueue: writeback wb_workfn (flush-254:0) >> Call trace: >>   __switch_to+0xf4/0x158 >>   __schedule+0x27c/0x908 >>   schedule+0x3c/0x118 >>   io_schedule+0x44/0x68 >>   folio_wait_bit_common+0x174/0x370 >>   __filemap_get_folio+0x214/0x348 >>   pagecache_get_page+0x20/0x70 >>   f2fs_get_read_data_page+0x150/0x3e8 >>   f2fs_get_lock_data_page+0x2c/0x160 >>   move_data_page+0x50/0x478 >>   do_garbage_collect+0xd38/0x1528 >>   f2fs_gc+0x240/0x7e0 >>   f2fs_balance_fs+0x1a0/0x208 >>   f2fs_write_single_data_page+0x6e4/0x730 >>   f2fs_write_cache_pages+0x378/0x9b0 >>   f2fs_write_data_pages+0x2e4/0x388 >>   do_writepages+0x8c/0x2c8 >>   __writeback_single_inode+0x4c/0x498 >>   writeback_sb_inodes+0x234/0x4a8 >>   __writeback_inodes_wb+0x58/0x118 >>   wb_writeback+0x2f8/0x3c0 >>   wb_workfn+0x2c4/0x508 >>   process_one_work+0x180/0x408 >>   worker_thread+0x258/0x368 >>   kthread+0x118/0x128 >>   ret_from_fork+0x10/0x200 >> >> INFO: task kworker/u8:8:2641297 blocked for more than 120 seconds. >>        Tainted: G           O       6.12.41-g3fe07ddf05ab #1 >> "echo 0 > /proc/sys/kernel/hung_task_timeout_secs" disables this >> message. >> task:kworker/u8:8    state:D stack:0     pid:2641297 tgid:2641297 >> ppid:2      flags:0x00000208 >> Workqueue: writeback wb_workfn (flush-254:0) >> Call trace: >>   __switch_to+0xf4/0x158 >>   __schedule+0x27c/0x908 >>   rt_mutex_schedule+0x30/0x60 >>   __rt_mutex_slowlock_locked.constprop.0+0x460/0x8a8 >>   rwbase_write_lock+0x24c/0x378 >>   down_write+0x1c/0x30 >>   f2fs_balance_fs+0x184/0x208 >>   f2fs_write_inode+0xf4/0x328 >>   __writeback_single_inode+0x370/0x498 >>   writeback_sb_inodes+0x234/0x4a8 >>   __writeback_inodes_wb+0x58/0x118 >>   wb_writeback+0x2f8/0x3c0 >>   wb_workfn+0x2c4/0x508 >>   process_one_work+0x180/0x408 >>   worker_thread+0x258/0x368 >>   kthread+0x118/0x128 >>   ret_from_fork+0x10/0x20 >> >> INFO: task B:1902 blocked for more than 120 seconds. >>        Tainted: G           O       6.12.41-g3fe07ddf05ab #1 >> "echo 0 > /proc/sys/kernel/hung_task_timeout_secs" disables this >> message. >> task:B     state:D stack:0     pid:1902  tgid:1626  ppid:1153 >> flags:0x0000020c >> Call trace: >>   __switch_to+0xf4/0x158 >>   __schedule+0x27c/0x908 >>   rt_mutex_schedule+0x30/0x60 >>   __rt_mutex_slowlock_locked.constprop.0+0x460/0x8a8 >>   rwbase_write_lock+0x24c/0x378 >>   down_write+0x1c/0x30 >>   f2fs_balance_fs+0x184/0x208 >>   f2fs_map_blocks+0x94c/0x1110 >>   f2fs_file_write_iter+0x228/0xb80 >>   do_iter_readv_writev+0xf0/0x1e0 >>   vfs_writev+0x138/0x2c8 >>   do_writev+0x88/0x130 >>   __arm64_sys_writev+0x28/0x40 >>   invoke_syscall+0x50/0x120 >>   el0_svc_common.constprop.0+0xc8/0xf0 >>   do_el0_svc+0x24/0x38 >>   el0_svc+0x30/0xf8 >>   el0t_64_sync_handler+0x120/0x130 >>   el0t_64_sync+0x190/0x198 >> >> INFO: task sync:2769849 blocked for more than 120 seconds. >>        Tainted: G           O       6.12.41-g3fe07ddf05ab #1 >> "echo 0 > /proc/sys/kernel/hung_task_timeout_secs" disables this >> message. >> task:sync            state:D stack:0     pid:2769849 tgid:2769849 >> ppid:736    flags:0x0000020c >> Call trace: >>   __switch_to+0xf4/0x158 >>   __schedule+0x27c/0x908 >>   schedule+0x3c/0x118 >>   wb_wait_for_completion+0xb0/0xe8 >>   sync_inodes_sb+0xc8/0x2b0 >>   sync_inodes_one_sb+0x24/0x38 >>   iterate_supers+0xa8/0x138 >>   ksys_sync+0x54/0xc8 >>   __arm64_sys_sync+0x18/0x30 >>   invoke_syscall+0x50/0x120 >>   el0_svc_common.constprop.0+0xc8/0xf0 >>   do_el0_svc+0x24/0x38 >>   el0_svc+0x30/0xf8 >>   el0t_64_sync_handler+0x120/0x130 >>   el0t_64_sync+0x190/0x198 >> >> The root cause is a potential deadlock between the following tasks: >> >> kworker/u8:11                Thread A >> - f2fs_write_single_data_page >>   - f2fs_do_write_data_page >>    - folio_start_writeback(X) >>    - f2fs_outplace_write_data >>     - bio_add_folio(X) >>   - folio_unlock(X) >>                     - truncate_inode_pages_range >>                      - __filemap_get_folio(X, FGP_LOCK) >>                      - truncate_inode_partial_folio(X) >>                       - folio_wait_writeback(X) >>   - f2fs_balance_fs >>    - f2fs_gc >>     - do_garbage_collect >>      - move_data_page >>       - f2fs_get_lock_data_page >>        - __filemap_get_folio(X, FGP_LOCK) >> >> Both threads try to access folio X. Thread A holds the lock but waits >> for writeback, while kworker waits for the lock. This causes a deadlock. >> >> Other threads also enter D state, waiting for locks such as gc_lock and >> writepages. >> >> OPU/IPU DATA folio are all affected by this issue. To avoid such >> potential deadlocks, always commit these cached folios before >> triggering f2fs_gc() in f2fs_balance_fs(). >> >> v2: >> - Commit cached OPU/IPU folios, not just OPU folios as in v1. >> >> v3: >> - Fixed minor grammatical issues >> - Add comment on lockless list_empty() to explain why it is safe >>    without holding bio_list_lock >> >> Suggested-by: Chao > > Chao Yu , :) > >> Signed-off-by: Ruipeng Qi > > Reviewed-by: Chao Yu > > Thanks, Hi Jaegeuk, Chao, Gentle ping. This patch has been discussed for about a month and already got Reviewed-by from Chao. Could you please pick up this patch when you have time? Thanks, Ruipeng