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 X-Spam-Level: X-Spam-Status: No, score=-5.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 71AA8C433ED for ; Tue, 18 May 2021 11:17:48 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 062A5610FA for ; Tue, 18 May 2021 11:17:47 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 062A5610FA Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=suse.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 8F4706B00D0; Tue, 18 May 2021 07:17:47 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8CA486B00D1; Tue, 18 May 2021 07:17:47 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 743A16B00D2; Tue, 18 May 2021 07:17:47 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0208.hostedemail.com [216.40.44.208]) by kanga.kvack.org (Postfix) with ESMTP id 40F316B00D0 for ; Tue, 18 May 2021 07:17:47 -0400 (EDT) Received: from smtpin36.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id BAA2E180AD830 for ; Tue, 18 May 2021 11:17:46 +0000 (UTC) X-FDA: 78154101732.36.351CE43 Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by imf05.hostedemail.com (Postfix) with ESMTP id 01280E000109 for ; Tue, 18 May 2021 11:17:43 +0000 (UTC) X-Virus-Scanned: by amavisd-new at test-mx.suse.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1621336665; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=htqqSuziJ3XS9X+MDWVgpvZ0mawTjFOdRU1/fBxrQ+s=; b=pnHF7k6CQQbOV5RHgq7RrNLxWJrStiO8vlJjmGpwtxcxdRXPxV9qh10HYpis86wlkklfxx r9UknxcH6JjrK6RDrLP/P0e64UHS5OsqnlcZ402Jw6HsZ8V4JjnF2P23tAhWilJ8kQTvZb G2cqTXwc6VQe/dUAduYPQu+ZDaQy96Y= Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 15527B127; Tue, 18 May 2021 11:17:45 +0000 (UTC) Date: Tue, 18 May 2021 13:17:43 +0200 From: Michal Hocko To: David Hildenbrand Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, Andrew Morton , Arnd Bergmann , Oscar Salvador , Matthew Wilcox , Andrea Arcangeli , Minchan Kim , Jann Horn , Jason Gunthorpe , Dave Hansen , Hugh Dickins , Rik van Riel , "Michael S . Tsirkin" , "Kirill A . Shutemov" , Vlastimil Babka , Richard Henderson , Ivan Kokshaysky , Matt Turner , Thomas Bogendoerfer , "James E.J. Bottomley" , Helge Deller , Chris Zankel , Max Filippov , Mike Kravetz , Peter Xu , Rolf Eike Beer , linux-alpha@vger.kernel.org, linux-mips@vger.kernel.org, linux-parisc@vger.kernel.org, linux-xtensa@linux-xtensa.org, linux-arch@vger.kernel.org, Linux API Subject: Re: [PATCH resend v2 2/5] mm/madvise: introduce MADV_POPULATE_(READ|WRITE) to prefault page tables Message-ID: References: <20210511081534.3507-1-david@redhat.com> <20210511081534.3507-3-david@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=suse.com header.s=susede1 header.b=pnHF7k6C; dmarc=pass (policy=quarantine) header.from=suse.com; spf=pass (imf05.hostedemail.com: domain of mhocko@suse.com designates 195.135.220.15 as permitted sender) smtp.mailfrom=mhocko@suse.com X-Stat-Signature: 4ddoe4y4wj3pshc1cu373ckygxqgcir1 X-Rspamd-Queue-Id: 01280E000109 X-Rspamd-Server: rspam02 X-HE-Tag: 1621336663-390264 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 18-05-21 12:32:12, David Hildenbrand wrote: > On 18.05.21 12:07, Michal Hocko wrote: > > [sorry for a long silence on this] > > > > On Tue 11-05-21 10:15:31, David Hildenbrand wrote: > > [...] > > > > Thanks for the extensive usecase description. That is certainly useful > > background. I am sorry to bring this up again but I am still not > > convinced that READ/WRITE variant are the best interface. > > Thanks for having time to look into this. > > > > While the use case for MADV_POPULATE_WRITE is fairly obvious (i.e., > > > preallocate memory and prefault page tables for VMs), one issue is that > > > whenever we prefault pages writable, the pages have to be marked dirty, > > > because the CPU could dirty them any time. while not a real problem for > > > hugetlbfs or dax/pmem, it can be a problem for shared file mappings: each > > > page will be marked dirty and has to be written back later when evicting. > > > > > > MADV_POPULATE_READ allows for optimizing this scenario: Pre-read a whole > > > mapping from backend storage without marking it dirty, such that eviction > > > won't have to write it back. As discussed above, shared file mappings > > > might require an explciit fallocate() upfront to achieve > > > preallcoation+prepopulation. > > > > This means that you want to have two different uses depending on the > > underlying mapping type. MADV_POPULATE_READ seems rather weak for > > anonymous/private mappings. Memory backed by zero pages seems rather > > unhelpful as the PF would need to do all the heavy lifting anyway. > > Or is there any actual usecase when this is desirable? > > Currently, userfaultfd-wp, which requires "some mapping" to be able to arm > successfully. In QEMU, we currently have to prefault the shared zeropage for > userfaultfd-wp to work as expected. Just for clarification. The aim is to reduce the memory footprint at the same time, right? If that is really the case then this is worth adding. > I expect that use case might vanish over > time (eventually with new kernels and updated user space), but it might > stick for a bit. Could you elaborate some more please? > Apart from that, populating the shared zeropage might be relevant in some > corner cases: I remember there are sparse matrix algorithms that operate > heavily on the shared zeropage. I am not sure I see why this would be a useful interface for those? Zero page read fault is really low cost. Or are you worried about cummulative overhead by entering the kernel many times? > > So the split into these two modes seems more like gup interface > > shortcomings bubbling up to the interface. I do expect userspace only > > cares about pre-faulting the address range. No matter what the backing > > storage is. > > > > Or do I still misunderstand all the usecases? > > Let me give you an example where we really cannot tell what would be best > from a kernel perspective. > > a) Mapping a file into a VM to be used as RAM. We might expect the guest > writing all memory immediately (e.g., booting Windows). We would want > MADV_POPULATE_WRITE as we expect a write access immediately. > > b) Mapping a file into a VM to be used as fake-NVDIMM, for example, ROOTFS > or just data storage. We expect mostly reading from this memory, thus, we > would want MADV_POPULATE_READ. I am afraid I do not follow. Could you be more explicit about advantages of using those two modes for those example usecases? Is that to share resources (e.g. by not breaking CoW)? > Instead of trying to be smart in the kernel, I think for this case it makes > much more sense to provide user space the options. IMHO it doesn't really > hurt to let user space decide on what it thinks is best. I am mostly worried that this will turn out to be more confusing than helpful. People will need to grasp non trivial concepts and kernel internal implementation details about how read/write faults are handled. Thanks! -- Michal Hocko SUSE Labs