@@ -4077,9 +4077,9 @@ static struct cftype mem_cgroup_legacy_files[] = {
40774077
40784078static DEFINE_IDR (mem_cgroup_idr );
40794079
4080- static void mem_cgroup_id_get (struct mem_cgroup * memcg )
4080+ static void mem_cgroup_id_get_many (struct mem_cgroup * memcg , unsigned int n )
40814081{
4082- atomic_inc ( & memcg -> id .ref );
4082+ atomic_add ( n , & memcg -> id .ref );
40834083}
40844084
40854085static struct mem_cgroup * mem_cgroup_id_get_online (struct mem_cgroup * memcg )
@@ -4100,9 +4100,9 @@ static struct mem_cgroup *mem_cgroup_id_get_online(struct mem_cgroup *memcg)
41004100 return memcg ;
41014101}
41024102
4103- static void mem_cgroup_id_put (struct mem_cgroup * memcg )
4103+ static void mem_cgroup_id_put_many (struct mem_cgroup * memcg , unsigned int n )
41044104{
4105- if (atomic_dec_and_test ( & memcg -> id .ref )) {
4105+ if (atomic_sub_and_test ( n , & memcg -> id .ref )) {
41064106 idr_remove (& mem_cgroup_idr , memcg -> id .id );
41074107 memcg -> id .id = 0 ;
41084108
@@ -4111,6 +4111,16 @@ static void mem_cgroup_id_put(struct mem_cgroup *memcg)
41114111 }
41124112}
41134113
4114+ static inline void mem_cgroup_id_get (struct mem_cgroup * memcg )
4115+ {
4116+ mem_cgroup_id_get_many (memcg , 1 );
4117+ }
4118+
4119+ static inline void mem_cgroup_id_put (struct mem_cgroup * memcg )
4120+ {
4121+ mem_cgroup_id_put_many (memcg , 1 );
4122+ }
4123+
41144124/**
41154125 * mem_cgroup_from_id - look up a memcg from a memcg id
41164126 * @id: the memcg id to look up
@@ -4745,16 +4755,18 @@ static void __mem_cgroup_clear_mc(void)
47454755 if (!mem_cgroup_is_root (mc .from ))
47464756 page_counter_uncharge (& mc .from -> memsw , mc .moved_swap );
47474757
4758+ mem_cgroup_id_put_many (mc .from , mc .moved_swap );
4759+
47484760 /*
47494761 * we charged both to->memory and to->memsw, so we
47504762 * should uncharge to->memory.
47514763 */
47524764 if (!mem_cgroup_is_root (mc .to ))
47534765 page_counter_uncharge (& mc .to -> memory , mc .moved_swap );
47544766
4755- css_put_many (& mc .from -> css , mc .moved_swap );
4767+ mem_cgroup_id_get_many (mc .to , mc .moved_swap );
4768+ css_put_many (& mc .to -> css , mc .moved_swap );
47564769
4757- /* we've already done css_get(mc.to) */
47584770 mc .moved_swap = 0 ;
47594771 }
47604772 memcg_oom_recover (from );
0 commit comments