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 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1F784C433F5 for ; Wed, 20 Oct 2021 11:09:36 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id ABA14613D3 for ; Wed, 20 Oct 2021 11:09:35 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org ABA14613D3 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id F0EAB6B0071; Wed, 20 Oct 2021 07:09:34 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E971E6B0072; Wed, 20 Oct 2021 07:09:34 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D3805900002; Wed, 20 Oct 2021 07:09:34 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0041.hostedemail.com [216.40.44.41]) by kanga.kvack.org (Postfix) with ESMTP id C041E6B0071 for ; Wed, 20 Oct 2021 07:09:34 -0400 (EDT) Received: from smtpin17.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 80BB782499A8 for ; Wed, 20 Oct 2021 11:09:34 +0000 (UTC) X-FDA: 78716545068.17.E3722AA Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf04.hostedemail.com (Postfix) with ESMTP id 75FAE50000B0 for ; Wed, 20 Oct 2021 11:09:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=bkwCMh1L283zu+NfIJRFcbJeljr6wS5Wxo/xoHye8V0=; b=qs3LMa2vVLIf+lJ7FoOL5f1hPx HEmWfTaYB8JoNXenwGFzUALEnFQKeMXjhKlAbc6DQX7/HBpz+oN6GiMSlzqIH6iuYmvJDzlX1JnAy H0iymAL0ShIkDqkn7ybPkjNgO0tVIxvyyI2ZZ8jc2EM0NpT5VV0vzV6xzqrM06KnnewYwZcd4NGK7 7LZeYo8yWTzpvfbswfHOBnyYjn7VcVmacTAWAdLFLyOdeEvWzsxnSrtcaRKYXbVGfgThMyGCHUQZG h0eRCRSxZhZGSSegjttcOVjVHLu1bDy1Af/5kTewfWFpdwftlbHeDqG/U9FEqPnw9FoB+U61eMw4K xiyoHe2Q==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1md9QJ-00CRJI-I7; Wed, 20 Oct 2021 11:06:49 +0000 Date: Wed, 20 Oct 2021 12:06:19 +0100 From: Matthew Wilcox To: David Howells Cc: kent.overstreet@gmail.com, Andrew Morton , Jeff Layton , linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2] mm: Stop filemap_read() from grabbing a superfluous page Message-ID: References: <163472463105.3126792.7056099385135786492.stgit@warthog.procyon.org.uk> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <163472463105.3126792.7056099385135786492.stgit@warthog.procyon.org.uk> X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: 75FAE50000B0 X-Stat-Signature: 3heq7t94ufnw4magz35ktn3y45ic6e1p Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=qs3LMa2v; spf=none (imf04.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org; dmarc=none X-HE-Tag: 1634728171-692718 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: On Wed, Oct 20, 2021 at 11:10:31AM +0100, David Howells wrote: > Under some circumstances, filemap_read() will allocate sufficient pages to > read to the end of the file, call readahead/readpages on them and copy the > data over - and then it will allocate another page at the EOF and call > readpage on that and then ignore it. This is unnecessary and a waste of > time and resources. > > filemap_read() *does* check for this, but only after it has already done > the allocation and I/O. Fix this by checking before calling > filemap_get_pages() also. > > Changes: > v2) Break out of the loop immediately rather than going to put_pages (the > pvec is unoccupied). Setting isize is then unnecessary. > > Signed-off-by: David Howells > cc: Kent Overstreet > cc: Matthew Wilcox (Oracle) > cc: Andrew Morton > cc: Jeff Layton > cc: linux-mm@kvack.org > cc: linux-fsdevel@vger.kernel.org > Link: https://lore.kernel.org/r/160588481358.3465195.16552616179674485179.stgit@warthog.procyon.org.uk/ > Link: https://lore.kernel.org/r/163456863216.2614702.6384850026368833133.stgit@warthog.procyon.org.uk/ Reviewed-by: Matthew Wilcox (Oracle)