Commit c7ce813f authored by Kent Overstreet's avatar Kent Overstreet Committed by Kent Overstreet

bcachefs: Add a tracepoint for the btree cache shrinker

This is to help with diagnosing why the btree node can doesn't seem to
be shrinking - we've had issues in the past with granularity/batch size,
since btree nodes are so big.
Signed-off-by: default avatarKent Overstreet <kent.overstreet@gmail.com>
parent d93cf685
......@@ -275,6 +275,7 @@ static unsigned long bch2_btree_cache_scan(struct shrinker *shrink,
unsigned long touched = 0;
unsigned long freed = 0;
unsigned i, flags;
unsigned long ret = SHRINK_STOP;
if (bch2_btree_shrinker_disabled)
return SHRINK_STOP;
......@@ -283,7 +284,7 @@ static unsigned long bch2_btree_cache_scan(struct shrinker *shrink,
if (sc->gfp_mask & __GFP_FS)
mutex_lock(&bc->lock);
else if (!mutex_trylock(&bc->lock))
return -1;
goto out_norestore;
flags = memalloc_nofs_save();
......@@ -358,8 +359,14 @@ static unsigned long bch2_btree_cache_scan(struct shrinker *shrink,
mutex_unlock(&bc->lock);
out:
ret = (unsigned long) freed * btree_pages(c);
memalloc_nofs_restore(flags);
return (unsigned long) freed * btree_pages(c);
out_norestore:
trace_btree_cache_scan(sc->nr_to_scan,
sc->nr_to_scan / btree_pages(c),
btree_cache_can_free(bc),
ret);
return ret;
}
static unsigned long bch2_btree_cache_count(struct shrinker *shrink,
......
......@@ -318,6 +318,34 @@ DEFINE_EVENT(btree_node, btree_set_root,
TP_ARGS(c, b)
);
TRACE_EVENT(btree_cache_scan,
TP_PROTO(unsigned long nr_to_scan_pages,
unsigned long nr_to_scan_nodes,
unsigned long can_free_nodes,
long ret),
TP_ARGS(nr_to_scan_pages, nr_to_scan_nodes, can_free_nodes, ret),
TP_STRUCT__entry(
__field(unsigned long, nr_to_scan_pages )
__field(unsigned long, nr_to_scan_nodes )
__field(unsigned long, can_free_nodes )
__field(long, ret )
),
TP_fast_assign(
__entry->nr_to_scan_pages = nr_to_scan_pages;
__entry->nr_to_scan_nodes = nr_to_scan_nodes;
__entry->can_free_nodes = can_free_nodes;
__entry->ret = ret;
),
TP_printk("scanned for %lu pages, %lu nodes, can free %lu nodes, ret %li",
__entry->nr_to_scan_pages,
__entry->nr_to_scan_nodes,
__entry->can_free_nodes,
__entry->ret)
);
/* Garbage collection */
DEFINE_EVENT(btree_node, btree_gc_rewrite_node,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment