Skip to contentSkip to conversation

avoid preemption in memory controller code

PATCH In review Tim Blechmann 4 participants 7 messages Dec 8, 2008 – Dec 11, 2008

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

PATCH 1/1 avoid preemption in memory controller code

the lru_lock of struct mem_group_per_zone is used to avoid preemption during the __mem_cgroup_stat_add_safe function.
therefore, a raw_spinlock_t should be used.

---
 mm/memcontrol.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
mm/memcontrol.c +2 -2
index 517f945..8661732 100644
@@ -95,9 +95,9 @@ enum mem_cgroup_zstat_index {
 
 struct mem_cgroup_per_zone {
 	/*
-	 * spin_lock to protect the per cgroup LRU
+	 * raw_spin_lock to protect the per cgroup LRU
 	 */
-	spinlock_t		lru_lock;
+	raw_spinlock_t		lru_lock;
 	struct list_head	active_list;
 	struct list_head	inactive_list;
 	unsigned long count[NR_MEM_CGROUP_ZSTAT];
Signature · 1 line
1.5.6.3
#1 lore raw

Hi Tim,

Quoted 3 lines · Tim Blechmann

the lru_lock of struct mem_group_per_zone is used to avoid preemption during the __mem_cgroup_stat_add_safe function.
therefore, a raw_spinlock_t should be used.

What is the reason that this must avoid preemption? Is there another way to solve this? I rather not just add a raw spinlock if we can help it.

-- Steve

Quoted 27 lines
---
 mm/memcontrol.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
mm/memcontrol.c +2 -2
index 517f945..8661732 100644
@@ -95,9 +95,9 @@ enum mem_cgroup_zstat_index {
 
 struct mem_cgroup_per_zone {
 	/*
-	 * spin_lock to protect the per cgroup LRU
+	 * raw_spin_lock to protect the per cgroup LRU
 	 */
-	spinlock_t		lru_lock;
+	raw_spinlock_t		lru_lock;
 	struct list_head	active_list;
 	struct list_head	inactive_list;
 	unsigned long count[NR_MEM_CGROUP_ZSTAT];
Signature · 1 line
1.5.6.3
#2 lore raw
Quoted 5 lines
Quoted 3 lines

the lru_lock of struct mem_group_per_zone is used to avoid preemption during the __mem_cgroup_stat_add_safe function.
therefore, a raw_spinlock_t should be used.

What is the reason that this must avoid preemption?

it guards a call to smp_processor_id() in __mem_cgroup_stat_add_safe(). see http://article.gmane.org/gmane.linux.rt.user/3690

Quoted 3 lines

Is there another
way to solve this? I rather not just add a raw spinlock if we can help it.

not sure, maybe one can disable preemption for that specific function?

tim

--
[email protected]
http://tim.klingt.org

Art is either a complaint or do something else
John Cage quoting Jasper Johns

#3 lore raw
Quoted 8 lines · Tim Blechmann
Quoted 5 lines
Quoted 3 lines

the lru_lock of struct mem_group_per_zone is used to avoid preemption during the __mem_cgroup_stat_add_safe function.
therefore, a raw_spinlock_t should be used.

What is the reason that this must avoid preemption?

it guards a call to smp_processor_id() in __mem_cgroup_stat_add_safe(). see http://article.gmane.org/gmane.linux.rt.user/3690

We could simply create a

	preempt_disable_rt();

that will only disable preemption when CONFIG_PREEMPT_RT is set. and then we could add

	int cpu;

	preempt_disable_rt();
	cpu = smp_processor_id();
	stat->cpustat[cpu].count[idx] += val;
	preempt_enable_rt();

Or something similar.

-- Steve

Quoted 16 lines
Quoted 4 lines

Is there another
way to solve this? I rather not just add a raw spinlock if we can help it.

not sure, maybe one can disable preemption for that specific function?

tim

--
[email protected]
http://tim.klingt.org

Art is either a complaint or do something else
John Cage quoting Jasper Johns

#4 lore raw

PATCH 1/1 preempt_disable_rt for CONFIG_PREEMPT_RT

in some cases, spinlocks are used to avoid preemption. does not work correctly, when CONFIG_PREEMPT_RT is enabled.

therefore two new macros are introduced:
preempt_disable_rt/preempt_disable_rt behave like their equivalents, if CONFIG_PREEMPT_RT is enabled, and as noops otherwise.

---
 include/linux/preempt.h |   10 ++++++++++
 1 files changed, 10 insertions(+), 0 deletions(-)
include/linux/preempt.h +10 -0
index 72b1a10..2526170 100644
@@ -93,6 +93,16 @@ do { \
 
 #endif
 
+#ifdef CONFIG_PREEMPT_RT
+#define preempt_disable_rt	preempt_disable
+#define preempt_enable_rt	preempt_enable
+#else
+#define
+#define preempt_disable_rt	do { } while (0)
+#define preempt_enable_rt	do { } while (0)
+#endif
+
+
 #ifdef CONFIG_PREEMPT_NOTIFIERS
 
 struct preempt_notifier;
Signature · 1 line
1.5.6.3
#5 lore raw
In reply to Tim Blechmann
CC Balbir Singh <[email protected]>
CC KAMEZAWA Hiroyuki <[email protected]>
Quoted 4 lines · Tim Blechmann

the lru_lock of struct mem_group_per_zone is used to avoid preemption during the __mem_cgroup_stat_add_safe function.
therefore, a raw_spinlock_t should be used.

FYI, this lru_lock no longer exists in -mm tree. The following patch removes that lock:

	http://marc.info/?l=linux-mm&m=122665814801979&w=2
Quoted 21 lines
---
 mm/memcontrol.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
mm/memcontrol.c +2 -2
index 517f945..8661732 100644
@@ -95,9 +95,9 @@ enum mem_cgroup_zstat_index {
 
 struct mem_cgroup_per_zone {
 	/*
-	 * spin_lock to protect the per cgroup LRU
+	 * raw_spin_lock to protect the per cgroup LRU
 	 */
-	spinlock_t		lru_lock;
+	raw_spinlock_t		lru_lock;
 	struct list_head	active_list;
 	struct list_head	inactive_list;
 	unsigned long count[NR_MEM_CGROUP_ZSTAT];
#6 lore raw
Quoted 25 lines · On Tue, 09 Dec 2008 09:13:12 +0800 Li Zefan <[email protected]> wrote:
CC Balbir Singh <[email protected]>
CC KAMEZAWA Hiroyuki <[email protected]>
Quoted 4 lines · Tim Blechmann

the lru_lock of struct mem_group_per_zone is used to avoid preemption during the __mem_cgroup_stat_add_safe function.
therefore, a raw_spinlock_t should be used.

FYI, this lru_lock no longer exists in -mm tree. The following patch removes that lock:

	http://marc.info/?l=linux-mm&m=122665814801979&w=2
Quoted 11 lines
---
 mm/memcontrol.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
mm/memcontrol.c +0 -0
index 517f945..8661732 100644
@@ -95,9 +95,9 @@ enum mem_cgroup_zstat_index {
 
Quoted 10 lines

mm/memcontrol.c enum mem_cgroup_zstat_index { · line 103

Quoted 10 lines
mm/memcontrol.c +2 -2
 struct mem_cgroup_per_zone {
 	/*
-	 * spin_lock to protect the per cgroup LRU
+	 * raw_spin_lock to protect the per cgroup LRU
 	 */
-	spinlock_t		lru_lock;
+	raw_spinlock_t		lru_lock;
 	struct list_head	active_list;
 	struct list_head	inactive_list;
 	unsigned long count[NR_MEM_CGROUP_ZSTAT];

yes..I remvoed that. Please see mmotm and subscribe linux-mm, if you have interests memory resource controller.

Anyway, thanks.

-Kame