Skip to content

RFC: assorted bcachefs patches

Kent Overstreet linux-block linux-btrfs linux-fsdevel linux-mm lkml 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 Latest10 patches 36 repliesIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/10mempool: Add mempool_init()/mempool_exit()include/linux/mempool.h mm/mempool.c+115 -271 reply
1/10mm: pagecache add lockfs/inode.c include/linux/fs.h include/linux/sched.h +2 more+115 -57 replies
2/10block: Convert bio_set to mempool_init()block/bio-integrity.c block/bio.c include/linux/bio.h+36 -391 reply
2/10mm: export find_get_pages()mm/filemap.c+1 -01 reply
3/10block: Add bioset_init()/bioset_exit()block/bio.c include/linux/bio.h+67 -281 reply
3/10locking: bring back lglocksinclude/linux/lglock.h kernel/locking/Makefile kernel/locking/lglock.c+203 -04 replies
4/10block: Use bioset_init() for fs_bio_setblock/bio.c block/blk-core.c drivers/target/target_core_iblock.c +1 more+7 -80 replies
4/10locking: export osq_lock()/osq_unlock()kernel/locking/osq_lock.c+2 -06 replies
5/10block: Add bio_copy_data_iter(), zero_fill_bio_iter()block/bio.c include/linux/bio.h+39 -230 replies
5/10don't use spin_lock_irqsave() unnecessarilymm/page-writeback.c+2 -31 reply
6/10block: Split out bio_list_copy_data()block/bio.c drivers/block/pktcdvd.c include/linux/bio.h+55 -350 replies
6/10Generic radix treesinclude/linux/generic-radix-tree.h lib/Makefile lib/generic-radix-tree.c+300 -12 replies
7/10block: Add missing flush_dcache_page() callblock/bio.c+2 -00 replies
7/10bcache: optimize continue_at_nobarrier()drivers/md/bcache/closure.h+8 -30 replies
8/10block: Add warning for bi_next not NULL in bio_endio()block/bio.c block/blk-core.c+10 -11 reply
8/10bcache: move closures to lib/drivers/md/bcache/Kconfig drivers/md/bcache/Makefile drivers/md/bcache/bcache.h +7 more+36 -341 reply
9/10block: Export bio check/set pages_dirtyblock/bio.c+2 -00 replies
9/10closures: closure_wait_event()include/linux/closure.h+22 -00 replies
10/10block: Add sysfs entry for fua supportblock/blk-sysfs.c+11 -00 replies
10/10Dynamic fault injectioninclude/asm-generic/vmlinux.lds.h include/linux/dynamic_fault.h lib/Kconfig.debug +2 more+888 -05 replies

Reviews trailers per patch

8 of 20 patches have a Reviewed-by or Acked-by.

PatchJohannes Thumshirn
1/10R-b
1/10R-b
2/10R-b
2/10R-b
3/10R-b
3/10R-b
4/10
4/10
5/10
5/10
6/10
6/10
7/10
7/10
8/10R-b
8/10R-b
9/10
9/10
10/10
10/10

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v1 thread

Cover letter [PATCH 00/10] RFC: assorted bcachefs patches

These are all the remaining patches in my bcachefs tree that touch stuff outside fs/bcachefs. Not all of them are suitable for inclusion as is, I wanted to get some discussion first.

* pagecache add lock

This is the only one that touches existing code in nontrivial ways. The problem it's solving is that there is no existing general mechanism for shooting down pages in the page and keeping them removed, which is a real problem if you're doing anything that modifies file data and isn't buffered writes.

Historically, the only problematic case has been direct IO, and people have been willing to say "well, if you mix buffered and direct IO you get what you deserve", and that's probably not unreasonable. But now we have fallocate insert range and collapse range, and those are broken in ways I frankly don't want to think about if they can't ensure consistency with the page cache.

Also, the mechanism truncate uses (i_size and sacrificing a goat) has historically been rather fragile, IMO it might be a good think if we switched it to a more general rigorous mechanism.

