All of lore.kernel.org
 help / color / mirror / Atom feed
From: Nikolay Borisov <nborisov@suse.com>
To: linux-btrfs@vger.kernel.org
Cc: Nikolay Borisov <nborisov@suse.com>
Subject: [PATCH v4 08/15] btrfs: Stop using call_rcu for device freeing
Date: Wed, 27 Mar 2019 14:24:11 +0200	[thread overview]
Message-ID: <20190327122418.24027-9-nborisov@suse.com> (raw)
In-Reply-To: <20190327122418.24027-1-nborisov@suse.com>

btrfs_device structs are freed from RCU context since device iteration
is protected by RCU. Currently this is achieved by using call_rcu since
no blocking functions are called within btrfs_free_device. Future
refactoring of pending/pinned chunks will require calling sleeping
functions. This patch is in preparation for these changes by simply
switching from RCU callbacks to explicit calls of synchronize_rcu and
calling btrfs_free_device directly.

Signed-off-by: Nikolay Borisov <nborisov@suse.com>
---
 fs/btrfs/volumes.c | 20 ++++++++------------
 fs/btrfs/volumes.h |  1 -
 2 files changed, 8 insertions(+), 13 deletions(-)

diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index d2d37adbc6fd..90eff8452c31 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -1230,14 +1230,6 @@ void btrfs_free_extra_devids(struct btrfs_fs_devices *fs_devices, int step)
 	mutex_unlock(&uuid_mutex);
 }
 
-static void free_device_rcu(struct rcu_head *head)
-{
-	struct btrfs_device *device;
-
-	device = container_of(head, struct btrfs_device, rcu);
-	btrfs_free_device(device);
-}
-
 static void btrfs_close_bdev(struct btrfs_device *device)
 {
 	if (!device->bdev)
@@ -1285,7 +1277,8 @@ static void btrfs_close_one_device(struct btrfs_device *device)
 	list_replace_rcu(&device->dev_list, &new_device->dev_list);
 	new_device->fs_devices = device->fs_devices;
 
-	call_rcu(&device->rcu, free_device_rcu);
+	synchronize_rcu();
+	btrfs_free_device(device);
 }
 
 static int close_fs_devices(struct btrfs_fs_devices *fs_devices)
@@ -2242,7 +2235,8 @@ int btrfs_rm_device(struct btrfs_fs_info *fs_info, const char *device_path,
 		btrfs_scratch_superblocks(device->bdev, device->name->str);
 
 	btrfs_close_bdev(device);
-	call_rcu(&device->rcu, free_device_rcu);
+	synchronize_rcu();
+	btrfs_free_device(device);
 
 	if (cur_devices->open_devices == 0) {
 		while (fs_devices) {
@@ -2310,7 +2304,8 @@ void btrfs_rm_dev_replace_free_srcdev(struct btrfs_fs_info *fs_info,
 	}
 
 	btrfs_close_bdev(srcdev);
-	call_rcu(&srcdev->rcu, free_device_rcu);
+	synchronize_rcu();
+	btrfs_free_device(srcdev);
 
 	/* if this is no devs we rather delete the fs_devices */
 	if (!fs_devices->num_devices) {
@@ -2368,7 +2363,8 @@ void btrfs_destroy_dev_replace_tgtdev(struct btrfs_device *tgtdev)
 	btrfs_scratch_superblocks(tgtdev->bdev, tgtdev->name->str);
 
 	btrfs_close_bdev(tgtdev);
-	call_rcu(&tgtdev->rcu, free_device_rcu);
+	synchronize_rcu();
+	btrfs_free_device(tgtdev);
 }
 
 static struct btrfs_device *btrfs_find_device_by_path(
diff --git a/fs/btrfs/volumes.h b/fs/btrfs/volumes.h
index a0f09aad3770..81784b68ca12 100644
--- a/fs/btrfs/volumes.h
+++ b/fs/btrfs/volumes.h
@@ -118,7 +118,6 @@ struct btrfs_device {
 	struct scrub_ctx *scrub_ctx;
 
 	struct btrfs_work work;
-	struct rcu_head rcu;
 
 	/* readahead state */
 	atomic_t reada_in_flight;
-- 
2.17.1


  parent reply	other threads:[~2019-03-27 12:24 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-03-27 12:24 [PATCH v4 00/15] FITRIM improvement Nikolay Borisov
2019-03-27 12:24 ` [PATCH v4 01/15] btrfs: Honour FITRIM range constraints during free space trim Nikolay Borisov
2019-05-25  2:30   ` Qu Wenruo
2019-03-27 12:24 ` [PATCH v4 02/15] btrfs: combine device update operations during transaction commit Nikolay Borisov
2019-05-03 10:23   ` David Sterba
2019-03-27 12:24 ` [PATCH v4 03/15] btrfs: Handle pending/pinned chunks before blockgroup relocation during device shrink Nikolay Borisov
2019-04-01 18:26   ` David Sterba
2019-04-02  5:55     ` Nikolay Borisov
2019-04-02 15:52       ` David Sterba
2019-03-27 12:24 ` [PATCH v4 04/15] btrfs: Rename and export clear_btree_io_tree Nikolay Borisov
2019-03-27 12:24 ` [PATCH v4 05/15] btrfs: Populate ->orig_block_len during read_one_chunk Nikolay Borisov
2019-03-27 12:24 ` [PATCH v4 06/15] btrfs: Introduce new bits for device allocation tree Nikolay Borisov
2019-03-27 12:24 ` [PATCH v4 07/15] btrfs: Implement set_extent_bits_nowait Nikolay Borisov
2019-03-27 12:24 ` Nikolay Borisov [this message]
2019-04-01 17:07   ` [PATCH v4 08/15] btrfs: Stop using call_rcu for device freeing David Sterba
2019-04-01 17:20     ` Nikolay Borisov
2019-04-02 16:12       ` David Sterba
2019-03-27 12:24 ` [PATCH v4 09/15] btrfs: replace pending/pinned chunks lists with io tree Nikolay Borisov
2024-02-29 10:00   ` Alex Lyakas
2024-02-29 10:54     ` Filipe Manana
2024-02-29 11:07       ` Alex Lyakas
2019-03-27 12:24 ` [PATCH v4 10/15] btrfs: Transpose btrfs_close_devices/btrfs_mapping_tree_free in close_ctree Nikolay Borisov
2019-03-27 12:24 ` [PATCH v4 11/15] btrfs: Remove 'trans' argument from find_free_dev_extent(_start) Nikolay Borisov
2019-03-27 12:24 ` [PATCH v4 12/15] btrfs: Factor out in_range macro Nikolay Borisov
2019-03-27 12:24 ` [PATCH v4 13/15] btrfs: Optimize unallocated chunks discard Nikolay Borisov
2019-04-01 18:44   ` David Sterba
2019-04-02  8:01     ` Nikolay Borisov
2019-03-27 12:24 ` [PATCH v4 14/15] btrfs: Implement find_first_clear_extent_bit Nikolay Borisov
2019-03-27 12:24 ` [PATCH v4 15/15] btrfs: Switch btrfs_trim_free_extents to find_first_clear_extent_bit Nikolay Borisov
2019-03-28 23:18 ` [PATCH v4 00/15] FITRIM improvement David Sterba
2019-03-29  6:20   ` Nikolay Borisov
2019-03-29  6:55     ` Qu Wenruo
2019-04-03 13:46 ` 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=20190327122418.24027-9-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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.