diff options
author | Kent Overstreet <kent.overstreet@gmail.com> | 2022-04-04 03:36:32 +0300 |
---|---|---|
committer | Kent Overstreet <kent.overstreet@linux.dev> | 2023-10-23 00:09:30 +0300 |
commit | 7c7e071d90ac278e462640570d739dd165d3acd0 (patch) | |
tree | cf32fcc59e4b382afe0776565de25bffebea0021 | |
parent | 4254f5bf6e3d62ab7108a556d5afc54188e17041 (diff) | |
download | linux-7c7e071d90ac278e462640570d739dd165d3acd0.tar.xz |
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>
-rw-r--r-- | fs/bcachefs/btree_cache.c | 13 | ||||
-rw-r--r-- | fs/bcachefs/trace.h | 28 |
2 files changed, 14 insertions, 27 deletions
diff --git a/fs/bcachefs/btree_cache.c b/fs/bcachefs/btree_cache.c index 92a8cc704cab..0e3db9ee65d2 100644 --- a/fs/bcachefs/btree_cache.c +++ b/fs/bcachefs/btree_cache.c @@ -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); diff --git a/fs/bcachefs/trace.h b/fs/bcachefs/trace.h index eeacb5291764..de6a17c92f5f 100644 --- a/fs/bcachefs/trace.h +++ b/fs/bcachefs/trace.h @@ -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, |