Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp6632342pxb; Wed, 17 Feb 2021 09:13:59 -0800 (PST) X-Google-Smtp-Source: ABdhPJz41GJL58GYJ9X14cT+zP8nuauIZgAADH0mmwtLzmPuzWgwX0BNJ9BCYXgJZr4voxQqCeIt X-Received: by 2002:a17:907:3e1b:: with SMTP id hp27mr25290539ejc.506.1613582039104; Wed, 17 Feb 2021 09:13:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1613582039; cv=none; d=google.com; s=arc-20160816; b=fYyauIok7vykvGRB/RLLl36u5s64ymuG2QeOZ5PMxwFAoXDWkzowP+sFsPmLQ1wm7/ o7ZMHpvsGCqLRlKGplwovOuQ4+d+SQ8XH5MCgrGtREs9BOMl/eTc3uRfEjMgs0An116W TumhUBJAyRukXgamkD+fnhcYscier03xFgYxsOQBtrosn+bPJSetv9TNmHb1VsUCgs0H 6pQoT+/bDhDCIcdTSNSfvvJYYO8pxg4VJ4RJBIEYLQTxvqMqnRc8vStTGQe6hlIp3rma tvI9rx8JTV/X/f6Fhjz+Z9QGK7g6CXamC2kSWi377+wOWnzsGQxmOkYdulQsCUeTpSSZ cWQQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:subject :organization:from:references:cc:to:dkim-signature; bh=teZTA6Q4Aw5qzYmTXQsisbEZn/CxzO/4FfFNpRMYgZg=; b=0aHKuveSsU71hASxsLS0lwcPzzQCWnSbQ6+0IgQ5aOkc7NWrlnQf1JdaDLRs6wGGQ1 4bCERhKSriNyNR5f2JlQU0lS2q+IT2KPzQP4zsWnoDEUdtgXwuo/P6gWIjdTh9oyVTIa dx4ihq7L8ZvL5evhAzpaBtRUFTlZ6+Ef/KYSXYJ7a7Z99mcgy5MpR1LpPGCJnxzUk8C/ 22xfZ0aBxUXa354noeo5oop2F9LjyKGAxT/uVrn+b3RgNR+gI/4HrjteeEyJFaH2bQQT GML6Nz+QIH6HaN1T00YBKPL1rf4oxpXyaHxowSIMYHvsP6s6OujVVXvS5WPMJhJZbKOd KStQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=ckJRyaeU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id r1si1743646edp.381.2021.02.17.09.13.16; Wed, 17 Feb 2021 09:13:59 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=ckJRyaeU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234327AbhBQRIb (ORCPT + 99 others); Wed, 17 Feb 2021 12:08:31 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:54825 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234260AbhBQRIZ (ORCPT ); Wed, 17 Feb 2021 12:08:25 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1613581619; 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=teZTA6Q4Aw5qzYmTXQsisbEZn/CxzO/4FfFNpRMYgZg=; b=ckJRyaeUX/4RQwqzKsp85kWaRPxtLdL+0qXyMabCPm4piZMsx0gIIpvZTb1+KFoOTy1lUT JIARDzMN2FxoB3dIeeeBKblkyzQpIchf/STHReHsVpm558E4qrWEzzJGhK5S50RkkMzy7+ 8SFpRMdRxoPKkFznmhtf6Ld3cTVnACY= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-586-_Tk9Tt78NC2R41z3BB0FMA-1; Wed, 17 Feb 2021 12:06:54 -0500 X-MC-Unique: _Tk9Tt78NC2R41z3BB0FMA-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id D3821192D790; Wed, 17 Feb 2021 17:06:49 +0000 (UTC) Received: from [10.36.114.178] (ovpn-114-178.ams2.redhat.com [10.36.114.178]) by smtp.corp.redhat.com (Postfix) with ESMTP id 02BFE10016F0; Wed, 17 Feb 2021 17:06:39 +0000 (UTC) To: Dave Hansen , linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, Andrew Morton , Arnd Bergmann , Michal Hocko , Oscar Salvador , Matthew Wilcox , Andrea Arcangeli , Minchan Kim , Jann Horn , Jason Gunthorpe , 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 , 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 References: <20210217154844.12392-1-david@redhat.com> <726b0766-9624-69c5-5a45-ffad42c446b1@intel.com> From: David Hildenbrand Organization: Red Hat GmbH Subject: Re: [PATCH RFC] mm/madvise: introduce MADV_POPULATE to prefault/prealloc memory Message-ID: <9129686d-a272-fa8a-3f99-2de2fac52c93@redhat.com> Date: Wed, 17 Feb 2021 18:06:39 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.7.0 MIME-Version: 1.0 In-Reply-To: <726b0766-9624-69c5-5a45-ffad42c446b1@intel.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 17.02.21 17:46, Dave Hansen wrote: > On 2/17/21 7:48 AM, David Hildenbrand wrote: >> While MADV_DONTNEED and FALLOC_FL_PUNCH_HOLE provide us ways to reliably >> discard memory, there is no generic approach to populate ("preallocate") >> memory. >> >> Although mmap() supports MAP_POPULATE, it is not applicable to the concept >> of sparse memory mappings, where we want to do populate/discard >> dynamically and avoid expensive/problematic remappings. In addition, >> we never actually report error during the final populate phase - it is >> best-effort only. > > Seems pretty sane to me. > > But, I was surprised that MADV_WILLNEED was no mentioned. It might be > nice to touch on on why MADV_WILLNEED is a bad choice for this > functionality? We could theoretically have it populate anonymous > mappings instead of just swapping in. I stumbled over it, but it ended up looking like mixing in different semantics. "Expect access in the near future." and "might be a good idea to read some pages" vs. "Definitely populate/preallocate all memory and definitely fail.". > > I guess it's possible that folks are using MADV_WILLNEED on sparse > mappings that they don't want to populate, but it would be nice to get > that in the changelog. Indeed: prime example is virtio-balloon in QEMU when deflating. Just because we are deflating the balloon doesn't mean that the guest is going to use all memory immediately - and that we want to actually consume memory immediately. ... we call MADV_WILLNEED unconditionally on any memory backing when deflating ... I'll definitely add that to the changelog - thanks. > > I was also a bit bummed to see the broad VM_IO/PFNMAP restriction show > up again. I was just looking at implementing pre-faulting for the new > SGX driver: I added that because __mm_populate() similarly skips over VM_IO | VM_PFNMAP. So it mimics existing "populate semantics" we have. > >> https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/arch/x86/kernel/cpu/sgx/driver.c > > It has a vm_ops->fault handler, but the VMAs are VM_IO. It obviously > don't work with gup, though. Not a deal breaker, and something we could > certainly add to this later. I assume you would then also want to support MAP_POPULATE, right? Because it ends up using __mm_populate() and would not work. Thanks! -- Thanks, David / dhildenb