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=-23.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_IN_DEF_DKIM_WL autolearn=ham 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 13292C433E0 for ; Wed, 3 Mar 2021 18:14:01 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 96A7164EEB for ; Wed, 3 Mar 2021 18:14:00 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 96A7164EEB Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 350BA6B0006; Wed, 3 Mar 2021 13:14:00 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 300736B0007; Wed, 3 Mar 2021 13:14:00 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1C8496B0008; Wed, 3 Mar 2021 13:14:00 -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 F411F6B0006 for ; Wed, 3 Mar 2021 13:13:59 -0500 (EST) Received: from smtpin23.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id AE3BC1803A173 for ; Wed, 3 Mar 2021 18:13:59 +0000 (UTC) X-FDA: 77879361798.23.C2A744B Received: from mail-ej1-f54.google.com (mail-ej1-f54.google.com [209.85.218.54]) by imf29.hostedemail.com (Postfix) with ESMTP id 4A3F6E8 for ; Wed, 3 Mar 2021 18:13:55 +0000 (UTC) Received: by mail-ej1-f54.google.com with SMTP id ci14so25014142ejc.7 for ; Wed, 03 Mar 2021 10:13:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=bpD0RaMDqf7Z66lLx19Nw3YO9e/Zfu9hvTlC9c/TTdQ=; b=iL/okFPl96aw14inj9n1SVBd7xMdas0YydLx5oBkq3SQKnafTNRLs5xgjyYRvmHWuS Uo64beUXwbhGRdY76A0YHsK0DDES4iiLcIhL5xqZy3JVw8ZljklTwXvGbDEItX6EfQVF J2HVuG/FKL8dIYGziZAHf2UOJP6kKUzlR3MIdJHEsm+vx8FGfWOKYEaUyyBZDpMfMGs7 Od+lPlfJofzeWRckzCJefpNs+vOfxkpeohcJTbBYUH9brN9e9u/1fNW0pXG7DdDE0+WG QV1vSl8eO7fdIXND4WH+p4J1OhG9F0463vIGuVKsjua57VdrI35eyHMnEXZj2AjzFHW3 Q3UQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=bpD0RaMDqf7Z66lLx19Nw3YO9e/Zfu9hvTlC9c/TTdQ=; b=m194lljq6fZAtfKoIKZqyZMGGPT17f5ETrsT8UkitIQrF+zKq1A2LsTG97MSKMyJKS 7c0lMpk9PTGmurhUwegNNpVLGrXOGtud+OZonIXu5LmFq7e20vU18LMMwdTzYg1wIvt5 nNhPM9EzgVu267XKj0pziKBh5l7BvitJ/i54hUroouwxnf5oJdKcf9kTD25weQXLzfIn N1qmdZPlE92sK/sRPWwstVqC3gbFb2xubmp17EXcG7/MraGA1Ceq+d2Yx6CyCC/C7ied 1QuJ+5/LWb6k0W6MQYPNkjMAy9HB2I9sx3/1lavgZsDz2VdT8H+igJHfGGFfEzADeJF2 8c8g== X-Gm-Message-State: AOAM531GGcsywt/S9bQMe68JEyVXrIxT2oHYjM6zH11CZ2+mXePrMU0M bF05WecEr/W8KLlTbK1E3z504cptIa8Ae0k+I0LkUQ== X-Google-Smtp-Source: ABdhPJw5AZ/c6u1egiHd+y/UURI+Oe7j8650RVp7gMoL2chG4BFCZHQYsBIZBv9fGIJcq9rTN/PyNaGgWQeQZ2foMJA= X-Received: by 2002:a17:906:2312:: with SMTP id l18mr95958eja.468.1614795234368; Wed, 03 Mar 2021 10:13:54 -0800 (PST) MIME-Version: 1.0 References: <20210303175235.3308220-1-bgeffon@google.com> In-Reply-To: <20210303175235.3308220-1-bgeffon@google.com> From: Brian Geffon Date: Wed, 3 Mar 2021 10:13:18 -0800 Message-ID: Subject: Re: [PATCH] mm: Allow shmem mappings with MREMAP_DONTUNMAP To: Andrew Morton Cc: Axel Rasmussen , Lokesh Gidra , Mike Rapoport , Peter Xu , Hugh Dickins , "Michael S . Tsirkin" , LKML , linux-mm , Andy Lutomirski , Vlastimil Babka , Andrea Arcangeli , Sonny Rao , Minchan Kim , "Kirill A . Shutemov" Content-Type: text/plain; charset="UTF-8" X-Stat-Signature: hgfz6smptdh96uttqmhw4brsk87g1a55 X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 4A3F6E8 Received-SPF: none (google.com>: No applicable sender policy available) receiver=imf29; identity=mailfrom; envelope-from=""; helo=mail-ej1-f54.google.com; client-ip=209.85.218.54 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1614795235-819722 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: I apologize, this patch didn't include my signed off by, here it is: Signed-off-by: Brian Geffon On Wed, Mar 3, 2021 at 9:53 AM Brian Geffon wrote: > > Currently MREMAP_DONTUNMAP only accepts private anonymous mappings. This change > will widen the support to include shmem mappings. The primary use case > is to support MREMAP_DONTUNMAP on mappings which may have been created from > a memfd. > > Lokesh Gidra who works on the Android JVM, provided an explanation of how such > a feature will improve Android JVM garbage collection: > "Android is developing a new garbage collector (GC), based on userfaultfd. The > garbage collector will use userfaultfd (uffd) on the java heap during compaction. > On accessing any uncompacted page, the application threads will find it missing, > at which point the thread will create the compacted page and then use UFFDIO_COPY > ioctl to get it mapped and then resume execution. Before starting this compaction, > in a stop-the-world pause the heap will be mremap(MREMAP_DONTUNMAP) so that the > java heap is ready to receive UFFD_EVENT_PAGEFAULT events after resuming execution. > > To speedup mremap operations, pagetable movement was optimized by moving PUD entries > instead of PTE entries [1]. It was necessary as mremap of even modest sized memory > ranges also took several milliseconds, and stopping the application for that long > isn't acceptable in response-time sensitive cases. With UFFDIO_CONTINUE feature [2], > it will be even more efficient to implement this GC, particularly the 'non-moveable' > portions of the heap. It will also help in reducing the need to copy (UFFDIO_COPY) > the pages. However, for this to work, the java heap has to be on a 'shared' vma. > Currently MREMAP_DONTUNMAP only supports private anonymous mappings, this patch will > enable using UFFDIO_CONTINUE for the new userfaultfd-based heap compaction." > > [1] https://lore.kernel.org/linux-mm/20201215030730.NC3CU98e4%25akpm@linux-foundation.org/ > [2] https://lore.kernel.org/linux-mm/20210302000133.272579-1-axelrasmussen@google.com/ > --- > mm/mremap.c | 3 +-- > 1 file changed, 1 insertion(+), 2 deletions(-) > > diff --git a/mm/mremap.c b/mm/mremap.c > index ec8f840399ed..6934d199da54 100644 > --- a/mm/mremap.c > +++ b/mm/mremap.c > @@ -653,8 +653,7 @@ static struct vm_area_struct *vma_to_resize(unsigned long addr, > return ERR_PTR(-EINVAL); > } > > - if (flags & MREMAP_DONTUNMAP && (!vma_is_anonymous(vma) || > - vma->vm_flags & VM_SHARED)) > + if (flags & MREMAP_DONTUNMAP && !(vma_is_anonymous(vma) || vma_is_shmem(vma))) > return ERR_PTR(-EINVAL); > > if (is_vm_hugetlb_page(vma)) > -- > 2.31.0.rc0.254.gbdcc3b1a9d-goog >