Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp12859ybv; Wed, 19 Feb 2020 15:24:22 -0800 (PST) X-Google-Smtp-Source: APXvYqy7HjxBF9BU5gSzPar0XeqBy3Xe0lZHiotb19hgpLYAGBi4dy/D7n4fIfzNVSggyIyKO4vy X-Received: by 2002:aca:ea43:: with SMTP id i64mr109035oih.30.1582154662555; Wed, 19 Feb 2020 15:24:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582154662; cv=none; d=google.com; s=arc-20160816; b=KZBke+OLe0SShSmTP4jgJMwcFasF2yibZ7JvH3cf4HH1EUERfVEmp9Fqaru1LfKbM/ QRieV2xtQj+8NuKMuqUTyiujlhTPPVp/pM3y3FFhrLetsq5KwVmV+1P7C/X2qmyhTbn1 vFdR95m7/BIvBfLxq6MbGSarVvr7KH4eV4QZQ4HU0XaO3/cdqBl6wBN2unUA1xiC6HSo sbfudLmXUZUvoNszCYRA/plGqMSsdfCr83S2g55/k/n2UvT9Rgq/JiiTj6Abf6VfT2Xz RxgC4yOc3dI4WC+TTePphnP9zilFk4jmoHk7N2bcYxKedz3bn2CIXPEnLosWjvpgNxeY 3fqg== 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=CeoKC7hzC6I62gTM+Mhw7YfGVER9ZVRo7JdMhdNPmSk=; b=xmJIsRMR7l6qqVxzLPEDMcF1rH6pKdWoQ9641kzowqs+MsN053QMHC+++meeWaUdPw o3Jgc708vONtcB/iQWWKuxhuLeFkGQpZ4b/GIlf+T6URyge+FJQC5ldv/jXk6TPE29dI E1Oemp0mJQavueeweZ8hwWC+iMhea8VBD0bmzqx8APHznJfpkRCegbtLXSd6wJMR1kf+ nNP17FAMVHBi9nPBIKZstvu2t7GEsTajqxC4kxasz7hAUthBuvFEIKnYcrgoQh11LS9Y 0wwFZHZnljlIV1f/jSmJ+DTIjPgaRodP/s5SdN8seTEqT5M77wvpMjj/bwrsCSjasT53 xNYg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=Cfn8V0Yc; 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=fail (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 x197si9631155oix.174.2020.02.19.15.24.10; Wed, 19 Feb 2020 15:24:22 -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=fail header.i=@gmail.com header.s=20161025 header.b=Cfn8V0Yc; 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=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726756AbgBSXXN (ORCPT + 99 others); Wed, 19 Feb 2020 18:23:13 -0500 Received: from mail-pf1-f193.google.com ([209.85.210.193]:42666 "EHLO mail-pf1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726613AbgBSXXM (ORCPT ); Wed, 19 Feb 2020 18:23:12 -0500 Received: by mail-pf1-f193.google.com with SMTP id 4so868514pfz.9; Wed, 19 Feb 2020 15:23:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:date:from:to:cc:subject:message-id:references:mime-version :content-disposition:content-transfer-encoding:in-reply-to :user-agent; bh=CeoKC7hzC6I62gTM+Mhw7YfGVER9ZVRo7JdMhdNPmSk=; b=Cfn8V0YciBTXAuwpgcp6rJ1RRQWQ8YESs/k45IyinbQAtZtOm98ulE4qaSflYZd7sl eywfyM46Y1P2n8SwDF1GidyApN6qI1rhNuAY1yOun/lyTDQAOc8V9KBHQNDycGniKiW7 1QHYPhY6hl/Sk8H2xcKnPJZVeHhhbF7evCksyKBIr6HqXEixSVZ3z1yqy7XkNHTVLnoP 9uEdM0hEDV5JdaI/2ncUBOfVa2z30hrBiLFjkfSBt4i4k0DIfGfQbQWzjYdjj5aoMRCF 5mVtod5EaNgCVF9gs2hmSmUyzTnVkTtBN9Vi903hiwAzzycvFDblncNDP14qPOmIeOVh jgrg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:from:to:cc:subject:message-id :references:mime-version:content-disposition :content-transfer-encoding:in-reply-to:user-agent; bh=CeoKC7hzC6I62gTM+Mhw7YfGVER9ZVRo7JdMhdNPmSk=; b=bCf4ND02/X4yjNOQ09cwtSpuBLihtrd31ztz8mg1L8oJEEgQlkt2XKLyqYh3uiWwHH fUdyt/J4DkFwyDlkHASuL7+F1opZGgNMDhNQ05ssVAG7ZfKOc8Qy4w3aCxTHx7IHYjPg CiHL9q/9PVuYknyGCH6XbUKjUkDc8EJZaKUAkz2Ul4A+fmpZI69Itpwi1dg1eQwKT2DF Vle9aAKlw1JS7exkOkeR8323w1EOZn9cUEi0PFDzyfwmu5u+uL8CNwAo2Dp6VytcPkPU bgHT2l6PXuV949Rcf9MQ/4O7jTg/vL5MoEBGKNnXwzO3M/043IPwfKXbQWABuf3KByUm DNDA== X-Gm-Message-State: APjAAAVvvvzPVQNYFJktkOm6/LWaZeJR/8eat9JLVPPrR4ex9fJerrJf 4aYIr+ET5pvxef6azor/rEM= X-Received: by 2002:aa7:820d:: with SMTP id k13mr30135749pfi.10.1582154592037; Wed, 19 Feb 2020 15:23:12 -0800 (PST) Received: from google.com ([2620:15c:211:1:3e01:2939:5992:52da]) by smtp.gmail.com with ESMTPSA id w11sm717199pfn.4.2020.02.19.15.23.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Feb 2020 15:23:11 -0800 (PST) Date: Wed, 19 Feb 2020 15:23:09 -0800 From: Minchan Kim 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 , Joel Fernandes , Yu Zhao , Jesse Barnes , Florian Weimer , "Kirill A . Shutemov" Subject: Re: [PATCH v6 1/2] mm: Add MREMAP_DONTUNMAP to mremap(). Message-ID: <20200219232309.GB148976@google.com> References: <20200218173221.237674-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: <20200218173221.237674-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 On Tue, Feb 18, 2020 at 09:32:20AM -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. 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." > > 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 Description and implemenation looks clean/sane for me. Reviewed-by: Minchan Kim When I review the patch, it seems to be broken with lots of "=20", not sure it's my mail client problem or yours. Anyway, please double check it. Thanks.