Skip to contentSkip to conversation

md: code cleanups

PATCH In review Pankaj Gupta 4 participants 7 messages Nov 11, 2020 – Nov 16, 2020 MD RAID

lore
Share & tools
lore
#0 lore raw

cover md: code cleanups

From: Pankaj Gupta <[email protected]>

This patch series does some cleanups during my attempt to understand the code.

Pankaj Gupta (3):
md: improve variable names in md_flush_request()
md: add comments in md_flush_request()
md: use current request time as base for ktime comparisons

 drivers/md/md.c | 12 ++++++++----
 drivers/md/md.h |  6 +++---
 2 files changed, 11 insertions(+), 7 deletions(-)
Signature · 1 line
2.20.1
#1 lore raw

PATCH 1/3 md: improve variable names in md_flush_request()

From: Pankaj Gupta <[email protected]>

This patch improves readability by using better variable names in flush request coalescing logic.

---
 drivers/md/md.c | 8 ++++----
 drivers/md/md.h | 6 +++---
 2 files changed, 7 insertions(+), 7 deletions(-)
drivers/md/md.c +4 -4
index 98bac4f304ae..167c80f98533 100644
@@ -639,7 +639,7 @@ static void md_submit_flush_data(struct work_struct *ws)
 	 * could wait for this and below md_handle_request could wait for those
 	 * bios because of suspend check
 	 */
-	mddev->last_flush = mddev->start_flush;
+	mddev->prev_flush_start = mddev->start_flush;
 	mddev->flush_bio = NULL;
 	wake_up(&mddev->sb_wait);
 