I need this solved for bcachefs because without this mechanism, the page cache inconsistencies lead to various assertions popping (primarily when we didn't think we need to get a disk reservation going by page cache state, but then do the actual write and disk space accounting says oops, we did need one). And having to reason about what can happen without a locking mechanism for this is not something I care to spend brain cycles on.

That said, my patch is kind of ugly, and it requires filesystem changes for other filesystems to take advantage of it. And unfortunately, since one of the code paths that needs locking is readahead, I don't see any realistic way of implementing the locking within just bcachefs code.

So I'm hoping someone has an idea for something cleaner (I think I recall Matthew Wilcox saying he had an idea for how to use xarray to solve this), but if not I'll polish up my pagecache add lock patch and see what I can do to make it less ugly, and hopefully other people find it palatable or at least useful.

* lglocks

They were removed by Peter Zijlstra when the last in kernel user was removed, but I've found them useful. His commit message seems to imply he doesn't think people should be using them, but I'm not sure why. They are a bit niche though, I can move them to fs/bcachefs if people would prefer.

* Generic radix trees

This is a very simple radix tree implementation that can store types of arbitrary size, not just pointers/unsigned long. It could probably replace flex arrays.

* Dynamic fault injection

I've actually had this code sitting in my tree since forever... I know we have an existing fault injection framework, but I think this one is quite a bit nicer to actually use.

It works very much like the dynamic debug infrastructure - for those who aren't familiar, dynamic debug makes it so you can list and individually enable/disable every pr_debug() callsite in debugfs.

So to add a fault injection site with this, you just stick a call to dynamic_fault("foobar") somewhere in your code - dynamic_fault() returns true if you should fail whatever it is you're testing. And then it'll show up in debugfs, where you can enable/disable faults by file/linenumber, module, name, etc.

The patch then also adds macros that wrap all the various memory allocation functions and fail if dynamic_fault("memory") returns true - which means you can see in debugfs every place you're allocating memory and fail all of them or just individually (I have tests that iterate over all the faults and flip them on one by one). I also use it in bcachefs to add fault injection points for uncommon error paths in the filesystem startup/recovery path, and for various hard to test slowpaths that only happen if we race in weird ways (race_fault()).

Kent Overstreet (10):
mm: pagecache add lock
mm: export find_get_pages()
locking: bring back lglocks
locking: export osq_lock()/osq_unlock()
don't use spin_lock_irqsave() unnecessarily
Generic radix trees
bcache: optimize continue_at_nobarrier()
bcache: move closures to lib/
closures: closure_wait_event()
Dynamic fault injection

 drivers/md/bcache/Kconfig                     |  10 +-
 drivers/md/bcache/Makefile                    |   6 +-
 drivers/md/bcache/bcache.h                    |   2 +-
 drivers/md/bcache/super.c                     |   1 -
 drivers/md/bcache/util.h                      |   3 +-
 fs/inode.c                                    |   1 +
 include/asm-generic/vmlinux.lds.h             |   4 +
 .../md/bcache => include/linux}/closure.h     |  50 +-
 include/linux/dynamic_fault.h                 | 117 +++
 include/linux/fs.h                            |  23 +
 include/linux/generic-radix-tree.h            | 131 +++
 include/linux/lglock.h                        |  97 +++
 include/linux/sched.h                         |   4 +
 init/init_task.c                              |   1 +
 kernel/locking/Makefile                       |   1 +
 kernel/locking/lglock.c                       | 105 +++
 kernel/locking/osq_lock.c                     |   2 +
 lib/Kconfig                                   |   3 +
 lib/Kconfig.debug                             |  14 +
 lib/Makefile                                  |   7 +-
 {drivers/md/bcache => lib}/closure.c          |  17 +-
 lib/dynamic_fault.c                           | 760 ++++++++++++++++++
 lib/generic-radix-tree.c                      | 167 ++++
 mm/filemap.c                                  |  92 ++-
 mm/page-writeback.c                           |   5 +-
 25 files changed, 1577 insertions(+), 46 deletions(-)
 rename {drivers/md/bcache => include/linux}/closure.h (92%)
 create mode 100644 include/linux/dynamic_fault.h
 create mode 100644 include/linux/generic-radix-tree.h
 create mode 100644 include/linux/lglock.h
 create mode 100644 kernel/locking/lglock.c
 rename {drivers/md/bcache => lib}/closure.c (95%)
 create mode 100644 lib/dynamic_fault.c
 create mode 100644 lib/generic-radix-tree.c
Signature · 1 line
2.17.0