bcachefs: Don't normalize to pages in btree cache shrinker
This behavior dates from the early, early days of bcache, and upon further delving appears to not make any sense. The shrinker only works in terms of 'objects' of unknown size; normalizing to pages only had the effect of changing the batch size, which we could do directly - if we wanted; we probably don't. Normalizing to pages meant our batch size was very small, which seems to have been keeping us from doing as much shrinking as we should be under heavy memory pressure; this patch appears to alleviate some OOMs we've been seeing. Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
This commit is contained in:
parent
4254f5bf6e
commit
7c7e071d90
@ -280,7 +280,7 @@ static unsigned long bch2_btree_cache_scan(struct shrinker *shrink,
|
||||
struct btree_cache *bc = &c->btree_cache;
|
||||
struct btree *b, *t;
|
||||
unsigned long nr = sc->nr_to_scan;
|
||||
unsigned long can_free;
|
||||
unsigned long can_free = 0;
|
||||
unsigned long touched = 0;
|
||||
unsigned long freed = 0;
|
||||
unsigned i, flags;
|
||||
@ -304,7 +304,6 @@ static unsigned long bch2_btree_cache_scan(struct shrinker *shrink,
|
||||
* succeed, so that inserting keys into the btree can always succeed and
|
||||
* IO can always make forward progress:
|
||||
*/
|
||||
nr /= btree_pages(c);
|
||||
can_free = btree_cache_can_free(bc);
|
||||
nr = min_t(unsigned long, nr, can_free);
|
||||
|
||||
@ -374,13 +373,10 @@ touched:
|
||||
|
||||
mutex_unlock(&bc->lock);
|
||||
out:
|
||||
ret = (unsigned long) freed * btree_pages(c);
|
||||
ret = freed;
|
||||
memalloc_nofs_restore(flags);
|
||||
out_norestore:
|
||||
trace_btree_cache_scan(sc->nr_to_scan,
|
||||
sc->nr_to_scan / btree_pages(c),
|
||||
btree_cache_can_free(bc),
|
||||
ret);
|
||||
trace_btree_cache_scan(sc->nr_to_scan, can_free, ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -394,7 +390,7 @@ static unsigned long bch2_btree_cache_count(struct shrinker *shrink,
|
||||
if (bch2_btree_shrinker_disabled)
|
||||
return 0;
|
||||
|
||||
return btree_cache_can_free(bc) * btree_pages(c);
|
||||
return btree_cache_can_free(bc);
|
||||
}
|
||||
|
||||
void bch2_fs_btree_cache_exit(struct bch_fs *c)
|
||||
@ -481,7 +477,6 @@ int bch2_fs_btree_cache_init(struct bch_fs *c)
|
||||
bc->shrink.count_objects = bch2_btree_cache_count;
|
||||
bc->shrink.scan_objects = bch2_btree_cache_scan;
|
||||
bc->shrink.seeks = 4;
|
||||
bc->shrink.batch = btree_pages(c) * 2;
|
||||
ret = register_shrinker(&bc->shrink, "%s/btree_cache", c->name);
|
||||
out:
|
||||
pr_verbose_init(c->opts, "ret %i", ret);
|
||||
|
@ -376,31 +376,23 @@ DEFINE_EVENT(btree_node, btree_set_root,
|
||||
);
|
||||
|
||||
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_PROTO(long nr_to_scan, long can_free, long ret),
|
||||
TP_ARGS(nr_to_scan, can_free, 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 )
|
||||
__field(long, nr_to_scan )
|
||||
__field(long, can_free )
|
||||
__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;
|
||||
__entry->nr_to_scan = nr_to_scan;
|
||||
__entry->can_free = can_free;
|
||||
__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)
|
||||
TP_printk("scanned for %li nodes, can free %li, ret %li",
|
||||
__entry->nr_to_scan, __entry->can_free, __entry->ret)
|
||||
);
|
||||
|
||||
TRACE_EVENT(btree_node_relock_fail,
|
||||
|
Loading…
x
Reference in New Issue
Block a user