mbox series

[v3,00/10] btrfs: add a shrinker for extent maps

Message ID cover.1713267925.git.fdmanana@suse.com (mailing list archive)
Headers show
Series btrfs: add a shrinker for extent maps | expand

Message

Filipe Manana April 16, 2024, 1:08 p.m. UTC
From: Filipe Manana <fdmanana@suse.com>

Currently we don't limit the amount of extent maps we can have for inodes
from a subvolume tree, which can result in excessive use of memory and in
some cases in running into OOM situations. This was reported some time ago
by a user and it's specially easier to trigger with direct IO.

The shrinker itself is patch 08/10, what comes before is simple preparatory
work and the rest just trace events. More details in the change logs.

V3: Removed some preparatory patches that are already in for-next.

    Updated patch 07/10 to avoid a lockdep warning due to attempt to read
    the percpu counter when freeing fs_info if during the open_ctree()
    path we had an error before initializing the counter. Reported by the
    Intel test robot.

    Update the shrinker patch (08/10) to use the nr_cached_objects and
    free_cached_objects callbacks of struct super_operations.
    Make the shrinker remember the last inode and root it processed, so
    that it starts from there the next time it runs.
    Also avoid a deadlock when trying to lock the mmap lock, not use a
    down_read_trylock() and comment about it.
    Avoid setting the inode full sync flag if an extent in the list of
    modified extents is from an older generation, whose transaction was
    already committed and therefore the file extent item was persisted.

V2: Split patch 09/11 into 3.
    Added two patches to export and use helper to find inode in a root.
    Updated patch 13/15 to use the helper for finding next inode and
    removed the #ifdef for 32 bits case which is irrelevant as on 32 bits
    systems we can't ever have more than ULONG_MAX extent maps allocated.

Filipe Manana (10):
  btrfs: pass the extent map tree's inode to add_extent_mapping()
  btrfs: pass the extent map tree's inode to clear_em_logging()
  btrfs: pass the extent map tree's inode to remove_extent_mapping()
  btrfs: pass the extent map tree's inode to replace_extent_mapping()
  btrfs: pass the extent map tree's inode to setup_extent_mapping()
  btrfs: pass the extent map tree's inode to try_merge_map()
  btrfs: add a global per cpu counter to track number of used extent maps
  btrfs: add a shrinker for extent maps
  btrfs: update comment for btrfs_set_inode_full_sync() about locking
  btrfs: add tracepoints for extent map shrinker events

 fs/btrfs/btrfs_inode.h            |   8 +-
 fs/btrfs/disk-io.c                |   9 +
 fs/btrfs/extent_io.c              |   2 +-
 fs/btrfs/extent_map.c             | 277 +++++++++++++++++++++++++-----
 fs/btrfs/extent_map.h             |   5 +-
 fs/btrfs/fs.h                     |   4 +
 fs/btrfs/super.c                  |  20 +++
 fs/btrfs/tests/extent-map-tests.c |  19 +-
 fs/btrfs/tree-log.c               |   4 +-
 include/trace/events/btrfs.h      |  99 +++++++++++
 10 files changed, 388 insertions(+), 59 deletions(-)