[RFC PATCH 7/7] bcache: add cond_resched() in bch_btree_node_get() if mca_alloc() fails

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



In bch_btree_node_get(), if mca_alloc() fails and returns NULL pointer,
it means no memory to allocate and the code will go to retry label to
call mca_alloc() again.

When few system memory to allocate, it takes time for in-memory btree
node cache shrink kthread to shrink the nodes, and same to the slab
memory shrinker callback routines. Therefore directly go to retry label
may just wast CPU cycles because the memory is still not available yet,
and the code has to jump to retry label again.

This patch adds cond_resched() before jumps to retry label, then there
will be much less re-jump to retry label when memory allocation fails.
it may relax the CPU cycles and give more time for shrink kthread and
other slab memory shrink callback routines.

Signed-off-by: Coly Li <colyli@xxxxxxx>
---
 drivers/md/bcache/btree.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/md/bcache/btree.c b/drivers/md/bcache/btree.c
index 48a097037da8..bd42b0b1af27 100644
--- a/drivers/md/bcache/btree.c
+++ b/drivers/md/bcache/btree.c
@@ -1081,8 +1081,10 @@ struct btree *bch_btree_node_get(struct cache_set *c, struct btree_op *op,
 		b = mca_alloc(c, op, k, level);
 		mutex_unlock(&c->bucket_lock);
 
-		if (!b)
+		if (!b) {
+			cond_resched();
 			goto retry;
+		}
 		if (IS_ERR(b))
 			return b;
 
-- 
2.16.4




[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Linux ARM Kernel]     [Linux Filesystem Development]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux OMAP]     [Linux MIPS]     [ECOS]     [Asterisk Internet PBX]     [Linux API]

  Powered by Linux