lkml.org 
[lkml]   [2020]   [Dec]   [20]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[RFC PATCH 2/2] mm: readahead: handle LARGE input to get_init_ra_size()
Date
Add a test to detect if the input ra request size has its high order
bit set (is negative when tested as a signed long). This would be a
really Huge readahead.

If so, WARN() with the value and a stack trace so that we can see
where this is happening and then make further corrections later.
Then adjust the size value so that it is not so Huge (although
this may not be needed).

Also correct a comment: the return value is not squared for
small size.

Signed-off-by: Randy Dunlap <rdunlap@infradead.org>
Cc: Jens Axboe <axboe@kernel.dk>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Toralf Förster <toralf.foerster@gmx.de>
Cc: linux-mm@kvack.org
---
Notes:
- Look for "WARNING:.*get_init_ra_size"
- If panic_on_warn is set, this will cause a kernel panic().

mm/readahead.c | 12 ++++++++++--
1 file changed, 10 insertions(+), 2 deletions(-)

--- linux-5.10.1.orig/mm/readahead.c
+++ linux-5.10.1/mm/readahead.c
@@ -14,6 +14,7 @@
#include <linux/export.h>
#include <linux/blkdev.h>
#include <linux/backing-dev.h>
+#include <linux/bug.h>
#include <linux/task_io_accounting_ops.h>
#include <linux/pagevec.h>
#include <linux/pagemap.h>
@@ -303,14 +304,21 @@ void force_page_cache_ra(struct readahea
}

/*
- * Set the initial window size, round to next power of 2 and square
+ * Set the initial window size, round to next power of 2
* for small size, x 4 for medium, and x 2 for large
* for 128k (32 page) max ra
* 1-8 page = 32k initial, > 8 page = 128k initial
*/
static unsigned long get_init_ra_size(unsigned long size, unsigned long max)
{
- unsigned long newsize = roundup_pow_of_two(size);
+ unsigned long newsize;
+
+ if ((signed long)size < 0) { /* high bit is set: ultra-large ra req */
+ WARN_ONCE(1, "%s: size=0x%lx\n", __func__, size);
+ size = -size; /* really only need to flip the high/sign bit */
+ }
+
+ newsize = roundup_pow_of_two(size);

if (newsize <= max / 32)
newsize = newsize * 4;
\
 
 \ /
  Last update: 2020-12-20 22:41    [W:2.731 / U:0.564 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site