Skip to contentSkip to conversation

vmscan: Unbalanced local_irq_disable and enable

RFC PATCH New John Kacur 3 participants 6 messages Feb 3, 2010 – Feb 5, 2010

Subsystems (3)
lore
Share & tools
lore

John Kacur

author
#0 lore raw

RFC PATCH 1/1 vmscan: Unbalanced local_irq_disable and enable

I was inspecting this code as I was trying to port some -rt patches to 2.6.33-rcX and it looks quite unusual. It is possible that it is working as designed and there is nothing wrong with it, so I would like your comments.

Normally a call to local_irq_disable() would be balanced by a call to local_irq_enable(). Furthermore a call to spin_lock() would be balanced by a call to spin_unlock() and not to spin_unlock_irq()

However, the call to spin_unlock_irq() will call local_irq_enable() so that will take care of the unbalanced local_irq_disable. Still it seems strange.

The patch that I am providing here, is what I think the code SHOULD look like just based on inspection, it is not at all well testing, I'm just providing it to illustrate what at least looks wrong with the current code.

Thanks

John Kacur (1):
vmscan: balance local_irq_disable() and local_irq_enable()

 mm/vmscan.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

author
#1 lore raw

RFC PATCH 1/1 vmscan: balance local_irq_disable() and local_irq_enable()

Balance local_irq_disable() and local_irq_enable() as well as spin_lock_irq() and spin_lock_unlock_irq

---
 mm/vmscan.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)
mm/vmscan.c +2 -1
index c26986c..b895025 100644
@@ -1200,8 +1200,9 @@ static unsigned long shrink_inactive_list(unsigned long max_scan,
 		if (current_is_kswapd())
 			__count_vm_events(KSWAPD_STEAL, nr_freed);
 		__count_zone_vm_events(PGSTEAL, zone, nr_freed);
+		local_irq_enable();
 
-		spin_lock(&zone->lru_lock);
+		spin_lock_irq(&zone->lru_lock);
 		/*
 		 * Put back any unfreeable pages.
 		 */
Signature · 7 lines
1.6.6

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#2 lore raw

Re: [RFC][PATCH] vmscan: balance local_irq_disable() and local_irq_enable()

Quoted 13 lines · John Kacur

Balance local_irq_disable() and local_irq_enable() as well as spin_lock_irq() and spin_lock_unlock_irq

---
 mm/vmscan.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)
mm/vmscan.c +0 -0
index c26986c..b895025 100644

