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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 32E32C43334 for ; Fri, 10 Jun 2022 14:36:41 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C38BA8D00BC; Fri, 10 Jun 2022 10:36:40 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id BE7F48D00B3; Fri, 10 Jun 2022 10:36:40 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AD7328D00BC; Fri, 10 Jun 2022 10:36:40 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 9F61F8D00B3 for ; Fri, 10 Jun 2022 10:36:40 -0400 (EDT) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 7F2EA35A6B for ; Fri, 10 Jun 2022 14:36:40 +0000 (UTC) X-FDA: 79562577360.29.AD6712F Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf09.hostedemail.com (Postfix) with ESMTP id 1195A14007F for ; Fri, 10 Jun 2022 14:36:39 +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=SL6WDHTUHkdLCnhdaxfAT0gjsC7EVcgs4nlCTy2yQcs=; b=n0k3JrwAYZyCYAsOslLE2JxjQa OsgsRLcb6Rf6lNXwqDwq/MtvzPQrIpz4fQVQjH/SYvErT8pwLpbK8c4eahqPJnzNpFWsxw5iAqGFH vA+r4LewVXcMEUogpzRrQthPEucxjFGzRsJao+r0Xjl5IQkmF7X1Vy7n7Av+7Wpe+gQHJbmDmH/QF qGTepPN0qZXlTJPInVVtJFS877dJoZV41ZbHAC/Cs3u/0d1TcbAXRMcwlz9xzsd42bX6hZDSs4y0L FPphnfyls/1NxxJH1KIlo6akHSttgTUNu8fLRNjgvWsiLrsdADBUL8/5S7KreeJZDWn43z2oRzYgF 9zrcuZfA==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1nzfkX-00EWMi-8G; Fri, 10 Jun 2022 14:36:33 +0000 Date: Fri, 10 Jun 2022 15:36:33 +0100 From: Matthew Wilcox To: Yu Kuai , kent.overstreet@gmail.com Cc: akpm@linux-foundation.org, axboe@kernel.dk, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, yi.zhang@huawei.com Subject: Re: [PATCH -next] mm/filemap: fix that first page is not mark accessed in filemap_read() Message-ID: References: <20220602082129.2805890-1-yukuai3@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1654871800; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=SL6WDHTUHkdLCnhdaxfAT0gjsC7EVcgs4nlCTy2yQcs=; b=I7iO0pXC7LrTLEI2URXoKHRi218/E7uNvl3e9Zmto1G1/yi62yeiP5Ld6wIJnYYEvtzK9y bF//XyVYhLmQUoYLH8JkXDQjd9mW4M+ZnxBuhmGY3hxJ7xMHg4VVkUWR79lKyeNjlt5yDj xBuWbR2+7/7FQLnjSuYrA8cxy/QEBWc= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1654871800; a=rsa-sha256; cv=none; b=y3ZAL+sbPIYN4RoFSKJk5mkrSvAy+/WaCVklmdi8i1bgFLvgn5yvZwXvrbio/8jQxOJ4V3 e5TbUSwlbd9mHBPedJRBPmGq23+cjp51NO8rcWw0evn43bpu/9PFRi92AiHVxElbhahIXr c75ZYPQfrOU9sVjGogqhvE1dPDr/+sc= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=n0k3JrwA; dmarc=none; spf=none (imf09.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=n0k3JrwA; dmarc=none; spf=none (imf09.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org X-Rspamd-Server: rspam08 X-Rspam-User: X-Stat-Signature: zc3e97puhab7p9hqx4oy14oek7hbmhb1 X-Rspamd-Queue-Id: 1195A14007F X-HE-Tag: 1654871799-544849 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 Fri, Jun 10, 2022 at 03:34:11PM +0100, Matthew Wilcox wrote: > On Mon, Jun 06, 2022 at 09:10:03AM +0800, Yu Kuai wrote: > > On 2022/06/03 2:30, Matthew Wilcox wrote: > > > On Thu, Jun 02, 2022 at 04:21:29PM +0800, Yu Kuai wrote: > > > > In filemap_read(), 'ra->prev_pos' is set to 'iocb->ki_pos + copied', > > > > while it should be 'iocb->ki_ops'. > > > > > > Can you walk me through your reasoning which leads you to believe that > > > it should be ki_pos instead of ki_pos + copied? As I understand it, > > > prev_pos is the end of the previous read, not the beginning of the > > > previous read. > > > > Hi, Matthew > > > > The main reason is the following judgement in flemap_read(): > > > > if (iocb->ki_pos >> PAGE_SHIFT != -> current page > > ra->prev_pos >> PAGE_SHIFT) -> previous page > > folio_mark_accessed(fbatch.folios[0]); > > > > Which means if current page is the same as previous page, don't mark > > page accessed. However, prev_pos is set to 'ki_pos + copied' during last > > read, which will cause 'prev_pos >> PAGE_SHIFT' to be current page > > instead of previous page. > > > > I was thinking that if prev_pos is set to the begining of the previous > > read, 'prev_pos >> PAGE_SHIFT' will be previous page as expected. Set to > > the end of previous read is ok, however, I think the caculation of > > previous page should be '(prev_pos - 1) >> PAGE_SHIFT' instead. > > OK, I think Kent broke this in 723ef24b9b37 ("mm/filemap/c: break > generic_file_buffered_read up into multiple functions"). Before: > > - prev_index = ra->prev_pos >> PAGE_SHIFT; > - prev_offset = ra->prev_pos & (PAGE_SIZE-1); > ... > - if (prev_index != index || offset != prev_offset) > - mark_page_accessed(page); > > After: > + if (iocb->ki_pos >> PAGE_SHIFT != ra->prev_pos >> PAGE_SHIFT) > + mark_page_accessed(page); > > So surely this should have been: > > + if (iocb->ki_pos != ra->prev_pos) > + mark_page_accessed(page); > > Kent, do you recall why you changed it the way you did? Oh, and if this is the right diagnosis, then this is the fix for the current tree: +++ b/mm/filemap.c @@ -2673,8 +2673,7 @@ ssize_t filemap_read(struct kiocb *iocb, struct iov_iter *iter, * When a sequential read accesses a page several times, only * mark it as accessed the first time. */ - if (iocb->ki_pos >> PAGE_SHIFT != - ra->prev_pos >> PAGE_SHIFT) + if (iocb->ki_pos != ra->prev_pos) folio_mark_accessed(fbatch.folios[0]); for (i = 0; i < folio_batch_count(&fbatch); i++) {