From: Zhaoyu Liu <liuzhaoyu.zackary@bytedance.com>
To: liuzhaoyu.zackary@bytedance.com
Cc: linux-kernel@vger.kernel.org
Subject: [PATCH] mm: swap: calculate pages via roundup() in __swapin_nr_pages()
Date: Mon, 8 Apr 2024 19:12:03 +0800 [thread overview]
Message-ID: <20240408111203.GA203766@bytedance> (raw)
Use roundup() to replace while&shift. When the "pages" is large,
using roundup() will be faster than while&shift.
Signed-off-by: Zhaoyu Liu <liuzhaoyu.zackary@bytedance.com>
---
mm/swap_state.c | 8 ++------
1 file changed, 2 insertions(+), 6 deletions(-)
diff --git a/mm/swap_state.c b/mm/swap_state.c
index 642c30d8376c..d34dc95d0910 100644
--- a/mm/swap_state.c
+++ b/mm/swap_state.c
@@ -590,12 +590,8 @@ static unsigned int __swapin_nr_pages(unsigned long prev_offset,
*/
if (offset != prev_offset + 1 && offset != prev_offset - 1)
pages = 1;
- } else {
- unsigned int roundup = 4;
- while (roundup < pages)
- roundup <<= 1;
- pages = roundup;
- }
+ } else
+ pages = roundup(pages, 4);
if (pages > max_pages)
pages = max_pages;
--
2.25.1
reply other threads:[~2024-04-08 11:12 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240408111203.GA203766@bytedance \
--to=liuzhaoyu.zackary@bytedance.com \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox