mm/swap_slots.c: assign|reset cache slot by value directly

Currently we use a tmp pointer, pentry, to transfer and reset swap cache
slot, which is a little redundant.  Swap cache slot stores the entry value
directly, assign and reset it by value would be straight forward.

Also this patch merges the else and if, since this is the only case we
refill and repeat swap cache.

Signed-off-by: Wei Yang <richard.weiyang@linux.alibaba.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Acked-by: Tim Chen <tim.c.chen@linux.intel.com>
Link: http://lkml.kernel.org/r/20200311055352.50574-1-richard.weiyang@linux.alibaba.com
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
This commit is contained in:
Wei Yang 2020-04-01 21:06:16 -07:00 committed by Linus Torvalds
parent 218209487c
commit 2406b76fe8
1 changed files with 5 additions and 7 deletions

View File

@ -309,7 +309,7 @@ int free_swap_slot(swp_entry_t entry)
swp_entry_t get_swap_page(struct page *page) swp_entry_t get_swap_page(struct page *page)
{ {
swp_entry_t entry, *pentry; swp_entry_t entry;
struct swap_slots_cache *cache; struct swap_slots_cache *cache;
entry.val = 0; entry.val = 0;
@ -336,13 +336,11 @@ swp_entry_t get_swap_page(struct page *page)
if (cache->slots) { if (cache->slots) {
repeat: repeat:
if (cache->nr) { if (cache->nr) {
pentry = &cache->slots[cache->cur++]; entry = cache->slots[cache->cur];
entry = *pentry; cache->slots[cache->cur++].val = 0;
pentry->val = 0;
cache->nr--; cache->nr--;
} else { } else if (refill_swap_slots_cache(cache)) {
if (refill_swap_slots_cache(cache)) goto repeat;
goto repeat;
} }
} }
mutex_unlock(&cache->alloc_lock); mutex_unlock(&cache->alloc_lock);