Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp2920547ybl; Sun, 26 Jan 2020 14:09:46 -0800 (PST) X-Google-Smtp-Source: APXvYqx4T+0DaPdwDO4i0Jg3WuXSGA0LJKu0o3UNWWUJnVIM34dhePdVFNW2Upug2yh0aIVzCAa2 X-Received: by 2002:aca:3354:: with SMTP id z81mr5941055oiz.129.1580076586528; Sun, 26 Jan 2020 14:09:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1580076586; cv=none; d=google.com; s=arc-20160816; b=F+oTtQE4Hk19UjZEPmDlRvOSTbRNhfrMmHZ0wjTvbC1iX7tCPeIyDBaDiKx0+b9z3b 6xfUdjOlfcefrkW3vtYEz0C9gA5RRBfkuW66AX/THT0z//yTPWftbLIeqAwTvsi422Jw ZEnvWznRTKWTmqbaF0n9VK4mGeAtlbMga33inHLGxMQ3ADs0ify7xxV+zFcBHFyYtczt RQaSy41fbdfRkrN+2vYLSOPvVqIomIT+8SqnRsPhkRgrE04adF1uOw9oYK4cK5u9dKLJ 83fZQ0uhoB43H7QZjlcxcOZyz5CUDyfxo4SmPNeLjSmqo2e/79O3/jxvQZe3TlH2NZWj I96w== 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-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=bIjpqXTvBSR6objHCm0IzTR/hQ3TPrKkme7EJy7SinQ=; b=iRdcwtYIWnoDmaoZ3ZxBO2Ch25zquyGv8LwRqwB2aLTN3Ve9WbfYlEPsmqTIqX7rUk 1h+2qldPvsRQS5OlbjxeeAgIg64fseOrrZtz0WBFuWAtoYQiAPD0zuC3iAu9hKo0TayC r+jZn69hzL8P9kFfQHPbiDnjahMis784pgTzw2UpNtGTYBd957mkOVGoYuCqDGYfexYg YhJAEYoa5mAJWxFACfGaTPd9u043iVB1oXgcCroT9di0zjUqdWarNqx9afyyychRGmx/ U09gJNKSnc2oW3qU3hD1FMy2WsA/rRO/vIbc5uWymfsxHP3Nkpo42Z+cDDFesuVRLyvG kNdg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@shutemov-name.20150623.gappssmtp.com header.s=20150623 header.b=vd7wN7va; 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 10si2567031ois.76.2020.01.26.14.09.09; Sun, 26 Jan 2020 14:09:46 -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=vd7wN7va; 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 S1727487AbgAZWGs (ORCPT + 99 others); Sun, 26 Jan 2020 17:06:48 -0500 Received: from mail-lf1-f65.google.com ([209.85.167.65]:36095 "EHLO mail-lf1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726438AbgAZWGr (ORCPT ); Sun, 26 Jan 2020 17:06:47 -0500 Received: by mail-lf1-f65.google.com with SMTP id f24so4911677lfh.3 for ; Sun, 26 Jan 2020 14:06:46 -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:in-reply-to; bh=bIjpqXTvBSR6objHCm0IzTR/hQ3TPrKkme7EJy7SinQ=; b=vd7wN7vaZJfsftvGGeIdYEwGAd4ISoPUjH4z/airo4c26P52SSKuDuY4RS0FCTd3jk KGJuozw/CRaeDQ8RBJpp+oWUfc2eDnUbiMFkXFrBXbs5ojteYSba/dGN1A/1KxD1aEzs kwJfOZOp2vtTZ1sI5xIYQJlNEmUxEGX6JXv4Xurm4zHypuUTquU8mvoaBx/394qcnVUj RzzbO3aM80carMr02Nqzb6oeiw1Uu4+S5GWqP8R0NK6qJX9IlkQ0sONrEey8uSOh9ukr a/5FajX0UzsqgSnvcxbbzkeC25sud1T/2dcmQXy0fbovFOy/mw4wm/rc/xExEVA6kt85 nmPg== 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:in-reply-to; bh=bIjpqXTvBSR6objHCm0IzTR/hQ3TPrKkme7EJy7SinQ=; b=PiNO+8of4s0sa8zxGPJYbCOPS79pteVw420dqZWKfIh5xiJMYfRCwsxsgeBZTGQ3Lk 5PGCaItof5UFo88FJGRwKtDx32Fveu9gOgGPXQbwH0p613sPIRDHu6IEIhEwAAcdwDZZ mQjrRFLJWnOuLHJgSorqIux/v1UlQSn+wnw/4uWpH282xeORr4VsSe6vdx4cZD/NoUls gabv1z6nO2T/JplKCTpcFBSDscwhI9b2aT0eObK0dJYbildds51Ix0sWzBD1FWB0XhCE ZcP/o55JSSvapKZepJGg5UL2yOeYM3B2ZpPJxTWZsVOrXnivS+yznpnKvuIz6hyOYaDA Dwww== X-Gm-Message-State: APjAAAXaIWA/yw5dEQjgb7GSz2YUYGAbtUC8uYdLSk1VxQ9WNKNhOJ0Q 6zfITu5P+miN0ZvaeUVMBuFbug== X-Received: by 2002:a19:4855:: with SMTP id v82mr6199593lfa.197.1580076405722; Sun, 26 Jan 2020 14:06:45 -0800 (PST) Received: from box.localdomain ([86.57.175.117]) by smtp.gmail.com with ESMTPSA id w20sm7129060ljo.33.2020.01.26.14.06.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 26 Jan 2020 14:06:44 -0800 (PST) Received: by box.localdomain (Postfix, from userid 1000) id 0082B100301; Mon, 27 Jan 2020 01:06:50 +0300 (+03) Date: Mon, 27 Jan 2020 01:06:50 +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 , Andrea Arcangeli , Sonny Rao , Minchan Kim , Joel Fernandes , Yu Zhao , Jesse Barnes Subject: Re: [PATCH v2] mm: Add MREMAP_DONTUNMAP to mremap(). Message-ID: <20200126220650.i4lwljpvohpgvsi2@box> References: <20200123014627.71720-1-bgeffon@google.com> <20200124190625.257659-1-bgeffon@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200124190625.257659-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, Jan 24, 2020 at 11:06:25AM -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 implies that MREMAP_FIXED is > also used. Implies? From code it looks like it requires MREMAP_FIXED. And MREMAP_FIXED requires MREMAP_MAYMOVE. That's strange flag chaining. I don't really see need in such dependencies. It maybe indeed implied, not requied. > The final result is two equally sized VMAs where the > destination contains the PTEs of the source. Could you clarify rmap situation here? How the rmap hierarchy will look like before and after the operation. Can the new VMA merge with the old one? Sounds fishy to me. > 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." -- Kirill A. Shutemov