LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* [Patch v2] mm/swap_slots.c: assign|reset cache slot by value directly
@ 2020-03-11  5:53 Wei Yang
  2020-03-11 16:10 ` Tim Chen
  0 siblings, 1 reply; 2+ messages in thread
From: Wei Yang @ 2020-03-11  5:53 UTC (permalink / raw)
  To: akpm; +Cc: linux-mm, linux-kernel, Wei Yang, Tim Chen

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>
CC: Tim Chen <tim.c.chen@linux.intel.com>

---
v2: keep the reset step after use, but remove the tmp pointer
---
 mm/swap_slots.c | 12 +++++-------
 1 file changed, 5 insertions(+), 7 deletions(-)

diff --git a/mm/swap_slots.c b/mm/swap_slots.c
index 63a7b4563a57..0975adc72253 100644
--- a/mm/swap_slots.c
+++ b/mm/swap_slots.c
@@ -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);
-- 
2.20.1 (Apple Git-117)


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [Patch v2] mm/swap_slots.c: assign|reset cache slot by value directly
  2020-03-11  5:53 [Patch v2] mm/swap_slots.c: assign|reset cache slot by value directly Wei Yang
@ 2020-03-11 16:10 ` Tim Chen
  0 siblings, 0 replies; 2+ messages in thread
From: Tim Chen @ 2020-03-11 16:10 UTC (permalink / raw)
  To: Wei Yang, akpm; +Cc: linux-mm, linux-kernel

On 3/10/20 10:53 PM, Wei Yang wrote:
> 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>
> CC: Tim Chen <tim.c.chen@linux.intel.com>

Acked-by: Tim Chen <tim.c.chen@linux.intel.com>

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


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-03-11 16:10 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-11  5:53 [Patch v2] mm/swap_slots.c: assign|reset cache slot by value directly Wei Yang
2020-03-11 16:10 ` Tim Chen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).