linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Re: [PATCH] mm: avoid possible multiple call to swap_node()
@ 2020-09-17 11:54 linmiaohe
  0 siblings, 0 replies; 3+ messages in thread
From: linmiaohe @ 2020-09-17 11:54 UTC (permalink / raw)
  To: Matthew Wilcox; +Cc: akpm, linux-mm, linux-kernel

Matthew Wilcox <willy@infradead.org> wrote:
> On Thu, Sep 17, 2020 at 07:44:49AM -0400, Miaohe Lin wrote:
>> Cache the swap_node() in a local variable to avoid possible multiple 
>> call to swap_node(), though compiler may do this for us.
>
>Why don't you find out?  Compare the assembly before and after, see what the compiler did.

In fact, I don't care if the compiler can really do this for us. I think it's better to do this explicity. I think this can improve the readability.
Thanks.


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

* Re: [PATCH] mm: avoid possible multiple call to swap_node()
  2020-09-17 11:44 Miaohe Lin
@ 2020-09-17 11:48 ` Matthew Wilcox
  0 siblings, 0 replies; 3+ messages in thread
From: Matthew Wilcox @ 2020-09-17 11:48 UTC (permalink / raw)
  To: Miaohe Lin; +Cc: akpm, linux-mm, linux-kernel

On Thu, Sep 17, 2020 at 07:44:49AM -0400, Miaohe Lin wrote:
> Cache the swap_node() in a local variable to avoid possible multiple call
> to swap_node(), though compiler may do this for us.

Why don't you find out?  Compare the assembly before and after, see what
the compiler did.

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

* [PATCH] mm: avoid possible multiple call to swap_node()
@ 2020-09-17 11:44 Miaohe Lin
  2020-09-17 11:48 ` Matthew Wilcox
  0 siblings, 1 reply; 3+ messages in thread
From: Miaohe Lin @ 2020-09-17 11:44 UTC (permalink / raw)
  To: akpm; +Cc: linux-mm, linux-kernel, linmiaohe

Cache the swap_node() in a local variable to avoid possible multiple call
to swap_node(), though compiler may do this for us.

Signed-off-by: Miaohe Lin <linmiaohe@huawei.com>
---
 mm/swapfile.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/mm/swapfile.c b/mm/swapfile.c
index 20012c0c0252..cd66b50f0490 100644
--- a/mm/swapfile.c
+++ b/mm/swapfile.c
@@ -2454,7 +2454,7 @@ static void setup_swap_info(struct swap_info_struct *p, int prio,
 			    unsigned char *swap_map,
 			    struct swap_cluster_info *cluster_info)
 {
-	int i;
+	int i, node;
 
 	if (prio >= 0)
 		p->prio = prio;
@@ -2465,11 +2465,12 @@ static void setup_swap_info(struct swap_info_struct *p, int prio,
 	 * low-to-high, while swap ordering is high-to-low
 	 */
 	p->list.prio = -p->prio;
+	node = swap_node(p);
 	for_each_node(i) {
 		if (p->prio >= 0)
 			p->avail_lists[i].prio = -p->prio;
 		else {
-			if (swap_node(p) == i)
+			if (node == i)
 				p->avail_lists[i].prio = 1;
 			else
 				p->avail_lists[i].prio = -p->prio;
-- 
2.19.1


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

end of thread, other threads:[~2020-09-17 11:58 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-17 11:54 [PATCH] mm: avoid possible multiple call to swap_node() linmiaohe
  -- strict thread matches above, loose matches on Subject: below --
2020-09-17 11:44 Miaohe Lin
2020-09-17 11:48 ` Matthew Wilcox

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).