Skip to contentSkip to conversation

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

PATCH Applied Wei Yang 2 participants 2 messages Mar 11, 2020 Memory management

lore
Share & tools
lore

Wei Yang

author
#0 lore raw

PATCH v2 1/1 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.

---
v2: keep the reset step after use, but remove the tmp pointer

---
 mm/swap_slots.c | 12 +++++-------
 1 file changed, 5 insertions(+), 7 deletions(-)
mm/swap_slots.c +5 -7
index 63a7b4563a57..0975adc72253 100644
@@ -309,7 +309,7 @@ int free_swap_slot(swp_entry_t entry)
 
 swp_entry_t get_swap_page(struct page *page)
 {
-	swp_entry_t entry, *pentry;
+	swp_entry_t entry;
 	struct swap_slots_cache *cache;
 
 	entry.val = 0;
@@ -336,13 +336,11 @@ swp_entry_t get_swap_page(struct page *page)
 		if (cache->slots) {
 repeat:
 			if (cache->nr) {
-				pentry = &cache->slots[cache->cur++];
-				entry = *pentry;
-				pentry->val = 0;
+				entry = cache->slots[cache->cur];
+				cache->slots[cache->cur++].val = 0;
 				cache->nr--;
-			} else {
-				if (refill_swap_slots_cache(cache))
-					goto repeat;
+			} else if (refill_swap_slots_cache(cache)) {
+				goto repeat;
 			}
 		}
 		mutex_unlock(&cache->alloc_lock);
Signature · 1 line
2.20.1 (Apple Git-117)
Acked-by on v2 1/1
#1 lore raw
Quoted 9 lines · Wei Yang

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.

Quoted 4 lines

---
v2: keep the reset step after use, but remove the tmp pointer
---