Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp3182778ybv; Sun, 9 Feb 2020 17:23:02 -0800 (PST) X-Google-Smtp-Source: APXvYqyiv1Ryv7m+X2rM1SHm5YCSpexUzMINbUSSJiGHBmsC3MbtgvSRxYsVCXAzaomApU5saDGt X-Received: by 2002:aca:c70b:: with SMTP id x11mr9355978oif.29.1581297782425; Sun, 09 Feb 2020 17:23:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1581297782; cv=none; d=google.com; s=arc-20160816; b=rYUIiEX0ZHuXw7vg92Jvott9S7+DVb9bwNhNaocdtoSFpwRURflx3i7OSu33iuB7Hr O3NyXZn7wkuLKKVLGP94/GYi8glrrYxKMk3o5cWOJM+hI6azENBcEhDkcSCaq5UiAw6N MvrVdQUCuUYgvgzxHTbtZpp5zxrzCFX5maQ3U/sdApSeAuS+UVPBVZ7tOnBocKKtG5SV fopG70P25xTgQOgcPXUXxocLo5hsB6NxkzW+EZZEDGxuzf0KSTIdPn1zpQ0a7CeI0alr FdlAXMKwM7ilmkSit13WBLcMk8PVNAhjDuNP6tsIEgE/8YPnBcdUhPEiDkYCcn198qDk fqGQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=9qE+730LGLrgGt66NQ9fAuV3BhQB77+sB3hIhTU4yxs=; b=N9O2Ja/Bs6Nh8cX4zI8MbOIhxwNIyNbikqAWzf3r1K4E4606/vlmlDAzH4/gQTQZaC aSddTnIt4zVfGr8IIyR0QyG/xRe4zlT2+4M10ID3ViVUC9vwxGegpOWGN8m4lUsgvdbz JLQWGO2mYC5EoeqIU79MmNVuOWJxafhBwL/rt6xlXPWwGb9eTCe4iMe8TJJcDkvEs06P tTuUamWscjfJAEoNURf3rDnzIYBEtz09vI5N9I3eUTZc2A5/vopb4+IUOJILkfa+OnYC uRp2CedE2OtNu+HPQ3j65LrglS5In3vIg/eZYIz4CpGFLIH756FCslEMDz7caB6dq8oi 2Vcw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=2hRd4Ukw; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q19si3775132otm.221.2020.02.09.17.22.50; Sun, 09 Feb 2020 17:23:02 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=2hRd4Ukw; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727369AbgBJBVm (ORCPT + 99 others); Sun, 9 Feb 2020 20:21:42 -0500 Received: from mail.kernel.org ([198.145.29.99]:33276 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727121AbgBJBVm (ORCPT ); Sun, 9 Feb 2020 20:21:42 -0500 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 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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?