From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0BB91C4361B for ; Sun, 20 Dec 2020 21:39:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id BCFFA22CA2 for ; Sun, 20 Dec 2020 21:39:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728353AbgLTVj3 (ORCPT ); Sun, 20 Dec 2020 16:39:29 -0500 Received: from casper.infradead.org ([90.155.50.34]:36426 "EHLO casper.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727446AbgLTVj3 (ORCPT ); Sun, 20 Dec 2020 16:39:29 -0500 X-Greylist: delayed 1680 seconds by postgrey-1.27 at vger.kernel.org; Sun, 20 Dec 2020 16:39:28 EST DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:Content-Type: MIME-Version:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:Content-ID: Content-Description:In-Reply-To:References; bh=NUqXj/POrl622LAUb62LCHSZurTWKJa2BeQnkYK49wc=; b=FPcvcPrKrhzWPxAmQIQUK56PGU Gl4asoz4GFZ50DLgihfaToYj5BUITjB4brnnYeeKn1Rhz84vY12DZY6Bklz0oN7pVvNGKrZWcN2zT Z/OzTO6+ew3dhZWP7gKR36yJoXirtRQdkEa8MG1AyoGyS9bcw0rjTWZU5GY28aCcSyHOmJziA+hhM ONjjVOJHHt9xZwB2V7GyfmC0NtLP0d+FejMskoSMwNkp9R2GAHIWHUxrChVvlZIA5XO9y0Jmjgkk7 2D52lZcyGi430lzzlwcOtz5/7ujlgvysAk/bTK4P/XXW3CKksqnj/Z+oWBctl3KGUN262NOnhoEf5 A6VFoV7Q==; Received: from [2601:1c0:6280:3f0::64ea] (helo=smtpauth.infradead.org) by casper.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1kr5yh-0005CV-KA; Sun, 20 Dec 2020 21:10:56 +0000 From: Randy Dunlap To: linux-kernel@vger.kernel.org Cc: Randy Dunlap , Jens Axboe , Andrew Morton , =?UTF-8?q?Toralf=20F=C3=B6rster?= , linux-mm@kvack.org Subject: [RFC PATCH 2/2] mm: readahead: handle LARGE input to get_init_ra_size() Date: Sun, 20 Dec 2020 13:10:51 -0800 Message-Id: <20201220211051.1416-1-rdunlap@infradead.org> X-Mailer: git-send-email 2.26.2 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 Cc: Jens Axboe Cc: Andrew Morton Cc: Toralf Förster 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 #include #include +#include #include #include #include @@ -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;