Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp2171120ybv; Mon, 24 Feb 2020 00:16:17 -0800 (PST) X-Google-Smtp-Source: APXvYqxbiIg7y5SiexsMu3LaM+kofxQ5I6XPqHO+xjRLpDik1zJM7xAoo6jWw6n5KjwU4ICiRh0h X-Received: by 2002:a05:6830:1257:: with SMTP id s23mr39213020otp.241.1582532173952; Mon, 24 Feb 2020 00:16:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582532173; cv=none; d=google.com; s=arc-20160816; b=hsMM2sSG4QoJHehghwJUjFBHLulgb7ROSm9wjYvS49FXYT0gKIiY4fEScFCVdIuJnX pq9SQnctWP05Pm+82v08f4dIdb5c1NNrc3u73jABwsXHMmrN8HHhfE/A2eHiH8fUY+qy aJWjJPH9lqmV2hAJDyFpI3iv9O+yQpeTvXFIn0dnrNBGKH553drHv4tya7aCOahUcZ8O PXhvcZwmezSK7fbzQg1zf61GX7XhtxkO6q5lvKavau6ep19L+yEo/GtFSJ77jhXgi5YD sQGrjjRKDKN8hh3FjVA9Kn1QrrL28W3Q7zTm6xh5KmjzAHLJwTKAvPonVX8/dWGg2uBj W0Rg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=9E4atKHNFhMUgRRiEy/HKZbsazKIFq0A6zQaS+Ym2Rs=; b=cFVwvn+V/JN4OFSggUT5u31ddux7qt/q8LKWDPfClef+k9360XhJlsVr1Fk6WUy4FQ j1LL9KF0CCw2VEnjqk8l0jnlq3LGfYgsxrk/DQXNha4/ZOLBRFPmTPDqMRKbdwfzBdrp Ej7QwRg1FstSKFkJBtvhklheYTB/4ESLRNjAwCHtmFvGeun/acOePkdzGjLLxVS3dFTU 4ZppvDU8sMmzo6mctmrghdRFMce7Bxk9MWf3/OJbSxMe0SOgCZpSkr7ZuNu0cce2+8kn 9sHO42mw9REEC+fS/gI106y/r6Sl6PzzqXOg2813ZndIqC79a3F5NXLmjqrEMW1n8ocv Ftwg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@shutemov-name.20150623.gappssmtp.com header.s=20150623 header.b=0aRJ8jlk; 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 z7si5992252oth.181.2020.02.24.00.16.00; Mon, 24 Feb 2020 00:16:13 -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=@shutemov-name.20150623.gappssmtp.com header.s=20150623 header.b=0aRJ8jlk; 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 S1727168AbgBXIPy (ORCPT + 99 others); Mon, 24 Feb 2020 03:15:54 -0500 Received: from mail-lj1-f196.google.com ([209.85.208.196]:45893 "EHLO mail-lj1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726216AbgBXIPx (ORCPT ); Mon, 24 Feb 2020 03:15:53 -0500 Received: by mail-lj1-f196.google.com with SMTP id e18so8991349ljn.12 for ; Mon, 24 Feb 2020 00:15:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=shutemov-name.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:content-transfer-encoding:in-reply-to; bh=9E4atKHNFhMUgRRiEy/HKZbsazKIFq0A6zQaS+Ym2Rs=; b=0aRJ8jlk7K/HKTsns95GBBaEHmGtOdnFbjYj9vIhbo4+tLtlyfufBnVwleKPB1/X98 Pgtv8FVCl9tXtLobT7bdmwNtDdZHepJTvYQCXdV9n1wLvHk+nzSJlzAmbOEH8mlNtA7v 2DGluNg5tOwwERslMq2gB1V/ls4vsq6Q3436qFBbuOHbRKV974b0zOc/iXXNTzaB7r9u 0Y+UxTJda51orCm8P6331EASksnvu6HLENq7I9WhIqKwFNvx+Aj7pHEwlDpT19zJbP6d hq9a+vogQGu+76vpLV9FQ94YnCrRP3OaxqfAj5NR7t5mEhqvtmmMD5AZ5LSwOYCEeT2G hHlg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to; bh=9E4atKHNFhMUgRRiEy/HKZbsazKIFq0A6zQaS+Ym2Rs=; b=d6nbSiQT8mHiQrl/7LyMzYoCYuDsFJAj7OrTktOooIZDkzlwz2DI+RD/t3TXJXs5oW cnJ/3PubEVkZ6ubNWIEHOme47ORyRcQxwHXTvL6VFJp6F6+R+X57wugAlg+UwKYCcb3F T9DY8EEx6D0zbg9Bm/ZibKWPqK+bYK/Y/GGn0WpjmS+CcxePLI95K2Q6/ZXpfswhh3fh yz1//Xdp05a9x9dB/6aACN4oBgylVpbZhqLbqdMcHkZXy9IeDQZ7H3KqZT36f+V6Bmm+ wQuGYiXX2kCrf/qK5kwG18JJYTDxY+a741kmyAbBeHjwJYP91CQaMyJx6YqFFtfny227 y7XA== X-Gm-Message-State: APjAAAWCCBTpWjKao6Z6Sj+RwW5Wr/sSlxVKSSzZkdE3YZVow7QNDGXH CSEdkVhF+vFKedDDW7yQ7tqBzg== X-Received: by 2002:a2e:9b5a:: with SMTP id o26mr29929299ljj.190.1582532151395; Mon, 24 Feb 2020 00:15:51 -0800 (PST) Received: from box.localdomain ([86.57.175.117]) by smtp.gmail.com with ESMTPSA id n189sm3008847lfa.14.2020.02.24.00.15.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Feb 2020 00:15:50 -0800 (PST) Received: by box.localdomain (Postfix, from userid 1000) id DF908100FD9; Mon, 24 Feb 2020 11:16:22 +0300 (+03) Date: Mon, 24 Feb 2020 11:16:22 +0300 From: "Kirill A. Shutemov" 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 , Will Deacon , Andrea Arcangeli , Sonny Rao , Minchan Kim , Joel Fernandes , Yu Zhao , Jesse Barnes , Florian Weimer , mtk.manpages@gmail.com, linux-man@vger.kernel.org, Lokesh Gidra Subject: Re: [PATCH v7 1/2] mm: Add MREMAP_DONTUNMAP to mremap(). Message-ID: <20200224081622.f4oy2pqk6aq6krfp@box> References: <20200221174248.244748-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: <20200221174248.244748-1-bgeffon@google.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Feb 21, 2020 at 09:42:46AM -0800, Brian Geffon wrote: > When remapping an anonymous, private mapping, if MREMAP_DONTUNMAP is > set, the source mapping will not be removed. The remap operation > will be performed as it would have been normally by moving over the > page tables to the new mapping. The old vma will have any locked > flags cleared, have no pagetables, and any userfaultfds that were > watching that range will continue watching it. > > For 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, it's not possible to resize > a VMA while also moving with MREMAP_DONTUNMAP so old_len must always > be equal to the new_len otherwise it will return -EINVAL. > > 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." > > v6 -> v7: > - Don't allow resizing VMA as part of MREMAP_DONTUNMAP. > There is no clear use case at the moment and it can be added > later as it simplifies the implementation for now. > > v5 -> v6: > - Code cleanup suggested by Kirill. > > v4 -> v5: > - Correct commit message to more accurately reflect the behavior. > - Clear VM_LOCKED and VM_LOCKEDONFAULT on the old vma. > ? ? > Signed-off-by: Brian Geffon > Reviewed-by: Minchan Kim > Tested-by: Lokesh Gidra Acked-by: Kirill A. Shutemov -- Kirill A. Shutemov