diff options
Diffstat (limited to 'fs/bcachefs/sysfs.c')
| -rw-r--r-- | fs/bcachefs/sysfs.c | 178 | 
1 files changed, 26 insertions, 152 deletions
diff --git a/fs/bcachefs/sysfs.c b/fs/bcachefs/sysfs.c index 5be92fe3f4ea..93ca74d108b1 100644 --- a/fs/bcachefs/sysfs.c +++ b/fs/bcachefs/sysfs.c @@ -140,9 +140,8 @@ write_attribute(trigger_gc);  write_attribute(trigger_discards);  write_attribute(trigger_invalidates);  write_attribute(trigger_journal_flush); -write_attribute(prune_cache); -write_attribute(btree_wakeup); -rw_attribute(btree_gc_periodic); +write_attribute(trigger_btree_cache_shrink); +write_attribute(trigger_btree_key_cache_shrink);  rw_attribute(gc_gens_pos);  read_attribute(uuid); @@ -189,12 +188,8 @@ static void bch2_write_refs_to_text(struct printbuf *out, struct bch_fs *c)  {  	bch2_printbuf_tabstop_push(out, 24); -	for (unsigned i = 0; i < ARRAY_SIZE(c->writes); i++) { -		prt_str(out, bch2_write_refs[i]); -		prt_tab(out); -		prt_printf(out, "%li", atomic_long_read(&c->writes[i])); -		prt_newline(out); -	} +	for (unsigned i = 0; i < ARRAY_SIZE(c->writes); i++) +		prt_printf(out, "%s\t%li\n", bch2_write_refs[i], atomic_long_read(&c->writes[i]));  }  #endif @@ -278,7 +273,7 @@ static int bch2_compression_stats_to_text(struct printbuf *out, struct bch_fs *c  			continue;  		ret = for_each_btree_key(trans, iter, id, POS_MIN, -					 BTREE_ITER_ALL_SNAPSHOTS, k, ({ +					 BTREE_ITER_all_snapshots, k, ({  			struct bkey_ptrs_c ptrs = bch2_bkey_ptrs_c(k);  			struct bch_extent_crc_unpacked crc;  			const union bch_extent_entry *entry; @@ -313,22 +308,11 @@ static int bch2_compression_stats_to_text(struct printbuf *out, struct bch_fs *c  	if (ret)  		return ret; -	prt_str(out, "type");  	printbuf_tabstop_push(out, 12); -	prt_tab(out); - -	prt_str(out, "compressed");  	printbuf_tabstop_push(out, 16); -	prt_tab_rjust(out); - -	prt_str(out, "uncompressed");  	printbuf_tabstop_push(out, 16); -	prt_tab_rjust(out); - -	prt_str(out, "average extent size");  	printbuf_tabstop_push(out, 24); -	prt_tab_rjust(out); -	prt_newline(out); +	prt_printf(out, "type\tcompressed\runcompressed\raverage extent size\r\n");  	for (unsigned i = 0; i < ARRAY_SIZE(s); i++) {  		bch2_prt_compression_type(out, i); @@ -362,21 +346,6 @@ static void bch2_gc_gens_pos_to_text(struct printbuf *out, struct bch_fs *c)  	prt_printf(out, "\n");  } -static void bch2_btree_wakeup_all(struct bch_fs *c) -{ -	struct btree_trans *trans; - -	seqmutex_lock(&c->btree_trans_lock); -	list_for_each_entry(trans, &c->btree_trans_list, list) { -		struct btree_bkey_cached_common *b = READ_ONCE(trans->locking); - -		if (b) -			six_lock_wakeup_all(&b->lock); - -	} -	seqmutex_unlock(&c->btree_trans_lock); -} -  SHOW(bch2_fs)  {  	struct bch_fs *c = container_of(kobj, struct bch_fs, kobj); @@ -392,8 +361,6 @@ SHOW(bch2_fs)  	if (attr == &sysfs_btree_write_stats)  		bch2_btree_write_stats_to_text(out, c); -	sysfs_printf(btree_gc_periodic, "%u",	(int) c->btree_gc_periodic); -  	if (attr == &sysfs_gc_gens_pos)  		bch2_gc_gens_pos_to_text(out, c); @@ -416,7 +383,7 @@ SHOW(bch2_fs)  		bch2_journal_debug_to_text(out, &c->journal);  	if (attr == &sysfs_btree_cache) -		bch2_btree_cache_to_text(out, c); +		bch2_btree_cache_to_text(out, &c->btree_cache);  	if (attr == &sysfs_btree_key_cache)  		bch2_btree_key_cache_to_text(out, &c->btree_key_cache); @@ -459,6 +426,9 @@ SHOW(bch2_fs)  	if (attr == &sysfs_disk_groups)  		bch2_disk_groups_to_text(out, c); +	if (attr == &sysfs_alloc_debug) +		bch2_fs_alloc_debug_to_text(out, c); +  	return 0;  } @@ -466,14 +436,6 @@ STORE(bch2_fs)  {  	struct bch_fs *c = container_of(kobj, struct bch_fs, kobj); -	if (attr == &sysfs_btree_gc_periodic) { -		ssize_t ret = strtoul_safe(buf, c->btree_gc_periodic) -			?: (ssize_t) size; - -		wake_up_process(c->gc_thread); -		return ret; -	} -  	if (attr == &sysfs_copy_gc_enabled) {  		ssize_t ret = strtoul_safe(buf, c->copy_gc_enabled)  			?: (ssize_t) size; @@ -505,7 +467,7 @@ STORE(bch2_fs)  	if (!bch2_write_ref_tryget(c, BCH_WRITE_REF_sysfs))  		return -EROFS; -	if (attr == &sysfs_prune_cache) { +	if (attr == &sysfs_trigger_btree_cache_shrink) {  		struct shrink_control sc;  		sc.gfp_mask = GFP_KERNEL; @@ -513,22 +475,17 @@ STORE(bch2_fs)  		c->btree_cache.shrink->scan_objects(c->btree_cache.shrink, &sc);  	} -	if (attr == &sysfs_btree_wakeup) -		bch2_btree_wakeup_all(c); - -	if (attr == &sysfs_trigger_gc) { -		/* -		 * Full gc is currently incompatible with btree key cache: -		 */ -#if 0 -		down_read(&c->state_lock); -		bch2_gc(c, false, false); -		up_read(&c->state_lock); -#else -		bch2_gc_gens(c); -#endif +	if (attr == &sysfs_trigger_btree_key_cache_shrink) { +		struct shrink_control sc; + +		sc.gfp_mask = GFP_KERNEL; +		sc.nr_to_scan = strtoul_or_return(buf); +		c->btree_key_cache.shrink->scan_objects(c->btree_cache.shrink, &sc);  	} +	if (attr == &sysfs_trigger_gc) +		bch2_gc_gens(c); +  	if (attr == &sysfs_trigger_discards)  		bch2_do_discards(c); @@ -594,13 +551,11 @@ SHOW(bch2_fs_counters)  		if (attr == &sysfs_##t) {					\  			counter             = percpu_u64_get(&c->counters[BCH_COUNTER_##t]);\  			counter_since_mount = counter - c->counters_on_mount[BCH_COUNTER_##t];\ -			prt_printf(out, "since mount:");				\ -			prt_tab(out);						\ +			prt_printf(out, "since mount:\t");			\  			prt_human_readable_u64(out, counter_since_mount);	\  			prt_newline(out);					\  										\ -			prt_printf(out, "since filesystem creation:");		\ -			prt_tab(out);						\ +			prt_printf(out, "since filesystem creation:\t");	\  			prt_human_readable_u64(out, counter);			\  			prt_newline(out);					\  		} @@ -660,8 +615,8 @@ struct attribute *bch2_fs_internal_files[] = {  	&sysfs_trigger_discards,  	&sysfs_trigger_invalidates,  	&sysfs_trigger_journal_flush, -	&sysfs_prune_cache, -	&sysfs_btree_wakeup, +	&sysfs_trigger_btree_cache_shrink, +	&sysfs_trigger_btree_key_cache_shrink,  	&sysfs_gc_gens_pos, @@ -677,6 +632,7 @@ struct attribute *bch2_fs_internal_files[] = {  	&sysfs_internal_uuid,  	&sysfs_disk_groups, +	&sysfs_alloc_debug,  	NULL  }; @@ -792,88 +748,6 @@ struct attribute *bch2_fs_time_stats_files[] = {  	NULL  }; -static void dev_alloc_debug_to_text(struct printbuf *out, struct bch_dev *ca) -{ -	struct bch_fs *c = ca->fs; -	struct bch_dev_usage stats = bch2_dev_usage_read(ca); -	unsigned i, nr[BCH_DATA_NR]; - -	memset(nr, 0, sizeof(nr)); - -	for (i = 0; i < ARRAY_SIZE(c->open_buckets); i++) -		nr[c->open_buckets[i].data_type]++; - -	printbuf_tabstop_push(out, 8); -	printbuf_tabstop_push(out, 16); -	printbuf_tabstop_push(out, 16); -	printbuf_tabstop_push(out, 16); -	printbuf_tabstop_push(out, 16); - -	bch2_dev_usage_to_text(out, &stats); - -	prt_newline(out); - -	prt_printf(out, "reserves:"); -	prt_newline(out); -	for (i = 0; i < BCH_WATERMARK_NR; i++) { -		prt_str(out, bch2_watermarks[i]); -		prt_tab(out); -		prt_u64(out, bch2_dev_buckets_reserved(ca, i)); -		prt_tab_rjust(out); -		prt_newline(out); -	} - -	prt_newline(out); - -	printbuf_tabstops_reset(out); -	printbuf_tabstop_push(out, 24); - -	prt_str(out, "freelist_wait"); -	prt_tab(out); -	prt_str(out, c->freelist_wait.list.first ? "waiting" : "empty"); -	prt_newline(out); - -	prt_str(out, "open buckets allocated"); -	prt_tab(out); -	prt_u64(out, OPEN_BUCKETS_COUNT - c->open_buckets_nr_free); -	prt_newline(out); - -	prt_str(out, "open buckets this dev"); -	prt_tab(out); -	prt_u64(out, ca->nr_open_buckets); -	prt_newline(out); - -	prt_str(out, "open buckets total"); -	prt_tab(out); -	prt_u64(out, OPEN_BUCKETS_COUNT); -	prt_newline(out); - -	prt_str(out, "open_buckets_wait"); -	prt_tab(out); -	prt_str(out, c->open_buckets_wait.list.first ? "waiting" : "empty"); -	prt_newline(out); - -	prt_str(out, "open_buckets_btree"); -	prt_tab(out); -	prt_u64(out, nr[BCH_DATA_btree]); -	prt_newline(out); - -	prt_str(out, "open_buckets_user"); -	prt_tab(out); -	prt_u64(out, nr[BCH_DATA_user]); -	prt_newline(out); - -	prt_str(out, "buckets_to_invalidate"); -	prt_tab(out); -	prt_u64(out, should_invalidate_buckets(ca, stats)); -	prt_newline(out); - -	prt_str(out, "btree reserve cache"); -	prt_tab(out); -	prt_u64(out, c->btree_reserve_cache_nr); -	prt_newline(out); -} -  static const char * const bch2_rw[] = {  	"read",  	"write", @@ -943,7 +817,7 @@ SHOW(bch2_dev)  		     * 100 / CONGESTED_MAX);  	if (attr == &sysfs_alloc_debug) -		dev_alloc_debug_to_text(out, ca); +		bch2_dev_alloc_debug_to_text(out, ca);  	return 0;  }  |