Skip to contentSkip to conversation

md: avoid potential long delay under pers_lock

PATCH In review Chao Yu 3 participants 5 messages Sep 25, 2014 – Sep 26, 2014 MD RAID

lore
Share & tools
lore

Chao Yu

author
#0 lore raw

PATCH 1/1 md: avoid potential long delay under pers_lock

printk may cause long time lapse if value of printk_delay in sysctl is configured large by user. If register_md_personality takes long time to print in spinlock pers_lock, we may encounter high CPU usage rate when there are other pers_lock competitors who may be blocked to spin.
We can avoid this condition by moving printk out of coverage of pers_lock spinlock.

---
 drivers/md/md.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/md/md.c +2 -1
index e02de05..5fcf215 100644
@@ -7200,9 +7200,10 @@ static const struct file_operations md_seq_fops = {
 
 int register_md_personality(struct md_personality *p)
 {
+	printk(KERN_INFO "md: %s personality registered for level %d\n",
+						p->name, p->level);
 	spin_lock(&pers_lock);
 	list_add_tail(&p->list, &pers_list);
-	printk(KERN_INFO "md: %s personality registered for level %d\n", p->name, p->level);
 	spin_unlock(&pers_lock);
 	return 0;
 }
Signature · 1 line
2.0.1.474.g72c7794
#1 lore raw
Quoted 18 lines · Chao Yu

printk may cause long time lapse if value of printk_delay in sysctl is configured large by user. If register_md_personality takes long time to print in spinlock pers_lock, we may encounter high CPU usage rate when there are other pers_lock competitors who may be blocked to spin.
We can avoid this condition by moving printk out of coverage of pers_lock spinlock.

---
 drivers/md/md.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/md/md.c +0 -0
index e02de05..5fcf215 100644
@@ -7200,9 +7200,10 @@ static const struct file_operations md_seq_fops = {
 

drivers/md/md.c static const struct file_operations md_seq_fops = { · line 7209

Quoted 10 lines
drivers/md/md.c +2 -1
 int register_md_personality(struct md_personality *p)
 {
+	printk(KERN_INFO "md: %s personality registered for level %d\n",
+						p->name, p->level);
 	spin_lock(&pers_lock);
 	list_add_tail(&p->list, &pers_list);
-	printk(KERN_INFO "md: %s personality registered for level %d\n", p->name, p->level);
 	spin_unlock(&pers_lock);
 	return 0;
 }

Wouldn't it make more sense to move the printk after the spin_unlock ?

Signature · 4 lines
  "One disk to rule them all, One disk to find them. One disk to bring
  them all and in the darkness grind them. In the Land of Redmond
  where the shadows lie." -- The Silicon Valley Tarot
  Henrique Holschuh
author
#2 lore raw
Quoted 26 lines

-----Original Message-----
From: Henrique de Moraes Holschuh [mailto:[email protected]]
Sent: Friday, September 26, 2014 12:51 AM
To: Chao Yu
Cc: [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH] md: avoid potential long delay under pers_lock

Quoted 18 lines · Chao Yu

printk may cause long time lapse if value of printk_delay in sysctl is configured large by user. If register_md_personality takes long time to print in spinlock pers_lock, we may encounter high CPU usage rate when there are other pers_lock competitors who may be blocked to spin.
We can avoid this condition by moving printk out of coverage of pers_lock spinlock.

---
 drivers/md/md.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/md/md.c +0 -0
index e02de05..5fcf215 100644
@@ -7200,9 +7200,10 @@ static const struct file_operations md_seq_fops = {
 
Quoted 12 lines

drivers/md/md.c static const struct file_operations md_seq_fops = { · line 7209

Quoted 10 lines
drivers/md/md.c +2 -1
 int register_md_personality(struct md_personality *p)
 {
+	printk(KERN_INFO "md: %s personality registered for level %d\n",
+						p->name, p->level);
 	spin_lock(&pers_lock);
 	list_add_tail(&p->list, &pers_list);
-	printk(KERN_INFO "md: %s personality registered for level %d\n", p->name, p->level);
 	spin_unlock(&pers_lock);
 	return 0;
 }

Wouldn't it make more sense to move the printk after the spin_unlock ?

As original printk msg in {,un}register_md_personality shows '{,un}registered' which means the main job is done before printk, it's better to move the printk after spin_unlock in both {,un}register_md_personality. But IMHO, it's another minor issue, should we fix in this patch?

Thanks,
Yu

Quoted 6 lines

--
"One disk to rule them all, One disk to find them. One disk to bring them all and in the darkness grind them. In the Land of Redmond where the shadows lie." -- The Silicon Valley Tarot Henrique Holschuh

#3 lore raw
In reply to Chao Yu
Quoted 18 lines · On Thu, 25 Sep 2014 15:28:34 +0800 Chao Yu <[email protected]> wrote:

printk may cause long time lapse if value of printk_delay in sysctl is configured large by user. If register_md_personality takes long time to print in spinlock pers_lock, we may encounter high CPU usage rate when there are other pers_lock competitors who may be blocked to spin.
We can avoid this condition by moving printk out of coverage of pers_lock spinlock.

---
 drivers/md/md.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/md/md.c +0 -0
index e02de05..5fcf215 100644
@@ -7200,9 +7200,10 @@ static const struct file_operations md_seq_fops = {
 

drivers/md/md.c static const struct file_operations md_seq_fops = { · line 7209

Quoted 10 lines
drivers/md/md.c +2 -1
 int register_md_personality(struct md_personality *p)
 {
+	printk(KERN_INFO "md: %s personality registered for level %d\n",
+						p->name, p->level);
 	spin_lock(&pers_lock);
 	list_add_tail(&p->list, &pers_list);
-	printk(KERN_INFO "md: %s personality registered for level %d\n", p->name, p->level);
 	spin_unlock(&pers_lock);
 	return 0;
 }

I'm not sure I see the pressing need for this - have you noticed actual problems?
However it seems to make sense so I've applied it.

Thanks,
NeilBrown

author
#4 lore raw
Quoted 27 lines

-----Original Message-----
From: NeilBrown [mailto:[email protected]]
Sent: Friday, September 26, 2014 8:36 AM
To: Chao Yu
Cc: [email protected]; [email protected]
Subject: Re: [PATCH] md: avoid potential long delay under pers_lock

Quoted 18 lines · On Thu, 25 Sep 2014 15:28:34 +0800 Chao Yu <[email protected]> wrote:

printk may cause long time lapse if value of printk_delay in sysctl is configured large by user. If register_md_personality takes long time to print in spinlock pers_lock, we may encounter high CPU usage rate when there are other pers_lock competitors who may be blocked to spin.
We can avoid this condition by moving printk out of coverage of pers_lock spinlock.

---
 drivers/md/md.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/md/md.c +0 -0
index e02de05..5fcf215 100644
@@ -7200,9 +7200,10 @@ static const struct file_operations md_seq_fops = {
 
Quoted 13 lines

drivers/md/md.c static const struct file_operations md_seq_fops = { · line 7209

Quoted 10 lines
drivers/md/md.c +2 -1
 int register_md_personality(struct md_personality *p)
 {
+	printk(KERN_INFO "md: %s personality registered for level %d\n",
+						p->name, p->level);
 	spin_lock(&pers_lock);
 	list_add_tail(&p->list, &pers_list);
-	printk(KERN_INFO "md: %s personality registered for level %d\n", p->name, p->level);
 	spin_unlock(&pers_lock);
 	return 0;
 }

I'm not sure I see the pressing need for this - have you noticed actual problems?

Haven't, I found this by code review.

Thanks,
Yu

Quoted 4 lines

However it seems to make sense so I've applied it.

Thanks,
NeilBrown