@@ -660,13 +660,13 @@ static void md_submit_flush_data(struct work_struct *ws)
  */
 bool md_flush_request(struct mddev *mddev, struct bio *bio)
 {
-	ktime_t start = ktime_get_boottime();
+	ktime_t req_start = ktime_get_boottime();
 	spin_lock_irq(&mddev->lock);
 	wait_event_lock_irq(mddev->sb_wait,
 			    !mddev->flush_bio ||
-			    ktime_after(mddev->last_flush, start),
+			    ktime_after(mddev->prev_flush_start, req_start),
 			    mddev->lock);
-	if (!ktime_after(mddev->last_flush, start)) {
+	if (!ktime_after(mddev->prev_flush_start, req_start)) {
 		WARN_ON(mddev->flush_bio);
 		mddev->flush_bio = bio;
 		bio = NULL;
drivers/md/md.h +3 -3
index ccfb69868c2e..2292c847f9dd 100644
@@ -495,9 +495,9 @@ struct mddev {
 	 */
 	struct bio *flush_bio;
 	atomic_t flush_pending;
-	ktime_t start_flush, last_flush; /* last_flush is when the last completed
-					  * flush was started.
-					  */
+	ktime_t start_flush, prev_flush_start; /* prev_flush_start is when the previous completed
+						* flush was started.
+						*/
 	struct work_struct flush_work;
 	struct work_struct event_work;	/* used by dm to report failure event */
 	mempool_t *serial_info_pool;
Signature · 1 line
2.20.1
Reviewed-by on v1 1/3
#2 lore raw

Re: [PATCH 1/3] md: improve variable names in md_flush_request()

Dear Pankaj,

Thank you for the cleanups.

Am 11.11.20 um 06:16 schrieb Pankaj Gupta:

Quoted 4 lines

From: Pankaj Gupta <[email protected]>

This patch improves readability by using better variable names in flush request coalescing logic.

Please do not indent the commit message.

Quoted 41 lines
---
  drivers/md/md.c | 8 ++++----
  drivers/md/md.h | 6 +++---
  2 files changed, 7 insertions(+), 7 deletions(-)
drivers/md/md.c +4 -4
index 98bac4f304ae..167c80f98533 100644
@@ -639,7 +639,7 @@ static void md_submit_flush_data(struct work_struct *ws)
  	 * could wait for this and below md_handle_request could wait for those
  	 * bios because of suspend check
  	 */
-	mddev->last_flush = mddev->start_flush;
+	mddev->prev_flush_start = mddev->start_flush;
  	mddev->flush_bio = NULL;
  	wake_up(&mddev->sb_wait);
 
@@ -660,13 +660,13 @@ static void md_submit_flush_data(struct work_struct *ws)
   */
  bool md_flush_request(struct mddev *mddev, struct bio *bio)
  {
-	ktime_t start = ktime_get_boottime();
+	ktime_t req_start = ktime_get_boottime();
  	spin_lock_irq(&mddev->lock);
  	wait_event_lock_irq(mddev->sb_wait,
  			    !mddev->flush_bio ||
-			    ktime_after(mddev->last_flush, start),
+			    ktime_after(mddev->prev_flush_start, req_start),
  			    mddev->lock);
-	if (!ktime_after(mddev->last_flush, start)) {
+	if (!ktime_after(mddev->prev_flush_start, req_start)) {
  		WARN_ON(mddev->flush_bio);
  		mddev->flush_bio = bio;
  		bio = NULL;
drivers/md/md.h +0 -0
index ccfb69868c2e..2292c847f9dd 100644

drivers/md/md.h struct mddev { · line 500

Quoted 9 lines
drivers/md/md.h +3 -3
@@ -495,9 +495,9 @@ struct mddev {
  	 */
  	struct bio *flush_bio;
  	atomic_t flush_pending;
-	ktime_t start_flush, last_flush; /* last_flush is when the last completed
-					  * flush was started.
-					  */
+	ktime_t start_flush, prev_flush_start; /* prev_flush_start is when the previous completed
+						* flush was started.
+						*/

With the new variable name, the comment could even be removed. ;-)

drivers/md/md.h struct mddev { · line 503

Quoted 3 lines
drivers/md/md.h +0 -0
  	struct work_struct flush_work;
  	struct work_struct event_work;	/* used by dm to report failure event */
  	mempool_t *serial_info_pool;

Kind regards,

Paul

#3 lore raw

Re: [PATCH 1/3] md: improve variable names in md_flush_request()

Hi Paul,

Quoted 4 lines
Quoted 2 lines

This patch improves readability by using better variable names in flush request coalescing logic.

Please do not indent the commit message.

o.k

Quoted 54 lines
Quoted 42 lines
---
  drivers/md/md.c | 8 ++++----
  drivers/md/md.h | 6 +++---
  2 files changed, 7 insertions(+), 7 deletions(-)
drivers/md/md.c +4 -4
index 98bac4f304ae..167c80f98533 100644
@@ -639,7 +639,7 @@ static void md_submit_flush_data(struct work_struct *ws)
       * could wait for this and below md_handle_request could wait for those
       * bios because of suspend check
       */
-     mddev->last_flush = mddev->start_flush;
+     mddev->prev_flush_start = mddev->start_flush;
      mddev->flush_bio = NULL;
      wake_up(&mddev->sb_wait);
 
@@ -660,13 +660,13 @@ static void md_submit_flush_data(struct work_struct *ws)
   */
  bool md_flush_request(struct mddev *mddev, struct bio *bio)
  {
-     ktime_t start = ktime_get_boottime();
+     ktime_t req_start = ktime_get_boottime();
      spin_lock_irq(&mddev->lock);
      wait_event_lock_irq(mddev->sb_wait,
                          !mddev->flush_bio ||
-                         ktime_after(mddev->last_flush, start),
+                         ktime_after(mddev->prev_flush_start, req_start),
                          mddev->lock);
-     if (!ktime_after(mddev->last_flush, start)) {
+     if (!ktime_after(mddev->prev_flush_start, req_start)) {
              WARN_ON(mddev->flush_bio);
              mddev->flush_bio = bio;
              bio = NULL;
drivers/md/md.h +0 -0
index ccfb69868c2e..2292c847f9dd 100644

drivers/md/md.h struct mddev { · line 500

Quoted 9 lines
drivers/md/md.h +3 -3
@@ -495,9 +495,9 @@ struct mddev {
       */
      struct bio *flush_bio;
      atomic_t flush_pending;
-     ktime_t start_flush, last_flush; /* last_flush is when the last completed
-                                       * flush was started.
-                                       */
+     ktime_t start_flush, prev_flush_start; /* prev_flush_start is when the previous completed
+                                             * flush was started.
+                                             */

With the new variable name, the comment could even be removed. ;-)

Quoted 5 lines

drivers/md/md.h struct mddev { · line 503

Quoted 3 lines
drivers/md/md.h +0 -0
      struct work_struct flush_work;
      struct work_struct event_work;  /* used by dm to report failure event */
      mempool_t *serial_info_pool;

Thanks,
Pankaj

Quoted 5 lines

Kind regards,

Paul

#4 lore raw

PATCH 2/3 md: add comments in md_flush_request()

In reply to Pankaj Gupta

From: Pankaj Gupta <[email protected]>

Request coalescing logic is dependent on flush time update in other context. This patch adds comments to understand the code flow better.

---
 drivers/md/md.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/md/md.c +4 -0
index 167c80f98533..a330e61876e0 100644
@@ -662,10 +662,14 @@ bool md_flush_request(struct mddev *mddev, struct bio *bio)
 {
 	ktime_t req_start = ktime_get_boottime();
 	spin_lock_irq(&mddev->lock);
+	/* flush requests wait until ongoing flush completes,
+	 * hence coalescing all the pending requests.
+	 */
 	wait_event_lock_irq(mddev->sb_wait,
 			    !mddev->flush_bio ||
 			    ktime_after(mddev->prev_flush_start, req_start),
 			    mddev->lock);
+	/* new request after previous flush is completed */
 	if (!ktime_after(mddev->prev_flush_start, req_start)) {
 		WARN_ON(mddev->flush_bio);
 		mddev->flush_bio = bio;
Signature · 1 line
2.20.1
#5 lore raw

PATCH 3/3 md: use current request time as base for ktime comparisons

In reply to Pankaj Gupta

From: Pankaj Gupta <[email protected]>

Request coalescing logic uses 'prev_flush_start' as base to compare the current request start time. 'prev_flush_start' is updated in other context.

This patch changes this by using ktime comparison base to 'req_start' for better readability of code.

---
 drivers/md/md.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/md/md.c +2 -2
index a330e61876e0..217b1e3312cb 100644
@@ -667,10 +667,10 @@ bool md_flush_request(struct mddev *mddev, struct bio *bio)
 	 */
 	wait_event_lock_irq(mddev->sb_wait,
 			    !mddev->flush_bio ||
-			    ktime_after(mddev->prev_flush_start, req_start),
+			    ktime_before(req_start, mddev->prev_flush_start),
 			    mddev->lock);
 	/* new request after previous flush is completed */
-	if (!ktime_after(mddev->prev_flush_start, req_start)) {
+	if (ktime_after(req_start, mddev->prev_flush_start)) {
 		WARN_ON(mddev->flush_bio);
 		mddev->flush_bio = bio;
 		bio = NULL;
Signature · 1 line
2.20.1
maintainer
#6 lore raw
In reply to Pankaj Gupta
Quoted 10 lines · Pankaj Gupta

From: Pankaj Gupta <[email protected]>

This patch series does some cleanups during my attempt to understand the code.

Pankaj Gupta (3):
md: improve variable names in md_flush_request()
md: add comments in md_flush_request()
md: use current request time as base for ktime comparisons

Thanks for the clean up. Applied to md-next.