Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 72BA1C7EE29 for ; Thu, 8 Jun 2023 11:54:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236230AbjFHLym (ORCPT ); Thu, 8 Jun 2023 07:54:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38008 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234001AbjFHLyl (ORCPT ); Thu, 8 Jun 2023 07:54:41 -0400 Received: from smtp-out2.suse.de (smtp-out2.suse.de [IPv6:2001:67c:2178:6::1d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7CFC11FEB for ; Thu, 8 Jun 2023 04:54:39 -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 3D5D31FDCA; Thu, 8 Jun 2023 11:54:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1686225278; h=from:from:reply-to:reply-to:date:date:message-id:message-id:to:to: cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Y+KP1u9aOzuVec+xDENikBr3uf5dy9EPyk6XWGm0AIs=; b=RXXgqHv91CAx9IIh+4ciqiaa3f//V8x0N9qVEdnUDpk2WQmAWnVej5k9mswbHj2NzG+jzF JVuBNkDgZUzBp3b71EATY1thL8nvWBqBGNgRfSzWyxvMkaDKTnzLL/iH4FxyRz4c+t5wxG PCxs0W+HXkuArAZya/M+VbTtIR8xTCs= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1686225278; h=from:from:reply-to:reply-to:date:date:message-id:message-id:to:to: cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Y+KP1u9aOzuVec+xDENikBr3uf5dy9EPyk6XWGm0AIs=; b=MkiTSkolbjgaESZYN53AEudmYNLbVAHGSBvPAgYDifze8ibTuxmJE+TULVNM+w93NE2o01 ADnnt5BZel0FCWAA== 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 13CC4138E6; Thu, 8 Jun 2023 11:54:38 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id QTD5A37BgWSMMQAAMHmgww (envelope-from ); Thu, 08 Jun 2023 11:54:38 +0000 Date: Thu, 8 Jun 2023 13:48:22 +0200 From: David Sterba To: Naohiro Aota Cc: David Sterba , Filipe Manana , Naohiro Aota , "linux-btrfs@vger.kernel.org" Subject: Re: [PATCH 4/4] btrfs: reinsert BGs failed to reclaim Message-ID: <20230608114821.GA28933@twin.jikos.cz> Reply-To: dsterba@suse.cz References: <20230606162323.GJ25292@twin.jikos.cz> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: Mutt/1.5.23.1-rc1 (2014-03-12) Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org On Tue, Jun 06, 2023 at 11:55:48PM +0000, Naohiro Aota wrote: > On Tue, Jun 06, 2023 at 06:23:23PM +0200, David Sterba wrote: > > On Tue, Jun 06, 2023 at 11:25:23AM +0100, Filipe Manana wrote: > > > On Tue, Jun 6, 2023 at 7:04 AM Naohiro Aota wrote: > > > > + spin_lock(&fs_info->unused_bgs_lock); > > > > + if (list_empty(&bg->bg_list)) > > > > + list_add_tail(&bg->bg_list, &fs_info->reclaim_bgs); > > > > + else > > > > + btrfs_put_block_group(bg); > > > > + spin_unlock(&fs_info->unused_bgs_lock); > > > > + spin_unlock(&bg->lock); > > > > + } > > > > > > Also, this is very similar to btrfs_mark_bg_to_reclaim(), so we should > > > use that, and simply have: > > > > > > btrfs_mark_bg_to_reclaim(); > > > btrfs_put_block_group(bg); > > Yeah, this looks nice. Thank you. > > > > > I can fold the diff below if you agree > > > > --- a/fs/btrfs/block-group.c > > +++ b/fs/btrfs/block-group.c > > @@ -1833,18 +1833,9 @@ void btrfs_reclaim_bgs_work(struct work_struct *work) > > } > > > > next: > > - if (!ret) { > > - btrfs_put_block_group(bg); > > - } else { > > - spin_lock(&bg->lock); > > - spin_lock(&fs_info->unused_bgs_lock); > > - if (list_empty(&bg->bg_list)) > > - list_add_tail(&bg->bg_list, &fs_info->reclaim_bgs); > > - else > > - btrfs_put_block_group(bg); > > - spin_unlock(&fs_info->unused_bgs_lock); > > - spin_unlock(&bg->lock); > > - } > > + if (!ret) > > + btrfs_mark_bg_to_reclaim(bg); > > Thank you for folding this, but the condition is flipped. We should add it > back to the list in a failure case. Ah right, fixed and pushed. The whole diff becomes: if (ret) btrfs_mark_bg_to_reclaim(bg);