From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.8 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2FF22C35679 for ; Mon, 24 Feb 2020 08:15:54 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 02BDD20714 for ; Mon, 24 Feb 2020 08:15:54 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=shutemov-name.20150623.gappssmtp.com header.i=@shutemov-name.20150623.gappssmtp.com header.b="0aRJ8jlk" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726744AbgBXIPx (ORCPT ); Mon, 24 Feb 2020 03:15:53 -0500 Received: from mail-lj1-f194.google.com ([209.85.208.194]:44076 "EHLO mail-lj1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726687AbgBXIPx (ORCPT ); Mon, 24 Feb 2020 03:15:53 -0500 Received: by mail-lj1-f194.google.com with SMTP id q8so8987740ljj.11 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=p87UcuW+ubp9Ik4+R4+uwoc/pUWvkqOCtDUMI5gPZ/UUAxsFqF0PO1zeEBV/Qt+30a CY3CJibaWDeAilCToSckqO4LV3Ra/flfcI49YyLj9QGkEp4QxFXOQ2bcWPPd/dWc4Pak bBsaFmRfjCjSz/ecFFacRiE0TVPdN2MSRZu9bCcePK43hWSpVU3PxrjREnuBQlJVxXRS QDWl8oi5va625G6xJzemQ34iQk2FhG4rSuTbaRh0tG/jDVZrJ7S6HTZM3YE6Y8hdQfvZ s2nW0zJwi8LWUTY+jvddSkclTZznfrWlknHQ1KRMfxQEVDCx2Al0ltXQSXUGwknp2nUq s8+w== X-Gm-Message-State: APjAAAWiyGrBN27QCsHHFZ3MDzBoU+2qs9QOgYCZ4Rr+pDSOJNEzBHjp cWU0anylkJmMnXD+YH49QrvAtQ== X-Google-Smtp-Source: APXvYqzgh1ZGX/532+S4qeKBsp3fOZk0JQWUNLbURDxZxQbr4hjc1+mWNY2lYVuZyvgFoFMOCV92hw== 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-man-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-man@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