Skip to contentSkip to conversation

xen/blkback: add LRU purge parameters

PATCH In review Roger Pau Monne 3 participants 7 messages Oct 15, 2020

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover xen/blkback: add LRU purge parameters

Add the LRU parameters as tunables.

Roger Pau Monne (2):
xen/blkback: turn the cache purge LRU interval into a parameter xen/blkback: turn the cache purge percent into a parameter

 .../ABI/testing/sysfs-driver-xen-blkback      | 19 +++++++++++++++++++
 drivers/block/xen-blkback/blkback.c           | 16 +++++++++++-----
 2 files changed, 30 insertions(+), 5 deletions(-)
Signature · 1 line
2.28.0
#1 lore raw

PATCH 1/2 xen/blkback: turn the cache purge LRU interval into a parameter

Assume that reads and writes to the variable will be atomic. The worse that could happen is that one of the LRU intervals is not calculated properly if a partially written value is read, but that would only be a transient issue.

---
Cc: Konrad Rzeszutek Wilk <[email protected]>
Cc: Jens Axboe <[email protected]>
Cc: Boris Ostrovsky <[email protected]>
Cc: SeongJae Park <[email protected]>
Cc: [email protected]
Cc: [email protected]
Cc: J. Roeleveld <[email protected]>
Cc: Jürgen Groß <[email protected]>

---
 Documentation/ABI/testing/sysfs-driver-xen-blkback | 10 ++++++++++
 drivers/block/xen-blkback/blkback.c                |  9 ++++++---
 2 files changed, 16 insertions(+), 3 deletions(-)
Documentation/ABI/testing/sysfs-driver-xen-blkback +10 -0
index ecb7942ff146..776f25d335ca 100644
@@ -35,3 +35,13 @@ Description:
                 controls the duration in milliseconds that blkback will not
                 cache any page not backed by a grant mapping.
                 The default is 10ms.
