Lines Matching +full:charge +full:- +full:ctrl +full:- +full:value

1 // SPDX-License-Identifier: GPL-2.0
24 * In typical usage, this swap_cgroup is accessed via memcg's charge/uncharge
28 * - we have no race in "exchange" when we're accessed via SwapCache because
30 * - When called via swap_free(), there is no user of this entry and no race.
42 struct swap_cgroup_ctrl *ctrl; in swap_cgroup_prepare() local
45 ctrl = &swap_cgroup_ctrl[type]; in swap_cgroup_prepare()
47 for (idx = 0; idx < ctrl->length; idx++) { in swap_cgroup_prepare()
51 ctrl->map[idx] = page; in swap_cgroup_prepare()
60 __free_page(ctrl->map[idx]); in swap_cgroup_prepare()
62 return -ENOMEM; in swap_cgroup_prepare()
65 static struct swap_cgroup *__lookup_swap_cgroup(struct swap_cgroup_ctrl *ctrl, in __lookup_swap_cgroup() argument
71 mappage = ctrl->map[offset / SC_PER_PAGE]; in __lookup_swap_cgroup()
80 struct swap_cgroup_ctrl *ctrl; in lookup_swap_cgroup() local
82 ctrl = &swap_cgroup_ctrl[swp_type(ent)]; in lookup_swap_cgroup()
84 *ctrlp = ctrl; in lookup_swap_cgroup()
85 return __lookup_swap_cgroup(ctrl, offset); in lookup_swap_cgroup()
89 * swap_cgroup_cmpxchg - cmpxchg mem_cgroup's id for this swp_entry.
100 struct swap_cgroup_ctrl *ctrl; in swap_cgroup_cmpxchg() local
105 sc = lookup_swap_cgroup(ent, &ctrl); in swap_cgroup_cmpxchg()
107 spin_lock_irqsave(&ctrl->lock, flags); in swap_cgroup_cmpxchg()
108 retval = sc->id; in swap_cgroup_cmpxchg()
110 sc->id = new; in swap_cgroup_cmpxchg()
113 spin_unlock_irqrestore(&ctrl->lock, flags); in swap_cgroup_cmpxchg()
118 * swap_cgroup_record - record mem_cgroup for a set of swap entries
123 * Returns old value at success, 0 at failure.
124 * (Of course, old value can be 0.)
129 struct swap_cgroup_ctrl *ctrl; in swap_cgroup_record() local
136 sc = lookup_swap_cgroup(ent, &ctrl); in swap_cgroup_record()
138 spin_lock_irqsave(&ctrl->lock, flags); in swap_cgroup_record()
139 old = sc->id; in swap_cgroup_record()
141 VM_BUG_ON(sc->id != old); in swap_cgroup_record()
142 sc->id = id; in swap_cgroup_record()
149 sc = __lookup_swap_cgroup(ctrl, offset); in swap_cgroup_record()
151 spin_unlock_irqrestore(&ctrl->lock, flags); in swap_cgroup_record()
157 * lookup_swap_cgroup_id - lookup mem_cgroup id tied to swap entry
164 return lookup_swap_cgroup(ent, NULL)->id; in lookup_swap_cgroup_id()
172 struct swap_cgroup_ctrl *ctrl; in swap_cgroup_swapon() local
181 ctrl = &swap_cgroup_ctrl[type]; in swap_cgroup_swapon()
183 ctrl->length = length; in swap_cgroup_swapon()
184 ctrl->map = array; in swap_cgroup_swapon()
185 spin_lock_init(&ctrl->lock); in swap_cgroup_swapon()
188 ctrl->map = NULL; in swap_cgroup_swapon()
189 ctrl->length = 0; in swap_cgroup_swapon()
200 return -ENOMEM; in swap_cgroup_swapon()
207 struct swap_cgroup_ctrl *ctrl; in swap_cgroup_swapoff() local
210 ctrl = &swap_cgroup_ctrl[type]; in swap_cgroup_swapoff()
211 map = ctrl->map; in swap_cgroup_swapoff()
212 length = ctrl->length; in swap_cgroup_swapoff()
213 ctrl->map = NULL; in swap_cgroup_swapoff()
214 ctrl->length = 0; in swap_cgroup_swapoff()