mm/vmscan.c static unsigned long shrink_inactive_list(unsigned long max_scan, · line 1208

Quoted 10 lines
mm/vmscan.c +2 -1
@@ -1200,8 +1200,9 @@ static unsigned long shrink_inactive_list(unsigned long max_scan,
 		if (current_is_kswapd())
 			__count_vm_events(KSWAPD_STEAL, nr_freed);
 		__count_zone_vm_events(PGSTEAL, zone, nr_freed);
+		local_irq_enable();
 
-		spin_lock(&zone->lru_lock);
+		spin_lock_irq(&zone->lru_lock);
 		/*
 		 * Put back any unfreeable pages.
 		 */

The above looks wrong. I don't know the code, but just by looking at where the locking and interrupts are, I can take a guess.

Lets add a little more of the code:

                local_irq_disable();
                if (current_is_kswapd())
                        __count_vm_events(KSWAPD_STEAL, nr_freed);
                __count_zone_vm_events(PGSTEAL, zone, nr_freed);

                spin_lock(&zone->lru_lock);
                /*

I'm guessing the __count_zone_vm_events and friends need interrupts disabled here, probably due to per cpu stuff. But if you enable interrupts before the spin_lock() you may let an interrupt come in and invalidate what was done above it.

So no, I do not think enabling interrupts here is a good thing.

-- Steve

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

author
#3 lore raw

Re: [RFC][PATCH] vmscan: balance local_irq_disable() and local_irq_enable()

Quoted 39 lines · Steven Rostedt
Quoted 13 lines · John Kacur

Balance local_irq_disable() and local_irq_enable() as well as spin_lock_irq() and spin_lock_unlock_irq

---
 mm/vmscan.c |    3 ++-

 1 files changed, 2 insertions(+), 1 deletions(-)
mm/vmscan.c +0 -0
index c26986c..b895025 100644

mm/vmscan.c static unsigned long shrink_inactive_list(unsigned long max_scan, · line 1208

Quoted 10 lines
mm/vmscan.c +2 -1
@@ -1200,8 +1200,9 @@ static unsigned long shrink_inactive_list(unsigned long max_scan,
               if (current_is_kswapd())
                       __count_vm_events(KSWAPD_STEAL, nr_freed);
               __count_zone_vm_events(PGSTEAL, zone, nr_freed);
+             local_irq_enable();
 
-             spin_lock(&zone->lru_lock);
+             spin_lock_irq(&zone->lru_lock);
               /*
                * Put back any unfreeable pages.
                */

The above looks wrong. I don't know the code, but just by looking at where the locking and interrupts are, I can take a guess.

Lets add a little more of the code:

               local_irq_disable();
               if (current_is_kswapd()) __count_vm_events(KSWAPD_STEAL, nr_freed); __count_zone_vm_events(PGSTEAL, zone, nr_freed);

               spin_lock(&zone->lru_lock);
               /*

Quoted 7 lines

I'm guessing the __count_zone_vm_events and friends need interrupts disabled here, probably due to per cpu stuff. But if you enable interrupts before the spin_lock() you may let an interrupt come in and invalidate what was done above it.

So no, I do not think enabling interrupts here is a good thing.

okay, and since we have already done local_irq_disable(), then that is why we only need the spin_lock() and not the spin_lock_irq() flavour?

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#4 lore raw

Re: [RFC][PATCH] vmscan: balance local_irq_disable() and local_irq_enable()

Quoted 45 lines · Steven Rostedt
Quoted 44 lines
Quoted 13 lines · John Kacur

Balance local_irq_disable() and local_irq_enable() as well as spin_lock_irq() and spin_lock_unlock_irq

---
 mm/vmscan.c |    3 ++-

 1 files changed, 2 insertions(+), 1 deletions(-)
mm/vmscan.c +0 -0
index c26986c..b895025 100644

mm/vmscan.c static unsigned long shrink_inactive_list(unsigned long max_scan, · line 1208

Quoted 10 lines
mm/vmscan.c +2 -1
@@ -1200,8 +1200,9 @@ static unsigned long shrink_inactive_list(unsigned long max_scan,
               if (current_is_kswapd())
                       __count_vm_events(KSWAPD_STEAL, nr_freed);
               __count_zone_vm_events(PGSTEAL, zone, nr_freed);
+             local_irq_enable();
 
-             spin_lock(&zone->lru_lock);
+             spin_lock_irq(&zone->lru_lock);
               /*
                * Put back any unfreeable pages.
                */

The above looks wrong. I don't know the code, but just by looking at where the locking and interrupts are, I can take a guess.

Lets add a little more of the code:

               local_irq_disable();
               if (current_is_kswapd()) __count_vm_events(KSWAPD_STEAL, nr_freed); __count_zone_vm_events(PGSTEAL, zone, nr_freed);

               spin_lock(&zone->lru_lock);
               /*

I'm guessing the __count_zone_vm_events and friends need interrupts disabled here, probably due to per cpu stuff. But if you enable interrupts before the spin_lock() you may let an interrupt come in and invalidate what was done above it.

Quoted 5 lines
Quoted 2 lines

So no, I do not think enabling interrupts here is a good thing.

okay, and since we have already done local_irq_disable(), then that is why we only need the spin_lock() and not the spin_lock_irq() flavour?

Yes, spin_lock_irq() is equivalent to spin_lock() + irq_disable(). Now, we already disabled irq. then, we only need spin_lock().

So, I don't think shrink_inactive_list need any fix.

author
#5 lore raw

Re: [RFC][PATCH] vmscan: balance local_irq_disable() and local_irq_enable()

Quoted 48 lines · KOSAKI Motohiro
Quoted 48 lines · Steven Rostedt
Quoted 46 lines
Quoted 13 lines · John Kacur

Balance local_irq_disable() and local_irq_enable() as well as spin_lock_irq() and spin_lock_unlock_irq

---
 mm/vmscan.c |    3 ++-

 1 files changed, 2 insertions(+), 1 deletions(-)
mm/vmscan.c +0 -0
index c26986c..b895025 100644

mm/vmscan.c static unsigned long shrink_inactive_list(unsigned long max_scan, · line 1208

Quoted 10 lines
mm/vmscan.c +2 -1
@@ -1200,8 +1200,9 @@ static unsigned long shrink_inactive_list(unsigned long max_scan,
               if (current_is_kswapd())
                       __count_vm_events(KSWAPD_STEAL, nr_freed);
               __count_zone_vm_events(PGSTEAL, zone, nr_freed);
+             local_irq_enable();
 
-             spin_lock(&zone->lru_lock);
+             spin_lock_irq(&zone->lru_lock);
               /*
                * Put back any unfreeable pages.
                */

The above looks wrong. I don't know the code, but just by looking at where the locking and interrupts are, I can take a guess.

Lets add a little more of the code:

               local_irq_disable();
               if (current_is_kswapd()) __count_vm_events(KSWAPD_STEAL, nr_freed); __count_zone_vm_events(PGSTEAL, zone, nr_freed);

               spin_lock(&zone->lru_lock);
               /*

I'm guessing the __count_zone_vm_events and friends need interrupts disabled here, probably due to per cpu stuff. But if you enable interrupts before the spin_lock() you may let an interrupt come in and invalidate what was done above it.

So no, I do not think enabling interrupts here is a good thing.

Quoted 8 lines
Quoted 2 lines

okay, and since we have already done local_irq_disable(), then that is why we only need the spin_lock() and not the spin_lock_irq() flavour?

Yes, spin_lock_irq() is equivalent to spin_lock() + irq_disable(). Now, we already disabled irq. then, we only need spin_lock().

So, I don't think shrink_inactive_list need any fix.

Thanks for the explanation!

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>