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.6 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, 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 46219C3567B for ; Mon, 24 Feb 2020 08:15:55 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id E435020658 for ; Mon, 24 Feb 2020 08:15:54 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=shutemov-name.20150623.gappssmtp.com header.i=@shutemov-name.20150623.gappssmtp.com header.b="0aRJ8jlk" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E435020658 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=shutemov.name Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 488C26B0005; Mon, 24 Feb 2020 03:15:54 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 439CB6B0006; Mon, 24 Feb 2020 03:15:54 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 328CA6B0007; Mon, 24 Feb 2020 03:15:54 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0102.hostedemail.com [216.40.44.102]) by kanga.kvack.org (Postfix) with ESMTP id 1B8816B0005 for ; Mon, 24 Feb 2020 03:15:54 -0500 (EST) Received: from smtpin10.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id D3A7B4404 for ; Mon, 24 Feb 2020 08:15:53 +0000 (UTC) X-FDA: 76524312186.10.drop27_1644ea369af19 X-HE-Tag: drop27_1644ea369af19 X-Filterd-Recvd-Size: 5990 Received: from mail-lj1-f193.google.com (mail-lj1-f193.google.com [209.85.208.193]) by imf32.hostedemail.com (Postfix) with ESMTP for ; Mon, 24 Feb 2020 08:15:52 +0000 (UTC) Received: by mail-lj1-f193.google.com with SMTP id h23so9019559ljc.8 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=OytWNUW3EfsYb7pFdkvfBseJxtQHy0QjbPOk3gJCXhWzugh4mORrkWp32DY1wtyrFp L98DonE2lZIkX4yR4Dn1X2POaSMAJxUFyO0e9BP9YeGMjDwM+e24Gevr9437IkNNHIyn 43bFRwt0z03rmOtiJ5BuR+loZDBSPY51yhAXweJErc7AGc2FkInJsz25z73l/F53HMyR ZI2fLSK0UbGrwQbT7zOWXQnlKpEMFyRLpYzAihSXdYb3J/4f/OMCou5pD6YDfmj4lbis Zp+W3yNKDQj2xSGzrU45poS26JD3A703ZbiNy52XCnVDLuiLzQtBe0lW6+QPLJNASl8X +l+Q== X-Gm-Message-State: APjAAAXP9AvnxQobmO1M7DbULFrfdsfViVXHJxWiGhZwFmzNA1DC37Hb HERe8e7Kdgcv3d2fgT5adC1MOQ== 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 In-Reply-To: <20200221174248.244748-1-bgeffon@google.com> Content-Transfer-Encoding: quoted-printable X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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. >=20 > For a mapping that is shared or not anonymous, MREMAP_DONTUNMAP will ca= use > the mremap() call to fail. Because MREMAP_DONTUNMAP always results in m= oving > 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. >=20 > 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 worr= y > about VMA permission changes. >=20 > 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 physi= cal > 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 consum= ing > 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." >=20 > 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. >=20 > v5 -> v6: > - Code cleanup suggested by Kirill. >=20 > v4 -> v5: > - Correct commit message to more accurately reflect the behavior. > - Clear VM_LOCKED and VM_LOCKEDONFAULT on the old vma. > =A0 =A0 > Signed-off-by: Brian Geffon > Reviewed-by: Minchan Kim > Tested-by: Lokesh Gidra Acked-by: Kirill A. Shutemov --=20 Kirill A. Shutemov