linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mm: simplify get_next_ra_size
@ 2018-10-28  6:13 Gao Xiang
  2018-10-28  6:27 ` Fengguang Wu
  2018-10-28 10:23 ` Matthew Wilcox
  0 siblings, 2 replies; 7+ messages in thread
From: Gao Xiang @ 2018-10-28  6:13 UTC (permalink / raw)
  To: Andrew Morton; +Cc: linux-mm, linux-kernel, Fengguang Wu, Gao Xiang

It's a trivial simplification for get_next_ra_size and
clear enough for humans to understand.

It also fixes potential overflow if ra->size(< ra_pages) is too large.

Cc: Fengguang Wu <fengguang.wu@intel.com>
Signed-off-by: Gao Xiang <hsiangkao@aol.com>
---
 mm/readahead.c | 12 +++++-------
 1 file changed, 5 insertions(+), 7 deletions(-)

diff --git a/mm/readahead.c b/mm/readahead.c
index 4e63014..205ac34 100644
--- a/mm/readahead.c
+++ b/mm/readahead.c
@@ -272,17 +272,15 @@ static unsigned long get_init_ra_size(unsigned long size, unsigned long max)
  *  return it as the new window size.
  */
 static unsigned long get_next_ra_size(struct file_ra_state *ra,
-						unsigned long max)
+				      unsigned long max)
 {
 	unsigned long cur = ra->size;
-	unsigned long newsize;
 
 	if (cur < max / 16)
-		newsize = 4 * cur;
-	else
-		newsize = 2 * cur;
-
-	return min(newsize, max);
+		return 4 * cur;
+	if (cur <= max / 2)
+		return 2 * cur;
+	return max;
 }
 
 /*
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 7+ messages in thread
* Re: [PATCH] mm: simplify get_next_ra_size
@ 2020-11-02 19:01 The Dellia’s
  2020-11-02 21:00 ` The Dellia’s
  0 siblings, 1 reply; 7+ messages in thread
From: The Dellia’s @ 2020-11-02 19:01 UTC (permalink / raw)
  To: hsiangkao; +Cc: akpm, fengguang.wu, linux-kernel, linux-mm




Sent from my iPhone

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

end of thread, other threads:[~2020-11-02 21:00 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-10-28  6:13 [PATCH] mm: simplify get_next_ra_size Gao Xiang
2018-10-28  6:27 ` Fengguang Wu
2018-10-28  7:05   ` Gao Xiang
2018-10-28 10:23 ` Matthew Wilcox
2018-10-28 11:05   ` Gao Xiang
2020-11-02 19:01 The Dellia’s
2020-11-02 21:00 ` The Dellia’s

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