Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp1265720pxa; Thu, 20 Aug 2020 07:06:46 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzIC6sq6Lw+k+Qke57lG3d8oZsNfB8ZgnTpJZ5bLllPiNEJCcYVLaOVquE+JZfG0D2vGVBo X-Received: by 2002:a17:906:2f17:: with SMTP id v23mr3329086eji.343.1597932406535; Thu, 20 Aug 2020 07:06:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597932406; cv=none; d=google.com; s=arc-20160816; b=BgHR1bBTHqAhWVyQPvu07yjsLwM5t58KhoXgnYfRRjapg9gOGWNoKOw/WSNm97nFYA mtV7mZxkXfrIByGh+FHqDdD7SlGPi5ptiZdpIyUobN9iPGyy1GDfgeLtXXHeGk0jZu1V RO6mCXc++sPLCTHUmsi1GOTDlY4IbZFU5oPYE/L8Nw2CJbAeWiXs1THX0o9tn8MA1Hfa bE7scSUlfrvG6Wl33DTGNtHDejlEbSxrdNuJyYTJRe/it5KxaBGqRX0afPJxCBDjE02H 5xsd1H/63anYasKBS9/gU2rcpJJVwPnTPvVwzAeTzAJtm+xRGrxM5hUUoJ0AVpKLrRLz EldA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=vz/JikVoaES5OoUAeW2V3jMQ3ACE59q4lpI5QxOpZ3E=; b=jpwqadac41aJTc32m9/X1uNSHJyLZMrH3tQ+mMV5L8/HX6UDOfunREWXxBkw3m1yrT UY/ud6bGWiAfigo+cWimS0HpIL1XXTZ25lrzWhag5pODY4lNHpysK+LCxgsGjI3zAy1h h+YLV+NrP7yzjOTE19GAV0fPj9dkq7mV0g8kmvmgQ0lp8prre8ETy3htW0eoGzLquRBX 8MgHxuzfs3wggstOVl80HQs/+vsqCYwoNvmm6d6aye/fapfHIEz4JhpGsA/FsSZtBP3s TUf0ewXDmZVenj5OsXKZ5NzEFJHb3wl2bxMiEC7Din/TaqQ3k8CNsBWP9S9Otp2LDIAT dObA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=1aMdTWsM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b6si1357862ejb.68.2020.08.20.07.06.21; Thu, 20 Aug 2020 07:06:46 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=1aMdTWsM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725852AbgHTN7q (ORCPT + 99 others); Thu, 20 Aug 2020 09:59:46 -0400 Received: from mail.kernel.org ([198.145.29.99]:59916 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726735AbgHTJX7 (ORCPT ); Thu, 20 Aug 2020 05:23:59 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id B682222D02; Thu, 20 Aug 2020 09:23:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1597915439; bh=yKmAMZWwCOzOAmbAJPyXG2Z9j6Mu8i6EZ/wMCEjEhhM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=1aMdTWsMzF0+ccw/wp86aOS3twRhTJp/5AGuxev5xrePU4ecc9lsirsCv0H6yj3ad zFX8mOp6wedkpw006Zv1/V9MkjGrTNReiCCB31KzEHWbdrYP7SVBD1KMz62m8PYreB vl7l9DXMHGlIzAMJfvkW31aUipgZyAJn4n/JHPtQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Greed Rong , Josef Bacik , Qu Wenruo , David Sterba Subject: [PATCH 5.8 014/232] btrfs: free anon block device right after subvolume deletion Date: Thu, 20 Aug 2020 11:17:45 +0200 Message-Id: <20200820091613.418255504@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200820091612.692383444@linuxfoundation.org> References: <20200820091612.692383444@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Qu Wenruo commit 082b6c970f02fefd278c7833880cda29691a5f34 upstream. [BUG] When a lot of subvolumes are created, there is a user report about transaction aborted caused by slow anonymous block device reclaim: BTRFS: Transaction aborted (error -24) WARNING: CPU: 17 PID: 17041 at fs/btrfs/transaction.c:1576 create_pending_snapshot+0xbc4/0xd10 [btrfs] RIP: 0010:create_pending_snapshot+0xbc4/0xd10 [btrfs] Call Trace: create_pending_snapshots+0x82/0xa0 [btrfs] btrfs_commit_transaction+0x275/0x8c0 [btrfs] btrfs_mksubvol+0x4b9/0x500 [btrfs] btrfs_ioctl_snap_create_transid+0x174/0x180 [btrfs] btrfs_ioctl_snap_create_v2+0x11c/0x180 [btrfs] btrfs_ioctl+0x11a4/0x2da0 [btrfs] do_vfs_ioctl+0xa9/0x640 ksys_ioctl+0x67/0x90 __x64_sys_ioctl+0x1a/0x20 do_syscall_64+0x5a/0x110 entry_SYSCALL_64_after_hwframe+0x44/0xa9 ---[ end trace 33f2f83f3d5250e9 ]--- BTRFS: error (device sda1) in create_pending_snapshot:1576: errno=-24 unknown BTRFS info (device sda1): forced readonly BTRFS warning (device sda1): Skipping commit of aborted transaction. BTRFS: error (device sda1) in cleanup_transaction:1831: errno=-24 unknown [CAUSE] The anonymous device pool is shared and its size is 1M. It's possible to hit that limit if the subvolume deletion is not fast enough and the subvolumes to be cleaned keep the ids allocated. [WORKAROUND] We can't avoid the anon device pool exhaustion but we can shorten the time the id is attached to the subvolume root once the subvolume becomes invisible to the user. Reported-by: Greed Rong Link: https://lore.kernel.org/linux-btrfs/CA+UqX+NTrZ6boGnWHhSeZmEY5J76CTqmYjO2S+=tHJX7nb9DPw@mail.gmail.com/ CC: stable@vger.kernel.org # 4.4+ Reviewed-by: Josef Bacik Signed-off-by: Qu Wenruo Reviewed-by: David Sterba Signed-off-by: David Sterba Signed-off-by: Greg Kroah-Hartman --- fs/btrfs/inode.c | 2 ++ 1 file changed, 2 insertions(+) --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -4041,6 +4041,8 @@ int btrfs_delete_subvolume(struct inode } } + free_anon_bdev(dest->anon_dev); + dest->anon_dev = 0; out_end_trans: trans->block_rsv = NULL; trans->bytes_reserved = 0;