[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20200221153537.GE24185@bombadil.infradead.org>
Date: Fri, 21 Feb 2020 07:35:37 -0800
From: Matthew Wilcox <willy@...radead.org>
To: John Hubbard <jhubbard@...dia.com>
Cc: linux-fsdevel@...r.kernel.org, linux-mm@...ck.org,
linux-kernel@...r.kernel.org, linux-btrfs@...r.kernel.org,
linux-erofs@...ts.ozlabs.org, linux-ext4@...r.kernel.org,
linux-f2fs-devel@...ts.sourceforge.net, cluster-devel@...hat.com,
ocfs2-devel@....oracle.com, linux-xfs@...r.kernel.org
Subject: Re: [PATCH v7 11/24] mm: Move end_index check out of readahead loop
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;
Powered by blists - more mailing lists