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 6DE9FC433EF for ; Wed, 12 Jan 2022 04:32:47 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DA2326B011A; Tue, 11 Jan 2022 23:32:46 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id D51856B011B; Tue, 11 Jan 2022 23:32:46 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C67676B011C; Tue, 11 Jan 2022 23:32:46 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0244.hostedemail.com [216.40.44.244]) by kanga.kvack.org (Postfix) with ESMTP id B78B36B011A for ; Tue, 11 Jan 2022 23:32:46 -0500 (EST) Received: from smtpin08.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 47FCA93D6D for ; Wed, 12 Jan 2022 04:32:46 +0000 (UTC) X-FDA: 79020364332.08.B9871CE Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf28.hostedemail.com (Postfix) with ESMTP id 51120C0005 for ; Wed, 12 Jan 2022 04:32:45 +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=5eLgB2WyWQPkc7m0camX6d8IeA1VEda0fgqfFrNeOtw=; b=doAYrs0dqZb/mzbDOgCE10yTcu +9/11AvgCj0QSAzmL7FAol0mTTNqyU4Lbk05ZQEOHL3m2s2iIZ/8wSxqiF3jW5eruSxPHDrE1jsQx rEG62ueGu7CgFFGPz5R8edIsnHlPsj5XcjsXZHbf0RaSmy6O9cO4DiMvMXi0kXTlvonswVQ/nOnVo csucgV8Rey4pHWIumO9lVyud8Q72HFTaZkFA3kHC8AOLNH2nT+HSc2gJXnnK5z7XMNk4GWYFYgNa6 p8meXad6uYaaYixQSWvjAWgJ7KSAC7E3N7JD/2bntFxSKXLDdVGQI8ww8yL9l0joWBr66snjq3z2Z 4gI2k9IQ==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1n7VJL-003p5A-0D; Wed, 12 Jan 2022 04:32:35 +0000 Date: Wed, 12 Jan 2022 04:32:34 +0000 From: Matthew Wilcox To: Hugh Dickins Cc: Peng Liang , David Hildenbrand , linux-mm@kvack.org, linux-kernel@vger.kernel.org, akpm@linux-foundation.org, xiexiangyou@huawei.com, zhengchuan@huawei.com, wanghao232@huawei.com Subject: Re: [RFC 0/1] memfd: Support mapping to zero page on reading Message-ID: References: <20211222123400.1659635-1-liangpeng10@huawei.com> <4b1885b8-eb95-c50-2965-11e7c8efbf36@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <4b1885b8-eb95-c50-2965-11e7c8efbf36@google.com> X-Rspamd-Queue-Id: 51120C0005 X-Stat-Signature: shd77mp3wjn1ziknr5pks84mw9cj84r8 Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=doAYrs0d; dmarc=none; spf=none (imf28.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-HE-Tag: 1641961965-531969 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 Tue, Jan 11, 2022 at 06:30:31PM -0800, Hugh Dickins wrote: > But I have to say that use of ZERO_PAGE for shmem/memfd/tmpfs read-fault > might (potentially) be very welcome. Not as some MFD_ZEROPAGE special > case, but as how it would always work. Deleting the shmem_recalc_inode() > cruft, which is there to correct accounting for the unmodified read-only > pages, after page reclaim has got around to freeing them later. > > It does require more work than you gave it in 1/1: mainly, as you call > out above, there's a need to note in the mapping's XArray when ZERO_PAGE > has been used at an offset, and do an rmap walk to unmap those ptes when > a writable page is substituted - see __xip_unmap() in Linux 3.19's > mm/filemap_xip.c for such an rmap walk. I think putting a pointer to the zero page in the XArray would introduce some unwelcome complexity, but the XArray has a special XA_ZERO_ENTRY which might be usable for such a thing. It would need some careful analysis and testing, of course, but it might also let us remove the special cases in the DAX code for DAX_ZERO_PAGE. I agree with you that temporarily allocating pages has worked "well enough", but maybe some workloads would benefit; even for files on block device filesystems, reading a hole and never writing to it may be common enough that this is an optimisation we've been missing for many years.