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 AE681C433EF for ; Fri, 10 Jun 2022 14:34:24 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0ED1B8D00B2; Fri, 10 Jun 2022 10:34:24 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 09D0F8D009C; Fri, 10 Jun 2022 10:34:24 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EA70C8D00B2; Fri, 10 Jun 2022 10:34:23 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id DC3108D009C for ; Fri, 10 Jun 2022 10:34:23 -0400 (EDT) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 9A761613BC for ; Fri, 10 Jun 2022 14:34:23 +0000 (UTC) X-FDA: 79562571606.16.5863AFD Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf15.hostedemail.com (Postfix) with ESMTP id B7C0DA0069 for ; Fri, 10 Jun 2022 14:34:22 +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=sgYdCWZmrc0bO6tRsB4xcpTV6Dk/0UYI28zBnLwu8Bs=; b=elwdjNnUnH6YAnK7XycKt05SI8 heZgbZnNVQ10zgCTLuaFHbHDlabqFJedlTpL6OOTRnVnbswPeR5D6/3tmdEnpW4nSgWEPqfN/tF5m POFy+MmLs5SFywyQqJa8c1FGo1NxbC3GB4m3YCCX8kUdvsjMVQphpcQCubiGiBxxOBm/IBUCHn3Jc vLLbSiXovpDf4Ltl9f7G44RzSnE7haHA1HpnymPg69to1P6/LOBra620BKhxc1QWniTfollSJG3Tv 40sYAXNJH4lPG9o05MyE590bWRkYCGPi4nbbehKyLctQg2gvJVTq4q5p29T4Ahmt2AyFGAgDcrIqu sgOdpEdg==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1nzfiF-00EWBp-W5; Fri, 10 Jun 2022 14:34:12 +0000 Date: Fri, 10 Jun 2022 15:34:11 +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-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1654871663; a=rsa-sha256; cv=none; b=NrnzZ3vFArnns4yt7dmHXZ5gcmQ/WMF98M+yHOrpz0sI4pjqZGcK9tQRxfb8lqAtbUsRLP kNeZMgKGFJtHDkmtEemBSnpYnP4iRoz1ZaxKbnLOgIPbJhZ0e4HDm/rUcO4zciI8fI8WWz XLXu2PNbxGhYqOFfGcp7iZcEePhJrvY= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=elwdjNnU; dmarc=none; spf=none (imf15.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1654871663; 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=sgYdCWZmrc0bO6tRsB4xcpTV6Dk/0UYI28zBnLwu8Bs=; b=SYWofkFdOwaGJ8aOZJq3Gu0jzKGnaESpPgYSka+CacD5k+f9myOG4w9x838cyYvwXL5ZJt wrZZ/L4aUIlB5oGcVqIx2IoteWC7/IfcGatGMeioKKmlsnQR445GLhoNb9Lzr5JoZqqA3k aV0cM19gFSTHkZAd3ajEHb8utBHXg60= X-Stat-Signature: 9enit7fqo8bfzsqgfnihxneqpmy1mjx9 X-Rspam-User: X-Rspamd-Queue-Id: B7C0DA0069 X-Rspamd-Server: rspam07 Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=elwdjNnU; dmarc=none; spf=none (imf15.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org X-HE-Tag: 1654871662-704645 X-Bogosity: Ham, tests=bogofilter, spamicity=0.002361, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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?