Skip to contentSkip to conversation

avoid preemption in memory controller code

PATCH In review Tim Blechmann 2 participants 3 messages Dec 11, 2008 – Dec 12, 2008

Subsystems (2)
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_charge_statistics function. this does not work correctly, when CONFIG_PREEMPT_RT is enabled.
therefore, the preemption is disabled using the preempt_disable_rt macro in these cases.

---
 mm/memcontrol.c |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)
mm/memcontrol.c +3 -1
index 562b94f..70493c4 100644
@@ -158,7 +158,7 @@ pcg_default_flags[NR_CHARGE_TYPE] = {
 };
 
 /*
- * Always modified under lru lock. Then, not necessary to preempt_disable()
+ * Always modified under lru lock. Disable preemption with preempt_disable_rt()
  */
 static void mem_cgroup_charge_statistics(struct mem_cgroup *mem,
 					 struct page_cgroup *pc,
@@ -170,6 +170,7 @@ static void mem_cgroup_charge_statistics(struct mem_cgroup *mem,
 
 	VM_BUG_ON(!irqs_disabled());
 
+	preempt_disable_rt();
 	cpustat = &stat->cpustat[smp_processor_id()];
 	if (PageCgroupCache(pc))
 		__mem_cgroup_stat_add_safe(cpustat, MEM_CGROUP_STAT_CACHE, val);
@@ -182,6 +183,7 @@ static void mem_cgroup_charge_statistics(struct mem_cgroup *mem,
 	else
 		__mem_cgroup_stat_add_safe(cpustat,
 				MEM_CGROUP_STAT_PGPGOUT_COUNT, 1);
+	preempt_enable_rt();
 }
 
 static struct mem_cgroup_per_zone *
Signature · 1 line
1.5.6.3
#1 lore raw
Quoted 7 lines · On Thu, 11 Dec 2008 20:00:45 +0100 Tim Blechmann <[email protected]> wrote:

the lru_lock of struct mem_group_per_zone is used to avoid preemption during the mem_cgroup_charge_statistics function. this does not work correctly, when CONFIG_PREEMPT_RT is enabled.
therefore, the preemption is disabled using the preempt_disable_rt macro in these cases.

Sorry, memcg's code this function in mmotm kernel is now, following. Please give me advice if some more thinking is necessary for RT.

==
static void mem_cgroup_charge_statistics(struct mem_cgroup *mem,
struct page_cgroup *pc, bool charge)

{
        int val = (charge)? 1 : -1;
        struct mem_cgroup_stat *stat = &mem->stat;
        struct mem_cgroup_stat_cpu *cpustat;
        int cpu = get_cpu();

        cpustat = &stat->cpustat[cpu];
        if (PageCgroupCache(pc))
                __mem_cgroup_stat_add_safe(cpustat, MEM_CGROUP_STAT_CACHE, val);
        else
                __mem_cgroup_stat_add_safe(cpustat, MEM_CGROUP_STAT_RSS, val);

        if (charge)
                __mem_cgroup_stat_add_safe(cpustat,
                                MEM_CGROUP_STAT_PGPGIN_COUNT, 1);
        else
                __mem_cgroup_stat_add_safe(cpustat,
                                MEM_CGROUP_STAT_PGPGOUT_COUNT, 1);
        put_cpu();
}

==

Regards,
-Kame

Quoted 42 lines
---
 mm/memcontrol.c |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)
mm/memcontrol.c +3 -1
index 562b94f..70493c4 100644
@@ -158,7 +158,7 @@ pcg_default_flags[NR_CHARGE_TYPE] = {
 };
 
 /*
- * Always modified under lru lock. Then, not necessary to preempt_disable()
+ * Always modified under lru lock. Disable preemption with preempt_disable_rt()
  */
 static void mem_cgroup_charge_statistics(struct mem_cgroup *mem,
 					 struct page_cgroup *pc,
@@ -170,6 +170,7 @@ static void mem_cgroup_charge_statistics(struct mem_cgroup *mem,
 
 	VM_BUG_ON(!irqs_disabled());
 
+	preempt_disable_rt();
 	cpustat = &stat->cpustat[smp_processor_id()];
 	if (PageCgroupCache(pc))
 		__mem_cgroup_stat_add_safe(cpustat, MEM_CGROUP_STAT_CACHE, val);
@@ -182,6 +183,7 @@ static void mem_cgroup_charge_statistics(struct mem_cgroup *mem,
 	else
 		__mem_cgroup_stat_add_safe(cpustat,
 				MEM_CGROUP_STAT_PGPGOUT_COUNT, 1);
+	preempt_enable_rt();
 }
 
 static struct mem_cgroup_per_zone *
Signature · 7 lines
1.5.6.3

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/
#2 lore raw
Quoted 10 lines
Quoted 7 lines

the lru_lock of struct mem_group_per_zone is used to avoid preemption during the mem_cgroup_charge_statistics function. this does not work correctly, when CONFIG_PREEMPT_RT is enabled.
therefore, the preemption is disabled using the preempt_disable_rt macro in these cases.

Sorry, memcg's code this function in mmotm kernel is now, following. Please give me advice if some more thinking is necessary for RT.

using get_cpu/put_cpu, the preemption is disabled ... so mmotm should not require any changes. my patch would only be required for an rt-patch, based on a current kernel version ...
instead of applying my patch, one could also use the specific part of mmotm for the RT tree ...

tim

Quoted 15 lines

static void mem_cgroup_charge_statistics(struct mem_cgroup *mem,
struct page_cgroup *pc, bool charge)

{
        int val = (charge)? 1 : -1;
        struct mem_cgroup_stat *stat = &mem->stat;
        struct mem_cgroup_stat_cpu *cpustat;
        int cpu = get_cpu();

        cpustat = &stat->cpustat[cpu];
        if (PageCgroupCache(pc))
                __mem_cgroup_stat_add_safe(cpustat, MEM_CGROUP_STAT_CACHE, val);
        else
                __mem_cgroup_stat_add_safe(cpustat, MEM_CGROUP_STAT_RSS, val);
Quoted 8 lines
        if (charge)
                __mem_cgroup_stat_add_safe(cpustat,
                                MEM_CGROUP_STAT_PGPGIN_COUNT, 1);
        else
                __mem_cgroup_stat_add_safe(cpustat,
                                MEM_CGROUP_STAT_PGPGOUT_COUNT, 1);
        put_cpu();
}

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

Silence is only frightening to people who are compulsively verbalizing.
William S. Burroughs