Received: by 2002:a05:6602:2086:0:0:0:0 with SMTP id a6csp4707551ioa; Wed, 27 Apr 2022 09:22:42 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy/N/+fDmo4tpKLEBxExSfUvLexK5knUVta61CaNEBTsbPX0gHXox8Q20Sm5LEbnMKhEtOq X-Received: by 2002:a17:902:f64f:b0:156:f1cc:b284 with SMTP id m15-20020a170902f64f00b00156f1ccb284mr29171798plg.147.1651076561897; Wed, 27 Apr 2022 09:22:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651076561; cv=none; d=google.com; s=arc-20160816; b=Mx2HRAwE3hnMrnEynPBpZi7B/iQJav0Jn9bsfijNpibap1vzC9Hrml6i2VWfFvs1pz mUO8esFomFuyhbL0mZ7pWllduTaVidg5ypGhfFEakr2QmkC33oOC/59LjUZ76xE1C1lx 1mD//ndexLQGjFVeFiIgEtQK7qyXgPNjoInfMcV79DMelGhEVNfmopBZYsMfRz3okayv PEQ0Rd6vNIOfxVYyRVzWRqBbU7RSY3MMVoXA4rxAnjd2RSp5Q5NCeuMGgtgUh+NoS/f5 kmfW3sg4LRguDgYuONgsW7gEQxqFg0hNDhxrU+RH59kosjoK2Xk50pdsbgm6CX0BJfJ6 KAtg== 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 :dkim-signature; bh=heKopi47f9pKe9eE0I4ebeW27yRXRnoWXGqNjuRsuVg=; b=e3f2w9veefFbq/oKyDmKd0LiyfGRIv1KGkvqWXu6m8H+waahf7HdKwZE8RNbuHx7JM NOmQYZc1MIEt5XG/RBW0q8lXjauwYtkWlj+So4kXVT4UPxasORoWAJlCGE1qp6F9UGgf awelvREONngbHZ5zDmbtqHzEFiPvmF9yp1OIxf0KBPG9UCg38Qhp+ESr6cGygv87rQcw /jigUrThecRltSqn+wVI4tfFjn9XUwMGistwZbYTZ6hNO5Hz3z/KueQ8XkkFkzEOgR22 UWtOQIQJGzUZSdbwfqeJQjuMjYMKLKQ+Je1FzarXqordQr+FlFeFQLt27RNIQtbgKoSm 48gQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=KeViPxci; dkim=neutral (no key) header.i=@suse.cz; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id g2-20020a170902934200b0015cf4ef50ffsi2015526plp.341.2022.04.27.09.22.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Apr 2022 09:22:41 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=KeViPxci; dkim=neutral (no key) header.i=@suse.cz; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id F28855AECA; Wed, 27 Apr 2022 08:52:42 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240348AbiD0Pzo (ORCPT + 99 others); Wed, 27 Apr 2022 11:55:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34814 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240503AbiD0Pxw (ORCPT ); Wed, 27 Apr 2022 11:53:52 -0400 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0ED6B54F8F for ; Wed, 27 Apr 2022 08:50:38 -0700 (PDT) Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out1.suse.de (Postfix) with ESMTP id 8B47C210F4; Wed, 27 Apr 2022 15:50:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1651074636; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=heKopi47f9pKe9eE0I4ebeW27yRXRnoWXGqNjuRsuVg=; b=KeViPxciFa7FopQyGzZy5wDIK8fZRfChmG/B/tjqNRwciwdKIZ3ua2uycVTsaOlttsxxR6 4RaAr/L+19ietn1V3YEX02vR2McUbBNNkO5LhLtRX+jedYdfkirwzClCX3vcNyw5+fXxOH bO1TZdjfV3UeAfNVe7f2xeJeSNf+his= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1651074636; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=heKopi47f9pKe9eE0I4ebeW27yRXRnoWXGqNjuRsuVg=; b=Tp21fA591TUSpNBh5T13LNIXgI62OBW87zHv8lSNKnz7M1dmfAIs/q8T8sAd6hnkjcGdv5 mGinPZoGqnbiSbAA== Received: from quack3.suse.cz (unknown [10.100.224.230]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by relay2.suse.de (Postfix) with ESMTPS id 73CEE2C143; Wed, 27 Apr 2022 15:50:36 +0000 (UTC) Received: by quack3.suse.cz (Postfix, from userid 1000) id 86F3FA0639; Wed, 27 Apr 2022 17:50:32 +0200 (CEST) Date: Wed, 27 Apr 2022 17:50:32 +0200 From: Jan Kara To: Harshad Shirwadkar Cc: linux-ext4@vger.kernel.org, riteshh@linux.ibm.com, jack@suse.cz, tytso@mit.edu Subject: Re: [PATCH v3 2/6] ext4: for committing inode, make ext4_fc_track_inode wait Message-ID: <20220427155032.pikb3jdb62732xvi@quack3.lan> References: <20220419173143.3564144-1-harshads@google.com> <20220419173143.3564144-3-harshads@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220419173143.3564144-3-harshads@google.com> X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org On Tue 19-04-22 10:31:39, Harshad Shirwadkar wrote: > From: Harshad Shirwadkar > > If the inode that's being requested to track using ext4_fc_track_inode > is being committed, then wait until the inode finishes the > commit. Also, add calls to ext4_fc_track_inode at the right places. > > With this patch, now calling ext4_reserve_inode_write() results in > inode being tracked for next fast commit. A subtle lock ordering > requirement with i_data_sem (which is documented in the code) requires > that ext4_fc_track_inode() be called before grabbing i_data_sem. So, > this patch also adds explicit ext4_fc_track_inode() calls in places > where i_data_sem grabbed. > > Signed-off-by: Harshad Shirwadkar > --- > fs/ext4/fast_commit.c | 38 ++++++++++++++++++++++++++++++++++++++ > fs/ext4/inline.c | 3 +++ > fs/ext4/inode.c | 5 ++++- > 3 files changed, 45 insertions(+), 1 deletion(-) > > diff --git a/fs/ext4/fast_commit.c b/fs/ext4/fast_commit.c > index c278060a15bc..55f4c5ddd8e5 100644 > --- a/fs/ext4/fast_commit.c > +++ b/fs/ext4/fast_commit.c > + /* > + * If we come here, we may sleep while waiting for the inode to > + * commit. We shouldn't be holding i_data_sem in write mode when we go > + * to sleep since the commit path needs to grab the lock while > + * committing the inode. > + */ > + WARN_ON(lockdep_is_held_type(&ei->i_data_sem, 1)); Note that we can deadlock even if we had i_data_sem for reading because another reader is not allowed to get the rwsem if there is writer waiting for it. So we need to check even that case here. > + while (ext4_test_inode_state(inode, EXT4_STATE_FC_COMMITTING)) { > +#if (BITS_PER_LONG < 64) > + DEFINE_WAIT_BIT(wait, &ei->i_state_flags, > + EXT4_STATE_FC_COMMITTING); > + wq = bit_waitqueue(&ei->i_state_flags, > + EXT4_STATE_FC_COMMITTING); > +#else > + DEFINE_WAIT_BIT(wait, &ei->i_flags, > + EXT4_STATE_FC_COMMITTING); > + wq = bit_waitqueue(&ei->i_flags, > + EXT4_STATE_FC_COMMITTING); > +#endif > + prepare_to_wait(wq, &wait.wq_entry, TASK_UNINTERRUPTIBLE); > + if (ext4_test_inode_state(inode, EXT4_STATE_FC_COMMITTING)) > + schedule(); > + finish_wait(wq, &wait.wq_entry); > + } > + > ret = ext4_fc_track_template(handle, inode, __track_inode, NULL, 1); > trace_ext4_fc_track_inode(handle, inode, ret); As we discussed in the call we should tell lockdep that this is equivalent to lock+unlock of let's say fc_committing_lock and the fastcommit code setting / clearing EXT4_STATE_FC_COMMITTING is equivalent to lock / unlock of fc_committing_lock. That way we get proper lockdep tracking of this waiting primitive. Honza -- Jan Kara SUSE Labs, CR