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=-0.6 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=no 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 8CEDEC35646 for ; Fri, 21 Feb 2020 15:35:41 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 31FAC2073A for ; Fri, 21 Feb 2020 15:35:40 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="e19h/tTJ" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 31FAC2073A 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 732596B0003; Fri, 21 Feb 2020 10:35:40 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 6E2E06B0006; Fri, 21 Feb 2020 10:35:40 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5F8C96B0007; Fri, 21 Feb 2020 10:35:40 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0127.hostedemail.com [216.40.44.127]) by kanga.kvack.org (Postfix) with ESMTP id 451706B0003 for ; Fri, 21 Feb 2020 10:35:40 -0500 (EST) Received: from smtpin02.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id D1BF7181AEF1D for ; Fri, 21 Feb 2020 15:35:39 +0000 (UTC) X-FDA: 76514533998.02.burn12_31651a681ea2d X-HE-Tag: burn12_31651a681ea2d X-Filterd-Recvd-Size: 3277 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf29.hostedemail.com (Postfix) with ESMTP for ; Fri, 21 Feb 2020 15:35:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.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=+ZsaQJllFuL8jpNObDQrHmpdC/B73n9RqMvE0qPHxaM=; b=e19h/tTJERLUFpOL5Gva3Nh5/X wd0VH9aVgKh+1Blgs+9Q15ijaVkaoTLAy7WypYckq6maI2+/Qpa5TYpUzL45zkwW6/rKVd4gOa/Q3 37XTTlJ3n85F+yMLVB8w0BnbSlS+Y+mVNSOJqRCX3b4kHG/mSGnd+/RHhL7LSbdq0PycpO3gHljyg 1ePLpWP66QKkQwSW3hqI4AmWyW4KZvprzI+VqeFwh8xfQgZxihaUIj3MuUi6DWndVunwNc8HfQSPa cJzgSNpVLmszdlcuXvTGALnsMeU2uXmuwM6kJU9UgfbmbAX46oAsryhNENVSPO0btKS8JfbqGc1YR ErE1c+gA==; Received: from willy by bombadil.infradead.org with local (Exim 4.92.3 #3 (Red Hat Linux)) id 1j5AL3-00062c-43; Fri, 21 Feb 2020 15:35:37 +0000 Date: Fri, 21 Feb 2020 07:35:37 -0800 From: Matthew Wilcox To: John Hubbard Cc: linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-btrfs@vger.kernel.org, linux-erofs@lists.ozlabs.org, linux-ext4@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net, cluster-devel@redhat.com, ocfs2-devel@oss.oracle.com, linux-xfs@vger.kernel.org Subject: Re: [PATCH v7 11/24] mm: Move end_index check out of readahead loop Message-ID: <20200221153537.GE24185@bombadil.infradead.org> References: <20200219210103.32400-1-willy@infradead.org> <20200219210103.32400-12-willy@infradead.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Bogosity: Ham, tests=bogofilter, spamicity=0.000002, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Thu, Feb 20, 2020 at 07:50:39PM -0800, John Hubbard wrote: > This tiny patch made me pause, because I wasn't sure at first of the exact > intent of the lines above. Once I worked it out, it seemed like it might > be helpful (or overkill??) to add a few hints for the reader, especially since > there are no hints in the function's (minimal) documentation header. What > do you think of this? > > /* > * If we can't read *any* pages without going past the inodes's isize > * limit, give up entirely: > */ > if (index > end_index) > return; > > /* Cap nr_to_read, in order to avoid overflowing the ULONG type: */ > if (index + nr_to_read < index) > nr_to_read = ULONG_MAX - index + 1; > > /* Cap nr_to_read, to avoid reading past the inode's isize limit: */ > if (index + nr_to_read >= end_index) > nr_to_read = end_index - index + 1; A little verbose for my taste ... How about this? end_index = (isize - 1) >> PAGE_SHIFT; if (index > end_index) return; /* Avoid wrapping to the beginning of the file */ if (index + nr_to_read < index) nr_to_read = ULONG_MAX - index + 1; /* Don't read past the page containing the last byte of the file */ if (index + nr_to_read >= end_index) nr_to_read = end_index - index + 1;