Skip to content

Commit

Permalink
bcachefs: Use mm_account_reclaimed_pages() when freeing btree nodes
Browse files Browse the repository at this point in the history
When freeing in a shrinker callback, we need to notify memory reclaim,
so it knows forward progress has been made.

Normally this is done in e.g. slab code, but we're not freeing through
slab - or rather we are, but these allocations are big, and use the
kmalloc_large() path.

This is really a bug in the slub code, but we're working around it here
for now.

Signed-off-by: Kent Overstreet <[email protected]>
  • Loading branch information
Kent Overstreet committed Sep 5, 2024
1 parent 7abab86 commit 9b6737e
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions fs/bcachefs/btree_cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

#include <linux/prefetch.h>
#include <linux/sched/mm.h>
#include <linux/swap.h>

#define BTREE_CACHE_NOT_FREED_INCREMENT(counter) \
do { \
Expand Down Expand Up @@ -63,6 +64,16 @@ static void btree_node_data_free(struct bch_fs *c, struct btree *b)
{
struct btree_cache *bc = &c->btree_cache;

/*
* This should really be done in slub/vmalloc, but we're using the
* kmalloc_large() path, so we're working around a slub bug by doing
* this here:
*/
if (b->data)
mm_account_reclaimed_pages(btree_buf_bytes(b) / PAGE_SIZE);
if (b->aux_data)
mm_account_reclaimed_pages(btree_aux_data_bytes(b) / PAGE_SIZE);

EBUG_ON(btree_node_write_in_flight(b));

clear_btree_node_just_written(b);
Expand Down

0 comments on commit 9b6737e

Please sign in to comment.