linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/5] Rework eviction space flushing
@ 2019-08-01 22:19 Josef Bacik
  2019-08-01 22:19 ` [PATCH 1/5] btrfs: add a flush step for delayed iputs Josef Bacik
                   ` (6 more replies)
  0 siblings, 7 replies; 9+ messages in thread
From: Josef Bacik @ 2019-08-01 22:19 UTC (permalink / raw)
  To: linux-btrfs, kernel-team

This is a set of patches to address how we do space flushing for inode
evictions.  Historically we've only been allowed to do a few things to reclaim
space for inode evictions, mostly because we'd deadlock with iput.  But we have
delayed iputs in place to make sure we're always doing iput where it's
completely safe to do an iput.

However we do run iputs for flushing, so we can't just do FLUSH_ALL, otherwise
we could deadlock.  Also we still want to prioritize evictions for space
reclamation because we likely will free up space for other people to make
reservations.

The first 4 patches are preparation patches, just refactoring so we can add this
new flushing time for eviction.  This allows us to clean up our current ad-hoc
loop we have for reclaiming space for evictions and use the common helpers that
everybody else uses.  Thanks,

Josef


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH 1/5] btrfs: add a flush step for delayed iputs
  2019-08-01 22:19 [PATCH 0/5] Rework eviction space flushing Josef Bacik
@ 2019-08-01 22:19 ` Josef Bacik
  2019-08-01 22:19 ` [PATCH 2/5] btrfs: unify error handling for ticket flushing Josef Bacik
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 9+ messages in thread
From: Josef Bacik @ 2019-08-01 22:19 UTC (permalink / raw)
  To: linux-btrfs, kernel-team

Delayed iputs could very well free up enough space without needing to
commit the transaction, so make this step it's own step.  This will
allow us to skip the step for evictions in a later patch.

Signed-off-by: Josef Bacik <josef@toxicpanda.com>
---
 fs/btrfs/ctree.h             | 3 ++-
 fs/btrfs/space-info.c        | 5 +++--
 include/trace/events/btrfs.h | 1 +
 3 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h
index 299e11e6c554..313a8194c0ef 100644
--- a/fs/btrfs/ctree.h
+++ b/fs/btrfs/ctree.h
@@ -2733,7 +2733,8 @@ enum btrfs_flush_state {
 	FLUSH_DELALLOC_WAIT	=	6,
 	ALLOC_CHUNK		=	7,
 	ALLOC_CHUNK_FORCE	=	8,
-	COMMIT_TRANS		=	9,
+	RUN_DELAYED_IPUTS	=	9,
+	COMMIT_TRANS		=	10,
 };
 
 /*
diff --git a/fs/btrfs/space-info.c b/fs/btrfs/space-info.c
index ab7b9ec4c240..7dfac0d4b24c 100644
--- a/fs/btrfs/space-info.c
+++ b/fs/btrfs/space-info.c
@@ -684,7 +684,7 @@ static void flush_space(struct btrfs_fs_info *fs_info,
 		if (ret > 0 || ret == -ENOSPC)
 			ret = 0;
 		break;
-	case COMMIT_TRANS:
+	case RUN_DELAYED_IPUTS:
 		/*
 		 * If we have pending delayed iputs then we could free up a
 		 * bunch of pinned space, so make sure we run the iputs before
@@ -692,7 +692,8 @@ static void flush_space(struct btrfs_fs_info *fs_info,
 		 */
 		btrfs_run_delayed_iputs(fs_info);
 		btrfs_wait_on_delayed_iputs(fs_info);
-
+		break;
+	case COMMIT_TRANS:
 		ret = may_commit_transaction(fs_info, space_info);
 		break;
 	default:
