linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: David Sterba <dsterba@suse.com>
To: linux-btrfs@vger.kernel.org
Cc: David Sterba <dsterba@suse.com>
Subject: [PATCH 0/5] Speedups and check_setget_bounds reporting updates
Date: Thu,  3 Feb 2022 18:26:22 +0100	[thread overview]
Message-ID: <cover.1643904960.git.dsterba@suse.com> (raw)

This is a followup to [1] disabling asserts by default. There's some
performance hit involved because of check_setget_bounds that's called
for any extent buffer item read/write. Trading correctness for speed is
should be considered but in general correctness should be favored.

I've optimized the helper so it should have negligible impact (one
inlined branch instead of function call and 2 branches), I haven't
measured that yet though.

How the checks and reporting works:

- any function generated by BTRFS_SETGET_FUNCS calls check_setget_bounds
  and verifies if the reguested bytes are within the extent buffer

- if the checks fail nothing is read or written to the buffer
  - set a bit in fs_info::fs_state so we know something happened
  - store information about the failed range into fs_info for later

- as the setget helpers aren't checked for errors, there are a few
  points where the transaction is ended/aborted once the bit is set

I've tested that in fstests with inserted failure [2] after each 100K
operations, this allows tests to proceed but fail eventually. This makes
i up to btrfs/020 and hits assert in warn_about_uncommitted_trans.

Possible improvements:

- there's a similar check/report for read_extent_buffer so that could
  also set the bit and fail fast

- can be used as base for the shutdown logic

[1] https://lore.kernel.org/linux-btrfs/20200724164147.39925-1-josef@toxicpanda.com

[2]
--- a/fs/btrfs/struct-funcs.c
+++ b/fs/btrfs/struct-funcs.c
@@ -33,7 +33,15 @@ static void report_setget_bounds(const struct extent_buffer *eb,
 static inline bool check_setget_bounds(const struct extent_buffer *eb,
                                       const void *ptr, unsigned off, int size)
 {
-       const unsigned long member_offset = (unsigned long)ptr + off;
+       unsigned long member_offset = (unsigned long)ptr + off;
+       static unsigned long failure = 1;
+       const unsigned long fail_after = 102400;
+
+       if (test_bit(BTRFS_FS_OPEN, &eb->fs_info->flags) &&
+           (failure++ % fail_after) == 0) {
+               printk(KERN_ERR "SETGET: trigger setget failure at %lu\n", failure);
+               member_offset = 128 * 1024;
+       }
---

David Sterba (5):
  btrfs: remove redundant check in up check_setget_bounds
  btrfs: factor out reporting when check_setget_bounds fails
  btrfs: store details about first setget bounds check failure
  btrfs: fail transaction when a setget bounds check failure is detected
  btrfs: move check_setget_bounds out of ASSERT

 fs/btrfs/ctree.h        | 16 +++++++++++--
 fs/btrfs/struct-funcs.c | 51 ++++++++++++++++++++++++++++-------------
 fs/btrfs/transaction.c  | 11 +++++++++
 3 files changed, 60 insertions(+), 18 deletions(-)

-- 
2.34.1


             reply	other threads:[~2022-02-03 17:27 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-03 17:26 David Sterba [this message]
2022-02-03 17:26 ` [PATCH 1/5] btrfs: remove redundant check in up check_setget_bounds David Sterba
2022-02-10 17:52   ` David Sterba
2022-02-03 17:26 ` [PATCH 2/5] btrfs: factor out reporting when check_setget_bounds fails David Sterba
2022-02-03 17:26 ` [PATCH 3/5] btrfs: store details about first setget bounds check failure David Sterba
2022-02-04 11:31   ` Filipe Manana
2022-02-10 17:27     ` David Sterba
2022-02-03 17:26 ` [PATCH 4/5] btrfs: fail transaction when a setget bounds check failure is detected David Sterba
2022-02-04 11:29   ` Filipe Manana
2022-02-04 13:38     ` Filipe Manana
2022-02-10 17:50     ` David Sterba
2022-02-11 11:23       ` Filipe Manana
2022-02-03 17:26 ` [PATCH 5/5] btrfs: move check_setget_bounds out of ASSERT David Sterba
2022-02-04  8:35 ` [PATCH 0/5] Speedups and check_setget_bounds reporting updates Johannes Thumshirn

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=cover.1643904960.git.dsterba@suse.com \
    --to=dsterba@suse.com \
    --cc=linux-btrfs@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).