+
+What:           /sys/module/xen_blkback/parameters/lru_internval
+Date:           October 2020
+KernelVersion:  5.10
+Contact:        Roger Pau Monné <[email protected]>
+Description:
+                The LRU mechanism to clean the lists of persistent grants needs
+                to be executed periodically. This parameter controls the time
+                interval between consecutive executions of the purge mechanism
+                is set in ms.
drivers/block/xen-blkback/blkback.c +6 -3
index adfc9352351d..6ad9b76fdb2b 100644
@@ -117,7 +117,10 @@ MODULE_PARM_DESC(max_ring_page_order, "Maximum order of pages to be used for the
  * be executed periodically. The time interval between consecutive executions
  * of the purge mechanism is set in ms.
  */
-#define LRU_INTERVAL 100
+static unsigned int lru_interval = 100;
+module_param_named(lru_interval, lru_interval, uint, 0644);
+MODULE_PARM_DESC(lru_internval,
+		 "Time interval between consecutive executions of the cache purge mechanism (in ms)");
 
 /*
  * When the persistent grants list is full we will remove unused grants
@@ -620,7 +623,7 @@ int xen_blkif_schedule(void *arg)
 		if (unlikely(vbd->size != vbd_sz(vbd)))
 			xen_vbd_resize(blkif);
 
-		timeout = msecs_to_jiffies(LRU_INTERVAL);
+		timeout = msecs_to_jiffies(lru_interval);
 
 		timeout = wait_event_interruptible_timeout(
 			ring->wq,
@@ -650,7 +653,7 @@ int xen_blkif_schedule(void *arg)
 		if (blkif->vbd.feature_gnt_persistent &&
 		    time_after(jiffies, ring->next_lru)) {
 			purge_persistent_gnt(ring);
-			ring->next_lru = jiffies + msecs_to_jiffies(LRU_INTERVAL);
+			ring->next_lru = jiffies + msecs_to_jiffies(lru_interval);
 		}
 
 		/* Shrink the free pages pool if it is too large. */
Signature · 1 line
2.28.0
#2 lore raw

Re: [PATCH 1/2] xen/blkback: turn the cache purge LRU interval into a parameter

Quoted 25 lines · Roger Pau Monne

Assume that reads and writes to the variable will be atomic. The worse that could happen is that one of the LRU intervals is not calculated properly if a partially written value is read, but that would only be a transient issue.

---
Cc: Konrad Rzeszutek Wilk <[email protected]>
Cc: Jens Axboe <[email protected]>
Cc: Boris Ostrovsky <[email protected]>
Cc: SeongJae Park <[email protected]>
Cc: [email protected]
Cc: [email protected]
Cc: J. Roeleveld <[email protected]>
Cc: Jürgen Groß <[email protected]>

---
  Documentation/ABI/testing/sysfs-driver-xen-blkback | 10 ++++++++++
  drivers/block/xen-blkback/blkback.c                |  9 ++++++---
  2 files changed, 16 insertions(+), 3 deletions(-)
Documentation/ABI/testing/sysfs-driver-xen-blkback +0 -0
index ecb7942ff146..776f25d335ca 100644

Documentation/ABI/testing/sysfs-driver-xen-blkback Description: · line 39

Quoted 5 lines
Documentation/ABI/testing/sysfs-driver-xen-blkback +2 -0
@@ -35,3 +35,13 @@ Description:
                  controls the duration in milliseconds that blkback will not
                  cache any page not backed by a grant mapping.
                  The default is 10ms.
+
+What:           /sys/module/xen_blkback/parameters/lru_internval

s/lru_internval/lru_interval/

Quoted 13 lines
Documentation/ABI/testing/sysfs-driver-xen-blkback +8 -0
+Date:           October 2020
+KernelVersion:  5.10
+Contact:        Roger Pau Monné <[email protected]>
+Description:
+                The LRU mechanism to clean the lists of persistent grants needs
+                to be executed periodically. This parameter controls the time
+                interval between consecutive executions of the purge mechanism
+                is set in ms.
drivers/block/xen-blkback/blkback.c +0 -0
index adfc9352351d..6ad9b76fdb2b 100644

drivers/block/xen-blkback/blkback.c MODULE_PARM_DESC(max_ring_page_order, "Maximum order of pages to be used for the · line 122

Quoted 7 lines
drivers/block/xen-blkback/blkback.c +3 -1
@@ -117,7 +117,10 @@ MODULE_PARM_DESC(max_ring_page_order, "Maximum order of pages to be used for the
   * be executed periodically. The time interval between consecutive executions
   * of the purge mechanism is set in ms.
   */
-#define LRU_INTERVAL 100
+static unsigned int lru_interval = 100;
+module_param_named(lru_interval, lru_interval, uint, 0644);
+MODULE_PARM_DESC(lru_internval,

s/lru_internval/lru_interval/

Quoted 15 lines
drivers/block/xen-blkback/blkback.c +2 -1
+		 "Time interval between consecutive executions of the cache purge mechanism (in ms)");
 
  /*
   * When the persistent grants list is full we will remove unused grants
@@ -620,7 +623,7 @@ int xen_blkif_schedule(void *arg)
  		if (unlikely(vbd->size != vbd_sz(vbd)))
  			xen_vbd_resize(blkif);
 
-		timeout = msecs_to_jiffies(LRU_INTERVAL);
+		timeout = msecs_to_jiffies(lru_interval);
 
  		timeout = wait_event_interruptible_timeout(
  			ring->wq,

drivers/block/xen-blkback/blkback.c int xen_blkif_schedule(void *arg) · line 659

Quoted 8 lines
drivers/block/xen-blkback/blkback.c +1 -1
@@ -650,7 +653,7 @@ int xen_blkif_schedule(void *arg)
  		if (blkif->vbd.feature_gnt_persistent &&
  		    time_after(jiffies, ring->next_lru)) {
  			purge_persistent_gnt(ring);
-			ring->next_lru = jiffies + msecs_to_jiffies(LRU_INTERVAL);
+			ring->next_lru = jiffies + msecs_to_jiffies(lru_interval);
  		}
 
  		/* Shrink the free pages pool if it is too large. */

Juergen

#3 lore raw

Re: [PATCH 1/2] xen/blkback: turn the cache purge LRU interval into a parameter

In reply to Roger Pau Monne
Quoted 28 lines · On Thu, 15 Oct 2020 16:24:15 +0200 Roger Pau Monne <[email protected]> wrote:

Assume that reads and writes to the variable will be atomic. The worse that could happen is that one of the LRU intervals is not calculated properly if a partially written value is read, but that would only be a transient issue.

---
Cc: Konrad Rzeszutek Wilk <[email protected]>
Cc: Jens Axboe <[email protected]>
Cc: Boris Ostrovsky <[email protected]>
Cc: SeongJae Park <[email protected]>
Cc: [email protected]
Cc: [email protected]
Cc: J. Roeleveld <[email protected]>
Cc: Jürgen Groß <[email protected]>

---
 Documentation/ABI/testing/sysfs-driver-xen-blkback | 10 ++++++++++
 drivers/block/xen-blkback/blkback.c                |  9 ++++++---
 2 files changed, 16 insertions(+), 3 deletions(-)
Documentation/ABI/testing/sysfs-driver-xen-blkback +0 -0
index ecb7942ff146..776f25d335ca 100644
@@ -35,3 +35,13 @@ Description:
                 controls the duration in milliseconds that blkback will not
                 cache any page not backed by a grant mapping.
                 The default is 10ms.

Documentation/ABI/testing/sysfs-driver-xen-blkback Description: · line 47

Quoted 10 lines
Documentation/ABI/testing/sysfs-driver-xen-blkback +10 -0
+
+What:           /sys/module/xen_blkback/parameters/lru_internval
+Date:           October 2020
+KernelVersion:  5.10
+Contact:        Roger Pau Monné <[email protected]>
+Description:
+                The LRU mechanism to clean the lists of persistent grants needs
+                to be executed periodically. This parameter controls the time
+                interval between consecutive executions of the purge mechanism
+                is set in ms.

I think noticing the default value (100ms) here would be better.

Thanks,
SeongJae Park

#4 lore raw

PATCH 2/2 xen/blkback: turn the cache purge percent into a parameter

In reply to Roger Pau Monne

Assume that reads and writes to the variable will be atomic. The worse that could happen is that one of the purges removes a partially written percentage of grants, but the cache itself will recover.

---
Cc: Konrad Rzeszutek Wilk <[email protected]>
Cc: Jens Axboe <[email protected]>
Cc: Boris Ostrovsky <[email protected]>
Cc: SeongJae Park <[email protected]>
Cc: [email protected]
Cc: [email protected]
Cc: J. Roeleveld <[email protected]>
Cc: Jürgen Groß <[email protected]>

---
 Documentation/ABI/testing/sysfs-driver-xen-blkback | 9 +++++++++
 drivers/block/xen-blkback/blkback.c                | 7 +++++--
 2 files changed, 14 insertions(+), 2 deletions(-)
Documentation/ABI/testing/sysfs-driver-xen-blkback +9 -0
index 776f25d335ca..7de791ad61f9 100644
@@ -45,3 +45,12 @@ Description:
                 to be executed periodically. This parameter controls the time
                 interval between consecutive executions of the purge mechanism
                 is set in ms.
+
+What:           /sys/module/xen_blkback/parameters/lru_percent_clean
+Date:           October 2020
+KernelVersion:  5.10
+Contact:        Roger Pau Monné <[email protected]>
+Description:
+                When the persistent grants list is full we will remove unused
+                grants from the list. The percent number of grants to be
+                removed at each LRU execution.
drivers/block/xen-blkback/blkback.c +5 -2
index 6ad9b76fdb2b..772852d45a5a 100644
@@ -127,7 +127,10 @@ MODULE_PARM_DESC(lru_internval,
  * from the list. The percent number of grants to be removed at each LRU
  * execution.
  */
-#define LRU_PERCENT_CLEAN 5
+static unsigned int lru_percent_clean = 5;
+module_param_named(lru_percent_clean, lru_percent_clean, uint, 0644);
+MODULE_PARM_DESC(lru_percent_clean,
+		 "Percentage of persistent grants to remove from the cache when full");
 
 /* Run-time switchable: /sys/module/blkback/parameters/ */
 static unsigned int log_stats;
@@ -404,7 +407,7 @@ static void purge_persistent_gnt(struct xen_blkif_ring *ring)
 	    !ring->blkif->vbd.overflow_max_grants)) {
 		num_clean = 0;
 	} else {
-		num_clean = (max_pgrants / 100) * LRU_PERCENT_CLEAN;
+		num_clean = (max_pgrants / 100) * lru_percent_clean;
 		num_clean = ring->persistent_gnt_c - max_pgrants + num_clean;
 		num_clean = min(ring->persistent_gnt_c, num_clean);
 		pr_debug("Going to purge at least %u persistent grants\n",
Signature · 1 line
2.28.0
#5 lore raw

Re: [PATCH 2/2] xen/blkback: turn the cache purge percent into a parameter

Quoted 53 lines · Roger Pau Monne

Assume that reads and writes to the variable will be atomic. The worse that could happen is that one of the purges removes a partially written percentage of grants, but the cache itself will recover.

---
Cc: Konrad Rzeszutek Wilk <[email protected]>
Cc: Jens Axboe <[email protected]>
Cc: Boris Ostrovsky <[email protected]>
Cc: SeongJae Park <[email protected]>
Cc: [email protected]
Cc: [email protected]
Cc: J. Roeleveld <[email protected]>
Cc: Jürgen Groß <[email protected]>

---
  Documentation/ABI/testing/sysfs-driver-xen-blkback | 9 +++++++++
  drivers/block/xen-blkback/blkback.c                | 7 +++++--
  2 files changed, 14 insertions(+), 2 deletions(-)
Documentation/ABI/testing/sysfs-driver-xen-blkback +9 -0
index 776f25d335ca..7de791ad61f9 100644
@@ -45,3 +45,12 @@ Description:
                  to be executed periodically. This parameter controls the time
                  interval between consecutive executions of the purge mechanism
                  is set in ms.
+
+What:           /sys/module/xen_blkback/parameters/lru_percent_clean
+Date:           October 2020
+KernelVersion:  5.10
+Contact:        Roger Pau Monné <[email protected]>
+Description:
+                When the persistent grants list is full we will remove unused
+                grants from the list. The percent number of grants to be
+                removed at each LRU execution.
drivers/block/xen-blkback/blkback.c +4 -1
index 6ad9b76fdb2b..772852d45a5a 100644
@@ -127,7 +127,10 @@ MODULE_PARM_DESC(lru_internval,
   * from the list. The percent number of grants to be removed at each LRU
   * execution.
   */
-#define LRU_PERCENT_CLEAN 5
+static unsigned int lru_percent_clean = 5;
+module_param_named(lru_percent_clean, lru_percent_clean, uint, 0644);
+MODULE_PARM_DESC(lru_percent_clean,
+		 "Percentage of persistent grants to remove from the cache when full");
 
  /* Run-time switchable: /sys/module/blkback/parameters/ */
  static unsigned int log_stats;

drivers/block/xen-blkback/blkback.c static void purge_persistent_gnt(struct xen_blkif_ring *ring) · line 410

Quoted 5 lines
drivers/block/xen-blkback/blkback.c +1 -1
@@ -404,7 +407,7 @@ static void purge_persistent_gnt(struct xen_blkif_ring *ring)
  	    !ring->blkif->vbd.overflow_max_grants)) {
  		num_clean = 0;
  	} else {
-		num_clean = (max_pgrants / 100) * LRU_PERCENT_CLEAN;
+		num_clean = (max_pgrants / 100) * lru_percent_clean;

Hmm, wouldn't it be better to use (max_grants * lru_percent_clean) / 100 here in order to support max_grants values less than 100?

Juergen

#6 lore raw

Re: [PATCH 2/2] xen/blkback: turn the cache purge percent into a parameter

Quoted 53 lines · Jürgen Groß
Quoted 52 lines · Roger Pau Monne

Assume that reads and writes to the variable will be atomic. The worse that could happen is that one of the purges removes a partially written percentage of grants, but the cache itself will recover.

---
Cc: Konrad Rzeszutek Wilk <[email protected]>
Cc: Jens Axboe <[email protected]>
Cc: Boris Ostrovsky <[email protected]>
Cc: SeongJae Park <[email protected]>
Cc: [email protected]
Cc: [email protected]
Cc: J. Roeleveld <[email protected]>
Cc: Jürgen Groß <[email protected]>

---
  Documentation/ABI/testing/sysfs-driver-xen-blkback | 9 +++++++++
  drivers/block/xen-blkback/blkback.c                | 7 +++++--
  2 files changed, 14 insertions(+), 2 deletions(-)
Documentation/ABI/testing/sysfs-driver-xen-blkback +9 -0
index 776f25d335ca..7de791ad61f9 100644
@@ -45,3 +45,12 @@ Description:
                  to be executed periodically. This parameter controls the time
                  interval between consecutive executions of the purge mechanism
                  is set in ms.
+
+What:           /sys/module/xen_blkback/parameters/lru_percent_clean
+Date:           October 2020
+KernelVersion:  5.10
+Contact:        Roger Pau Monné <[email protected]>
+Description:
+                When the persistent grants list is full we will remove unused
+                grants from the list. The percent number of grants to be
+                removed at each LRU execution.
drivers/block/xen-blkback/blkback.c +4 -1
index 6ad9b76fdb2b..772852d45a5a 100644
@@ -127,7 +127,10 @@ MODULE_PARM_DESC(lru_internval,
   * from the list. The percent number of grants to be removed at each LRU
   * execution.
   */
-#define LRU_PERCENT_CLEAN 5
+static unsigned int lru_percent_clean = 5;
+module_param_named(lru_percent_clean, lru_percent_clean, uint, 0644);
+MODULE_PARM_DESC(lru_percent_clean,
+		 "Percentage of persistent grants to remove from the cache when full");
  /* Run-time switchable: /sys/module/blkback/parameters/ */
  static unsigned int log_stats;
@@ -404,7 +407,7 @@ static void purge_persistent_gnt(struct xen_blkif_ring *ring)
Quoted 8 lines

drivers/block/xen-blkback/blkback.c static void purge_persistent_gnt(struct xen_blkif_ring *ring) · line 410

Quoted 5 lines
drivers/block/xen-blkback/blkback.c +1 -1
  	    !ring->blkif->vbd.overflow_max_grants)) {
  		num_clean = 0;
  	} else {
-		num_clean = (max_pgrants / 100) * LRU_PERCENT_CLEAN;
+		num_clean = (max_pgrants / 100) * lru_percent_clean;

Hmm, wouldn't it be better to use (max_grants * lru_percent_clean) / 100 here in order to support max_grants values less than 100?

Yes, we should have done that when moving max_pgrants to a parameter, it used to be fixed first.

Will do in next version since I'm already changing the line.

Thanks, Roger.