From: Kent Overstreet <kent.overstreet@linux.dev>
To: linux-bcachefs@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: Kent Overstreet <kent.overstreet@linux.dev>,
djwong@kernel.org, bfoster@redhat.com
Subject: [PATCH 18/21] bcachefs: bch_acct_compression
Date: Sat, 24 Feb 2024 21:38:20 -0500 [thread overview]
Message-ID: <20240225023826.2413565-19-kent.overstreet@linux.dev> (raw)
In-Reply-To: <20240225023826.2413565-1-kent.overstreet@linux.dev>
This adds per-compression-type accounting of compressed and uncompressed
size as well as number of extents - meaning we can now see compression
ratio (without walking the whole filesystem).
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
---
fs/bcachefs/buckets.c | 45 ++++++++++++++++++++++++----
fs/bcachefs/disk_accounting.c | 4 +++
fs/bcachefs/disk_accounting_format.h | 8 ++++-
3 files changed, 51 insertions(+), 6 deletions(-)
diff --git a/fs/bcachefs/buckets.c b/fs/bcachefs/buckets.c
index 506bb580bff4..6078b67e51cf 100644
--- a/fs/bcachefs/buckets.c
+++ b/fs/bcachefs/buckets.c
@@ -503,6 +503,7 @@ static int __trigger_extent(struct btree_trans *trans,
: BCH_DATA_user;
s64 dirty_sectors = 0;
int ret = 0;
+ u64 compression_acct[3] = { 1, 0, 0 };
struct disk_accounting_key acc = {
.type = BCH_DISK_ACCOUNTING_replicas,
@@ -511,6 +512,10 @@ static int __trigger_extent(struct btree_trans *trans,
.replicas.nr_required = 1,
};
+ struct disk_accounting_key compression_key = {
+ .type = BCH_DISK_ACCOUNTING_compression,
+ };
+
bkey_for_each_ptr_decode(k.k, ptrs, p, entry) {
s64 disk_sectors;
ret = bch2_trigger_pointer(trans, btree_id, level, k, p, &disk_sectors, flags);
@@ -519,12 +524,13 @@ static int __trigger_extent(struct btree_trans *trans,
bool stale = ret > 0;
+ if (p.ptr.cached && stale)
+ continue;
+
if (p.ptr.cached) {
- if (!stale) {
- ret = bch2_mod_dev_cached_sectors(trans, p.ptr.dev, disk_sectors, gc);
- if (ret)
- return ret;
- }
+ ret = bch2_mod_dev_cached_sectors(trans, p.ptr.dev, disk_sectors, gc);
+ if (ret)
+ return ret;
} else if (!p.has_ec) {
dirty_sectors += disk_sectors;
acc.replicas.devs[acc.replicas.nr_devs++] = p.ptr.dev;
@@ -540,6 +546,26 @@ static int __trigger_extent(struct btree_trans *trans,
*/
acc.replicas.nr_required = 0;
}
+
+ if (compression_key.compression.type &&
+ compression_key.compression.type != p.crc.compression_type) {
+ if (flags & BTREE_TRIGGER_OVERWRITE)
+ bch2_u64s_neg(compression_acct, 3);
+
+ ret = bch2_disk_accounting_mod(trans, &compression_key, compression_acct, 2, gc);
+ if (ret)
+ return ret;
+
+ compression_acct[0] = 1;
+ compression_acct[1] = 0;
+ compression_acct[2] = 0;
+ }
+
+ compression_key.compression.type = p.crc.compression_type;
+ if (p.crc.compression_type) {
+ compression_acct[1] += p.crc.uncompressed_size;
+ compression_acct[2] += p.crc.compressed_size;
+ }
}
if (acc.replicas.nr_devs) {
@@ -548,6 +574,15 @@ static int __trigger_extent(struct btree_trans *trans,
return ret;
}
+ if (compression_key.compression.type) {
+ if (flags & BTREE_TRIGGER_OVERWRITE)
+ bch2_u64s_neg(compression_acct, 3);
+
+ ret = bch2_disk_accounting_mod(trans, &compression_key, compression_acct, 3, gc);
+ if (ret)
+ return ret;
+ }
+
return 0;
}
diff --git a/fs/bcachefs/disk_accounting.c b/fs/bcachefs/disk_accounting.c
index 8d7b6ab66e71..dc020d651d0a 100644
--- a/fs/bcachefs/disk_accounting.c
+++ b/fs/bcachefs/disk_accounting.c
@@ -5,6 +5,7 @@
#include "btree_update.h"
#include "btree_write_buffer.h"
#include "buckets.h"
+#include "compress.h"
#include "disk_accounting.h"
#include "error.h"
#include "journal_io.h"
@@ -91,6 +92,9 @@ void bch2_accounting_key_to_text(struct printbuf *out, struct disk_accounting_ke
case BCH_DISK_ACCOUNTING_dev_stripe_buckets:
prt_printf(out, "dev=%u", k->dev_stripe_buckets.dev);
break;
+ case BCH_DISK_ACCOUNTING_compression:
+ bch2_prt_compression_type(out, k->compression.type);
+ break;
}
}
diff --git a/fs/bcachefs/disk_accounting_format.h b/fs/bcachefs/disk_accounting_format.h
index e06a42f0d578..75bfc9bce79f 100644
--- a/fs/bcachefs/disk_accounting_format.h
+++ b/fs/bcachefs/disk_accounting_format.h
@@ -95,7 +95,8 @@ static inline bool data_type_is_hidden(enum bch_data_type type)
x(persistent_reserved, 1) \
x(replicas, 2) \
x(dev_data_type, 3) \
- x(dev_stripe_buckets, 4)
+ x(dev_stripe_buckets, 4) \
+ x(compression, 5)
enum disk_accounting_type {
#define x(f, nr) BCH_DISK_ACCOUNTING_##f = nr,
@@ -120,6 +121,10 @@ struct bch_dev_stripe_buckets {
__u8 dev;
};
+struct bch_acct_compression {
+ __u8 type;
+};
+
struct disk_accounting_key {
union {
struct {
@@ -130,6 +135,7 @@ struct disk_accounting_key {
struct bch_replicas_entry_v1 replicas;
struct bch_dev_data_type dev_data_type;
struct bch_dev_stripe_buckets dev_stripe_buckets;
+ struct bch_acct_compression compression;
};
};
struct bpos _pad;
--
2.43.0
next prev parent reply other threads:[~2024-02-25 2:38 UTC|newest]
Thread overview: 39+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-02-25 2:38 [PATCH 00/21] bcachefs disk accounting rewrite Kent Overstreet
2024-02-25 2:38 ` [PATCH 01/21] bcachefs: KEY_TYPE_accounting Kent Overstreet
2024-02-27 15:49 ` Brian Foster
2024-02-28 19:39 ` Kent Overstreet
2024-02-29 18:43 ` Brian Foster
2024-02-29 21:24 ` Kent Overstreet
2024-03-01 15:03 ` Brian Foster
2024-03-01 19:30 ` Kent Overstreet
2024-02-25 2:38 ` [PATCH 02/21] bcachefs: Accumulate accounting keys in journal replay Kent Overstreet
2024-02-27 15:49 ` Brian Foster
2024-02-28 20:06 ` Kent Overstreet
2024-02-25 2:38 ` [PATCH 03/21] bcachefs: btree write buffer knows how to accumulate bch_accounting keys Kent Overstreet
2024-02-27 15:50 ` Brian Foster
2024-02-28 22:42 ` Kent Overstreet
2024-02-29 18:44 ` Brian Foster
2024-02-29 20:25 ` Kent Overstreet
2024-02-25 2:38 ` [PATCH 04/21] bcachefs: Disk space accounting rewrite Kent Overstreet
2024-02-27 15:55 ` Brian Foster
2024-02-29 4:10 ` Kent Overstreet
2024-02-29 18:44 ` Brian Foster
2024-02-29 21:16 ` Kent Overstreet
2024-03-01 15:03 ` Brian Foster
2024-02-25 2:38 ` [PATCH 05/21] bcachefs: dev_usage updated by new accounting Kent Overstreet
2024-02-25 2:38 ` [PATCH 06/21] bcachefs: Kill bch2_fs_usage_initialize() Kent Overstreet
2024-02-25 2:38 ` [PATCH 07/21] bcachefs: Convert bch2_ioctl_fs_usage() to new accounting Kent Overstreet
2024-02-25 2:38 ` [PATCH 08/21] bcachefs: kill bch2_fs_usage_read() Kent Overstreet
2024-02-25 2:38 ` [PATCH 09/21] bcachefs: Kill writing old accounting to journal Kent Overstreet
2024-02-25 2:38 ` [PATCH 10/21] bcachefs: Delete journal-buf-sharded old style accounting Kent Overstreet
2024-02-25 2:38 ` [PATCH 11/21] bcachefs: Kill bch2_fs_usage_to_text() Kent Overstreet
2024-02-25 2:38 ` [PATCH 12/21] bcachefs: Kill fs_usage_online Kent Overstreet
2024-02-25 2:38 ` [PATCH 13/21] bcachefs: Kill replicas_journal_res Kent Overstreet
2024-02-25 2:38 ` [PATCH 14/21] bcachefs: Convert gc to new accounting Kent Overstreet
2024-02-25 2:38 ` [PATCH 15/21] bcachefs: Convert bch2_replicas_gc2() " Kent Overstreet
2024-02-25 2:38 ` [PATCH 16/21] bcachefs: bch2_verify_accounting_clean() Kent Overstreet
2024-02-25 2:38 ` [PATCH 17/21] bcachefs: Eytzinger accumulation for accounting keys Kent Overstreet
2024-02-25 2:38 ` Kent Overstreet [this message]
2024-02-25 2:38 ` [PATCH 19/21] bcachefs: Convert bch2_compression_stats_to_text() to new accounting Kent Overstreet
2024-02-25 2:38 ` [PATCH 20/21] bcachefs: bch2_fs_accounting_to_text() Kent Overstreet
2024-02-25 2:38 ` [PATCH 21/21] bcachefs: bch2_fs_usage_base_to_text() Kent Overstreet
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240225023826.2413565-19-kent.overstreet@linux.dev \
--to=kent.overstreet@linux.dev \
--cc=bfoster@redhat.com \
--cc=djwong@kernel.org \
--cc=linux-bcachefs@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox