Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp535183ybl; Tue, 28 Jan 2020 07:28:55 -0800 (PST) X-Google-Smtp-Source: APXvYqyVSH5ZgNBHh0/iDTzWJiGdEF3B80XbtnnofRRlVRIMRxkecjgoL48ReCnyA3MsnbzvvlXr X-Received: by 2002:aca:a997:: with SMTP id s145mr3233973oie.71.1580225335083; Tue, 28 Jan 2020 07:28:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1580225335; cv=none; d=google.com; s=arc-20160816; b=QXKeXKB92SROjR4JrVss8J92t6GtTT29sbWzUzW+TWgIl/nKGubLSkeok+Vf41RDWy TaSoNRjFJANvgmO4AZzcysd2FiHz9MlJVNy7M/9sq7nMOPnmK43tZpCrXgF9x1fhl+O2 D+k7HJXBVdkum5fvIs13lsoGmYwAoUV4jnaWE9t0WWanBVHJZY8fc1mFIqrMcO21VcCC GiqLIF37ExAHHrmtRSSNAmJjrF0FRh8tNTc7Dm1fj2itaadWE4LZu67GNT1Y8SjiRz0i Hv6eVLn3bGJ3Rq9+8BlnjLOb1FWB5bMv1G+WcrJ8y6kcmgV5O6cm6xQgIcRrJJMLj1Xc M5/w== 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=64umP3o7La+LXjhX/kROrHHv+rTWDXxoUrgxZS+iJYQ=; b=m8BTQSmYFMdLRPBDAXAeq7+6agoZK3shvtwNximyqEXFllm8IV8bBzMrYh9aF9Fgo+ q6R5QYpPdmjqM2oRJy2fFaFDwa/hb+Y589J1CBnZVqw24IuxiqrSzNoI3MI/ig4F4H2p KSdyBnzl44cM0A6/6rjSs/J1rk4RMshkhGVt0t7rREzx7gPTf0OLNHDccSr4LgWjTN+G eFVJ0n5Xl2+aVw5/RearW7hnYeWBW+xfDz5YG8gMD7gzN0GZikex5VFL/n0oG7x1WznL rAfmIkxNJGlPxukKMQ9mDx2UFcBdqzt3AbNZjvfU9ymrVy8ZA2T4ywGsI+6WGPJWgJIu FXiQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=OHv6vMz+; 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 w24si4730693oic.260.2020.01.28.07.28.43; Tue, 28 Jan 2020 07:28:55 -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=OHv6vMz+; 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 S1726548AbgA1P0t (ORCPT + 99 others); Tue, 28 Jan 2020 10:26:49 -0500 Received: from mail.kernel.org ([198.145.29.99]:34362 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726141AbgA1P0t (ORCPT ); Tue, 28 Jan 2020 10:26:49 -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 B4087207FD; Tue, 28 Jan 2020 15:26:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1580225208; bh=dj+J/+PtbTGjVK/oHj202CDxS9GCGCuwxkfK9zJalX8=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=OHv6vMz+yD5U8x6jcim8pbmwQnkrN4uZpX7DzpHQsMWV60vUZW+5b6hLCopr+YzlV m58G8lzyFU8S/neJVArtj7ee0qKQp3rxEnBv8B767ntyNTp9k+KoplSvW6qGdVbECq lE7l0SpLW/1wIyvzaUMpqwNlQSy8Oc2/OTqCeXKc= Date: Tue, 28 Jan 2020 15:26:42 +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: <20200128152641.GA29776@willie-the-truck> References: <20200123014627.71720-1-bgeffon@google.com> <20200127053056.213679-1-bgeffon@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20200127053056.213679-1-bgeffon@google.com> 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 Hi Brian, 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? 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? ? > Signed-off-by: Brian Geffon > --- > include/uapi/linux/mman.h | 5 +++-- > mm/mremap.c | 38 +++++++++++++++++++++++++++++++------- > 2 files changed, 34 insertions(+), 9 deletions(-) Could you also a include a patch to update the mremap man page, please? https://www.kernel.org/doc/man-pages/patches.html Cheers, Will