Received: by 2002:a05:7412:31a9:b0:e2:908c:2ebd with SMTP id et41csp3217527rdb; Wed, 13 Sep 2023 05:57:43 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH3+8pAD2/00dwhZ9RkZuRz5D9fx+DVkmTh7ST3VqmvpkCxH+gtPmzndtjiZRMVj3UaQySE X-Received: by 2002:a05:6870:9a25:b0:1ba:cc77:1d81 with SMTP id fo37-20020a0568709a2500b001bacc771d81mr2932693oab.46.1694609863135; Wed, 13 Sep 2023 05:57:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694609863; cv=none; d=google.com; s=arc-20160816; b=Kq4BNByfwfSMcwFMfYOBFrJUAYqa5AT+R0Gc2B7flRNFImj+psujIiJ2tYfnUEWXNj DHIzzMvnEGpUcxIHpACTvrdk8O2SCDidK8xV5vR1rVWLuCcA9U06CNAptR6zlcrP9vNg M5zB5riJX2FjauGgz13v5K5SQoAqE3QM8DeJuGt/5S9SQ0Kk2lt2r+43DcrE4cPTKokc qBF5KN3zkrAoDRKcGq3K13HUCVBm8RrPOXhp03H3hLdiCZ/vDca0hm6QGuoZsUTiwNpC hqL1pHE5B/ExWba/I7Y1MqEEK0BiyyaC+KNd8/BirIYiOdq6vYNOlKvxbDcEs8ryGhCP 9NvA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=yca8PUM3QyWyw68pFhqPGUBbJpwzeWvmNmmR4ZNkwJU=; fh=HUXgsCgHbOiPVI1Wtzq4h5Ud1hFKPgYIo8GwLyGLRkU=; b=LMDrfol+c0ehIuA03ec42jrW1q+ooDlcAWF/YxeoU3uLkbel0B1slyILmfSAlo34qJ oGgpOFIZh7Xcvektv9324keL8/y+DZfp2H9WleWt8wY/+xpS8ncAclzdo+/TbionDxgT pXj2waufTEnep1Pey42lQo4pM0CNHHTJmjKVf90SnM12Rztq9m3xnQxGVA88GIDPttOp JnCRxtGfICgHy/esbd0YO/50X4VbOdHSRUU9z5Yv3kc6J7jbZTiIOUYdHazTDcbVGrND pcNRLBqsAU/Bez4qCguO3Qyh7tYdoLkMpiq0fagQeQaqG6z3Kh/hSVBVmvlsjhmpVKVs gIxg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=nZlNAPdN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from howler.vger.email (howler.vger.email. [23.128.96.34]) by mx.google.com with ESMTPS id c129-20020a633587000000b005404f8dd0easi9841933pga.292.2023.09.13.05.57.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Sep 2023 05:57:43 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) client-ip=23.128.96.34; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=nZlNAPdN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id 0CDE5833CE0E; Wed, 13 Sep 2023 01:42:33 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239034AbjIMImc (ORCPT + 99 others); Wed, 13 Sep 2023 04:42:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55742 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239018AbjIMIma (ORCPT ); Wed, 13 Sep 2023 04:42:30 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D89A1199F; Wed, 13 Sep 2023 01:42:26 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id DCC5DC433C7; Wed, 13 Sep 2023 08:42:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1694594546; bh=W+VUSozvNXeGpFMvMp4FfznnkGX7JB/VmlgBW0qQOqk=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=nZlNAPdNm06tIDx0KabaxN+MPiCm8if7HJhr/hlkFyg2hkx37e3IKEFI5qFTcp+3Q hJBy/+sJcEVU/ggVjRTovtV+aIJKzfibN21RQ2rt4XOp27OwmvKjiJ8plTndMV3pMS xXHo/ENipz8NW+ToAjj87pxJrSvqm1dJSZCr3EXHWXUobkr+v6qUf93lRpkVHasQGF OIRXwkpAp5xhQxk9f7q828uwSewVpGbZ4Aksz0WzWGnct7ISPETTR7agV/pIghPMye g6vIMeLOcbDd8+U7dHNz8UdOqRb6h4+ziuWHKU8FroSXFGgtb+/FJbd9vzuOFw1Mc4 eqVZg3nAQa1jg== Date: Wed, 13 Sep 2023 10:42:21 +0200 From: Christian Brauner To: Chunhai Guo Cc: viro@zeniv.linux.org.uk, chao@kernel.org, jaegeuk@kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Jan Kara Subject: Re: [PATCH] fs-writeback: writeback_sb_inodes: Do not increase 'total_wrote' when nothing is written Message-ID: <20230913-spionieren-goldschatz-3d15c1ce2743@brauner> References: <20230912142043.283495-1-guochunhai@vivo.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20230912142043.283495-1-guochunhai@vivo.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Wed, 13 Sep 2023 01:42:33 -0700 (PDT) [+Cc Jan] On Tue, Sep 12, 2023 at 08:20:43AM -0600, Chunhai Guo wrote: > I am encountering a deadlock issue as shown below. There is a commit > 344150999b7f ("f2fs: fix to avoid potential deadlock") can fix this issue. > However, from log analysis, it appears that this is more likely a fake > progress issue similar to commit 68f4c6eba70d ("fs-writeback: > writeback_sb_inodes: Recalculate 'wrote' according skipped pages"). In each > writeback iteration, nothing is written, while writeback_sb_inodes() > increases 'total_wrote' each time, causing an infinite loop. This patch > fixes this issue by not increasing 'total_wrote' when nothing is written. > > wb_writeback fsync (inode-Y) > blk_start_plug(&plug) > for (;;) { > iter i-1: some reqs with page-X added into plug->mq_list // f2fs node page-X with PG_writeback > filemap_fdatawrite > __filemap_fdatawrite_range // write inode-Y with sync_mode WB_SYNC_ALL > do_writepages > f2fs_write_data_pages > __f2fs_write_data_pages // wb_sync_req[DATA]++ for WB_SYNC_ALL > f2fs_write_cache_pages > f2fs_write_single_data_page > f2fs_do_write_data_page > f2fs_outplace_write_data > f2fs_update_data_blkaddr > f2fs_wait_on_page_writeback > wait_on_page_writeback // wait for f2fs node page-X > iter i: > progress = __writeback_inodes_wb(wb, work) > . writeback_sb_inodes > . __writeback_single_inode // write inode-Y with sync_mode WB_SYNC_NONE > . . do_writepages > . . f2fs_write_data_pages > . . . __f2fs_write_data_pages // skip writepages due to (wb_sync_req[DATA]>0) > . . . wbc->pages_skipped += get_dirty_pages(inode) // wbc->pages_skipped = 1 > . if (!(inode->i_state & I_DIRTY_ALL)) // i_state = I_SYNC | I_SYNC_QUEUED > . total_wrote++; // total_wrote = 1 > . requeue_inode // requeue inode-Y to wb->b_dirty queue due to non-zero pages_skipped > if (progress) // progress = 1 > continue; > iter i+1: > queue_io > // similar process with iter i, infinite for-loop ! > } > blk_finish_plug(&plug) // flush plug won't be called > > Signed-off-by: Chunhai Guo > --- > fs/fs-writeback.c | 4 +++- > 1 file changed, 3 insertions(+), 1 deletion(-) > > diff --git a/fs/fs-writeback.c b/fs/fs-writeback.c > index 969ce991b0b0..54cdee906be9 100644 > --- a/fs/fs-writeback.c > +++ b/fs/fs-writeback.c > @@ -1820,6 +1820,7 @@ static long writeback_sb_inodes(struct super_block *sb, > struct inode *inode = wb_inode(wb->b_io.prev); > struct bdi_writeback *tmp_wb; > long wrote; > + bool is_dirty_before; > > if (inode->i_sb != sb) { > if (work->sb) { > @@ -1881,6 +1882,7 @@ static long writeback_sb_inodes(struct super_block *sb, > continue; > } > inode->i_state |= I_SYNC; > + is_dirty_before = inode->i_state & I_DIRTY_ALL; > wbc_attach_and_unlock_inode(&wbc, inode); > > write_chunk = writeback_chunk_size(wb, work); > @@ -1918,7 +1920,7 @@ static long writeback_sb_inodes(struct super_block *sb, > */ > tmp_wb = inode_to_wb_and_lock_list(inode); > spin_lock(&inode->i_lock); > - if (!(inode->i_state & I_DIRTY_ALL)) > + if (!(inode->i_state & I_DIRTY_ALL) && is_dirty_before) > total_wrote++; > requeue_inode(inode, tmp_wb, &wbc); > inode_sync_complete(inode); > -- > 2.25.1 >