From: Nikolay Borisov <nborisov@suse.com>
To: linux-btrfs@vger.kernel.org
Cc: Nikolay Borisov <nborisov@suse.com>
Subject: [PATCH v3 2/2] btrfs: Hook btrfs' DRW lock to locktorture infrastructure
Date: Mon, 24 Feb 2020 17:26:37 +0200 [thread overview]
Message-ID: <20200224152637.30774-3-nborisov@suse.com> (raw)
In-Reply-To: <20200224152637.30774-1-nborisov@suse.com>
Signed-off-by: Nikolay Borisov <nborisov@suse.com>
---
fs/btrfs/locking.c | 5 +++
fs/btrfs/locking.h | 1 +
kernel/locking/locktorture.c | 77 +++++++++++++++++++++++++++++++++++-
3 files changed, 82 insertions(+), 1 deletion(-)
diff --git a/fs/btrfs/locking.c b/fs/btrfs/locking.c
index d890833694c9..e7645f3fd9cd 100644
--- a/fs/btrfs/locking.c
+++ b/fs/btrfs/locking.c
@@ -614,6 +614,7 @@ bool btrfs_drw_try_write_lock(struct btrfs_drw_lock *lock)
return true;
}
+EXPORT_SYMBOL(btrfs_drw_try_write_lock);
void btrfs_drw_write_lock(struct btrfs_drw_lock *lock)
{
@@ -623,12 +624,14 @@ void btrfs_drw_write_lock(struct btrfs_drw_lock *lock)
wait_event(lock->pending_writers, !atomic_read(&lock->readers));
}
}
+EXPORT_SYMBOL(btrfs_drw_write_lock);
void btrfs_drw_write_unlock(struct btrfs_drw_lock *lock)
{
percpu_counter_dec(&lock->writers);
cond_wake_up(&lock->pending_readers);
}
+EXPORT_SYMBOL(btrfs_drw_write_unlock);
void btrfs_drw_read_lock(struct btrfs_drw_lock *lock)
{
@@ -645,6 +648,7 @@ void btrfs_drw_read_lock(struct btrfs_drw_lock *lock)
wait_event(lock->pending_readers,
percpu_counter_sum(&lock->writers) == 0);
}
+EXPORT_SYMBOL(btrfs_drw_read_lock);
void btrfs_drw_read_unlock(struct btrfs_drw_lock *lock)
{
@@ -655,3 +659,4 @@ void btrfs_drw_read_unlock(struct btrfs_drw_lock *lock)
if (atomic_dec_and_test(&lock->readers))
wake_up(&lock->pending_writers);
}
+EXPORT_SYMBOL(btrfs_drw_read_unlock);
diff --git a/fs/btrfs/locking.h b/fs/btrfs/locking.h
index ba60318c53d5..c56b0cf59357 100644
--- a/fs/btrfs/locking.h
+++ b/fs/btrfs/locking.h
@@ -10,6 +10,7 @@
#include <linux/atomic.h>
#include <linux/wait.h>
#include <linux/percpu_counter.h>
+#include "extent_io.h"
#define BTRFS_WRITE_LOCK 1
#define BTRFS_READ_LOCK 2
diff --git a/kernel/locking/locktorture.c b/kernel/locking/locktorture.c
index 99475a66c94f..921afbd58fff 100644
--- a/kernel/locking/locktorture.c
+++ b/kernel/locking/locktorture.c
@@ -29,6 +29,8 @@
#include <linux/slab.h>
#include <linux/percpu-rwsem.h>
#include <linux/torture.h>
+#include "../../fs/btrfs/ctree.h"
+#include "../../fs/btrfs/locking.h"
MODULE_LICENSE("GPL");
MODULE_AUTHOR("Paul E. McKenney <paulmck@linux.ibm.com>");
@@ -84,6 +86,7 @@ struct lock_torture_ops {
unsigned long flags; /* for irq spinlocks */
const char *name;
+ bool multiple;
};
struct lock_torture_cxt {
@@ -599,6 +602,7 @@ static void torture_percpu_rwsem_up_read(void) __releases(pcpu_rwsem)
percpu_up_read(&pcpu_rwsem);
}
+
static struct lock_torture_ops percpu_rwsem_lock_ops = {
.init = torture_percpu_rwsem_init,
.writelock = torture_percpu_rwsem_down_write,
@@ -611,6 +615,76 @@ static struct lock_torture_ops percpu_rwsem_lock_ops = {
.name = "percpu_rwsem_lock"
};
+static struct btrfs_drw_lock torture_drw_lock;
+
+void torture_drw_init(void)
+{
+ BUG_ON(btrfs_drw_lock_init(&torture_drw_lock));
+}
+
+static int torture_drw_write_lock(void) __acquires(torture_drw_lock)
+{
+ btrfs_drw_write_lock(&torture_drw_lock);
+ return 0;
+}
+
+static void torture_drw_write_unlock(void) __releases(torture_drw_lock)
+{
+ btrfs_drw_write_unlock(&torture_drw_lock);
+}
+
+static int torture_drw_read_lock(void) __acquires(torture_drw_lock)
+{
+ btrfs_drw_read_lock(&torture_drw_lock);
+ return 0;
+}
+
+static void torture_drw_read_unlock(void) __releases(torture_drw_lock)
+{
+ btrfs_drw_read_unlock(&torture_drw_lock);
+}
+
+static void torture_drw_write_delay(struct torture_random_state *trsp)
+{
+ const unsigned long longdelay_ms = 100;
+
+ /* We want a long delay occasionally to force massive contention. */
+ if (!(torture_random(trsp) %
+ (cxt.nrealwriters_stress * 2000 * longdelay_ms)))
+ mdelay(longdelay_ms * 10);
+ else
+ mdelay(longdelay_ms / 10);
+ if (!(torture_random(trsp) % (cxt.nrealwriters_stress * 20000)))
+ torture_preempt_schedule(); /* Allow test to be preempted. */
+}
+
+static void torture_drw_read_delay(struct torture_random_state *trsp)
+{
+ const unsigned long longdelay_ms = 100;
+
+ /* We want a long delay occasionally to force massive contention. */
+ if (!(torture_random(trsp) %
+ (cxt.nrealreaders_stress * 2000 * longdelay_ms)))
+ mdelay(longdelay_ms * 2);
+ else
+ mdelay(longdelay_ms / 2);
+ if (!(torture_random(trsp) % (cxt.nrealreaders_stress * 20000)))
+ torture_preempt_schedule(); /* Allow test to be preempted. */
+}
+
+static struct lock_torture_ops btrfs_drw_lock_ops = {
+ .init = torture_drw_init,
+ .writelock = torture_drw_write_lock,
+ .write_delay = torture_drw_write_delay,
+ .task_boost = torture_boost_dummy,
+ .writeunlock = torture_drw_write_unlock,
+ .readlock = torture_drw_read_lock,
+ .read_delay = torture_drw_read_delay, /* figure what to do with this */
+ .readunlock = torture_drw_read_unlock,
+ .multiple = true,
+ .name = "btrfs_drw_lock"
+};
+
/*
* Lock torture writer kthread. Repeatedly acquires and releases
* the lock, checking for duplicate acquisitions.
@@ -629,7 +703,7 @@ static int lock_torture_writer(void *arg)
cxt.cur_ops->task_boost(&rand);
cxt.cur_ops->writelock();
- if (WARN_ON_ONCE(lock_is_write_held))
+ if (!cxt.cur_ops->multiple && WARN_ON_ONCE(lock_is_write_held))
lwsp->n_lock_fail++;
lock_is_write_held = 1;
if (WARN_ON_ONCE(lock_is_read_held))
@@ -851,6 +925,7 @@ static int __init lock_torture_init(void)
#endif
&rwsem_lock_ops,
&percpu_rwsem_lock_ops,
+ &btrfs_drw_lock_ops
};
if (!torture_init_begin(torture_type, verbose))
--
2.17.1
next prev parent reply other threads:[~2020-02-24 15:26 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-02-24 15:26 [PATCH v3 0/2] Refactor snapshot vs nocow writers locking Nikolay Borisov
2020-02-24 15:26 ` [PATCH v3 1/2] btrfs: convert snapshot/nocow exlcusion to drw lock Nikolay Borisov
2020-02-24 15:26 ` Nikolay Borisov [this message]
2020-02-24 15:32 ` [PATCH v3 2/2] btrfs: Hook btrfs' DRW lock to locktorture infrastructure Nikolay Borisov
2020-02-24 15:32 ` [PATCH 1/2] btrfs: Implement DRW lock Nikolay Borisov
2020-02-24 16:02 ` [PATCH v3 0/2] Refactor snapshot vs nocow writers locking David Sterba
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=20200224152637.30774-3-nborisov@suse.com \
--to=nborisov@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