1. 06 12月, 2022 3 次提交
    • J
      btrfs: move file-item prototypes into their own header · 7c8ede16
      Josef Bacik 提交于
      Move these prototypes out of ctree.h and into file-item.h.
      Reviewed-by: NJohannes Thumshirn <johannes.thumshirn@wdc.com>
      Signed-off-by: NJosef Bacik <josef@toxicpanda.com>
      Reviewed-by: NDavid Sterba <dsterba@suse.com>
      Signed-off-by: NDavid Sterba <dsterba@suse.com>
      7c8ede16
    • J
      btrfs: move BTRFS_FS_STATE* definitions and helpers to fs.h · ec8eb376
      Josef Bacik 提交于
      We're going to use fs.h to hold fs wide related helpers and definitions,
      move the FS_STATE enum and related helpers to fs.h, and then update all
      files that need these definitions to include fs.h.
      Reviewed-by: NJohannes Thumshirn <johannes.thumshirn@wdc.com>
      Reviewed-by: NAnand Jain <anand.jain@oracle.com>
      Signed-off-by: NJosef Bacik <josef@toxicpanda.com>
      Reviewed-by: NDavid Sterba <dsterba@suse.com>
      Signed-off-by: NDavid Sterba <dsterba@suse.com>
      ec8eb376
    • Q
      btrfs: make module init/exit match their sequence · 5565b8e0
      Qu Wenruo 提交于
      [BACKGROUND]
      In theory init_btrfs_fs() and exit_btrfs_fs() should match their
      sequence, thus normally they should look like this:
      
          init_btrfs_fs()   |   exit_btrfs_fs()
      ----------------------+------------------------
          init_A();         |
          init_B();         |
          init_C();         |
                            |   exit_C();
                            |   exit_B();
                            |   exit_A();
      
      So is for the error path of init_btrfs_fs().
      
      But it's not the case, some exit functions don't match their init
      functions sequence in init_btrfs_fs().
      
      Furthermore in init_btrfs_fs(), we need to have a new error label for
      each new init function we added.  This is not really expandable,
      especially recently we may add several new functions to init_btrfs_fs().
      
      [ENHANCEMENT]
      The patch will introduce the following things to enhance the situation:
      
      - struct init_sequence
        Just a wrapper of init and exit function pointers.
      
        The init function must use int type as return value, thus some init
        functions need to be updated to return 0.
      
        The exit function can be NULL, as there are some init sequence just
        outputting a message.
      
      - struct mod_init_seq[] array
        This is a const array, recording all the initialization we need to do
        in init_btrfs_fs(), and the order follows the old init_btrfs_fs().
      
      - bool mod_init_result[] array
        This is a bool array, recording if we have initialized one entry in
        mod_init_seq[].
      
        The reason to split mod_init_seq[] and mod_init_result[] is to avoid
        section mismatch in reference.
      
        All init function are in .init.text, but if mod_init_seq[] records
        the @initialized member it can no longer be const, thus will be put
        into .data section, and cause modpost warning.
      
      For init_btrfs_fs() we just call all init functions in their order in
      mod_init_seq[] array, and after each call, setting corresponding
      mod_init_result[] to true.
      
      For exit_btrfs_fs() and error handling path of init_btrfs_fs(), we just
      iterate mod_init_seq[] in reverse order, and skip all uninitialized
      entry.
      
      With this patch, init_btrfs_fs()/exit_btrfs_fs() will be much easier to
      expand and will always follow the strict order.
      Signed-off-by: NQu Wenruo <wqu@suse.com>
      Signed-off-by: NDavid Sterba <dsterba@suse.com>
      5565b8e0
  2. 09 11月, 2022 1 次提交
    • J
      fs: fix leaked psi pressure state · 82e60d00
      Johannes Weiner 提交于
      When psi annotations were added to to btrfs compression reads, the psi
      state tracking over add_ra_bio_pages and btrfs_submit_compressed_read was
      faulty.  A pressure state, once entered, is never left.  This results in
      incorrectly elevated pressure, which triggers OOM kills.
      
      pflags record the *previous* memstall state when we enter a new one.  The
      code tried to initialize pflags to 1, and then optimize the leave call
      when we either didn't enter a memstall, or were already inside a nested
      stall.  However, there can be multiple PageWorkingset pages in the bio, at
      which point it's that path itself that enters repeatedly and overwrites
      pflags.  This causes us to miss the exit.
      
      Enter the stall only once if needed, then unwind correctly.
      
      erofs has the same problem, fix that up too.  And move the memstall exit
      past submit_bio() to restore submit accounting originally added by
      b8e24a93 ("block: annotate refault stalls from IO submission").
      
      Link: https://lkml.kernel.org/r/Y2UHRqthNUwuIQGS@cmpxchg.org
      Fixes: 4088a47e ("btrfs: add manual PSI accounting for compressed reads")
      Fixes: 99486c51 ("erofs: add manual PSI accounting for the compressed address space")
      Fixes: 118f3663 ("block: remove PSI accounting from the bio layer")
      Link: https://lore.kernel.org/r/d20a0a85-e415-cf78-27f9-77dd7a94bc8d@leemhuis.info/Signed-off-by: NJohannes Weiner <hannes@cmpxchg.org>
      Reported-by: NThorsten Leemhuis <linux@leemhuis.info>
      Tested-by: NThorsten Leemhuis <linux@leemhuis.info>
      Cc: Chao Yu <chao@kernel.org>
      Cc: Chris Mason <clm@fb.com>
      Cc: Christoph Hellwig <hch@lst.de>
      Cc: David Sterba <dsterba@suse.com>
      Cc: Gao Xiang <xiang@kernel.org>
      Cc: Jens Axboe <axboe@kernel.dk>
      Cc: Josef Bacik <josef@toxicpanda.com>
      Cc: Suren Baghdasaryan <surenb@google.com>
      Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
      82e60d00
  3. 26 9月, 2022 4 次提交
  4. 20 9月, 2022 1 次提交
  5. 12 9月, 2022 1 次提交
  6. 26 7月, 2022 3 次提交
    • C
      btrfs: don't call btrfs_page_set_checked in finish_compressed_bio_read · 0b078d9d
      Christoph Hellwig 提交于
      This flag was used to communicate that the low-level compression code
      already did verify the checksum to the high-level I/O completion code.
      
      But it has been unused for a long time as the upper btrfs_bio for the
      decompressed data had a NULL csum pointer basically since that pointer
      existed and the code already checks for that a little later.
      
      Note that this does not affect the other use of the checked flag, which
      is only used for the COW fixup worker.
      Reviewed-by: NNikolay Borisov <nborisov@suse.com>
      Signed-off-by: NChristoph Hellwig <hch@lst.de>
      Signed-off-by: NDavid Sterba <dsterba@suse.com>
      0b078d9d
    • C
      btrfs: fix repair of compressed extents · 81bd9328
      Christoph Hellwig 提交于
      Currently the checksum of compressed extents is verified based on the
      compressed data and the lower btrfs_bio, but the actual repair process
      is driven by end_bio_extent_readpage on the upper btrfs_bio for the
      decompressed data.
      
      This has a bunch of issues, including not being able to properly
      communicate the failed mirror up in case that the I/O submission got
      preempted, a general loss of if an error was an I/O error or a checksum
      verification failure, but most importantly that this design causes
      btrfs_clean_io_failure to eventually write back the uncompressed good
      data onto the disk sectors that are supposed to contain compressed data.
      
      Fix this by moving the repair to the lower btrfs_bio.  To do so, a fair
      amount of code has to be reshuffled:
      
       a) the lower btrfs_bio now needs a valid csum pointer.  The easiest way
          to achieve that is to pass NULL btrfs_lookup_bio_sums and just use
          the btrfs_bio management of csums.  For a compressed_bio that is
          split into multiple btrfs_bios this means additional memory
          allocations, but the code becomes a lot more regular.
       b) checksum verification now runs directly on the lower btrfs_bio instead
          of the compressed_bio.  This actually nicely simplifies the end I/O
          processing.
       c) btrfs_repair_one_sector can't just look up the logical address for
          the file offset any more, as there is no corresponding relative
          offsets that apply to the file offset and the logic address for
          compressed extents.  Instead require that the saved bvec_iter in the
          btrfs_bio is filled out for all read bios and use that, which again
          removes a fair amount of code.
      Reviewed-by: NNikolay Borisov <nborisov@suse.com>
      Signed-off-by: NChristoph Hellwig <hch@lst.de>
      Signed-off-by: NDavid Sterba <dsterba@suse.com>
      81bd9328
    • C
      btrfs: simplify the pending I/O counting in struct compressed_bio · 524bcd1e
      Christoph Hellwig 提交于
      Instead of counting the sectors just count the bios, with an extra
      reference held during submission.  This significantly simplifies the
      submission side error handling.
      
      This slightly changes completion and error handling of
      btrfs_submit_compressed_{read,write} because with the old code the
      compressed_bio could have been completed in
      submit_compressed_{read,write} only if there was an error during
      submission for one of the lower bio, whilst with the new code there is a
      chance for this to happen even for successful submission if the all the
      lower bios complete before the end of the function is reached.
      Reviewed-by: NNikolay Borisov <nborisov@suse.com>
      Reviewed-by: NBoris Burkov <boris@bur.io>
      Signed-off-by: NChristoph Hellwig <hch@lst.de>
      Signed-off-by: NDavid Sterba <dsterba@suse.com>
      524bcd1e
  7. 25 7月, 2022 5 次提交
  8. 15 7月, 2022 1 次提交
  9. 16 5月, 2022 4 次提交
  10. 06 4月, 2022 1 次提交
  11. 14 3月, 2022 6 次提交
  12. 07 1月, 2022 1 次提交
  13. 03 1月, 2022 1 次提交
  14. 27 10月, 2021 8 次提交
    • D
      Revert "btrfs: compression: drop kmap/kunmap from generic helpers" · 3a60f653
      David Sterba 提交于
      This reverts commit 4c2bf276.
      
      The kmaps in compression code are still needed and cause crashes on
      32bit machines (ARM, x86). Reproducible eg. by running fstest btrfs/004
      with enabled LZO or ZSTD compression.
      
      Link: https://lore.kernel.org/all/CAJCQCtT+OuemovPO7GZk8Y8=qtOObr0XTDp8jh4OHD6y84AFxw@mail.gmail.com/
      Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=214839Signed-off-by: NDavid Sterba <dsterba@suse.com>
      3a60f653
    • Q
      btrfs: subpage: make end_compressed_bio_writeback() compatible · 741ec653
      Qu Wenruo 提交于
      In end_compressed_writeback() we just clear the full page writeback.
      For subpage case, if there are two delalloc ranges in the same page, the
      2nd range will trigger a BUG_ON() as the page writeback is already
      cleared by previous range.
      
      Fix it by using btrfs_page_clamp_clear_writeback() helper.
      Signed-off-by: NQu Wenruo <wqu@suse.com>
      Signed-off-by: NDavid Sterba <dsterba@suse.com>
      741ec653
    • Q
      btrfs: subpage: make btrfs_submit_compressed_write() compatible · bbbff01a
      Qu Wenruo 提交于
      There is a WARN_ON() checking if @start is aligned to PAGE_SIZE, not
      sectorsize, which will cause false alert for subpage.  Fix it to check
      against sectorsize.
      
      Furthermore:
      
      - Use ASSERT() to do the check
        So that in the future we may skip the check for production build
      
      - Also check alignment for @len
      Signed-off-by: NQu Wenruo <wqu@suse.com>
      Signed-off-by: NDavid Sterba <dsterba@suse.com>
      bbbff01a
    • Q
      btrfs: determine stripe boundary at bio allocation time in btrfs_submit_compressed_write · 91507240
      Qu Wenruo 提交于
      Currently btrfs_submit_compressed_write() will check
      btrfs_bio_fits_in_stripe() each time a new page is going to be added.
      Even if compressed extent is small, we don't really need to do that for
      every page.
      
      Align the behavior to extent_io.c, by determining the stripe boundary
      when allocating a bio.
      
      Unlike extent_io.c, in compressed.c we don't need to bother things like
      different bio flags, thus no need to re-use bio_ctrl.
      
      Here we just manually introduce new local variable, next_stripe_start,
      and use that value returned from alloc_compressed_bio() to calculate
      the stripe boundary.
      
      Then each time we add some page range into the bio, we check if we
      reached the boundary.  And if reached, submit it.
      
      Also, since we have @cur_disk_bytenr to determine whether we're the last
      bio, we don't need a explicit last_bio: tag for error handling any more.
      
      And since we use @cur_disk_bytenr to wait, there is no need for
      pending_bios, also remove it to save some memory of compressed_bio.
      Signed-off-by: NQu Wenruo <wqu@suse.com>
      Signed-off-by: NDavid Sterba <dsterba@suse.com>
      91507240
    • Q
      btrfs: determine stripe boundary at bio allocation time in btrfs_submit_compressed_read · f472c28f
      Qu Wenruo 提交于
      Currently btrfs_submit_compressed_read() will check
      btrfs_bio_fits_in_stripe() each time a new page is going to be added.
      Even if compressed extent is small, we don't really need to do that for
      every page.
      
      This patch will align the behavior to extent_io.c, by determining the
      stripe boundary when allocating a bio.
      
      Unlike extent_io.c, in compressed.c we don't need to bother things like
      different bio flags, thus no need to re-use bio_ctrl.
      
      Here we just manually introduce new local variable, next_stripe_start,
      and teach alloc_compressed_bio() to calculate the stripe boundary.
      
      Then each time we add some page range into the bio, we check if we
      reached the boundary.  And if reached, submit it.
      
      Also, since we have @cur_disk_byte to determine whether we're the last
      bio, we don't need a explicit last_bio: tag for error handling any more.
      
      And we can use @cur_disk_byte to track which range has been added to
      bio, we can also use @cur_disk_byte to calculate the wait condition, no
      need for @pending_bios.
      Signed-off-by: NQu Wenruo <wqu@suse.com>
      Signed-off-by: NDavid Sterba <dsterba@suse.com>
      f472c28f
    • Q
      btrfs: introduce alloc_compressed_bio() for compression · 22c306fe
      Qu Wenruo 提交于
      Just aggregate the bio allocation code into one helper, so that we can
      replace 4 call sites.
      
      There is one special note for zoned write.
      
      Currently btrfs_submit_compressed_write() will only allocate the first
      bio using ZONE_APPEND.  If we have to submit current bio due to stripe
      boundary, the new bio allocated will not use ZONE_APPEND.
      
      In theory this should be a bug, but considering zoned mode currently
      only support SINGLE profile, which doesn't have any stripe boundary
      limit, it should never be a problem and we have assertions in place.
      
      This function will provide a good entrance for any work which needs to
      be done at bio allocation time. Like determining the stripe boundary.
      Signed-off-by: NQu Wenruo <wqu@suse.com>
      Signed-off-by: NDavid Sterba <dsterba@suse.com>
      22c306fe
    • Q
      btrfs: introduce submit_compressed_bio() for compression · 2d4e0b84
      Qu Wenruo 提交于
      The new helper, submit_compressed_bio(), will aggregate the following
      work:
      
      - Increase compressed_bio::pending_bios
      - Remap the endio function
      - Map and submit the bio
      
      This slightly reorders calls to btrfs_csum_one_bio or
      btrfs_lookup_bio_sums but but none of them does anything regarding IO
      submission so this is effectively no change. We mainly care about order
      of
      
      - atomic_inc
      - btrfs_bio_wq_end_io
      - btrfs_map_bio
      Signed-off-by: NQu Wenruo <wqu@suse.com>
      Signed-off-by: NDavid Sterba <dsterba@suse.com>
      2d4e0b84
    • Q
      btrfs: handle errors properly inside btrfs_submit_compressed_write() · 6853c64a
      Qu Wenruo 提交于
      Just like btrfs_submit_compressed_read(), there are quite some BUG_ON()s
      inside btrfs_submit_compressed_write() for the bio submission path.
      
      Fix them using the same method:
      
      - For last bio, just endio the bio
        As in that case, one of the endio function of all these submitted bio
        will be able to free the compressed_bio
      
      - For half-submitted bio, wait and finish the compressed_bio manually
        In this case, as long as all other bio finish, we're the only one
        referring the compressed bio, and can manually finish it.
      Signed-off-by: NQu Wenruo <wqu@suse.com>
      Signed-off-by: NDavid Sterba <dsterba@suse.com>
      6853c64a