Blob Blame History Raw
From: Mikulas Patocka <mpatocka@redhat.com>
Date: Thu, 12 Sep 2019 10:44:46 +0200
Subject: [PATCH] dm bufio: introduce a global queue
Git-commit: af53badc0cd8a511b016a10c0cccf916692f1fc2
Patch-mainline: v5.4-rc1
References: bsc#1175995,jsc#SLE-15608

Rename param_spinlock to global_spinlock and introduce a global queue of
all used buffers.  The queue will be used in the following commits.

Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
Signed-off-by: Mike Snitzer <snitzer@redhat.com>
Acked-by: Hannes Reinecke <hare@suse.com>
---
 drivers/md/dm-bufio.c | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/drivers/md/dm-bufio.c b/drivers/md/dm-bufio.c
index 58df20fd5465..2451a4d68aed 100644
--- a/drivers/md/dm-bufio.c
+++ b/drivers/md/dm-bufio.c
@@ -132,6 +132,7 @@ enum data_mode {
 struct dm_buffer {
 	struct rb_node node;
 	struct list_head lru_list;
+	struct list_head global_list;
 	sector_t block;
 	void *data;
 	unsigned char data_mode;		/* DATA_MODE_* */
@@ -192,7 +193,9 @@ static unsigned long dm_bufio_cache_size;
  */
 static unsigned long dm_bufio_cache_size_latch;
 
-static DEFINE_SPINLOCK(param_spinlock);
+static DEFINE_SPINLOCK(global_spinlock);
+
+static LIST_HEAD(global_queue);
 
 /*
  * Buffers are freed after this timeout
@@ -301,7 +304,7 @@ static void adjust_total_allocated(struct dm_buffer *b, bool unlink)
 	if (unlink)
 		diff = -diff;
 
-	spin_lock(&param_spinlock);
+	spin_lock(&global_spinlock);
 
 	*class_ptr[data_mode] += diff;
 
@@ -310,7 +313,13 @@ static void adjust_total_allocated(struct dm_buffer *b, bool unlink)
 	if (dm_bufio_current_allocated > dm_bufio_peak_allocated)
 		dm_bufio_peak_allocated = dm_bufio_current_allocated;
 
-	spin_unlock(&param_spinlock);
+	if (!unlink) {
+		list_add(&b->global_list, &global_queue);
+	} else {
+		list_del(&b->global_list);
+	}
+
+	spin_unlock(&global_spinlock);
 }
 
 /*
-- 
2.16.4