438
439
440
441
442
443
444
445static int shmem_free_swp(swp_entry_t *dir, swp_entry_t *edir,
446 spinlock_t *punch_lock)
447{
448 spinlock_t *punch_unlock = NULL;
449 swp_entry_t *ptr;
450 int freed = 0;
451
452 for (ptr = dir; ptr < edir; ptr++) {
453 if (ptr->val) {
454 if (unlikely(punch_lock)) {
455 punch_unlock = punch_lock;
456 punch_lock = NULL;
457 spin_lock(punch_unlock);
458 if (!ptr->val)
459 continue;
460 }
461 free_swap_and_cache(*ptr);
462 *ptr = (swp_entry_t){0};
463 freed++;
464 }
465 }
466 if (punch_unlock)
467 spin_unlock(punch_unlock);
468 return freed;
469}
470
471static int shmem_map_and_free_swp(struct page *subdir, int offset,
472 int limit, struct page ***dir, spinlock_t *punch_lock)
473{
474 swp_entry_t *ptr;
475 int freed = 0;
476
477 ptr = shmem_swp_map(subdir);
478 for (; offset < limit; offset += LATENCY_LIMIT) {