Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp1574415ybl; Thu, 30 Jan 2020 02:14:36 -0800 (PST) X-Google-Smtp-Source: APXvYqzgyLerCkSa0CTDn+l0FBz0Y2gAIXyt/Ar2Uj8h6WE94szVfzsDDhU3j6MWxUNBKyyqOSgv X-Received: by 2002:a05:6830:15d2:: with SMTP id j18mr3013476otr.187.1580379276029; Thu, 30 Jan 2020 02:14:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1580379276; cv=none; d=google.com; s=arc-20160816; b=Ssg5m9NegvOSremwbIrTpkj70g3+CPY0J0zgbcry/D0q250rwkFTVrAPrVb8Uy2b8e gnGbI96cmSNPYuZsWJuhTEZ2ge47zTko24aFI6nKYPHYNND6AI+KT6qW3hVtlhh1itjO fRrbROKM8ZOpT+sLY2X/CXr83FzFRgQRkMqAk+ObcyC2eB4huDKoKyZ0AOeHqVwmPaLv 7qu6Tr4OisEYU3I10TVTRlMCxz1zU5GlsH97gUsuCivuhhx7Lk0UQU23Cbl+jh0qtHXa o4OSYthS5JgHUNMe6TStMC1hCOW1hJsY8/o2jok58d/eb1NmgPxuiGJpAbjPLVa96cbG dxog== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-transfer-encoding:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=o9RlSKsvO5FNf6Pjy66wM0L2qv8RqiBMQd0h7PKa6vQ=; b=orH7lWUerUzKvsvXcwfQAkU9Ur2kfqOsIoVOR2L4dSsX7eeV9ekynCBsh17LkEVQRg PlWNGAVfg4o+tZwRF2fJcQ2VdAQRM4JBrLIb43VNlW2jCAQUlRcS7XpF/NKUjV1XNKtX T0RbZfMn0EvckDzpEz7UCpPwbcSkB2kbeKqy9Dj9URhS6huHkC0W9Zw52LGCqypNTGS7 cwTXMwVbaIrsJ6I6XMkiCeRJfjaBYjzPg1Jd+O5789HVdoaIKgF1buJodiSu7wvdv1nm bYdOsFKq4o+L7xzaGPCCzhwUiayjDqbG3JNnO7LgwibwZUEqln8FN7kl13uoJf3oskyE XM9w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=UGpunH0f; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a3si2624145oib.168.2020.01.30.02.14.24; Thu, 30 Jan 2020 02:14:36 -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=UGpunH0f; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727154AbgA3KMO (ORCPT + 99 others); Thu, 30 Jan 2020 05:12:14 -0500 Received: from mail.kernel.org ([198.145.29.99]:52546 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726873AbgA3KMO (ORCPT ); Thu, 30 Jan 2020 05:12:14 -0500 Received: from willie-the-truck (236.31.169.217.in-addr.arpa [217.169.31.236]) (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 B091B206D5; Thu, 30 Jan 2020 10:12:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1580379133; bh=P9h3/Bn/eSdl3ZWgp0VveGQkiQrefKB9XBTyKjeDoOU=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=UGpunH0fs3194+uliHqPn4YZ2qcxfggN5Fnih63Cr4LzINmDuXU5FKyXBHbI2h58v XKQqlp5J9a2fMtK23kis7NWl7LHYOrVRsZG8MDuDaQAxM1CdiUR7H2sVdsEK2VtnYM jTIWHwaFeUXyLoM2qZHNgBruUVDtYHwedNjFfpSo= Date: Thu, 30 Jan 2020 10:12:07 +0000 From: Will Deacon To: Brian Geffon Cc: Andrew Morton , "Michael S . Tsirkin" , Arnd Bergmann , linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-api@vger.kernel.org, Andy Lutomirski , Andrea Arcangeli , Sonny Rao , Minchan Kim , Joel Fernandes , Yu Zhao , Jesse Barnes , Nathan Chancellor Subject: Re: [PATCH v3] mm: Add MREMAP_DONTUNMAP to mremap(). Message-ID: <20200130101207.GB1532@willie-the-truck> References: <20200123014627.71720-1-bgeffon@google.com> <20200127053056.213679-1-bgeffon@google.com> <20200128152641.GA29776@willie-the-truck> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20200128152641.GA29776@willie-the-truck> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jan 28, 2020 at 03:26:41PM +0000, Will Deacon wrote: > On Sun, Jan 26, 2020 at 09:30:56PM -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. ?If a userfaultfd was watching > > the source, it will continue to watch the new mapping. ?For a mapping > > that is shared or not anonymous, MREMAP_DONTUNMAP will cause the > > mremap() call to fail. MREMAP_DONTUNMAP requires that MREMAP_FIXED is > > also used. The final result is two equally sized VMAs where the > > destination contains the PTEs of the source. > > ? ? > > 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. > > ? ? > > 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." > > Hmm, this sounds like you're dealing with a multi-threaded environment, > yet your change only supports private mappings. How does that work? Sorry, this was badly worded. I was trying to understand how the GC is implememented, and whether everything was part of the same process or if things like memfds or something else were being used to share memory. Having spoken to Brian off-list, it's all one process... > It's also worrying because, with two private mappings of the same anonymous > memory live simultaneously, you run the risk of hitting D-cache aliasing > issues on some architectures and losing coherency between them as a result > (even in a single-threaded scenario). Is userspace just supposed to deal > with this, or should we be enforcing SHMLBA alignment? ... and this was me completely misreading the patch. The old mapping is still torn down, but then replaced with a new private mapping rather than being unmapped. However, looks like there are some issues handling shared mappings with this patch (and possibly mlock()?), so I'll wait for a new spin. Will