diff --git a/include/trace/events/btrfs.h b/include/trace/events/btrfs.h
index 2f6a669408bb..08f294f96424 100644
--- a/include/trace/events/btrfs.h
+++ b/include/trace/events/btrfs.h
@@ -1088,6 +1088,7 @@ TRACE_EVENT(btrfs_trigger_flush,
 		{ FLUSH_DELAYED_REFS,		"FLUSH_ELAYED_REFS"},		\
 		{ ALLOC_CHUNK,			"ALLOC_CHUNK"},			\
 		{ ALLOC_CHUNK_FORCE,		"ALLOC_CHUNK_FORCE"},		\
+		{ RUN_DELAYED_IPUTS,		"RUN_DELAYED_IPUTS"},		\
 		{ COMMIT_TRANS,			"COMMIT_TRANS"})
 
 TRACE_EVENT(btrfs_flush_space,
-- 
2.21.0


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH 2/5] btrfs: unify error handling for ticket flushing
  2019-08-01 22:19 [PATCH 0/5] Rework eviction space flushing Josef Bacik
  2019-08-01 22:19 ` [PATCH 1/5] btrfs: add a flush step for delayed iputs Josef Bacik
@ 2019-08-01 22:19 ` Josef Bacik
  2019-08-01 22:19 ` [PATCH 3/5] btrfs: factor out the ticket flush handling Josef Bacik
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 9+ messages in thread
From: Josef Bacik @ 2019-08-01 22:19 UTC (permalink / raw)
  To: linux-btrfs, kernel-team

Currently we handle the cleanup of errored out tickets in both the
priority flush path and the normal flushing path.  This is the same code
in both places, so just refactor so we don't duplicate the cleanup work.

Signed-off-by: Josef Bacik <josef@toxicpanda.com>
---
 fs/btrfs/space-info.c | 32 +++++++++++---------------------
 1 file changed, 11 insertions(+), 21 deletions(-)

diff --git a/fs/btrfs/space-info.c b/fs/btrfs/space-info.c
index 7dfac0d4b24c..ce7ae1cd1153 100644
--- a/fs/btrfs/space-info.c
+++ b/fs/btrfs/space-info.c
@@ -898,20 +898,19 @@ static void priority_reclaim_metadata_space(struct btrfs_fs_info *fs_info,
 	} while (flush_state < ARRAY_SIZE(priority_flush_states));
 }
 
-static int wait_reserve_ticket(struct btrfs_fs_info *fs_info,
-			       struct btrfs_space_info *space_info,
-			       struct reserve_ticket *ticket)
+static void wait_reserve_ticket(struct btrfs_fs_info *fs_info,
+				struct btrfs_space_info *space_info,
+				struct reserve_ticket *ticket)
 
 {
 	DEFINE_WAIT(wait);
-	u64 reclaim_bytes = 0;
 	int ret = 0;
 
 	spin_lock(&space_info->lock);
 	while (ticket->bytes > 0 && ticket->error == 0) {
 		ret = prepare_to_wait_event(&ticket->wait, &wait, TASK_KILLABLE);
 		if (ret) {
-			ret = -EINTR;
+			ticket->error = -EINTR;
 			break;
 		}
 		spin_unlock(&space_info->lock);
@@ -921,18 +920,7 @@ static int wait_reserve_ticket(struct btrfs_fs_info *fs_info,
 		finish_wait(&ticket->wait, &wait);
 		spin_lock(&space_info->lock);
 	}
-	if (!ret)
-		ret = ticket->error;
-	if (!list_empty(&ticket->list))
-		list_del_init(&ticket->list);
-	if (ticket->bytes && ticket->bytes < ticket->orig_bytes)
-		reclaim_bytes = ticket->orig_bytes - ticket->bytes;
 	spin_unlock(&space_info->lock);
-
-	if (reclaim_bytes)
-		btrfs_space_info_add_old_bytes(fs_info, space_info,
-					       reclaim_bytes);
-	return ret;
 }
 
 /**
@@ -1030,16 +1018,18 @@ static int __reserve_metadata_bytes(struct btrfs_fs_info *fs_info,
 		return ret;
 
 	if (flush == BTRFS_RESERVE_FLUSH_ALL)
-		return wait_reserve_ticket(fs_info, space_info, &ticket);
+		wait_reserve_ticket(fs_info, space_info, &ticket);
+	else
+		priority_reclaim_metadata_space(fs_info, space_info, &ticket);
 
-	ret = 0;
-	priority_reclaim_metadata_space(fs_info, space_info, &ticket);
 	spin_lock(&space_info->lock);
-	if (ticket.bytes) {
+	ret = ticket.error;
+	if (ticket.bytes || ticket.error) {
 		if (ticket.bytes < orig_bytes)
 			reclaim_bytes = orig_bytes - ticket.bytes;
 		list_del_init(&ticket.list);
-		ret = -ENOSPC;
+		if (!ret)
+			ret = -ENOSPC;
 	}
 	spin_unlock(&space_info->lock);
 
-- 
2.21.0


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH 3/5] btrfs: factor out the ticket flush handling
  2019-08-01 22:19 [PATCH 0/5] Rework eviction space flushing Josef Bacik
  2019-08-01 22:19 ` [PATCH 1/5] btrfs: add a flush step for delayed iputs Josef Bacik
  2019-08-01 22:19 ` [PATCH 2/5] btrfs: unify error handling for ticket flushing Josef Bacik
@ 2019-08-01 22:19 ` Josef Bacik
  2019-08-01 22:19 ` [PATCH 4/5] btrfs: refactor priority_reclaim_metadata_space Josef Bacik
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 9+ messages in thread
From: Josef Bacik @ 2019-08-01 22:19 UTC (permalink / raw)
  To: linux-btrfs, kernel-team

We're going to make this logic a little more complicated for evict, so
factor the ticket flushing/waiting code out of __reserve_metadata_bytes.
This has no functional change.

Signed-off-by: Josef Bacik <josef@toxicpanda.com>
---
 fs/btrfs/space-info.c | 64 ++++++++++++++++++++++++++++---------------
 1 file changed, 42 insertions(+), 22 deletions(-)

diff --git a/fs/btrfs/space-info.c b/fs/btrfs/space-info.c
index ce7ae1cd1153..71749b355136 100644
--- a/fs/btrfs/space-info.c
+++ b/fs/btrfs/space-info.c
@@ -923,6 +923,47 @@ static void wait_reserve_ticket(struct btrfs_fs_info *fs_info,
 	spin_unlock(&space_info->lock);
 }
 
+/**
+ * handle_reserve_ticket - do the appropriate flushing and waiting for a ticket
+ * @fs_info - the fs_info for the fs.
+ * @space_info - the space_info for the reservation.
+ * @ticket - the ticket for the reservation.
+ * @flush - how much we can flush.
+ *
+ * This does the work of figuring out how to flush for the ticket, waiting for
+ * the reservation, and returning the appropriate error if there is one.
+ */
+static int handle_reserve_ticket(struct btrfs_fs_info *fs_info,
+				 struct btrfs_space_info *space_info,
+				 struct reserve_ticket *ticket,
+				 enum btrfs_reserve_flush_enum flush)
+{
+	u64 reclaim_bytes = 0;
+	int ret;
+
+	if (flush == BTRFS_RESERVE_FLUSH_ALL)
+		wait_reserve_ticket(fs_info, space_info, ticket);
+	else
+		priority_reclaim_metadata_space(fs_info, space_info, ticket);
+
+	spin_lock(&space_info->lock);
+	ret = ticket->error;
+	if (ticket->bytes || ticket->error) {
+		if (ticket->bytes < ticket->orig_bytes)
+			reclaim_bytes = ticket->orig_bytes - ticket->bytes;
+		list_del_init(&ticket->list);
+		if (!ret)
+			ret = -ENOSPC;
+	}
+	spin_unlock(&space_info->lock);
+
+	if (reclaim_bytes)
+		btrfs_space_info_add_old_bytes(fs_info, space_info,
+					       reclaim_bytes);
+	ASSERT(list_empty(&ticket->list));
+	return ret;
+}
+
 /**
  * reserve_metadata_bytes - try to reserve bytes from the block_rsv's space
  * @root - the root we're allocating for
@@ -945,7 +986,6 @@ static int __reserve_metadata_bytes(struct btrfs_fs_info *fs_info,
 {
 	struct reserve_ticket ticket;
 	u64 used;
-	u64 reclaim_bytes = 0;
 	int ret = 0;
 
 	ASSERT(orig_bytes);
@@ -1017,27 +1057,7 @@ static int __reserve_metadata_bytes(struct btrfs_fs_info *fs_info,
 	if (!ret || flush == BTRFS_RESERVE_NO_FLUSH)
 		return ret;
 
-	if (flush == BTRFS_RESERVE_FLUSH_ALL)
-		wait_reserve_ticket(fs_info, space_info, &ticket);
-	else
-		priority_reclaim_metadata_space(fs_info, space_info, &ticket);
-
-	spin_lock(&space_info->lock);
-	ret = ticket.error;
-	if (ticket.bytes || ticket.error) {
-		if (ticket.bytes < orig_bytes)
-			reclaim_bytes = orig_bytes - ticket.bytes;
-		list_del_init(&ticket.list);
-		if (!ret)
-			ret = -ENOSPC;
-	}
-	spin_unlock(&space_info->lock);
-
-	if (reclaim_bytes)
-		btrfs_space_info_add_old_bytes(fs_info, space_info,
-					       reclaim_bytes);
-	ASSERT(list_empty(&ticket.list));
-	return ret;
+	return handle_reserve_ticket(fs_info, space_info, &ticket, flush);
 }
 
 /**
-- 
2.21.0


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH 4/5] btrfs: refactor priority_reclaim_metadata_space
  2019-08-01 22:19 [PATCH 0/5] Rework eviction space flushing Josef Bacik
                   ` (2 preceding siblings ...)
  2019-08-01 22:19 ` [PATCH 3/5] btrfs: factor out the ticket flush handling Josef Bacik
@ 2019-08-01 22:19 ` Josef Bacik
  2019-08-19 16:22   ` David Sterba
  2019-08-01 22:19 ` [PATCH 5/5] btrfs: introduce an evict flushing state Josef Bacik
                   ` (2 subsequent siblings)
  6 siblings, 1 reply; 9+ messages in thread
From: Josef Bacik @ 2019-08-01 22:19 UTC (permalink / raw)
  To: linux-btrfs, kernel-team

With the eviction flushing stuff we'll want to allow for different
states, but still work basically the same way that
priority_reclaim_metadata_space works currently.  Refactor this to take
the flushing states and size as an argument so we can use the same logic
for limit flushing and eviction flushing.

Signed-off-by: Josef Bacik <josef@toxicpanda.com>
---
 fs/btrfs/space-info.c | 17 +++++++++++------
 1 file changed, 11 insertions(+), 6 deletions(-)

diff --git a/fs/btrfs/space-info.c b/fs/btrfs/space-info.c
index 71749b355136..03556e411b11 100644
--- a/fs/btrfs/space-info.c
+++ b/fs/btrfs/space-info.c
@@ -868,9 +868,12 @@ static const enum btrfs_flush_state priority_flush_states[] = {
 	ALLOC_CHUNK,
 };
 
-static void priority_reclaim_metadata_space(struct btrfs_fs_info *fs_info,
-					    struct btrfs_space_info *space_info,
-					    struct reserve_ticket *ticket)
+static void
+priority_reclaim_metadata_space(struct btrfs_fs_info *fs_info,
+				struct btrfs_space_info *space_info,
+				struct reserve_ticket *ticket,
+				const enum btrfs_flush_state *states,
+				int states_nr)
 {
 	u64 to_reclaim;
 	int flush_state;
@@ -887,7 +890,7 @@ static void priority_reclaim_metadata_space(struct btrfs_fs_info *fs_info,
 	flush_state = 0;
 	do {
 		flush_space(fs_info, space_info, to_reclaim,
-			    priority_flush_states[flush_state]);
+			    states[flush_state]);
 		flush_state++;
 		spin_lock(&space_info->lock);
 		if (ticket->bytes == 0) {
@@ -895,7 +898,7 @@ static void priority_reclaim_metadata_space(struct btrfs_fs_info *fs_info,
 			return;
 		}
 		spin_unlock(&space_info->lock);
-	} while (flush_state < ARRAY_SIZE(priority_flush_states));
+	} while (flush_state < states_nr);
 }
 
 static void wait_reserve_ticket(struct btrfs_fs_info *fs_info,
@@ -944,7 +947,9 @@ static int handle_reserve_ticket(struct btrfs_fs_info *fs_info,
 	if (flush == BTRFS_RESERVE_FLUSH_ALL)
 		wait_reserve_ticket(fs_info, space_info, ticket);
 	else
-		priority_reclaim_metadata_space(fs_info, space_info, ticket);
+		priority_reclaim_metadata_space(fs_info, space_info, ticket,
+						priority_flush_states,
+						ARRAY_SIZE(priority_flush_states));
 
 	spin_lock(&space_info->lock);
 	ret = ticket->error;
-- 
2.21.0


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH 5/5] btrfs: introduce an evict flushing state
  2019-08-01 22:19 [PATCH 0/5] Rework eviction space flushing Josef Bacik
                   ` (3 preceding siblings ...)
  2019-08-01 22:19 ` [PATCH 4/5] btrfs: refactor priority_reclaim_metadata_space Josef Bacik
@ 2019-08-01 22:19 ` Josef Bacik
  2019-08-05 17:50 ` [PATCH 0/5] Rework eviction space flushing David Sterba
  2019-08-19 16:20 ` David Sterba
  6 siblings, 0 replies; 9+ messages in thread
