Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp898839rwr; Wed, 3 May 2023 07:38:32 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6HP63KnSh4MlevY5GD00mzUaeb9eXDwivk4VJ7bPn8JWEjoFIE5UVXV6WmadYR0oSKlEl0 X-Received: by 2002:a05:6a00:1d83:b0:627:fe88:a2e with SMTP id z3-20020a056a001d8300b00627fe880a2emr22257912pfw.0.1683124711817; Wed, 03 May 2023 07:38:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683124711; cv=none; d=google.com; s=arc-20160816; b=uJolreZOr6g+OaIPTe57qe+HeHsMtDNL7kQzfAGK+PhYhlVjy8dNy2w3GoAJym54e8 wEoUV8GsB08sHdpuP7AyA1fsDMcLiMjqw9Zp0n45LxYH1UtSqG6GdaTaQoqmRs9LZHH8 +0HZITfzXaGDvcF7dpSBgsQbnJHwHkeOBHtYaNUHx5FRp/ASDjNv30UIKfDj8NwR4z+d F88uOLXgsXWdu9qO1C8noOKSOVw2XFrfaKqdAtKP0sYgOvdu/XuntAvbE8yGRCUq6jNH G7Q6KBWMokvuxeYapJhP/6Wy61TL8esmkHyvAKB4soiiBpR9qtAOPmerVW6sKjuQ3R1j yzCA== 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=aWbejA8GNeDgBmTGmuQLR46IgsXBuRjQO+luuyV9faA=; b=BZmOY3L5b6mYQ6c6UWR/hHCgeKnGce/fjDKQq0EYmTL7DalbPuNVAgVeX07jzy15wQ bCXySbGBnclYmrOxUZQ/Io+UQUwRGG0WoMHfU6smPD8WoYz2hTdW0JwZysqv+qFCKwwA jZ4EB9NKXzicJm3w6jgfK7Monzg35Fc21eoMaMAkSqx1E6FDIHCt8GfWF7x0diIdfVtL 694XbwEXzflZSsu8lvPBPztO9PQawXJ36khYhsEalMamQpN2WbvJQhZW5t4KspJHW602 99V49kevK3wisOnRaapgo+ntvoD0ISXQx1AJ0r6tg2/jwSMt91JDvouaeZu8Zu3/Z0QW sVeA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=lomW53Q4; dkim=neutral (no key) header.i=@suse.cz header.s=susede2_ed25519 header.b=bONJMVUm; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id m125-20020a625883000000b006361df3aa86si24065493pfb.88.2023.05.03.07.38.19; Wed, 03 May 2023 07:38:31 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=lomW53Q4; dkim=neutral (no key) header.i=@suse.cz header.s=susede2_ed25519 header.b=bONJMVUm; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230349AbjECOcd (ORCPT + 99 others); Wed, 3 May 2023 10:32:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53556 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230323AbjECOc0 (ORCPT ); Wed, 3 May 2023 10:32:26 -0400 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3E02F6A7E; Wed, 3 May 2023 07:32:14 -0700 (PDT) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id D158D203FE; Wed, 3 May 2023 14:32:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1683124332; 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=aWbejA8GNeDgBmTGmuQLR46IgsXBuRjQO+luuyV9faA=; b=lomW53Q4MFMMrBfg3/UmKarSndasuFyqA820h4nhqMuczqgQMrpokE54KslIo8/zGrMoFn RKD2VRzdCo/SCC8EsVMCiAKEqN14F6mRXYQUppyyT0meabeaCzlAfAqN2VeEvk+Y+uusuu +04p9kwlZ2uegyMP+u/SoeSAoP9DS78= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1683124332; 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=aWbejA8GNeDgBmTGmuQLR46IgsXBuRjQO+luuyV9faA=; b=bONJMVUmO/LddXIMIzcxO9i7JGfxADf0n7IvwshI0cB4TqR1JBRtx1Fu8NNhn4TQ7d2IsQ QViIs1XkKib6YMDA== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id C423C1331F; Wed, 3 May 2023 14:32:12 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id x+XgL2xwUmSARgAAMHmgww (envelope-from ); Wed, 03 May 2023 14:32:12 +0000 Received: by quack3.suse.cz (Postfix, from userid 1000) id 579D4A0744; Wed, 3 May 2023 16:32:12 +0200 (CEST) Date: Wed, 3 May 2023 16:32:12 +0200 From: Jan Kara To: Baokun Li Cc: linux-ext4@vger.kernel.org, tytso@mit.edu, adilger.kernel@dilger.ca, jack@suse.cz, ritesh.list@gmail.com, linux-kernel@vger.kernel.org, yi.zhang@huawei.com, yangerkun@huawei.com, yukuai3@huawei.com Subject: Re: [PATCH v4 08/12] ext4: using nofail preallocation in ext4_es_insert_extent() Message-ID: <20230503143212.t7o7lme54k2f23xx@quack3> References: <20230424033846.4732-1-libaokun1@huawei.com> <20230424033846.4732-9-libaokun1@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230424033846.4732-9-libaokun1@huawei.com> X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham 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-kernel@vger.kernel.org On Mon 24-04-23 11:38:42, Baokun Li wrote: > Similar to in ext4_es_insert_delayed_block(), we use preallocations that > do not fail to avoid inconsistencies, but we do not care about es that are > not must be kept, and we return 0 even if such es memory allocation fails. > > Suggested-by: Jan Kara > Signed-off-by: Baokun Li Looks good to me. Feel free to add: Reviewed-by: Jan Kara Honza > --- > fs/ext4/extents_status.c | 38 ++++++++++++++++++++++++++------------ > 1 file changed, 26 insertions(+), 12 deletions(-) > > diff --git a/fs/ext4/extents_status.c b/fs/ext4/extents_status.c > index f892277155fa..91828cf7395b 100644 > --- a/fs/ext4/extents_status.c > +++ b/fs/ext4/extents_status.c > @@ -840,8 +840,11 @@ int ext4_es_insert_extent(struct inode *inode, ext4_lblk_t lblk, > { > struct extent_status newes; > ext4_lblk_t end = lblk + len - 1; > - int err = 0; > + int err1 = 0; > + int err2 = 0; > struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb); > + struct extent_status *es1 = NULL; > + struct extent_status *es2 = NULL; > > if (EXT4_SB(inode->i_sb)->s_mount_state & EXT4_FC_REPLAY) > return 0; > @@ -869,29 +872,40 @@ int ext4_es_insert_extent(struct inode *inode, ext4_lblk_t lblk, > > ext4_es_insert_extent_check(inode, &newes); > > +retry: > + if (err1 && !es1) > + es1 = __es_alloc_extent(true); > + if ((err1 || err2) && !es2) > + es2 = __es_alloc_extent(true); > write_lock(&EXT4_I(inode)->i_es_lock); > - err = __es_remove_extent(inode, lblk, end, NULL, NULL); > - if (err != 0) > + > + err1 = __es_remove_extent(inode, lblk, end, NULL, es1); > + if (err1 != 0) > + goto error; > + > + err2 = __es_insert_extent(inode, &newes, es2); > + if (err2 == -ENOMEM && !ext4_es_must_keep(&newes)) > + err2 = 0; > + if (err2 != 0) > goto error; > -retry: > - err = __es_insert_extent(inode, &newes, NULL); > - if (err == -ENOMEM && __es_shrink(EXT4_SB(inode->i_sb), > - 128, EXT4_I(inode))) > - goto retry; > - if (err == -ENOMEM && !ext4_es_must_keep(&newes)) > - err = 0; > > if (sbi->s_cluster_ratio > 1 && test_opt(inode->i_sb, DELALLOC) && > (status & EXTENT_STATUS_WRITTEN || > status & EXTENT_STATUS_UNWRITTEN)) > __revise_pending(inode, lblk, len); > > + /* es is pre-allocated but not used, free it. */ > + if (es1 && !es1->es_len) > + __es_free_extent(es1); > + if (es2 && !es2->es_len) > + __es_free_extent(es2); > error: > write_unlock(&EXT4_I(inode)->i_es_lock); > + if (err1 || err2) > + goto retry; > > ext4_es_print_tree(inode); > - > - return err; > + return 0; > } > > /* > -- > 2.31.1 > -- Jan Kara SUSE Labs, CR