net_sched: make traffic control network namespace aware
[pandora-kernel.git] / mm / page_cgroup.c
index 3d535d5..3dd8853 100644 (file)
@@ -334,6 +334,37 @@ not_enough_page:
        return -ENOMEM;
 }
 
+/**
+ * swap_cgroup_cmpxchg - cmpxchg mem_cgroup's id for this swp_entry.
+ * @end: swap entry to be cmpxchged
+ * @old: old id
+ * @new: new id
+ *
+ * Returns old id at success, 0 at failure.
+ * (There is no mem_cgroup useing 0 as its id)
+ */
+unsigned short swap_cgroup_cmpxchg(swp_entry_t ent,
+                                       unsigned short old, unsigned short new)
+{
+       int type = swp_type(ent);
+       unsigned long offset = swp_offset(ent);
+       unsigned long idx = offset / SC_PER_PAGE;
+       unsigned long pos = offset & SC_POS_MASK;
+       struct swap_cgroup_ctrl *ctrl;
+       struct page *mappage;
+       struct swap_cgroup *sc;
+
+       ctrl = &swap_cgroup_ctrl[type];
+
+       mappage = ctrl->map[idx];
+       sc = page_address(mappage);
+       sc += pos;
+       if (cmpxchg(&sc->id, old, new) == old)
+               return old;
+       else
+               return 0;
+}
+
 /**
  * swap_cgroup_record - record mem_cgroup for this swp_entry.
  * @ent: swap entry to be recorded into
@@ -358,8 +389,7 @@ unsigned short swap_cgroup_record(swp_entry_t ent, unsigned short id)
        mappage = ctrl->map[idx];
        sc = page_address(mappage);
        sc += pos;
-       old = sc->id;
-       sc->id = id;
+       old = xchg(&sc->id, id);
 
        return old;
 }