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 CA6BDC43334 for ; Fri, 10 Jun 2022 17:23:25 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 101D68D00CC; Fri, 10 Jun 2022 13:23:25 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 0B16B8D00CB; Fri, 10 Jun 2022 13:23:25 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EBC2C8D00CC; Fri, 10 Jun 2022 13:23:24 -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 DCA928D00CB for ; Fri, 10 Jun 2022 13:23:24 -0400 (EDT) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id AB14035CA3 for ; Fri, 10 Jun 2022 17:23:24 +0000 (UTC) X-FDA: 79562997528.14.7861E45 Received: from mail-qv1-f49.google.com (mail-qv1-f49.google.com [209.85.219.49]) by imf11.hostedemail.com (Postfix) with ESMTP id 3FDAE4007D for ; Fri, 10 Jun 2022 17:23:24 +0000 (UTC) Received: by mail-qv1-f49.google.com with SMTP id 43so318qvb.3 for ; Fri, 10 Jun 2022 10:23:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:date:mime-version:user-agent:subject:content-language:to :cc:references:from:in-reply-to:content-transfer-encoding; bh=ACMCDBad9TbnXtFF1l9kHpG+4dWc333XEZyLbnWKY0k=; b=QsvngpAL+7JLouZsHYdLb8NHMutaEvweFnaVmp9QLT8eO1OyXaN2I2wdgFqoLR37en oKSZo6fsOfu6LnRNIm3ZaC7cOml/bRetzqrnIaoJkZGxci/hZrYK39ZGWB3PT2BsjSzq C3UrEfeKvGQnS0qsczft/YsBcUxcozgPRRqirIFw9gZvPBt49IhICA7v0/QUdfi74tA1 NCItXaLokOgiMNqRsHKw0Ubqxh31cKmYW5nQh68ogksNp4zupT9hAAgbtSJFmfajs0Ib 32UBkicfFJjnYByn0FBCSYvKMa02qoVEwsvQRVt3Zo0U8Stjaik6LwSr1D6T8ckho9le wlQw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:cc:references:from:in-reply-to :content-transfer-encoding; bh=ACMCDBad9TbnXtFF1l9kHpG+4dWc333XEZyLbnWKY0k=; b=gZL13Z4FjccYY34xnNJgK86lh60dwUa98foopaiSydQzJSptNBhNrT4OQPkVTH//aR afk/r0pNrTV13A/1lRB/lSL+jdndIQP+4oasxS8R21fXpbNqrivfeqH0xw3xTKfXGrb8 tcP0G++HBFkvi+pJRO2bGI0UEWHyXSbAmR8sLkvOTjwAaHe5HooG7sWDzxgJ4J3lzOkB tPz+0b/YykNfIgFMGvoRlwqGXgHWxfeDRiq99iCIqHOWfVqWkYxgfecm0yMwc7QOIuOs j+rOODQOdfWHKcWpFHNYDYHfhh+ehRTVGz/AE0Qv/bKHb8EW87M7eldSltnMHgc7fWh3 mXqQ== X-Gm-Message-State: AOAM5331rBKJQeQQNpsNCIRN3WmLAwVVDGIg8ktOo4k9vfqCLQFnrmVB 039dyd6zx2HVzFX4qv7aXA== X-Google-Smtp-Source: ABdhPJyoH90+gyZLKikOzlW2U25UtQU5qb0MNUzrxkww+g20/Nw85mlOMPe+d8cvA41TuPgzYzhM8g== X-Received: by 2002:a05:6214:1c45:b0:46b:d221:de2c with SMTP id if5-20020a0562141c4500b0046bd221de2cmr10875631qvb.34.1654881803196; Fri, 10 Jun 2022 10:23:23 -0700 (PDT) Received: from [192.168.1.210] (c-73-219-103-14.hsd1.vt.comcast.net. [73.219.103.14]) by smtp.gmail.com with ESMTPSA id n79-20020a374052000000b0069fc13ce23dsm21584990qka.110.2022.06.10.10.23.21 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 10 Jun 2022 10:23:22 -0700 (PDT) Message-ID: Date: Fri, 10 Jun 2022 13:23:21 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.10.0 Subject: Re: [PATCH -next] mm/filemap: fix that first page is not mark accessed in filemap_read() Content-Language: en-US To: Matthew Wilcox , Yu Kuai 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 References: <20220602082129.2805890-1-yukuai3@huawei.com> From: Kent Overstreet In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1654881804; a=rsa-sha256; cv=none; b=VyNvonuDDnr5BmFQUCtD/r3694kgrgaXbA+JnyOMN5Cf7szL1UNHV0eGD57xGuOY6LgUAl XWqMxueN3ooVM7KEEKECabBsxzn2sogVt3XoRuIPJgwbS5aqdmwjkpfM1ObjEK6FI2p5Ug rDqMIuJ+mF4Kz9JZZG/2+9wvkk3hcxE= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=QsvngpAL; spf=pass (imf11.hostedemail.com: domain of kent.overstreet@gmail.com designates 209.85.219.49 as permitted sender) smtp.mailfrom=kent.overstreet@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1654881804; 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:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=ACMCDBad9TbnXtFF1l9kHpG+4dWc333XEZyLbnWKY0k=; b=D5iy8jxVjLHOAL+Btfaice1O1LYCjZf6MW37oUpRrmcztUVro2FXdFGDz6naIcF83xJQrt 5ICiX9Ve7I2fBp7hgzc2+4ffGOcsuqn1TTZfyTGpsIdk3SxgDKj6uJpMwiqNPBAre65Ofn aEBiWtk2gsu3lr3LsU9tzVmxaXK8igw= X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 3FDAE4007D X-Stat-Signature: bpquej6rox6hwz8rfer1ir5cmim5h86j X-Rspam-User: Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=QsvngpAL; spf=pass (imf11.hostedemail.com: domain of kent.overstreet@gmail.com designates 209.85.219.49 as permitted sender) smtp.mailfrom=kent.overstreet@gmail.com; dmarc=pass (policy=none) header.from=gmail.com X-HE-Tag: 1654881804-493128 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000116, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On 6/10/22 10:36, Matthew Wilcox wrote: > 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? So the idea was that if we're reading from a different _page_ that we read from previously, we should be marking it accessed. But there's an off by one error, it should have been if (iocb->ki_pos >> PAGE_SHIFT != (ra->prev_pos - 1) >> PAGE_SHIFT) folio_mark_accessed(fbatch.folios[0]) It looks like this is what Yukai was arriving at too when he was saying ki_pos + copied - 1, this is just a cleaner way of writing it :)