From patchwork Fri Feb 2 23:12:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Boris Burkov X-Patchwork-Id: 13543567 Received: from wout4-smtp.messagingengine.com (wout4-smtp.messagingengine.com [64.147.123.20]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A465512C806 for ; Fri, 2 Feb 2024 23:11:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=64.147.123.20 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706915470; cv=none; b=lkqoAS+Ccvr6YJIx4MufLLVFvy+k/E7PZ6FqAMhe0KZqenFB7sbsk3iUNs5/tTam6TxEkCM8TwQ9fj1LuCT8J1SopvHekrZni/Xjet+BPklAy6l4JpU960jQ8CFZOoT11/gTlRx+nztcibxXl4LFo9aRaoQZOLQ9AhzpbtGvsAs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706915470; c=relaxed/simple; bh=licd7DP9pCSmAue1+Q+46FOuUMqfMaLxflGRfp2EAAg=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=JL5n7JaynrVgtqN7zmKeJRxeE7BvCMM3pbrJmq0CMq5x2dZsJb8IZNB8dBFru56HpSeUD1QncI3T57jXTwvs1ZD4x1xx0wvUgmjSS7tWILTt35cUGc6KrT4Ta81fU5c3/7z8ReEYejLb8tLlbqCdGvMPqIvo7vvkMD23O2hXLOQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=bur.io; spf=pass smtp.mailfrom=bur.io; dkim=pass (2048-bit key) header.d=bur.io header.i=@bur.io header.b=RzmZxP5p; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=bf+ciNiB; arc=none smtp.client-ip=64.147.123.20 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=bur.io Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bur.io Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bur.io header.i=@bur.io header.b="RzmZxP5p"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="bf+ciNiB" Received: from compute7.internal (compute7.nyi.internal [10.202.2.48]) by mailout.west.internal (Postfix) with ESMTP id 8C6803200A33; Fri, 2 Feb 2024 18:11:07 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute7.internal (MEProxy); Fri, 02 Feb 2024 18:11:07 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bur.io; h=cc :content-transfer-encoding:content-type:date:date:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to; s=fm1; t=1706915467; x= 1707001867; bh=IMKo+0BPrIi8IiIoBYvcebctVOv9mvT57y/QGI+hISo=; b=R zmZxP5pFALkFd89Ztfrf4CY47mNEaicB7n7RnIZ2T8A/N2xY++tjsMxowSTIXCxb hBVWn9gLyChp0HrMernw3KNY+yjw++ucwi4u74Y+UQpWL1fqWQm0egR5qiDJm/y3 H6F66yiuPOpOj9DLwmo1mPxcsdrgdt/B5iGtiUdxAAnKMC9TVOCsGY78AJvTCJcz JgR/JCnfYY6+IhogyrgOur9van483E8m3r2ldY+2K8z+Y0kw1tgbHxn5NLx5J6Y4 Chb2M2oAdil1ppo/BKeFRvuFagZvDMJZme71pxAJfulJijJBaE5L8dpWbMQ9L8bR umQY/MZghUhK7Hhj0uHKA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :date:date:feedback-id:feedback-id:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm3; t=1706915467; x=1707001867; bh=IMKo+0BPrIi8I iIoBYvcebctVOv9mvT57y/QGI+hISo=; b=bf+ciNiBDfdQgBYGI3SuyUVEiZuuH Vy+u4K0kw73JH9oomih5R5SP034Uc3CA7CUcAPrBp0pQ7FZLlyp+R7xlA1p6clsT zC0ikCAXqHq+gkfY/2fsBv47f2FGkiCfQSjTJEyVZZaTBwE6YnIf4lYoMKVTIQy6 4SdFw+UkK90nn6wqqTGSkUDkNPjgeUF9vnXnuSuZUqxsAqq3iue/KDFzK4a6z/3s teYmvXdeQlZVZi2A2S/vg4mqK4n1jt5uFIvz0Es/ywdDpRMxVPq0C/fcZUrWFPm4 HHl+gVCgS/6I/5i4LELRXbhgiZbJlcCmRG15AvxLKjvmi5K4Ocb2z+w9Q== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvkedrfeduhedgtdeiucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefhvffufffkofgjfhgggfestdekre dtredttdenucfhrhhomhepuehorhhishcuuehurhhkohhvuceosghorhhishessghurhdr ihhoqeenucggtffrrghtthgvrhhnpeeiueffuedvieeujefhheeigfekvedujeejjeffve dvhedtudefiefhkeegueehleenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhep mhgrihhlfhhrohhmpegsohhrihhssegsuhhrrdhioh X-ME-Proxy: Feedback-ID: i083147f8:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 2 Feb 2024 18:11:06 -0500 (EST) From: Boris Burkov To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH 1/6] btrfs: report reclaim count in sysfs Date: Fri, 2 Feb 2024 15:12:43 -0800 Message-ID: X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 When evaluating various reclaim strategies/thresholds against each other, it is useful to collect data about the amount of reclaim happening. Expose it via sysfs per space_info. Signed-off-by: Boris Burkov --- fs/btrfs/block-group.c | 3 +++ fs/btrfs/space-info.h | 6 ++++++ fs/btrfs/sysfs.c | 2 ++ 3 files changed, 11 insertions(+) diff --git a/fs/btrfs/block-group.c b/fs/btrfs/block-group.c index a9be9ac99222..7f05fdcee199 100644 --- a/fs/btrfs/block-group.c +++ b/fs/btrfs/block-group.c @@ -1858,6 +1858,9 @@ void btrfs_reclaim_bgs_work(struct work_struct *work) div64_u64(bg->used * 100, bg->length), div64_u64(zone_unusable * 100, bg->length)); trace_btrfs_reclaim_block_group(bg); + spin_lock(&space_info->lock); + space_info->reclaim_count++; + spin_unlock(&space_info->lock); ret = btrfs_relocate_chunk(fs_info, bg->start); if (ret) { btrfs_dec_block_group_ro(bg); diff --git a/fs/btrfs/space-info.h b/fs/btrfs/space-info.h index 92c595fed1b0..da3e68612d5c 100644 --- a/fs/btrfs/space-info.h +++ b/fs/btrfs/space-info.h @@ -156,6 +156,12 @@ struct btrfs_space_info { struct kobject kobj; struct kobject *block_group_kobjs[BTRFS_NR_RAID_TYPES]; + + /* + * Monotonically increasing counter of relocated block groups. + * Exposed in /sys/fs//allocation//reclaim_count + */ + u64 reclaim_count; }; struct reserve_ticket { diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c index 84c05246ffd8..1b866b2a01ce 100644 --- a/fs/btrfs/sysfs.c +++ b/fs/btrfs/sysfs.c @@ -894,6 +894,7 @@ SPACE_INFO_ATTR(bytes_readonly); SPACE_INFO_ATTR(bytes_zone_unusable); SPACE_INFO_ATTR(disk_used); SPACE_INFO_ATTR(disk_total); +SPACE_INFO_ATTR(reclaim_count); BTRFS_ATTR_RW(space_info, chunk_size, btrfs_chunk_size_show, btrfs_chunk_size_store); BTRFS_ATTR(space_info, size_classes, btrfs_size_classes_show); @@ -949,6 +950,7 @@ static struct attribute *space_info_attrs[] = { BTRFS_ATTR_PTR(space_info, bg_reclaim_threshold), BTRFS_ATTR_PTR(space_info, chunk_size), BTRFS_ATTR_PTR(space_info, size_classes), + BTRFS_ATTR_PTR(space_info, reclaim_count), #ifdef CONFIG_BTRFS_DEBUG BTRFS_ATTR_PTR(space_info, force_chunk_alloc), #endif From patchwork Fri Feb 2 23:12:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Boris Burkov X-Patchwork-Id: 13543568 Received: from wout4-smtp.messagingengine.com (wout4-smtp.messagingengine.com [64.147.123.20]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7CB1C12D779 for ; Fri, 2 Feb 2024 23:11:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=64.147.123.20 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706915473; cv=none; b=idxpWKp+bfdKNb8s+gle9oastoQJDwF65oyIJguyyRhC9Tjr7o+MzvO1iaegL2kQoEL9i6WnjxgrSqQv2APdee9wVV8vpvpX0GRKo4LNINSiHGQx/yUd5T5KR5SBHZMw1ZUZFe5ngfNoXlPOzc+5yG+5fhZ7PfX7Ps58hSCSJG4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706915473; c=relaxed/simple; bh=RRFp1wdAzsV8MwFV+pHvrHQ1qzhaSBepTrROcOJ2iB8=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=T7A/HlG/EgCFbhndZCGnOX685vrjZ1mDe27zTqtTUCTBQa/34ehflcLQ4VgkY1Trie1Yei58Jh5ykYce1mOqyfXbMIhOuxjrInsifD/aC9i3ucVMmmbfgdJdi/SFWiuHHTMEc52PMO+F/VMmCuk9SwxQG8WknasA5kw64xCHYdc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=bur.io; spf=pass smtp.mailfrom=bur.io; dkim=pass (2048-bit key) header.d=bur.io header.i=@bur.io header.b=VS35667T; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=CfDEEt80; arc=none smtp.client-ip=64.147.123.20 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=bur.io Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bur.io Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bur.io header.i=@bur.io header.b="VS35667T"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="CfDEEt80" Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailout.west.internal (Postfix) with ESMTP id 633EE32004AE; Fri, 2 Feb 2024 18:11:10 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute3.internal (MEProxy); Fri, 02 Feb 2024 18:11:10 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bur.io; h=cc :content-transfer-encoding:content-type:date:date:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to; s=fm1; t=1706915469; x= 1707001869; bh=OKjvy2r1eZ/rVlfeeKzqtmCoxVKBsPtDopcT9hC1t6w=; b=V S35667Td6x7L/yKAWqRGAqveAFiSVdoQHy6zX6zJHVVJYZ20mIGRy8nguf4aS/7x 6PmYDEqBcfTcL5U91fL2GqbHd1blXZMXK0hSDoLxW3eOiwghTpB0Quljcm3JtcGT 6ikciloD/5HvpTTzaIAaFc0gngcGddaNNqPv2ZrfOpdD7NHTlTatDHUDd7IjmK7s yRBNINiSRiu/5ku2NyzHgtMowF17TAI9y79NA7SKlfSLKLY6toDIL5gjH+ByV63c aMGjOjI0nS20tZ/4ie2KVkUV+fUfWvXvQf6+PoZHbWlzCiWIg149CMtn3OLTdlOr nsAoO8rhn0Yy2FY08DHig== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :date:date:feedback-id:feedback-id:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm3; t=1706915469; x=1707001869; bh=OKjvy2r1eZ/rV lfeeKzqtmCoxVKBsPtDopcT9hC1t6w=; b=CfDEEt80JId3/s3v07sD0o62R4oYD jqCiuFd1E/cQgfxxQgCm8Il5fX3WBOZ9qr7W80VuMW9Kq0gaDqIynf1miUwmuh3U eEetKfvVLzSYE8MJzpHR52ckC6kmciv0yrzbzrpIBxVOvmYED67Uoe2FRWzWejIk 6S28uUW6c2Nr2MGEVnMbMlo6+2FYicJgrAfHAJyXweMcy7j9taUVmJ8kHobGbVn/ LHQhJRzLoU3ST7Lu40cgTAWq3WnAvBbs8Sa0QFHQ5XDbq+xHlm6eCUXci69AyDdx SJJ/Cs1fD59PIzyUjGDmBZaJJbUqMUdCZ52/DH4ypXwnmQk3BQSJVhSCw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvkedrfeduhedgtdeiucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefhvffufffkofgjfhgggfestdekre dtredttdenucfhrhhomhepuehorhhishcuuehurhhkohhvuceosghorhhishessghurhdr ihhoqeenucggtffrrghtthgvrhhnpeeiueffuedvieeujefhheeigfekvedujeejjeffve dvhedtudefiefhkeegueehleenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhep mhgrihhlfhhrohhmpegsohhrihhssegsuhhrrdhioh X-ME-Proxy: Feedback-ID: i083147f8:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 2 Feb 2024 18:11:09 -0500 (EST) From: Boris Burkov To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH 2/6] btrfs: store fs_info on space_info Date: Fri, 2 Feb 2024 15:12:44 -0800 Message-ID: <766679bb8556bdc9aec4e3e2557965348cfab833.1706914865.git.boris@bur.io> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 This is handy when computing space_info dynamic reclaim thresholds where we do not have access to a block group. We could add it to the various functions as a parameter, but it seems reasonable for space_info to have an fs_info pointer. Signed-off-by: Boris Burkov --- fs/btrfs/space-info.c | 1 + fs/btrfs/space-info.h | 1 + 2 files changed, 2 insertions(+) diff --git a/fs/btrfs/space-info.c b/fs/btrfs/space-info.c index 571bb13587d5..f4a1e6341ca6 100644 --- a/fs/btrfs/space-info.c +++ b/fs/btrfs/space-info.c @@ -233,6 +233,7 @@ static int create_space_info(struct btrfs_fs_info *info, u64 flags) if (!space_info) return -ENOMEM; + space_info->fs_info = info; for (i = 0; i < BTRFS_NR_RAID_TYPES; i++) INIT_LIST_HEAD(&space_info->block_groups[i]); init_rwsem(&space_info->groups_sem); diff --git a/fs/btrfs/space-info.h b/fs/btrfs/space-info.h index da3e68612d5c..1cc4ef8dca38 100644 --- a/fs/btrfs/space-info.h +++ b/fs/btrfs/space-info.h @@ -85,6 +85,7 @@ enum btrfs_flush_state { }; struct btrfs_space_info { + struct btrfs_fs_info *fs_info; spinlock_t lock; u64 total_bytes; /* total bytes in the space, From patchwork Fri Feb 2 23:12:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Boris Burkov X-Patchwork-Id: 13543569 Received: from wout4-smtp.messagingengine.com (wout4-smtp.messagingengine.com [64.147.123.20]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2EF2112F368 for ; Fri, 2 Feb 2024 23:11:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=64.147.123.20 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706915476; cv=none; b=tRWZueyMBVRoCjLOpmTI3T/BFYx5/QHlEjlCGkJpvrIyzg3T2+183U3U0qHC2X5UO0onnqB8ybTOC8XdM0yZGW2hPdEkEdLfvOyNjMKRckDZND+LxOylIWogladRI3lyEoGqedVdy6UeMYx2SJs0jxD1Q786+RWj9jqDy0cvfG0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706915476; c=relaxed/simple; bh=vKh1MNmopN06WeiwR2tErH2Q4e6bAcob4FXAm4AV/d0=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=NkTw57llXemf3cFu1TfvkqAzTc+yX5Z3lRORHjbAenUvjZJgie6s6ykwYGw7wpiHFU3HwqTBb6UQza6VZN368ODlFya4q3ZTniKbkFfqI4/BNLq0uGVY2JqSwj5X3ItWmBRMJpi9j40mX5H/uhcPtauHe+dlY4GnJW0xrpzZkdI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=bur.io; spf=pass smtp.mailfrom=bur.io; dkim=pass (2048-bit key) header.d=bur.io header.i=@bur.io header.b=KitVcQjX; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=Ze3L/Oo5; arc=none smtp.client-ip=64.147.123.20 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=bur.io Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bur.io Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bur.io header.i=@bur.io header.b="KitVcQjX"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="Ze3L/Oo5" Received: from compute7.internal (compute7.nyi.internal [10.202.2.48]) by mailout.west.internal (Postfix) with ESMTP id 2281F3200A4C; Fri, 2 Feb 2024 18:11:13 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute7.internal (MEProxy); Fri, 02 Feb 2024 18:11:13 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bur.io; h=cc :content-transfer-encoding:content-type:date:date:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to; s=fm1; t=1706915472; x= 1707001872; bh=WUuebHPYVgNc/dEkt1GaEDZbMhsX8ZQSKsSpAgasREI=; b=K itVcQjXx97aTVV+8cCkaeH11C676gco1dSMK/3zA3qeFB+aYSo/aZivEwdkF3ycl FwcCcHgFIa0bGFtC/0KHOH9Xz4IOsXSPauA+/jAeXA3i7LU4r52bGuttnZuork9U 6cmwrWJ4CDUion/ZX7yLwN9A1paSYSkGUFeuUqOMGxtCwUhyyx3TAruGI++Jq3dw 5cveQ47NUFUVCvjS98lMSeyakfGOMGSuHZwG44ryqPOg1OOCLsUhnNtjpNnK5/NE e+khBSOQKP/GBZJZQ9fx383OoRVcX7W2m0eovqTv2HbcTQFd3DbbgYm/m6ucMsF0 1tF2Hc937uPQm1YWskUOA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :date:date:feedback-id:feedback-id:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm3; t=1706915472; x=1707001872; bh=WUuebHPYVgNc/ dEkt1GaEDZbMhsX8ZQSKsSpAgasREI=; b=Ze3L/Oo5mlQoPvwlNhigQRUOht/qf nMVqIHuSOTdSnvi6ONe0aXQha1YxZNNohLQUEUlFsvYzHMwBPciBPdz3WlJQzoCo sKv2ehC/Xw99YgI80sqMtVQ1nxHfMBbPyNcXqIj0Cdvc2la0NJDyWH/KToP/8k0x xRl90oqa8a6GuDBKafWgHENjwP0WkfERZfZoh+4FWiCetgzdL5ZP+qQe9Ab8DkPg OOAtgOjyQGOB/JcqKMlGCyvc9CHlNOnkqceYghRfTUk0UbrcRzfTEfH5nCPivBl2 8RRkkcC7jnel6EzKFHrfJS27iRDc6M9IfqnRK/nkPwVEKl61I7YxWBLgw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvkedrfeduhedgtdeiucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefhvffufffkofgjfhgggfestdekre dtredttdenucfhrhhomhepuehorhhishcuuehurhhkohhvuceosghorhhishessghurhdr ihhoqeenucggtffrrghtthgvrhhnpeeiueffuedvieeujefhheeigfekvedujeejjeffve dvhedtudefiefhkeegueehleenucevlhhushhtvghrufhiiigvpedunecurfgrrhgrmhep mhgrihhlfhhrohhmpegsohhrihhssegsuhhrrdhioh X-ME-Proxy: Feedback-ID: i083147f8:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 2 Feb 2024 18:11:12 -0500 (EST) From: Boris Burkov To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH 3/6] btrfs: dynamic block_group reclaim threshold Date: Fri, 2 Feb 2024 15:12:45 -0800 Message-ID: <45e9faf9636b0ccc4dbaf66f4c2a20c3466bb32d.1706914865.git.boris@bur.io> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 We can currently recover allocated block_groups by: - explicitly starting balance operations - "auto reclaim" via bg_reclaim_threshold The latter works by checking against a fixed threshold on frees. If we pass from above the threshold to below, relocation triggers and the block group will get reclaimed by the cleaner thread (assuming it is still eligible) Picking a threshold is challenging. Too high, and you end up trying to reclaim very full block_groups which is quite costly, and you don't do reclaim on block_groups that don't get quite THAT full, but could still be quite fragmented and stranding a lot of space. Too low, and you similarly miss out on reclaim even if you badly need it to avoid running out of unallocated space, if you have heavily fragmented block groups living above the threshold. No matter the threshold, it suffers from a workload that happens to bounce around that threshold, which can introduce arbitrary amounts of reclaim waste. To improve this situation, introduce a dynamic threshold. The basic idea behind this threshold is that it should be high when there is lots of unused space, and little unallocated space, relative to fs size. OTOH, when either unused is low or unallocated is high, reclaim is not that important, so we can set a quite low threshold. The formula to acheive this is: (unused / allocated) * (unused / unallocated) which is also clamped to 90% as fuller than that is very challenging to reclaim flat out, and means the file system is legitimately quite full. I tested this by running it on three interesting workloads: 1. bounce allocations around X% full. 2. fill up all the way and introduce full fragmentation. 3. write in a fragmented way until the filesystem is just about full. 1. and 2. attack the weaknesses of a fixed threshold; fixed either works perfectly or fully falls apart, depending on the threshold. Dynamic always handles these cases well. 3. attacks dynamic by checking whether it is too zealous to reclaim in conditions with low unallocated and low unused. It tends to claw back 1GiB of unallocated fairly aggressively, but not much more. Early versions of dynamic threshold struggled on this test. Additional work could be done to intelligently ratchet up the urgency of reclaim in very low unallocated conditions. Existing mechanisms are already useless in that case anyway. Signed-off-by: Boris Burkov --- fs/btrfs/block-group.c | 18 +++++----- fs/btrfs/space-info.c | 74 ++++++++++++++++++++++++++++++++++++++++++ fs/btrfs/space-info.h | 8 +++++ fs/btrfs/sysfs.c | 43 +++++++++++++++++++++++- 4 files changed, 134 insertions(+), 9 deletions(-) diff --git a/fs/btrfs/block-group.c b/fs/btrfs/block-group.c index 7f05fdcee199..6244c76f3584 100644 --- a/fs/btrfs/block-group.c +++ b/fs/btrfs/block-group.c @@ -1702,24 +1702,21 @@ static inline bool btrfs_should_reclaim(struct btrfs_fs_info *fs_info) static bool should_reclaim_block_group(struct btrfs_block_group *bg, u64 bytes_freed) { - const struct btrfs_space_info *space_info = bg->space_info; - const int reclaim_thresh = READ_ONCE(space_info->bg_reclaim_threshold); + const int thresh_pct = btrfs_calc_reclaim_threshold(bg->space_info); + u64 thresh_bytes = mult_perc(bg->length, thresh_pct); const u64 new_val = bg->used; const u64 old_val = new_val + bytes_freed; - u64 thresh; - if (reclaim_thresh == 0) + if (thresh_bytes == 0) return false; - thresh = mult_perc(bg->length, reclaim_thresh); - /* * If we were below the threshold before don't reclaim, we are likely a * brand new block group and we don't want to relocate new block groups. */ - if (old_val < thresh) + if (old_val < thresh_bytes) return false; - if (new_val >= thresh) + if (new_val >= thresh_bytes) return false; return true; } @@ -1779,6 +1776,7 @@ void btrfs_reclaim_bgs_work(struct work_struct *work) /* Don't race with allocators so take the groups_sem */ down_write(&space_info->groups_sem); + spin_lock(&space_info->lock); spin_lock(&bg->lock); if (bg->reserved || bg->pinned || bg->ro) { /* @@ -1788,6 +1786,7 @@ void btrfs_reclaim_bgs_work(struct work_struct *work) * this block group. */ spin_unlock(&bg->lock); + spin_unlock(&space_info->lock); up_write(&space_info->groups_sem); goto next; } @@ -1806,6 +1805,7 @@ void btrfs_reclaim_bgs_work(struct work_struct *work) if (!btrfs_test_opt(fs_info, DISCARD_ASYNC)) btrfs_mark_bg_unused(bg); spin_unlock(&bg->lock); + spin_unlock(&space_info->lock); up_write(&space_info->groups_sem); goto next; @@ -1822,10 +1822,12 @@ void btrfs_reclaim_bgs_work(struct work_struct *work) */ if (!should_reclaim_block_group(bg, bg->length)) { spin_unlock(&bg->lock); + spin_unlock(&space_info->lock); up_write(&space_info->groups_sem); goto next; } spin_unlock(&bg->lock); + spin_unlock(&space_info->lock); /* * Get out fast, in case we're read-only or unmounting the diff --git a/fs/btrfs/space-info.c b/fs/btrfs/space-info.c index f4a1e6341ca6..86a87501af08 100644 --- a/fs/btrfs/space-info.c +++ b/fs/btrfs/space-info.c @@ -1,5 +1,6 @@ // SPDX-License-Identifier: GPL-2.0 +#include #include "misc.h" #include "ctree.h" #include "space-info.h" @@ -191,6 +192,8 @@ void btrfs_clear_space_info_full(struct btrfs_fs_info *info) */ #define BTRFS_DEFAULT_ZONED_RECLAIM_THRESH (75) +#define BTRFS_DYNAMIC_RECLAIM_THRESH_MAX (90) + /* * Calculate chunk size depending on volume type (regular or zoned). */ @@ -1870,3 +1873,74 @@ u64 btrfs_account_ro_block_groups_free_space(struct btrfs_space_info *sinfo) return free_bytes; } + +static u64 calc_pct_ratio(u64 x, u64 y) +{ + int err; + + if (!y) + return 0; +again: + err = check_mul_overflow(100, x, &x); + if (err) + goto lose_precision; + return div64_u64(x, y); +lose_precision: + x >>= 10; + y >>= 10; + if (!y) + y = 1; + goto again; +} + +/* + * The dynamic threshold formula is: + * (unused / allocated) * (unused / unallocated) or equivalently + * unused^2 / (allocated * unallocated) + * + * The fundamental goal of automatic reclaim is to protect the filesystem's + * unallocated space and thus minimize the probability of the filesystem going + * read only when a metadata allocation failure causes a transaction abort. + * + * However, relocations happen into the space_info's unused space, therefore + * automatic reclaim must also back off as that space runs low. There is no + * value in doing trivial "relocations" of re-writing the same block group + * into a fresh one. + * + * unused / allocated sets a baseline, very conservative threshold which + * properly goes to 0 as unused goes to a small portion of the allocated space. + * + * On its own, this would likely do very little reclaim, so include + * unused / unallocated (which can be greatly in excess of 100%) to bias heavily + * towards reclaim when unallocated goes low or unused goes high. + */ + +static int calc_dynamic_reclaim_threshold(struct btrfs_space_info *space_info) +{ + struct btrfs_fs_info *fs_info = space_info->fs_info; + u64 unalloc = atomic64_read(&fs_info->free_chunk_space); + u64 alloc = space_info->total_bytes; + u64 used = btrfs_space_info_used(space_info, false); + u64 unused = alloc - used; + /* unused <= alloc; clamped to 100 */ + int unused_pct = calc_pct_ratio(unused, alloc); + u64 unused_unalloc_ratio = calc_pct_ratio(unused, unalloc); + int err; + u64 thresh; + + err = check_mul_overflow(unused_pct, unused_unalloc_ratio, &thresh); + if (err) + return BTRFS_DYNAMIC_RECLAIM_THRESH_MAX; + /* Both quantities are percentages; remove the squared factor of 100. */ + thresh = div64_u64(thresh, 100); + return clamp_val(thresh, 0, BTRFS_DYNAMIC_RECLAIM_THRESH_MAX); +} + +int btrfs_calc_reclaim_threshold(struct btrfs_space_info *space_info) +{ + lockdep_assert_held(&space_info->lock); + + if (READ_ONCE(space_info->dynamic_reclaim)) + return calc_dynamic_reclaim_threshold(space_info); + return READ_ONCE(space_info->bg_reclaim_threshold); +} diff --git a/fs/btrfs/space-info.h b/fs/btrfs/space-info.h index 1cc4ef8dca38..2f4c00525a08 100644 --- a/fs/btrfs/space-info.h +++ b/fs/btrfs/space-info.h @@ -163,6 +163,12 @@ struct btrfs_space_info { * Exposed in /sys/fs//allocation//reclaim_count */ u64 reclaim_count; + + /* + * If true, use the dynamic relocation threshold, instead of the + * fixed bg_reclaim_threshold. + */ + bool dynamic_reclaim; }; struct reserve_ticket { @@ -245,4 +251,6 @@ void btrfs_dump_space_info_for_trans_abort(struct btrfs_fs_info *fs_info); void btrfs_init_async_reclaim_work(struct btrfs_fs_info *fs_info); u64 btrfs_account_ro_block_groups_free_space(struct btrfs_space_info *sinfo); +int btrfs_calc_reclaim_threshold(struct btrfs_space_info *space_info); + #endif /* BTRFS_SPACE_INFO_H */ diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c index 1b866b2a01ce..0683a23e5254 100644 --- a/fs/btrfs/sysfs.c +++ b/fs/btrfs/sysfs.c @@ -903,8 +903,12 @@ static ssize_t btrfs_sinfo_bg_reclaim_threshold_show(struct kobject *kobj, char *buf) { struct btrfs_space_info *space_info = to_space_info(kobj); + ssize_t ret; - return sysfs_emit(buf, "%d\n", READ_ONCE(space_info->bg_reclaim_threshold)); + spin_lock(&space_info->lock); + ret = sysfs_emit(buf, "%d\n", btrfs_calc_reclaim_threshold(space_info)); + spin_unlock(&space_info->lock); + return ret; } static ssize_t btrfs_sinfo_bg_reclaim_threshold_store(struct kobject *kobj, @@ -915,6 +919,9 @@ static ssize_t btrfs_sinfo_bg_reclaim_threshold_store(struct kobject *kobj, int thresh; int ret; + if (READ_ONCE(space_info->dynamic_reclaim)) + return -EINVAL; + ret = kstrtoint(buf, 10, &thresh); if (ret) return ret; @@ -931,6 +938,39 @@ BTRFS_ATTR_RW(space_info, bg_reclaim_threshold, btrfs_sinfo_bg_reclaim_threshold_show, btrfs_sinfo_bg_reclaim_threshold_store); +static ssize_t btrfs_sinfo_dynamic_reclaim_show(struct kobject *kobj, + struct kobj_attribute *a, + char *buf) +{ + struct btrfs_space_info *space_info = to_space_info(kobj); + + return sysfs_emit(buf, "%d\n", READ_ONCE(space_info->dynamic_reclaim)); +} + +static ssize_t btrfs_sinfo_dynamic_reclaim_store(struct kobject *kobj, + struct kobj_attribute *a, + const char *buf, size_t len) +{ + struct btrfs_space_info *space_info = to_space_info(kobj); + int dynamic_reclaim; + int ret; + + ret = kstrtoint(buf, 10, &dynamic_reclaim); + if (ret) + return ret; + + if (dynamic_reclaim < 0) + return -EINVAL; + + WRITE_ONCE(space_info->dynamic_reclaim, dynamic_reclaim != 0); + + return len; +} + +BTRFS_ATTR_RW(space_info, dynamic_reclaim, + btrfs_sinfo_dynamic_reclaim_show, + btrfs_sinfo_dynamic_reclaim_store); + /* * Allocation information about block group types. * @@ -948,6 +988,7 @@ static struct attribute *space_info_attrs[] = { BTRFS_ATTR_PTR(space_info, disk_used), BTRFS_ATTR_PTR(space_info, disk_total), BTRFS_ATTR_PTR(space_info, bg_reclaim_threshold), + BTRFS_ATTR_PTR(space_info, dynamic_reclaim), BTRFS_ATTR_PTR(space_info, chunk_size), BTRFS_ATTR_PTR(space_info, size_classes), BTRFS_ATTR_PTR(space_info, reclaim_count), From patchwork Fri Feb 2 23:12:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Boris Burkov X-Patchwork-Id: 13543570 Received: from wout4-smtp.messagingengine.com (wout4-smtp.messagingengine.com [64.147.123.20]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CB10A12C7FB for ; Fri, 2 Feb 2024 23:11:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=64.147.123.20 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706915478; cv=none; b=DSAeDk+dUgi5PhqizvNcVa7ZS8XIuI2diuuzYpP31A7l9HtzkXhUSPm8bz5TUz+taPZRrhIjj5GsDmBM/pDk5VPQWPGf/HvzJ1SZqWYavQX7IekJv8gMDdPyhq3JcJM9IFXoUR9efNTX/4OD5tBsrMtdQgsA8pJzJki6+1kWsYU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706915478; c=relaxed/simple; bh=MwPCUsDSyNQsPVWxVFrJD0rPXmwUZ+OcsXt+WTsECpE=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=to62sHw/vDTqSj4noxRBfXt84AAjBEAnir59hZ5j8z4+Jk/2Z13GQa2GPh3do0VgrfMXlLvHrXvY6f5RwG+xw48zxkou6eDH1T/JCGY1x5rXzIwelgZVnkUdmsKg3ga0jpvagArgOA5k2MH5KxCtIlhslvYxJZtLidijN6/Kf/0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=bur.io; spf=pass smtp.mailfrom=bur.io; dkim=pass (2048-bit key) header.d=bur.io header.i=@bur.io header.b=qp7UN+k1; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=X7sEuNN4; arc=none smtp.client-ip=64.147.123.20 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=bur.io Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bur.io Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bur.io header.i=@bur.io header.b="qp7UN+k1"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="X7sEuNN4" Received: from compute6.internal (compute6.nyi.internal [10.202.2.47]) by mailout.west.internal (Postfix) with ESMTP id E60BB3200A28; Fri, 2 Feb 2024 18:11:15 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute6.internal (MEProxy); Fri, 02 Feb 2024 18:11:16 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bur.io; h=cc :content-transfer-encoding:content-type:date:date:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to; s=fm1; t=1706915475; x= 1707001875; bh=h9O7dxLO/acKwh8Dnm/WI1eMQYqwQZvPi7iExUHv/1E=; b=q p7UN+k1TsEnHHG/DpN34wDoLtIQpgoWcGq57coVBtsKWGS+rP7YfztroOjtWmlEv 49gjDrZ2rvFQ7ka1cUPpHxtfdkEac6MXwokte/kYfRTkucWLHtV0B+CJ8djEUvzn WZIJ2vzJH3eMVSoKHI/6Vxqg5M6GyqWk2bJn/vqwFZJleTvWICSYH5xWMz+vvUIv PDkdTwbAOvLzVBKaHA5u3r11ebnqX5voAxIrqcF3wkA0xauY9rlzR8WBxTKirvlP eO4wAkJerzLCP1XXA7fMvTJ6l9oejtBJ08DUiUrFfw8+3URuhIO2bgvqT1/nfjPt lBRM0c+yP9kjEesLEA54A== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :date:date:feedback-id:feedback-id:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm3; t=1706915475; x=1707001875; bh=h9O7dxLO/acKw h8Dnm/WI1eMQYqwQZvPi7iExUHv/1E=; b=X7sEuNN4pU7xIuYZIe/OmYQbtsztH Y3XmXAdL0JR+LzLlqK2b6yUZqFssmPQjaXLAJ3H8YvCEIQAwImpPhcIbpp7f9svg ZQKj0t1kYbTQDq+WUWFONzhncZOH8kVBXjuWvsZ7H1CzfGBLlcEbw21B/kPsgdbH 7pTFd8wC/0WC8eFEK1uDPHZ3Shjzjy/FZjb72hUmJqJBMShz3bJ+UkKsGukGMmwn yNGzwt7OGIeDB0AH94I5bF61030uI9FCaJ3/hpwQ1LggDtf643m1baOg8O+D/Vk9 pIKsD5HPGsOrSvMLklMXHoYnPVnX5gNSLXW4dus7Q8D5OkiBrm2CLcXbw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvkedrfeduhedgtdejucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefhvffufffkofgjfhgggfestdekre dtredttdenucfhrhhomhepuehorhhishcuuehurhhkohhvuceosghorhhishessghurhdr ihhoqeenucggtffrrghtthgvrhhnpeeiueffuedvieeujefhheeigfekvedujeejjeffve dvhedtudefiefhkeegueehleenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhep mhgrihhlfhhrohhmpegsohhrihhssegsuhhrrdhioh X-ME-Proxy: Feedback-ID: i083147f8:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 2 Feb 2024 18:11:14 -0500 (EST) From: Boris Burkov To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH 4/6] btrfs: periodic block_group reclaim Date: Fri, 2 Feb 2024 15:12:46 -0800 Message-ID: <1173e535ec7b46bda33ed2dc4219027502763902.1706914865.git.boris@bur.io> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 We currently employ a edge-triggered block group reclaim strategy which marks block groups for reclaim as they free down past a threshold. With a dynamic threshold, this is worse than doing it in a level-triggered fashion periodically. That is because the reclaim itself happens periodically, so the threshold at that point in time is what really matters, not the threshold at freeing time. If we mark the reclaim in a big pass, then sort by usage and do reclaim, we also benefit from a negative feedback loop preventing unnecessary reclaims as we crunch through the "best" candidates. Since this is quite a different model, it requires some additional support. The edge triggered reclaim has a good heuristic for not reclaiming fresh block groups, so we need to replace that with a typical GC sweep mark which skips block groups that have seen an allocation since the last sweep. Signed-off-by: Boris Burkov --- fs/btrfs/block-group.c | 2 ++ fs/btrfs/block-group.h | 1 + fs/btrfs/space-info.c | 51 ++++++++++++++++++++++++++++++++++++++++++ fs/btrfs/space-info.h | 7 ++++++ fs/btrfs/sysfs.c | 34 ++++++++++++++++++++++++++++ 5 files changed, 95 insertions(+) diff --git a/fs/btrfs/block-group.c b/fs/btrfs/block-group.c index 6244c76f3584..1a752a8a1bea 100644 --- a/fs/btrfs/block-group.c +++ b/fs/btrfs/block-group.c @@ -1898,6 +1898,7 @@ void btrfs_reclaim_bgs_work(struct work_struct *work) void btrfs_reclaim_bgs(struct btrfs_fs_info *fs_info) { + btrfs_reclaim_sweep(fs_info); spin_lock(&fs_info->unused_bgs_lock); if (!list_empty(&fs_info->reclaim_bgs)) queue_work(system_unbound_wq, &fs_info->reclaim_bgs_work); @@ -3565,6 +3566,7 @@ int btrfs_update_block_group(struct btrfs_trans_handle *trans, old_val += num_bytes; cache->used = old_val; cache->reserved -= num_bytes; + cache->reclaim_mark = 0; space_info->bytes_reserved -= num_bytes; space_info->bytes_used += num_bytes; space_info->disk_used += num_bytes * factor; diff --git a/fs/btrfs/block-group.h b/fs/btrfs/block-group.h index c4a1f01cc1c2..24b576b7a88c 100644 --- a/fs/btrfs/block-group.h +++ b/fs/btrfs/block-group.h @@ -250,6 +250,7 @@ struct btrfs_block_group { struct work_struct zone_finish_work; struct extent_buffer *last_eb; enum btrfs_block_group_size_class size_class; + u64 reclaim_mark; }; static inline u64 btrfs_block_group_end(struct btrfs_block_group *block_group) diff --git a/fs/btrfs/space-info.c b/fs/btrfs/space-info.c index 86a87501af08..fc4e307669ef 100644 --- a/fs/btrfs/space-info.c +++ b/fs/btrfs/space-info.c @@ -1944,3 +1944,54 @@ int btrfs_calc_reclaim_threshold(struct btrfs_space_info *space_info) return calc_dynamic_reclaim_threshold(space_info); return READ_ONCE(space_info->bg_reclaim_threshold); } + +static int do_reclaim_sweep(struct btrfs_fs_info *fs_info, + struct btrfs_space_info *space_info, int raid) +{ + struct btrfs_block_group *bg; + int thresh_pct; + + spin_lock(&space_info->lock); + thresh_pct = btrfs_calc_reclaim_threshold(space_info); + spin_unlock(&space_info->lock); + + down_read(&space_info->groups_sem); + list_for_each_entry(bg, &space_info->block_groups[raid], list) { + u64 thresh; + bool reclaim = false; + + btrfs_get_block_group(bg); + spin_lock(&bg->lock); + thresh = mult_perc(bg->length, thresh_pct); + if (bg->used < thresh && bg->reclaim_mark) + reclaim = true; + bg->reclaim_mark++; + spin_unlock(&bg->lock); + if (reclaim) + btrfs_mark_bg_to_reclaim(bg); + btrfs_put_block_group(bg); + } + up_read(&space_info->groups_sem); + return 0; +} + +int btrfs_reclaim_sweep(struct btrfs_fs_info *fs_info) +{ + int ret; + int raid; + struct btrfs_space_info *space_info; + + list_for_each_entry(space_info, &fs_info->space_info, list) { + if (space_info->flags & BTRFS_BLOCK_GROUP_SYSTEM) + continue; + if (!READ_ONCE(space_info->periodic_reclaim)) + continue; + for (raid = 0; raid < BTRFS_NR_RAID_TYPES; raid++) { + ret = do_reclaim_sweep(fs_info, space_info, raid); + if (ret) + return ret; + } + } + + return ret; +} diff --git a/fs/btrfs/space-info.h b/fs/btrfs/space-info.h index 2f4c00525a08..2917bc4247db 100644 --- a/fs/btrfs/space-info.h +++ b/fs/btrfs/space-info.h @@ -169,6 +169,12 @@ struct btrfs_space_info { * fixed bg_reclaim_threshold. */ bool dynamic_reclaim; + + /* + * Periodically check all block groups against the reclaim + * threshold in the cleaner thread. + */ + bool periodic_reclaim; }; struct reserve_ticket { @@ -252,5 +258,6 @@ void btrfs_init_async_reclaim_work(struct btrfs_fs_info *fs_info); u64 btrfs_account_ro_block_groups_free_space(struct btrfs_space_info *sinfo); int btrfs_calc_reclaim_threshold(struct btrfs_space_info *space_info); +int btrfs_reclaim_sweep(struct btrfs_fs_info *fs_info); #endif /* BTRFS_SPACE_INFO_H */ diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c index 0683a23e5254..98bd8efaa2dc 100644 --- a/fs/btrfs/sysfs.c +++ b/fs/btrfs/sysfs.c @@ -971,6 +971,39 @@ BTRFS_ATTR_RW(space_info, dynamic_reclaim, btrfs_sinfo_dynamic_reclaim_show, btrfs_sinfo_dynamic_reclaim_store); +static ssize_t btrfs_sinfo_periodic_reclaim_show(struct kobject *kobj, + struct kobj_attribute *a, + char *buf) +{ + struct btrfs_space_info *space_info = to_space_info(kobj); + + return sysfs_emit(buf, "%d\n", READ_ONCE(space_info->periodic_reclaim)); +} + +static ssize_t btrfs_sinfo_periodic_reclaim_store(struct kobject *kobj, + struct kobj_attribute *a, + const char *buf, size_t len) +{ + struct btrfs_space_info *space_info = to_space_info(kobj); + int periodic_reclaim; + int ret; + + ret = kstrtoint(buf, 10, &periodic_reclaim); + if (ret) + return ret; + + if (periodic_reclaim < 0) + return -EINVAL; + + WRITE_ONCE(space_info->periodic_reclaim, periodic_reclaim != 0); + + return len; +} + +BTRFS_ATTR_RW(space_info, periodic_reclaim, + btrfs_sinfo_periodic_reclaim_show, + btrfs_sinfo_periodic_reclaim_store); + /* * Allocation information about block group types. * @@ -992,6 +1025,7 @@ static struct attribute *space_info_attrs[] = { BTRFS_ATTR_PTR(space_info, chunk_size), BTRFS_ATTR_PTR(space_info, size_classes), BTRFS_ATTR_PTR(space_info, reclaim_count), + BTRFS_ATTR_PTR(space_info, periodic_reclaim), #ifdef CONFIG_BTRFS_DEBUG BTRFS_ATTR_PTR(space_info, force_chunk_alloc), #endif From patchwork Fri Feb 2 23:12:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Boris Burkov X-Patchwork-Id: 13543571 Received: from wout4-smtp.messagingengine.com (wout4-smtp.messagingengine.com [64.147.123.20]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id ADE2B12F365 for ; Fri, 2 Feb 2024 23:11:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=64.147.123.20 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706915481; cv=none; b=QdeZ5FVjFLkPDv1GktOWT3AAHvw2Xmq5C+NElz4HBiIjMM4tZ46B33lZpgeJSX6uqR7I5DsdIHchOtkMJnNL6tCmDKAU9ACc+AvJ3Y/51Z/eZDmkMTOXcroGQcC5ZvclYJAFicMhO+WZD9cAnEPI4tN1F0oXdgCevyRnvMxVKqo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706915481; c=relaxed/simple; bh=l9YURtbeIUuyNk5PEmNwlwr7hiVMyrTp3TPGK5Mpbs8=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=BWOS5crgkMwTGPJDFyBMsqAebonHB8QCi0YFRyZGLPyg8ijT+IjwGmaEUpaqCKVd6lj+aetC1/mxpql7ma9WLzG/lprnZeTTWV0IKe4MLmIYBq4/DB8tCRgMZr/TMSSrcYFH5OB2ZwNVR76Mpa9b5/aV+HpzrvemmX9Nh2IHEpM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=bur.io; spf=pass smtp.mailfrom=bur.io; dkim=pass (2048-bit key) header.d=bur.io header.i=@bur.io header.b=CkUoNkY6; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=mXsiiWlF; arc=none smtp.client-ip=64.147.123.20 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=bur.io Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bur.io Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bur.io header.i=@bur.io header.b="CkUoNkY6"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="mXsiiWlF" Received: from compute6.internal (compute6.nyi.internal [10.202.2.47]) by mailout.west.internal (Postfix) with ESMTP id A43193200A48; Fri, 2 Feb 2024 18:11:18 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute6.internal (MEProxy); Fri, 02 Feb 2024 18:11:19 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bur.io; h=cc :content-transfer-encoding:content-type:date:date:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to; s=fm1; t=1706915478; x= 1707001878; bh=5bdReofwLGtO+8cUIAEc6icgAkBeYI2dmaEEhoxLCeM=; b=C kUoNkY6H3hiKaHxdlbrroU6Y8olhIYN6/9i1c6Cqx7nMIkLeOd3ZMzVWh/P8V2S4 IYKzdUotqTbTSo+9o/OCW2ViBilgdL0S0UZPqtVM4kzP0Rw+Mxl6QflppPlao6qh 0r21EppP9JDdMqzt8WqeAWfa5xH596bFQAOOgxH2AROqQ6ZhAR0DQI7vxQITOyIW xXrv1J7HQuumCNNbIXltNG+4ONY53u0zn6m7AOpPmQ2Gsr40xt8vwFm9ppa8VFe9 sTOp3Hs/CucxY2QcugfEDZ6MOJnP4HlUuYsDAZhx7iWbddnD1zNgUb/C1NUCL4bK yjHVHFwFANDaS2Wkixcag== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :date:date:feedback-id:feedback-id:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm3; t=1706915478; x=1707001878; bh=5bdReofwLGtO+ 8cUIAEc6icgAkBeYI2dmaEEhoxLCeM=; b=mXsiiWlFYXrFOnRmw9v7VUGSxWCns nW0RyRC2bGMTHvXnDXfU91xYuPVd0W1s87MCPJ751TrR6zyxnViAl548orOso2D1 YeIi5YtzLKNHcpIBMR54v2em7lArsL+b/7oe9KrSkf+l4iUQiV5Xep1N8TX960uY 9nM1xdIunlX1jM+uL/rittYcgzBChZk6DD0C9DwdslpOqXGQXHdincKcnlpDSqm7 oNaR5a2mTqRr9FxABXVXoQum4uANQWy3zElcJF3beI8LZmbq+x74K5VVRMnJt+VN ba37+/9OXMvB8vue2RyQBDIuSvbn+zLnEwmbHGLto6DVFxjGLCJZXCDgg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvkedrfeduhedgtdejucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefhvffufffkofgjfhgggfestdekre dtredttdenucfhrhhomhepuehorhhishcuuehurhhkohhvuceosghorhhishessghurhdr ihhoqeenucggtffrrghtthgvrhhnpeeiueffuedvieeujefhheeigfekvedujeejjeffve dvhedtudefiefhkeegueehleenucevlhhushhtvghrufhiiigvpedunecurfgrrhgrmhep mhgrihhlfhhrohhmpegsohhrihhssegsuhhrrdhioh X-ME-Proxy: Feedback-ID: i083147f8:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 2 Feb 2024 18:11:17 -0500 (EST) From: Boris Burkov To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH 5/6] btrfs: urgent periodic reclaim pass Date: Fri, 2 Feb 2024 15:12:47 -0800 Message-ID: X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Periodic reclaim attempts to avoid block_groups seeing active use with a sweep mark that gets cleared on allocation and set on a sweep. In urgent conditions where we have very little unallocated space, we want to be able to override this mechanism. Introduce a second pass that only happens if we fail to find a reclaim candidate and reclaim is urgent. In that case, do a second pass where all block groups are eligible. Signed-off-by: Boris Burkov --- fs/btrfs/space-info.c | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/fs/btrfs/space-info.c b/fs/btrfs/space-info.c index fc4e307669ef..7ec775979637 100644 --- a/fs/btrfs/space-info.c +++ b/fs/btrfs/space-info.c @@ -1945,17 +1945,35 @@ int btrfs_calc_reclaim_threshold(struct btrfs_space_info *space_info) return READ_ONCE(space_info->bg_reclaim_threshold); } +/* + * Under "urgent" reclaim, we will reclaim even fresh block groups that have + * recently seen successful allocations, as we are desperate to reclaim + * whatever we can to avoid ENOSPC in a transaction leading to a readonly fs. + */ +static bool is_reclaim_urgent(struct btrfs_space_info *space_info) +{ + struct btrfs_fs_info *fs_info = space_info->fs_info; + u64 unalloc = atomic64_read(&fs_info->free_chunk_space); + u64 chunk_size = min(READ_ONCE(space_info->chunk_size), SZ_1G); + + return unalloc < chunk_size; +} + static int do_reclaim_sweep(struct btrfs_fs_info *fs_info, struct btrfs_space_info *space_info, int raid) { struct btrfs_block_group *bg; int thresh_pct; + bool try_again = true; + bool urgent; spin_lock(&space_info->lock); + urgent = is_reclaim_urgent(space_info); thresh_pct = btrfs_calc_reclaim_threshold(space_info); spin_unlock(&space_info->lock); down_read(&space_info->groups_sem); +again: list_for_each_entry(bg, &space_info->block_groups[raid], list) { u64 thresh; bool reclaim = false; @@ -1963,14 +1981,29 @@ static int do_reclaim_sweep(struct btrfs_fs_info *fs_info, btrfs_get_block_group(bg); spin_lock(&bg->lock); thresh = mult_perc(bg->length, thresh_pct); - if (bg->used < thresh && bg->reclaim_mark) + if (bg->used < thresh && bg->reclaim_mark) { + try_again = false; reclaim = true; + } bg->reclaim_mark++; spin_unlock(&bg->lock); if (reclaim) btrfs_mark_bg_to_reclaim(bg); btrfs_put_block_group(bg); } + + /* + * In situations where we are very motivated to reclaim (low unalloc) + * use two passes to make the reclaim mark check best effort. + * + * If we have any staler groups, we don't touch the fresher ones, but if we + * really need a block group, do take a fresh one. + */ + if (try_again && urgent) { + try_again = false; + goto again; + } + up_read(&space_info->groups_sem); return 0; } From patchwork Fri Feb 2 23:12:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Boris Burkov X-Patchwork-Id: 13543572 Received: from wout4-smtp.messagingengine.com (wout4-smtp.messagingengine.com [64.147.123.20]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AF7AE12F365 for ; Fri, 2 Feb 2024 23:11:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=64.147.123.20 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706915484; cv=none; b=lMu0BiPRYFkmWOI0G9BSPIC4+8fcBG5heupl/85bLcn93WVleuByIi7MEZkbAESRzgUbjh9FIJwwmVOp/YFddj67NqHxBupl6faZC0ejClymP0HfhOHCG0cOYEA6LOrnRIuSXObKFpgMvp+tgZao1LLT6Rgo8ezs4X4XDforS60= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706915484; c=relaxed/simple; bh=z2Z9CCBLISpITabUZJ/AIIS7zWcSf1tkkVa+GDQtWp4=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=JJEPi13HtRtgNHtiHU5JTretEZAp/WFkT4De/E2n+gjBRwI3uhnc4m9aR1L1M2ZCenjCTMRzVNg2ouIqd8SK6qsFYHQIPyzn6aCeTkJbGnKLZrT9sD9KUzFElJTnxrEQ4l9wIa4ann+xSSCVN2ll9CQL+4Ji3NBvoVmxsEWZllU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=bur.io; spf=pass smtp.mailfrom=bur.io; dkim=pass (2048-bit key) header.d=bur.io header.i=@bur.io header.b=C4e3ul5G; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=Q8fpsxbM; arc=none smtp.client-ip=64.147.123.20 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=bur.io Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bur.io Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bur.io header.i=@bur.io header.b="C4e3ul5G"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="Q8fpsxbM" Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailout.west.internal (Postfix) with ESMTP id 6C2743200A48; Fri, 2 Feb 2024 18:11:21 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute3.internal (MEProxy); Fri, 02 Feb 2024 18:11:21 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bur.io; h=cc :content-transfer-encoding:content-type:date:date:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to; s=fm1; t=1706915480; x= 1707001880; bh=AGFsIildfQigbbuhNKfEDjdgPucteGfeucMmu1awsDs=; b=C 4e3ul5GcvUvw8nLNvqthxUcbbXXw0FszDMK6d0+eDbeDcCAVqbUkYheix98PnOgo nJoQA8cWHpoT2AdyCHFVGI453hjf5GBDaHxa3VXKSzxbxK0B8dkZFfUOtv6kPZs3 r87rHoPL9zuk933A0Ixme2XnFMMUawwUQNBGODzjGpaV+aipIN6+Tc7sk62dVfSB 5nDu5SPqAkbKycmrF1jibd3I2TWi3ixKQstqfvX0XeCBp9G46LXvtBkazxlMOmZY oPqGPeA2WjsC8/5uT5Rb3K+//KNULQCxRpJOnL9Q8kIaULVL3KoEoEc+sRSPMPdG dtfaVDfJkHazxHg7mE3zw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :date:date:feedback-id:feedback-id:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm3; t=1706915480; x=1707001880; bh=AGFsIildfQigb buhNKfEDjdgPucteGfeucMmu1awsDs=; b=Q8fpsxbMVe7cWwAiGaxYIteNK0a4b h6UF/rJnfy2NG784a5T1FnwVQReuVgcniVAVAstHRJWj6b/xv083r8WNbncr/i7G WckNY+MhUmXggzEfokSqWFM463gTHh4RLCFFHZnZUeBJdU/kwoDz8F1l1DU30FCq nvm2s9QxyuW2wrUm+bS1x+lORpnvr9Cou2QfDpEtd8QVMnkbkPljjwVxla/DGivU oFR5BB+S7H8HeEe+8pMVXisUCiLPEQHNTvGdtXTy+iW5M+nxmGrWBSe60cqMmFuZ ZwTbFNnaVUG7dL8ypzLxhwj0kNMsKnAaQ1DR7syFCY7B/OjFk5NzKIMZg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvkedrfeduhedgtdeiucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefhvffufffkofgjfhgggfestdekre dtredttdenucfhrhhomhepuehorhhishcuuehurhhkohhvuceosghorhhishessghurhdr ihhoqeenucggtffrrghtthgvrhhnpeeiueffuedvieeujefhheeigfekvedujeejjeffve dvhedtudefiefhkeegueehleenucevlhhushhtvghrufhiiigvpedunecurfgrrhgrmhep mhgrihhlfhhrohhmpegsohhrihhssegsuhhrrdhioh X-ME-Proxy: Feedback-ID: i083147f8:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 2 Feb 2024 18:11:20 -0500 (EST) From: Boris Burkov To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH 6/6] btrfs: prevent pathological periodic reclaim loops Date: Fri, 2 Feb 2024 15:12:48 -0800 Message-ID: X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Periodic reclaim runs the risk of getting stuck in a state where it keeps reclaiming the same block group over and over. This can happen if 1. reclaiming that block_group fails 2. reclaiming that block_group fails to move any extents into existing block_groups and just allocates a fresh chunk and moves everything. Currently, 1. is a very tight loop inside the reclaim worker. That is critical for edge triggered reclaim or else we risk forgetting about a reclaimable group. On the other hand, with level triggered reclaim we can break out of that loop and get it later. With that fixed, 2. applies to both failures and "successes" with no progress. If we have done a periodic reclaim on a space_info and nothing has changed in that space_info, there is not much point to trying again, so don't, until some space gets free. Signed-off-by: Boris Burkov --- fs/btrfs/block-group.c | 3 ++- fs/btrfs/space-info.c | 6 ++++++ fs/btrfs/space-info.h | 6 ++++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/fs/btrfs/block-group.c b/fs/btrfs/block-group.c index 1a752a8a1bea..41b9320d3d3b 100644 --- a/fs/btrfs/block-group.c +++ b/fs/btrfs/block-group.c @@ -1871,7 +1871,7 @@ void btrfs_reclaim_bgs_work(struct work_struct *work) } next: - if (ret) + if (ret && !READ_ONCE(space_info->periodic_reclaim)) btrfs_mark_bg_to_reclaim(bg); btrfs_put_block_group(bg); @@ -3580,6 +3580,7 @@ int btrfs_update_block_group(struct btrfs_trans_handle *trans, space_info->bytes_used -= num_bytes; space_info->disk_used -= num_bytes * factor; + space_info->periodic_reclaim_ready = true; reclaim = should_reclaim_block_group(cache, num_bytes); spin_unlock(&cache->lock); diff --git a/fs/btrfs/space-info.c b/fs/btrfs/space-info.c index 7ec775979637..bef4d29c07dd 100644 --- a/fs/btrfs/space-info.c +++ b/fs/btrfs/space-info.c @@ -1968,6 +1968,12 @@ static int do_reclaim_sweep(struct btrfs_fs_info *fs_info, bool urgent; spin_lock(&space_info->lock); + if (space_info->periodic_reclaim_ready) { + space_info->periodic_reclaim_ready = false; + } else { + spin_unlock(&space_info->lock); + return 0; + } urgent = is_reclaim_urgent(space_info); thresh_pct = btrfs_calc_reclaim_threshold(space_info); spin_unlock(&space_info->lock); diff --git a/fs/btrfs/space-info.h b/fs/btrfs/space-info.h index 2917bc4247db..e6e3f82c2409 100644 --- a/fs/btrfs/space-info.h +++ b/fs/btrfs/space-info.h @@ -175,6 +175,12 @@ struct btrfs_space_info { * threshold in the cleaner thread. */ bool periodic_reclaim; + + /* + * Periodic reclaim should be a no-op if a space_info hasn't + * freed any space since the last time we tried. + */ + bool periodic_reclaim_ready; }; struct reserve_ticket {