Received: by 2002:a05:6a10:2785:0:0:0:0 with SMTP id ia5csp2333307pxb; Mon, 11 Jan 2021 07:08:20 -0800 (PST) X-Google-Smtp-Source: ABdhPJyNEaouunVMpqi/+3rauJzYLaZc8mLIw3KX2Q1aaKn2UiYRRVeDhiEg8JLUayS18aCRePPx X-Received: by 2002:a05:6402:2207:: with SMTP id cq7mr14354021edb.310.1610377700617; Mon, 11 Jan 2021 07:08:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610377700; cv=none; d=google.com; s=arc-20160816; b=eY4Y550OVuTU3+vpNfvh1uuA77xXAKtwzn1q/ljdA0s7tLxkgO2QUzD/SDSk23b6zl rS0efVXaTw6vBy0z+kymygxO7X1ryP52ggxDLWPWvs3IKV4A2/isCUEHKqCW9maRYqUN QT7KmYgSbxBfwvzUSxXwQbTjCwK+zOYlq+eK2NcMi2Ks5e9dliLquoQ4yIKTybB19mfa 84uH/ogMp/gl4XsUxgLyfQajMnzaLUxQZpoFFlBLxdB9fGyS7T+swIFdRcPBLB68e9cm bDMS/CdSNiERlN5Du2P2YDhQUar1IDK6uZhlM5Bv64cQIP28i25jsid8vVr/AxrzR6ac 8TPA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=QdrSOzf48JmiCfgqTz753bXASYsjBUI5seG7kvRylD8=; b=KGJBbYU9gYGIpnTqpuaAbENgz3TG50hi2wEW+A0kuK8wHKDW52hLrG8lQQdK4hHzvy vnHGU1JCvQFpeg5iuzAPiCfCHOezt5nnW/3U4pi9jUtFj+HVPLD3szOK5wkz1V9zPTov MybvWGjH271rzddDTY5s+8LL5Wpx0RSD348u2xDD8kxk31VBKlmXzLbemsMUTuEwbPG6 ij0X+B7vV+jzbtNIxjRVCde+bRs4VYqDbKbI+ZLMWAUZeEIpKsgGB2djCpFG0BmKXGiY lTF+D36F3pSR1nPINR+ADTd968KA8K2z1WwynWURYAnDUoDrukWfEHusb5fKhm0Zx2Pc OO9Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id m10si13152eds.453.2021.01.11.07.07.57; Mon, 11 Jan 2021 07:08:20 -0800 (PST) Received-SPF: pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732321AbhAKPGF (ORCPT + 99 others); Mon, 11 Jan 2021 10:06:05 -0500 Received: from mx2.suse.de ([195.135.220.15]:48150 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726459AbhAKPGF (ORCPT ); Mon, 11 Jan 2021 10:06:05 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 7A52CAFE2; Mon, 11 Jan 2021 15:05:23 +0000 (UTC) Received: by quack2.suse.cz (Postfix, from userid 1000) id 39E501E0807; Mon, 11 Jan 2021 16:05:23 +0100 (CET) Date: Mon, 11 Jan 2021 16:05:23 +0100 From: Jan Kara To: Eric Biggers Cc: linux-fsdevel@vger.kernel.org, linux-xfs@vger.kernel.org, linux-ext4@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net, Theodore Ts'o , Christoph Hellwig Subject: Re: [PATCH v2 09/12] fs: improve comments for writeback_single_inode() Message-ID: <20210111150523.GH18475@quack2.suse.cz> References: <20210109075903.208222-1-ebiggers@kernel.org> <20210109075903.208222-10-ebiggers@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210109075903.208222-10-ebiggers@kernel.org> User-Agent: Mutt/1.10.1 (2018-07-13) Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org On Fri 08-01-21 23:59:00, Eric Biggers wrote: > From: Eric Biggers > > Some comments for writeback_single_inode() and > __writeback_single_inode() are outdated or not very helpful, especially > with regards to writeback list handling. Update them. > > Signed-off-by: Eric Biggers Yeah, looks more comprehensible :). Thanks for the cleanup. Feel free to add: Reviewed-by: Jan Kara Honza > --- > fs/fs-writeback.c | 57 +++++++++++++++++++++++++++-------------------- > 1 file changed, 33 insertions(+), 24 deletions(-) > > diff --git a/fs/fs-writeback.c b/fs/fs-writeback.c > index cee1df6e3bd43..e91980f493884 100644 > --- a/fs/fs-writeback.c > +++ b/fs/fs-writeback.c > @@ -1442,9 +1442,15 @@ static void requeue_inode(struct inode *inode, struct bdi_writeback *wb, > } > > /* > - * Write out an inode and its dirty pages. Do not update the writeback list > - * linkage. That is left to the caller. The caller is also responsible for > - * setting I_SYNC flag and calling inode_sync_complete() to clear it. > + * Write out an inode and its dirty pages (or some of its dirty pages, depending > + * on @wbc->nr_to_write), and clear the relevant dirty flags from i_state. > + * > + * This doesn't remove the inode from the writeback list it is on, except > + * potentially to move it from b_dirty_time to b_dirty due to timestamp > + * expiration. The caller is otherwise responsible for writeback list handling. > + * > + * The caller is also responsible for setting the I_SYNC flag beforehand and > + * calling inode_sync_complete() to clear it afterwards. > */ > static int > __writeback_single_inode(struct inode *inode, struct writeback_control *wbc) > @@ -1487,9 +1493,10 @@ __writeback_single_inode(struct inode *inode, struct writeback_control *wbc) > } > > /* > - * Some filesystems may redirty the inode during the writeback > - * due to delalloc, clear dirty metadata flags right before > - * write_inode() > + * Get and clear the dirty flags from i_state. This needs to be done > + * after calling writepages because some filesystems may redirty the > + * inode during writepages due to delalloc. It also needs to be done > + * after handling timestamp expiration, as that may dirty the inode too. > */ > spin_lock(&inode->i_lock); > dirty = inode->i_state & I_DIRTY; > @@ -1524,12 +1531,13 @@ __writeback_single_inode(struct inode *inode, struct writeback_control *wbc) > } > > /* > - * Write out an inode's dirty pages. Either the caller has an active reference > - * on the inode or the inode has I_WILL_FREE set. > + * Write out an inode's dirty data and metadata on-demand, i.e. separately from > + * the regular batched writeback done by the flusher threads in > + * writeback_sb_inodes(). @wbc controls various aspects of the write, such as > + * whether it is a data-integrity sync (%WB_SYNC_ALL) or not (%WB_SYNC_NONE). > * > - * This function is designed to be called for writing back one inode which > - * we go e.g. from filesystem. Flusher thread uses __writeback_single_inode() > - * and does more profound writeback list handling in writeback_sb_inodes(). > + * To prevent the inode from going away, either the caller must have a reference > + * to the inode, or the inode must have I_WILL_FREE or I_FREEING set. > */ > static int writeback_single_inode(struct inode *inode, > struct writeback_control *wbc) > @@ -1544,23 +1552,23 @@ static int writeback_single_inode(struct inode *inode, > WARN_ON(inode->i_state & I_WILL_FREE); > > if (inode->i_state & I_SYNC) { > - if (wbc->sync_mode != WB_SYNC_ALL) > - goto out; > /* > - * It's a data-integrity sync. We must wait. Since callers hold > - * inode reference or inode has I_WILL_FREE set, it cannot go > - * away under us. > + * Writeback is already running on the inode. For WB_SYNC_NONE, > + * that's enough and we can just return. For WB_SYNC_ALL, we > + * must wait for the existing writeback to complete, then do > + * writeback again if there's anything left. > */ > + if (wbc->sync_mode != WB_SYNC_ALL) > + goto out; > __inode_wait_for_writeback(inode); > } > WARN_ON(inode->i_state & I_SYNC); > /* > - * Skip inode if it is clean and we have no outstanding writeback in > - * WB_SYNC_ALL mode. We don't want to mess with writeback lists in this > - * function since flusher thread may be doing for example sync in > - * parallel and if we move the inode, it could get skipped. So here we > - * make sure inode is on some writeback list and leave it there unless > - * we have completely cleaned the inode. > + * If the inode is already fully clean, then there's nothing to do. > + * > + * For data-integrity syncs we also need to check whether any pages are > + * still under writeback, e.g. due to prior WB_SYNC_NONE writeback. If > + * there are any such pages, we'll need to wait for them. > */ > if (!(inode->i_state & I_DIRTY_ALL) && > (wbc->sync_mode != WB_SYNC_ALL || > @@ -1576,8 +1584,9 @@ static int writeback_single_inode(struct inode *inode, > wb = inode_to_wb_and_lock_list(inode); > spin_lock(&inode->i_lock); > /* > - * If inode is clean, remove it from writeback lists. Otherwise don't > - * touch it. See comment above for explanation. > + * If the inode is now fully clean, then it can be safely removed from > + * its writeback list (if any). Otherwise the flusher threads are > + * responsible for the writeback lists. > */ > if (!(inode->i_state & I_DIRTY_ALL)) > inode_io_list_del_locked(inode, wb); > -- > 2.30.0 > -- Jan Kara SUSE Labs, CR