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.1 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,NICE_REPLY_A, SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 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 70E63C433ED for ; Tue, 18 May 2021 10:32:26 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 1EF38611B0 for ; Tue, 18 May 2021 10:32:26 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1EF38611B0 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id AFC8B6B0095; Tue, 18 May 2021 06:32:25 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id AD25D6B0096; Tue, 18 May 2021 06:32:25 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 94C9A8D0001; Tue, 18 May 2021 06:32:25 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0174.hostedemail.com [216.40.44.174]) by kanga.kvack.org (Postfix) with ESMTP id 65A776B0095 for ; Tue, 18 May 2021 06:32:25 -0400 (EDT) Received: from smtpin11.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 0B3618249980 for ; Tue, 18 May 2021 10:32:25 +0000 (UTC) X-FDA: 78153987450.11.916F41B Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf08.hostedemail.com (Postfix) with ESMTP id 66D5780192E0 for ; Tue, 18 May 2021 10:32:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1621333944; h=from:from: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; bh=I3GoBhYUm/DKIxdTnLjldHt3dau0GNiE51gCpNBcSM0=; b=TDm0eP5BZfgFjahPbiprgYe9Uvt+rOvoWCgasrDsT5Rfvs7mJOMztYO00SOh4n1mVL32BY MsygG3MNZeZ46OshRyT/n2SV75f52m8lIrFyb+1Xlf5CVqDnuhRBkC1NtqyPucD8KQUwFz ScoBGu4iBo4nSwjHmu/O9CgQuXY3PSM= Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-602-tg2dwZDeMqKgQW6lIyY3OQ-1; Tue, 18 May 2021 06:32:15 -0400 X-MC-Unique: tg2dwZDeMqKgQW6lIyY3OQ-1 Received: by mail-wr1-f72.google.com with SMTP id c13-20020a5d6ccd0000b029010ec741b84bso5364995wrc.23 for ; Tue, 18 May 2021 03:32:15 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:to:cc:references:from:organization:subject :message-id:date:user-agent:mime-version:in-reply-to :content-language:content-transfer-encoding; bh=I3GoBhYUm/DKIxdTnLjldHt3dau0GNiE51gCpNBcSM0=; b=V2oTUMrbt9Ij3gpUkp/MODpEOwSRO9eTxilEofUv/U7eXtb1I1/lcZec/SN8m/wvJk 4emtRlnVTHE+0p+AZXuwDQmeff5ho0KgcruGY6vCn65hzdTn/b+9p/hDwH1RfKEwCArM y6FwH3RBpvgvfehx5T2jCryOmZZlRtygWi1mR7p+xN4Qv3onrzZJYhIUm00nhUsTxnkN YpnnA0ftEV+ZN6VvI03AeXbSIXe52FB1Gk7m+eaG/rJaFzzK58elar5wlsHgIGr56TLV 3+rw0TEIzhXS9bg6oHKf+T9WGYAOVNdjZ72Kzm5pB/YkL1SXLCgzYSMe0Cg7gJ6c+c3o RQaA== X-Gm-Message-State: AOAM533xaYwGRJmnKE6ohZyocsbK3022kTAk6T2pFOD/lhIlvmb59aeI QBQdWBKfel34/C0sTBFE474U6wCd1B0ml6UukZxoRp67RktC6FzBqtAs70ZThayfAdE33ZOaGWb z2wGGCKKF6P0= X-Received: by 2002:a1c:730b:: with SMTP id d11mr4111571wmb.20.1621333934509; Tue, 18 May 2021 03:32:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyNi/tkWCoG0NuBlaiGe8ooTg64rxLuGj3IhddCSk72nVE1RVc10kp/QPhwhI1TNBxYXIrVfw== X-Received: by 2002:a1c:730b:: with SMTP id d11mr4111530wmb.20.1621333934226; Tue, 18 May 2021 03:32:14 -0700 (PDT) Received: from [192.168.3.132] (p5b0c64fd.dip0.t-ipconnect.de. [91.12.100.253]) by smtp.gmail.com with ESMTPSA id f26sm2241521wmj.30.2021.05.18.03.32.12 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 18 May 2021 03:32:13 -0700 (PDT) To: Michal Hocko 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 References: <20210511081534.3507-1-david@redhat.com> <20210511081534.3507-3-david@redhat.com> From: David Hildenbrand Organization: Red Hat Subject: Re: [PATCH resend v2 2/5] mm/madvise: introduce MADV_POPULATE_(READ|WRITE) to prefault page tables Message-ID: Date: Tue, 18 May 2021 12:32:12 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.10.1 MIME-Version: 1.0 In-Reply-To: X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US X-Rspamd-Queue-Id: 66D5780192E0 Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=TDm0eP5B; dmarc=pass (policy=none) header.from=redhat.com; spf=none (imf08.hostedemail.com: domain of david@redhat.com has no SPF policy when checking 170.10.133.124) smtp.mailfrom=david@redhat.com X-Rspamd-Server: rspam03 X-Stat-Signature: nse7anjpeafmqmz6dubgxgx4ct9dki94 X-HE-Tag: 1621333941-679271 Content-Transfer-Encoding: quoted-printable 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 18.05.21 12:07, Michal Hocko wrote: > [sorry for a long silence on this] >=20 > On Tue 11-05-21 10:15:31, David Hildenbrand wrote: > [...] >=20 > 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. > =20 >> While the use case for MADV_POPULATE_WRITE is fairly obvious (i.e., >> preallocate memory and prefault page tables for VMs), one issue is tha= t >> 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 fo= r >> hugetlbfs or dax/pmem, it can be a problem for shared file mappings: e= ach >> page will be marked dirty and has to be written back later when evicti= ng. >> >> MADV_POPULATE_READ allows for optimizing this scenario: Pre-read a who= le >> mapping from backend storage without marking it dirty, such that evict= ion >> won't have to write it back. As discussed above, shared file mappings >> might require an explciit fallocate() upfront to achieve >> preallcoation+prepopulation. >=20 > 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=20 arm successfully. In QEMU, we currently have to prefault the shared=20 zeropage for userfaultfd-wp to work as expected. I expect that use case=20 might vanish over time (eventually with new kernels and updated user=20 space), but it might stick for a bit. Apart from that, populating the shared zeropage might be relevant in=20 some corner cases: I remember there are sparse matrix algorithms that=20 operate heavily on the shared zeropage. >=20 > 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. >=20 > Or do I still misunderstand all the usecases? Let me give you an example where we really cannot tell what would be=20 best from a kernel perspective. a) Mapping a file into a VM to be used as RAM. We might expect the guest=20 writing all memory immediately (e.g., booting Windows). We would want=20 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,=20 ROOTFS or just data storage. We expect mostly reading from this memory,=20 thus, we would want MADV_POPULATE_READ. Instead of trying to be smart in the kernel, I think for this case it=20 makes much more sense to provide user space the options. IMHO it doesn't=20 really hurt to let user space decide on what it thinks is best. --=20 Thanks, David / dhildenb