From patchwork Sun Dec 20 21:10:51 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Randy Dunlap X-Patchwork-Id: 11984027 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=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,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 DD207C4361B for ; Sun, 20 Dec 2020 21:11:05 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 6612222273 for ; Sun, 20 Dec 2020 21:11:05 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6612222273 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 026956B005D; Sun, 20 Dec 2020 16:11:05 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id F173B6B0068; Sun, 20 Dec 2020 16:11:04 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E07096B006C; Sun, 20 Dec 2020 16:11:04 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0187.hostedemail.com [216.40.44.187]) by kanga.kvack.org (Postfix) with ESMTP id C9C4F6B005D for ; Sun, 20 Dec 2020 16:11:04 -0500 (EST) Received: from smtpin21.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 80851180AD82F for ; Sun, 20 Dec 2020 21:11:04 +0000 (UTC) X-FDA: 77614905648.21.heat76_480391427451 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin21.hostedemail.com (Postfix) with ESMTP id 5FE5F180442C0 for ; Sun, 20 Dec 2020 21:11:04 +0000 (UTC) X-HE-Tag: heat76_480391427451 X-Filterd-Recvd-Size: 3660 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf18.hostedemail.com (Postfix) with ESMTP for ; Sun, 20 Dec 2020 21:11:03 +0000 (UTC) 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_F=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 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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 Reported-by: and Tested-by: on the patch? --- 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;