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=-0.8 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,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 ACA27C35254 for ; Mon, 10 Feb 2020 01:21:44 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 6859121775 for ; Mon, 10 Feb 2020 01:21:44 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=kernel.org header.i=@kernel.org header.b="2hRd4Ukw" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6859121775 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=linux-foundation.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id C2B336B0085; Sun, 9 Feb 2020 20:21:43 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id BDC4D6B0087; Sun, 9 Feb 2020 20:21:43 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AF17A6B0088; Sun, 9 Feb 2020 20:21:43 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0052.hostedemail.com [216.40.44.52]) by kanga.kvack.org (Postfix) with ESMTP id 95B706B0085 for ; Sun, 9 Feb 2020 20:21:43 -0500 (EST) Received: from smtpin29.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 4EA6F8248047 for ; Mon, 10 Feb 2020 01:21:43 +0000 (UTC) X-FDA: 76472465286.29.heart95_66489d8c0b209 X-HE-Tag: heart95_66489d8c0b209 X-Filterd-Recvd-Size: 3783 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by imf41.hostedemail.com (Postfix) with ESMTP for ; Mon, 10 Feb 2020 01:21:42 +0000 (UTC) Received: from localhost.localdomain (c-73-231-172-41.hsd1.ca.comcast.net [73.231.172.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 3D3B320715; Mon, 10 Feb 2020 01:21:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1581297701; bh=EMJSH/+fxbjqTriNCLnX9H5eLVo9MEbkL9v2d8yQXu4=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=2hRd4UkwzYaBQqxVNYTCBj2kHb/MDQuC9Z1fGcFA1UNI5fONtunwFEWo1E/c8p53I x8RQ1+fMTkPNgbpt730GyDZZuu2C6FBLpO4aoaYc5CHSArPmGPHQMQnWE06WL0iEgw GwhT9uL9PNhAYZhya/4hkVny40rFtHLljp5o8ANc= Date: Sun, 9 Feb 2020 17:21:40 -0800 From: Andrew Morton To: Brian Geffon Cc: "Michael S . Tsirkin" , Arnd Bergmann , linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-api@vger.kernel.org, Andy Lutomirski , Will Deacon , Andrea Arcangeli , Sonny Rao , Minchan Kim , Joel Fernandes , Yu Zhao , Jesse Barnes , Nathan Chancellor , Florian Weimer , "Kirill A . Shutemov" Subject: Re: [PATCH v4] mm: Add MREMAP_DONTUNMAP to mremap(). Message-Id: <20200209172140.aa60488e10e0408c4f74f11b@linux-foundation.org> In-Reply-To: <20200207201856.46070-1-bgeffon@google.com> References: <20200207201856.46070-1-bgeffon@google.com> X-Mailer: Sylpheed 3.5.1 (GTK+ 2.24.31; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 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 Fri, 7 Feb 2020 12:18:56 -0800 Brian Geffon wrote: > When remapping an anonymous, private mapping, if MREMAP_DONTUNMAP is > set, the source mapping will not be removed. Instead it will be > cleared as if a brand new anonymous, private mapping had been created > atomically as part of the mremap() call. =A0If a userfaultfd was watching > the source, it will continue to watch the new mapping. =A0For a mapping > that is shared or not anonymous, MREMAP_DONTUNMAP will cause the > mremap() call to fail. Because MREMAP_DONTUNMAP always results in moving > a VMA you MUST use the MREMAP_MAYMOVE flag. The final result is two > equally sized VMAs where the destination contains the PTEs of the source. >=20 > We hope to use this in Chrome OS where with userfaultfd we could write > an anonymous mapping to disk without having to STOP the process or worry > about VMA permission changes. >=20 > This feature also has a use case in Android, Lokesh Gidra has said > that "As part of using userfaultfd for GC, We'll have to move the physical > pages of the java heap to a separate location. For this purpose mremap > will be used. Without the MREMAP_DONTUNMAP flag, when I mremap the java > heap, its virtual mapping will be removed as well. Therefore, we'll > require performing mmap immediately after. This is not only time consuming > but also opens a time window where a native thread may call mmap and > reserve the java heap's address range for its own usage. This flag > solves the problem." This seems useful and reasonably mature, so I'll queue it for additional testing and shall await review feedback. Could we please get some self-test code for this feature in tools/testing/selftests/vm? Perhaps in userfaultfd.c?