|
22 | 22 | #include "buckets.h" |
23 | 23 | #include "clock.h" |
24 | 24 | #include "compress.h" |
| 25 | +#include "disk_accounting.h" |
25 | 26 | #include "disk_groups.h" |
26 | 27 | #include "ec.h" |
27 | 28 | #include "inode.h" |
@@ -255,91 +256,42 @@ static size_t bch2_btree_cache_size(struct bch_fs *c) |
255 | 256 |
|
256 | 257 | static int bch2_compression_stats_to_text(struct printbuf *out, struct bch_fs *c) |
257 | 258 | { |
258 | | - struct btree_trans *trans; |
259 | | - enum btree_id id; |
260 | | - struct compression_type_stats { |
261 | | - u64 nr_extents; |
262 | | - u64 sectors_compressed; |
263 | | - u64 sectors_uncompressed; |
264 | | - } s[BCH_COMPRESSION_TYPE_NR]; |
265 | | - u64 compressed_incompressible = 0; |
266 | | - int ret = 0; |
267 | | - |
268 | | - memset(s, 0, sizeof(s)); |
269 | | - |
270 | | - if (!test_bit(BCH_FS_started, &c->flags)) |
271 | | - return -EPERM; |
272 | | - |
273 | | - trans = bch2_trans_get(c); |
274 | | - |
275 | | - for (id = 0; id < BTREE_ID_NR; id++) { |
276 | | - if (!btree_type_has_ptrs(id)) |
277 | | - continue; |
278 | | - |
279 | | - ret = for_each_btree_key(trans, iter, id, POS_MIN, |
280 | | - BTREE_ITER_all_snapshots, k, ({ |
281 | | - struct bkey_ptrs_c ptrs = bch2_bkey_ptrs_c(k); |
282 | | - struct bch_extent_crc_unpacked crc; |
283 | | - const union bch_extent_entry *entry; |
284 | | - bool compressed = false, incompressible = false; |
285 | | - |
286 | | - bkey_for_each_crc(k.k, ptrs, crc, entry) { |
287 | | - incompressible |= crc.compression_type == BCH_COMPRESSION_TYPE_incompressible; |
288 | | - compressed |= crc_is_compressed(crc); |
289 | | - |
290 | | - if (crc_is_compressed(crc)) { |
291 | | - s[crc.compression_type].nr_extents++; |
292 | | - s[crc.compression_type].sectors_compressed += crc.compressed_size; |
293 | | - s[crc.compression_type].sectors_uncompressed += crc.uncompressed_size; |
294 | | - } |
295 | | - } |
296 | | - |
297 | | - compressed_incompressible += compressed && incompressible; |
298 | | - |
299 | | - if (!compressed) { |
300 | | - unsigned t = incompressible ? BCH_COMPRESSION_TYPE_incompressible : 0; |
301 | | - |
302 | | - s[t].nr_extents++; |
303 | | - s[t].sectors_compressed += k.k->size; |
304 | | - s[t].sectors_uncompressed += k.k->size; |
305 | | - } |
306 | | - 0; |
307 | | - })); |
308 | | - } |
309 | | - |
310 | | - bch2_trans_put(trans); |
311 | | - |
312 | | - if (ret) |
313 | | - return ret; |
314 | | - |
| 259 | + prt_str(out, "type"); |
315 | 260 | printbuf_tabstop_push(out, 12); |
316 | 261 | printbuf_tabstop_push(out, 16); |
317 | 262 | printbuf_tabstop_push(out, 16); |
318 | 263 | printbuf_tabstop_push(out, 24); |
319 | 264 | prt_printf(out, "type\tcompressed\runcompressed\raverage extent size\r\n"); |
320 | 265 |
|
321 | | - for (unsigned i = 0; i < ARRAY_SIZE(s); i++) { |
| 266 | + for (unsigned i = 1; i < BCH_COMPRESSION_TYPE_NR; i++) { |
| 267 | + struct disk_accounting_pos a = { |
| 268 | + .type = BCH_DISK_ACCOUNTING_compression, |
| 269 | + .compression.type = i, |
| 270 | + }; |
| 271 | + struct bpos p = disk_accounting_pos_to_bpos(&a); |
| 272 | + u64 v[3]; |
| 273 | + bch2_accounting_mem_read(c, p, v, ARRAY_SIZE(v)); |
| 274 | + |
| 275 | + u64 nr_extents = v[0]; |
| 276 | + u64 sectors_uncompressed = v[1]; |
| 277 | + u64 sectors_compressed = v[2]; |
| 278 | + |
322 | 279 | bch2_prt_compression_type(out, i); |
323 | 280 | prt_tab(out); |
324 | 281 |
|
325 | | - prt_human_readable_u64(out, s[i].sectors_compressed << 9); |
| 282 | + prt_human_readable_u64(out, sectors_compressed << 9); |
326 | 283 | prt_tab_rjust(out); |
327 | 284 |
|
328 | | - prt_human_readable_u64(out, s[i].sectors_uncompressed << 9); |
| 285 | + prt_human_readable_u64(out, sectors_uncompressed << 9); |
329 | 286 | prt_tab_rjust(out); |
330 | 287 |
|
331 | | - prt_human_readable_u64(out, s[i].nr_extents |
332 | | - ? div_u64(s[i].sectors_uncompressed << 9, s[i].nr_extents) |
| 288 | + prt_human_readable_u64(out, nr_extents |
| 289 | + ? div_u64(sectors_uncompressed << 9, nr_extents) |
333 | 290 | : 0); |
334 | 291 | prt_tab_rjust(out); |
335 | 292 | prt_newline(out); |
336 | 293 | } |
337 | 294 |
|
338 | | - if (compressed_incompressible) { |
339 | | - prt_printf(out, "%llu compressed & incompressible extents", compressed_incompressible); |
340 | | - prt_newline(out); |
341 | | - } |
342 | | - |
343 | 295 | return 0; |
344 | 296 | } |
345 | 297 |
|
|
0 commit comments