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 288F4C433E6 for ; Wed, 3 Mar 2021 19:11:00 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 8A20D64EED for ; Wed, 3 Mar 2021 19:10:59 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8A20D64EED 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 074C26B0005; Wed, 3 Mar 2021 14:10:59 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 030456B0006; Wed, 3 Mar 2021 14:10:58 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DB91C6B0007; Wed, 3 Mar 2021 14:10:58 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0084.hostedemail.com [216.40.44.84]) by kanga.kvack.org (Postfix) with ESMTP id BAE756B0005 for ; Wed, 3 Mar 2021 14:10:58 -0500 (EST) Received: from smtpin01.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 6D1A56D64 for ; Wed, 3 Mar 2021 19:10:58 +0000 (UTC) X-FDA: 77879505396.01.7D84551 Received: from mail-wr1-f52.google.com (mail-wr1-f52.google.com [209.85.221.52]) by imf17.hostedemail.com (Postfix) with ESMTP id ACCF340F8C04 for ; Wed, 3 Mar 2021 19:10:54 +0000 (UTC) Received: by mail-wr1-f52.google.com with SMTP id l12so24914644wry.2 for ; Wed, 03 Mar 2021 11:10:54 -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=emB76DYl8PmmcmITFjkIlLA/KjBQhOxxjznaA2F8hE4=; b=bt17grf5jTznLnyyJrRe5nSPyIJhqqI/eIkQkXHehzw1+by6/BaEkgNQZV5Wq1kReo yTZyzGYsWknSfPNib1svKGo6bL+jUsd+if0RrYvFKHkp5A0QOYIWx4qvvMFsz78XT8jx H8Zs1EyzxkLlTebyu0KkBvHHyC/zLoi/OXaWpkLUL0//E4AJOdtcEvUowmMolZhegrqt o2ZAduUYxBM/gFwzFDva01tjU2BHnDTcouoJfGR4JJ/Bcs5cshwl3tBK1MyIdozXAD8g 1ERdwVMfXHlKsifQ1DcmnjHNunYIRgiPEGc9yywQkwhxEz9SUI+EXG3Q8udjPaLXg7Au Cppg== 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=emB76DYl8PmmcmITFjkIlLA/KjBQhOxxjznaA2F8hE4=; b=C4JKyz6aUGvFpW1OlUgTlrIpFS5TjsCt5c07kb7C9vW9FizsjUm8WPy4cPtf79g0I4 IiHscE75xQaSHkqXqcrNwEmcJ2dmLe+mTtF1K+2P2eHJ/CqUwYCBOamT0OioovRKDI2X 4FMlnwnRETJDICZsCKHBGlfJyXBtzlcNg7swjhj1XOtNBwkIU3l7Ie2dw/6D+HwMri/+ OVqNL5h4mypw8HQf57Ozrpyzg5RxqlN3wKyXI0owjLXf72ZAYsylZLcQrndFwUaaM27s iCmLuf1tmyBZ3fJanAZIa48ZEOmancGBJXLd313GJr9GscR0577uGeoDCNtI/WL1btM6 ew/g== X-Gm-Message-State: AOAM531YjRJzUNRAY2013+tlBVkGuae1pFFPklUt4TlszaNhQkn0ZZTi NlQ1DS2iPb4ofEOcvrtFt4f4Og2nfXGVannTbB4s+C0xVsM= X-Google-Smtp-Source: ABdhPJxLmIMCD5thMPhEljfIP3oZXUuagP+sz6u1sBLxpvrEkxxiOzwKhxFS1Rlm6E3fXMFuSM+0j9eA0/LHaG2Fc+g= X-Received: by 2002:a17:906:3603:: with SMTP id q3mr257584ejb.201.1614798284132; Wed, 03 Mar 2021 11:04:44 -0800 (PST) MIME-Version: 1.0 References: <20210303175235.3308220-1-bgeffon@google.com> In-Reply-To: From: Lokesh Gidra Date: Wed, 3 Mar 2021 11:04:32 -0800 Message-ID: Subject: Re: [PATCH] mm: Allow shmem mappings with MREMAP_DONTUNMAP To: Brian Geffon Cc: Andrew Morton , Axel Rasmussen , 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-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: ACCF340F8C04 X-Stat-Signature: npp5so91a1dpq4rccyz9wirhchoocrwq Received-SPF: none (google.com>: No applicable sender policy available) receiver=imf17; identity=mailfrom; envelope-from=""; helo=mail-wr1-f52.google.com; client-ip=209.85.221.52 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1614798654-275451 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 Wed, Mar 3, 2021 at 10:13 AM Brian Geffon wrote: > > 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/ Thanks for the patch, Brian. I've tested mremap(MREMAP_DONTUNMAP) on a memfd memory range. Tested-by: Lokesh Gidra > > --- > > 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 > >