From: Josef Bacik @ 2019-08-01 22:19 UTC (permalink / raw)
  To: linux-btrfs, kernel-team

We have this weird space flushing loop inside inode.c for evict where
we'll do the normal LIMIT flush, and then commit the transaction and
hope we get our space.  This is super janky, and in fact there's really
nothing stopping us from using FLUSH_ALL except that we run delayed
iputs, which means we could deadlock.  So introduce a new flush state
for eviction that does the normal priority flushing with all of the
states that are safe for eviction.

The nice side-effect of this is that we'll try harder for evictions.
Previously if (for example generic/269) you had a bunch of other
operations happening on the fs you could race with those reservations
when committing the transaction, and eventually miss getting a
reservation for the evict.  With this code we'll have our ticket in
place through the transaction commit, so any pinned bytes will go to our
pending evictions first.

Signed-off-by: Josef Bacik <josef@toxicpanda.com>
---
 fs/btrfs/ctree.h      |  1 +
 fs/btrfs/inode.c      | 81 +++++++++++++++++++------------------------
 fs/btrfs/space-info.c | 27 +++++++++++++--
 3 files changed, 62 insertions(+), 47 deletions(-)

diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h
index 313a8194c0ef..ecd52c86d061 100644
--- a/fs/btrfs/ctree.h
+++ b/fs/btrfs/ctree.h
@@ -2721,6 +2721,7 @@ enum btrfs_reserve_flush_enum {
 	 * case, use FLUSH LIMIT
 	 */
 	BTRFS_RESERVE_FLUSH_LIMIT,
+	BTRFS_RESERVE_FLUSH_EVICT,
 	BTRFS_RESERVE_FLUSH_ALL,
 };
 
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index ee582a36653d..10a3f62470b9 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -5347,59 +5347,50 @@ static struct btrfs_trans_handle *evict_refill_and_join(struct btrfs_root *root,
 {
 	struct btrfs_fs_info *fs_info = root->fs_info;
 	struct btrfs_block_rsv *global_rsv = &fs_info->global_block_rsv;
+	struct btrfs_trans_handle *trans;
 	u64 delayed_refs_extra = btrfs_calc_trans_metadata_size(fs_info, 1);
-	int failures = 0;
-
-	for (;;) {
-		struct btrfs_trans_handle *trans;
-		int ret;
-
-		ret = btrfs_block_rsv_refill(root, rsv,
-					     rsv->size + delayed_refs_extra,
-					     BTRFS_RESERVE_FLUSH_LIMIT);
-
-		if (ret && ++failures > 2) {
-			btrfs_warn(fs_info,
-				   "could not allocate space for a delete; will truncate on mount");
-			return ERR_PTR(-ENOSPC);
-		}
-
-		/*
-		 * Evict can generate a large amount of delayed refs without
-		 * having a way to add space back since we exhaust our temporary
-		 * block rsv.  We aren't allowed to do FLUSH_ALL in this case
-		 * because we could deadlock with so many things in the flushing
-		 * code, so we have to try and hold some extra space to
-		 * compensate for our delayed ref generation.  If we can't get
-		 * that space then we need see if we can steal our minimum from
-		 * the global reserve.  We will be ratelimited by the amount of
-		 * space we have for the delayed refs rsv, so we'll end up
-		 * committing and trying again.
-		 */
-		trans = btrfs_join_transaction(root);
-		if (IS_ERR(trans) || !ret) {
-			if (!IS_ERR(trans)) {
-				trans->block_rsv = &fs_info->trans_block_rsv;
-				trans->bytes_reserved = delayed_refs_extra;
-				btrfs_block_rsv_migrate(rsv, trans->block_rsv,
-							delayed_refs_extra, 1);
-			}
-			return trans;
-		}
+	int ret;
 
+	/*
+	 * Eviction should be taking place at some place safe because of our
+	 * delayed iputs.  However the normal flushing code will run delayed
+	 * iputs, so we cannot use FLUSH_ALL otherwise we'll deadlock.
+	 *
+	 * We reserve the delayed_refs_extra here again because we can't use
+	 * btrfs_start_transaction(root, 0) for the same deadlocky reason as
+	 * above.  We reserve our extra bit here because we generate a ton of
+	 * delayed refs activity by truncating.
+	 *
+	 * If we cannot make our reservation we'll attempt to steal from the
+	 * global reserve, because we really want to be able to free up space.
+	 */
+	ret = btrfs_block_rsv_refill(root, rsv, rsv->size + delayed_refs_extra,
+				     BTRFS_RESERVE_FLUSH_EVICT);
+	if (ret) {
 		/*
 		 * Try to steal from the global reserve if there is space for
 		 * it.
 		 */
-		if (!btrfs_check_space_for_delayed_refs(fs_info) &&
-		    !btrfs_block_rsv_migrate(global_rsv, rsv, rsv->size, 0))
-			return trans;
+		if (btrfs_check_space_for_delayed_refs(fs_info) ||
+		    btrfs_block_rsv_migrate(global_rsv, rsv, rsv->size, 0)) {
+			btrfs_warn(fs_info,
+				   "could not allocate space for delete; will truncate on mount");
+			return ERR_PTR(-ENOSPC);
+		}
+		delayed_refs_extra = 0;
+	}
 
-		/* If not, commit and try again. */
-		ret = btrfs_commit_transaction(trans);
-		if (ret)
-			return ERR_PTR(ret);
+	trans = btrfs_join_transaction(root);
+	if (IS_ERR(trans))
+		return trans;
+
+	if (delayed_refs_extra) {
+		trans->block_rsv = &fs_info->trans_block_rsv;
+		trans->bytes_reserved = delayed_refs_extra;
+		btrfs_block_rsv_migrate(rsv, trans->block_rsv,
+					delayed_refs_extra, 1);
 	}
+	return trans;
 }
 
 void btrfs_evict_inode(struct inode *inode)
diff --git a/fs/btrfs/space-info.c b/fs/btrfs/space-info.c
index 03556e411b11..95bf2625ff9b 100644
--- a/fs/btrfs/space-info.c
+++ b/fs/btrfs/space-info.c
@@ -868,6 +868,17 @@ static const enum btrfs_flush_state priority_flush_states[] = {
 	ALLOC_CHUNK,
 };
 
+static const enum btrfs_flush_state evict_flush_states[] = {
+	FLUSH_DELAYED_ITEMS_NR,
+	FLUSH_DELAYED_ITEMS,
+	FLUSH_DELAYED_REFS_NR,
+	FLUSH_DELAYED_REFS,
+	FLUSH_DELALLOC,
+	FLUSH_DELALLOC_WAIT,
+	ALLOC_CHUNK,
+	COMMIT_TRANS,
+};
+
 static void
 priority_reclaim_metadata_space(struct btrfs_fs_info *fs_info,
 				struct btrfs_space_info *space_info,
@@ -944,12 +955,24 @@ static int handle_reserve_ticket(struct btrfs_fs_info *fs_info,
 	u64 reclaim_bytes = 0;
 	int ret;
 
-	if (flush == BTRFS_RESERVE_FLUSH_ALL)
+	switch (flush) {
+	case BTRFS_RESERVE_FLUSH_ALL:
 		wait_reserve_ticket(fs_info, space_info, ticket);
-	else
+		break;
+	case BTRFS_RESERVE_FLUSH_LIMIT:
 		priority_reclaim_metadata_space(fs_info, space_info, ticket,
 						priority_flush_states,
 						ARRAY_SIZE(priority_flush_states));
+		break;
+	case BTRFS_RESERVE_FLUSH_EVICT:
+		priority_reclaim_metadata_space(fs_info, space_info, ticket,
+						evict_flush_states,
+						ARRAY_SIZE(evict_flush_states));
+		break;
+	default:
+		ASSERT(0);
+		break;
+	}
 
 	spin_lock(&space_info->lock);
 	ret = ticket->error;
-- 
2.21.0


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH 0/5] Rework eviction space flushing
  2019-08-01 22:19 [PATCH 0/5] Rework eviction space flushing Josef Bacik
                   ` (4 preceding siblings ...)
  2019-08-01 22:19 ` [PATCH 5/5] btrfs: introduce an evict flushing state Josef Bacik
@ 2019-08-05 17:50 ` David Sterba
  2019-08-19 16:20 ` David Sterba
  6 siblings, 0 replies; 9+ messages in thread
From: David Sterba @ 2019-08-05 17:50 UTC (permalink / raw)
  To: Josef Bacik; +Cc: linux-btrfs, kernel-team

On Thu, Aug 01, 2019 at 06:19:32PM -0400, Josef Bacik wrote:
> This is a set of patches to address how we do space flushing for inode
> evictions.  Historically we've only been allowed to do a few things to reclaim
> space for inode evictions, mostly because we'd deadlock with iput.  But we have
> delayed iputs in place to make sure we're always doing iput where it's
> completely safe to do an iput.
> 
> However we do run iputs for flushing, so we can't just do FLUSH_ALL, otherwise
> we could deadlock.  Also we still want to prioritize evictions for space
> reclamation because we likely will free up space for other people to make
> reservations.
> 
> The first 4 patches are preparation patches, just refactoring so we can add this
> new flushing time for eviction.  This allows us to clean up our current ad-hoc
> loop we have for reclaiming space for evictions and use the common helpers that
> everybody else uses.  Thanks,

I'll add this as a topic branch to for-next for testing, I have only
skimmed the patches and did not do any kind of review.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 0/5] Rework eviction space flushing
  2019-08-01 22:19 [PATCH 0/5] Rework eviction space flushing Josef Bacik
                   ` (5 preceding siblings ...)
  2019-08-05 17:50 ` [PATCH 0/5] Rework eviction space flushing David Sterba
@ 2019-08-19 16:20 ` David Sterba
  6 siblings, 0 replies; 9+ messages in thread
From: David Sterba @ 2019-08-19 16:20 UTC (permalink / raw)
  To: Josef Bacik; +Cc: linux-btrfs, kernel-team

On Thu, Aug 01, 2019 at 06:19:32PM -0400, Josef Bacik wrote:
> This is a set of patches to address how we do space flushing for inode
> evictions.  Historically we've only been allowed to do a few things to reclaim
> space for inode evictions, mostly because we'd deadlock with iput.  But we have
> delayed iputs in place to make sure we're always doing iput where it's
> completely safe to do an iput.
> 
> However we do run iputs for flushing, so we can't just do FLUSH_ALL, otherwise
> we could deadlock.  Also we still want to prioritize evictions for space
> reclamation because we likely will free up space for other people to make
> reservations.
> 
> The first 4 patches are preparation patches, just refactoring so we can add this
> new flushing time for eviction.  This allows us to clean up our current ad-hoc
> loop we have for reclaiming space for evictions and use the common helpers that
> everybody else uses.  Thanks,

1-5 added to misc-next, thanks.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 4/5] btrfs: refactor priority_reclaim_metadata_space
  2019-08-01 22:19 ` [PATCH 4/5] btrfs: refactor priority_reclaim_metadata_space Josef Bacik
@ 2019-08-19 16:22   ` David Sterba
  0 siblings, 0 replies; 9+ messages in thread
From: David Sterba @ 2019-08-19 16:22 UTC (permalink / raw)
  To: Josef Bacik; +Cc: linux-btrfs, kernel-team

On Thu, Aug 01, 2019 at 06:19:36PM -0400, Josef Bacik wrote:
> With the eviction flushing stuff we'll want to allow for different
> states, but still work basically the same way that
> priority_reclaim_metadata_space works currently.  Refactor this to take
> the flushing states and size as an argument so we can use the same logic
> for limit flushing and eviction flushing.
> 
> Signed-off-by: Josef Bacik <josef@toxicpanda.com>
> ---
>  fs/btrfs/space-info.c | 17 +++++++++++------
>  1 file changed, 11 insertions(+), 6 deletions(-)
> 
> diff --git a/fs/btrfs/space-info.c b/fs/btrfs/space-info.c
> index 71749b355136..03556e411b11 100644
> --- a/fs/btrfs/space-info.c
> +++ b/fs/btrfs/space-info.c
> @@ -868,9 +868,12 @@ static const enum btrfs_flush_state priority_flush_states[] = {
>  	ALLOC_CHUNK,
>  };
>  
> -static void priority_reclaim_metadata_space(struct btrfs_fs_info *fs_info,
> -					    struct btrfs_space_info *space_info,
> -					    struct reserve_ticket *ticket)
> +static void
> +priority_reclaim_metadata_space(struct btrfs_fs_info *fs_info,

Please note that the split type and function name is the reverse of the
coding style used in btrfs, I fix such things but please don't introduce
it in new patches namely when the original code is using the correct
style.

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2019-08-19 16:21 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-08-01 22:19 [PATCH 0/5] Rework eviction space flushing Josef Bacik
2019-08-01 22:19 ` [PATCH 1/5] btrfs: add a flush step for delayed iputs Josef Bacik
2019-08-01 22:19 ` [PATCH 2/5] btrfs: unify error handling for ticket flushing Josef Bacik
2019-08-01 22:19 ` [PATCH 3/5] btrfs: factor out the ticket flush handling Josef Bacik
2019-08-01 22:19 ` [PATCH 4/5] btrfs: refactor priority_reclaim_metadata_space Josef Bacik
2019-08-19 16:22   ` David Sterba
2019-08-01 22:19 ` [PATCH 5/5] btrfs: introduce an evict flushing state Josef Bacik
2019-08-05 17:50 ` [PATCH 0/5] Rework eviction space flushing David Sterba
2019-08-19 16:20 ` David Sterba

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).