linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] memcg: mem_cgroup->prev_priority protected by lock.
@ 2008-12-02  7:11 KOSAKI Motohiro
  2008-12-02  7:13 ` [PATCH 2/2] memcg: make memory.swappiness file KOSAKI Motohiro
  2008-12-02  7:15 ` [PATCH 1/2] memcg: mem_cgroup->prev_priority protected by lock KAMEZAWA Hiroyuki
  0 siblings, 2 replies; 4+ messages in thread
From: KOSAKI Motohiro @ 2008-12-02  7:11 UTC (permalink / raw)
  To: LKML, linux-mm, Balbir Singh, KAMEZAWA Hiroyuki, Andrew Morton
  Cc: kosaki.motohiro


Currently, mem_cgroup doesn't have own lock and almost its member doesn't need.
 (e.g. info is protected by zone lock, stat is per cpu variable)

However, there is one explict exception. mem_cgroup->prev_priorit need lock,
but doesn't protect.
Luckly, this is NOT bug because prev_priority isn't used for current reclaim code.

However, we plan to use prev_priority future again.
Therefore, fixing is better.


In addision, we plan to reuse this lock for another member.
Then "misc_lock" name is better than "prev_priority_lock".



Signed-off-by: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
---
 mm/memcontrol.c |   20 +++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)

Index: b/mm/memcontrol.c
===================================================================
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -142,6 +142,13 @@ struct mem_cgroup {
 	 */
 	struct mem_cgroup_lru_info info;
 
+	/*
+	  Almost mem_cgroup member doesn't need lock.
+	  (e.g. info is protected by zone lock, stat is per cpu variable)
+	  However, rest few member need explict lock.
+	*/
+	spinlock_t misc_lock;
+
 	int	prev_priority;	/* for recording reclaim priority */
 
 	/*
@@ -393,18 +400,28 @@ int mem_cgroup_calc_mapped_ratio(struct 
  */
 int mem_cgroup_get_reclaim_priority(struct mem_cgroup *mem)
 {
-	return mem->prev_priority;
+	int prev_priority;
+
+	spin_lock(&mem->misc_lock);
+	prev_priority = mem->prev_priority;
+	spin_unlock(&mem->misc_lock);
+
+	return prev_priority;
 }
 
 void mem_cgroup_note_reclaim_priority(struct mem_cgroup *mem, int priority)
 {
+	spin_lock(&mem->misc_lock);
 	if (priority < mem->prev_priority)
 		mem->prev_priority = priority;
+	spin_unlock(&mem->misc_lock);
 }
 
 void mem_cgroup_record_reclaim_priority(struct mem_cgroup *mem, int priority)
 {
+	spin_lock(&mem->misc_lock);
 	mem->prev_priority = priority;
+	spin_unlock(&mem->misc_lock);
 }
 
 /*
@@ -1967,6 +1984,7 @@ mem_cgroup_create(struct cgroup_subsys *
 	}
 
 	mem->last_scanned_child = NULL;
+	spin_lock_init(&mem->misc_lock);
 
 	return &mem->css;
 free_out:


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

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2008-12-02  7:19 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-12-02  7:11 [PATCH 1/2] memcg: mem_cgroup->prev_priority protected by lock KOSAKI Motohiro
2008-12-02  7:13 ` [PATCH 2/2] memcg: make memory.swappiness file KOSAKI Motohiro
2008-12-02  7:15 ` [PATCH 1/2] memcg: mem_cgroup->prev_priority protected by lock KAMEZAWA Hiroyuki
2008-12-02  7:19   ` KOSAKI Motohiro

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox