Lines Matching defs:cache
3 * Manage cache of swap slots to be used for and returned from
25 * The swap slots cache is protected by a mutex instead of
43 /* Serialize swap slots cache enable/disable operations */
104 /* if global pool of slot caches too low, deactivate cache */
113 struct swap_slots_cache *cache;
127 cache = &per_cpu(swp_slots, cpu);
128 if (cache->slots) {
129 /* cache already allocated */
137 if (!cache->lock_initialized) {
138 mutex_init(&cache->alloc_lock);
139 cache->lock_initialized = true;
141 cache->nr = 0;
142 cache->cur = 0;
143 cache->n_ret = 0;
146 * !cache->slots or !cache->slots_ret to know if it is safe to acquire
147 * the corresponding lock and use the cache. Memory barrier below
151 cache->slots = slots;
158 struct swap_slots_cache *cache;
160 cache = &per_cpu(swp_slots, cpu);
161 if (cache->slots) {
162 mutex_lock(&cache->alloc_lock);
163 swapcache_free_entries(cache->slots + cache->cur, cache->nr);
164 cache->cur = 0;
165 cache->nr = 0;
166 if (free_slots && cache->slots) {
167 kvfree(cache->slots);
168 cache->slots = NULL;
170 mutex_unlock(&cache->alloc_lock);
181 * left over slots are in cache when we remove
183 * 2) disabling of swap slot cache, when we run low
198 * fill any swap slots in slots cache of such cpu.
222 "without swap slots cache.\n", __func__))
233 /* called with swap slot cache's alloc lock held */
234 static int refill_swap_slots_cache(struct swap_slots_cache *cache)
239 cache->cur = 0;
241 cache->nr = get_swap_pages(SWAP_SLOTS_CACHE_SIZE,
242 cache->slots, 0);
244 return cache->nr;
250 struct swap_slots_cache *cache;
264 * mutex cache->alloc_lock.
266 * The alloc path here does not touch cache->slots_ret
267 * so cache->free_lock is not taken.
269 cache = raw_cpu_ptr(&swp_slots);
271 if (likely(check_cache_active() && cache->slots)) {
272 mutex_lock(&cache->alloc_lock);
273 if (cache->slots) {
275 if (cache->nr) {
276 entry = cache->slots[cache->cur];
277 cache->slots[cache->cur++].val = 0;
278 cache->nr--;
279 } else if (refill_swap_slots_cache(cache)) {
283 mutex_unlock(&cache->alloc_lock);