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=-10.1 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, MENTIONS_GIT_HOSTING,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=ham 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 1563EC433DB for ; Wed, 17 Feb 2021 17:07:00 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 9DAA464E4D for ; Wed, 17 Feb 2021 17:06:59 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9DAA464E4D 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 D78916B0006; Wed, 17 Feb 2021 12:06:58 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id D28A86B006C; Wed, 17 Feb 2021 12:06:58 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BCBCC6B006E; Wed, 17 Feb 2021 12:06:58 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0200.hostedemail.com [216.40.44.200]) by kanga.kvack.org (Postfix) with ESMTP id A88E56B0006 for ; Wed, 17 Feb 2021 12:06:58 -0500 (EST) Received: from smtpin25.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 6E25818042E23 for ; Wed, 17 Feb 2021 17:06:58 +0000 (UTC) X-FDA: 77828389716.25.5CF7B9A Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by imf15.hostedemail.com (Postfix) with ESMTP id 3F09CA0009D1 for ; Wed, 17 Feb 2021 17:06:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1613581617; 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=Gpb+J8dp6CkVjY4reiUnk9V/e+84nsohs0qJ0sOiFNE0Sclr14OTGtfryptCqbKQHHNF32 GrXZmPmc+tmRNOzbN9RAAgNGEFiJuEQLhcWoh3NcgVRIMS/v1LIszvtZ7s5UaDgDF3Wmxe vRaMp70FI8RHWKFMukqhBeHRETrwR+o= 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 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 3F09CA0009D1 X-Stat-Signature: 6ocxxrkzf5m97sad56xdrwct153jonub Received-SPF: none (redhat.com>: No applicable sender policy available) receiver=imf15; identity=mailfrom; envelope-from=""; helo=us-smtp-delivery-124.mimecast.com; client-ip=63.128.21.124 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1613581617-135138 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 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 reliab= ly >> discard memory, there is no generic approach to populate ("preallocate= ") >> memory. >> >> Although mmap() supports MAP_POPULATE, it is not applicable to the con= cept >> 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. >=20 > Seems pretty sane to me. >=20 > 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=20 semantics. "Expect access in the near future." and "might be a good idea to read=20 some pages" vs. "Definitely populate/preallocate all memory and=20 definitely fail.". >=20 > 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=20 because we are deflating the balloon doesn't mean that the guest is=20 going to use all memory immediately - and that we want to actually=20 consume memory immediately. ... we call MADV_WILLNEED unconditionally on=20 any memory backing when deflating ... I'll definitely add that to the changelog - thanks. >=20 > 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 |=20 VM_PFNMAP. So it mimics existing "populate semantics" we have. >=20 >> https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tre= e/arch/x86/kernel/cpu/sgx/driver.c >=20 > 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 coul= d > certainly add to this later. I assume you would then also want to support MAP_POPULATE, right?=20 Because it ends up using __mm_populate() and would not work. Thanks! --=20 Thanks, David / dhildenb