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=-26.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_AGENT_GIT,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 59CD1C433C1 for ; Tue, 23 Mar 2021 18:25:35 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id BDBFC619BF for ; Tue, 23 Mar 2021 18:25:34 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org BDBFC619BF 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 34D536B0281; Tue, 23 Mar 2021 14:25:34 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2D9316B0282; Tue, 23 Mar 2021 14:25:34 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 151866B0283; Tue, 23 Mar 2021 14:25:34 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0188.hostedemail.com [216.40.44.188]) by kanga.kvack.org (Postfix) with ESMTP id E92636B0281 for ; Tue, 23 Mar 2021 14:25:33 -0400 (EDT) Received: from smtpin23.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 9927B180AD5C5 for ; Tue, 23 Mar 2021 18:25:33 +0000 (UTC) X-FDA: 77951966946.23.590B2F4 Received: from mail-pf1-f201.google.com (mail-pf1-f201.google.com [209.85.210.201]) by imf09.hostedemail.com (Postfix) with ESMTP id 8A4DB600011F for ; Tue, 23 Mar 2021 18:25:32 +0000 (UTC) Received: by mail-pf1-f201.google.com with SMTP id b21so2692426pfo.0 for ; Tue, 23 Mar 2021 11:25:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=ZLSbe0msUPGoJbO5z3RPkVHQZpnKpWfj8nNzVB1WJoM=; b=XGOV7o4gmjGI5erW92akFqPLGTXl3Og7bgkQxChThRnwJKoMamywmF0UDEpRXuBfqF ooMp2qwGHBybBKQO9DF/lsTfAAq97lCH3Dy8JYuSaJi0F4T8flh49k7ISuqYb9njVOSy dcu3j9MJLxRRwbC1vIprWy8ymy82ife+Q6PLDpg0mXRKPn1mkJPeCbKiT7w3RIttVw0m 62Jh+6iT330dfgGTkDU4NjnDVfDA6PQ2QgFFsex6P7T6+ReU/UuaJHDWLT9mT5BiE1Bf pIT4kdQktf6sZ3FAl3V7lL6dLpHmFynMlB/d5yqJta62AabG8lp7nV3w5g2miG9DMM/n LW8w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=ZLSbe0msUPGoJbO5z3RPkVHQZpnKpWfj8nNzVB1WJoM=; b=NcjmX24TdwvnEe/F4VUHkGFqkFzrIAuW7nu6md57N2XnQT1ttijaLKaAfldEgKt5D4 OcdOTHVsV1N54lhzojCjX1V+6tGu31hER6lBZMBc0D9Xh4S0yeNxXWV51VIqDmuPT9pp 61efUML1EBdCX+cO3qDnZP39e2jzVKdVG8qju7lAg87LEfkJBQ8jRDOd7kmwA+3gytUq m0i22szFQP4uQ48DcxuU3qUahZBGPw146dx99OHxVBL88ee0x3bsM1jFBx0BQSGvmwjY R9PHO113ykhjGOH43BFpeOvWzVCWhPzI0DVESs35DlCfNY13BPPQHZLKjWb4zvcOtWwv 2wdA== X-Gm-Message-State: AOAM531bnKKQqa1GQNNWvl5A/mlqKlF3puEwBI+twoNZNEMgX2TYtzfh V+qeEjVn/SQ2XR8lek2ermGU24f9LT4k X-Google-Smtp-Source: ABdhPJyjdDd3Dru52GbT0K29c5H12+F+r8WSy64N5iba6zTVrxc7m+fJNI6FZVL4+GCI04lFEiiP/Hy5bERc X-Received: from bg.sfo.corp.google.com ([2620:15c:8:10:b047:e98d:2134:b4dd]) (user=bgeffon job=sendgmr) by 2002:aa7:80d1:0:b029:21d:d2ce:ad6 with SMTP id a17-20020aa780d10000b029021dd2ce0ad6mr1620778pfn.37.1616523931968; Tue, 23 Mar 2021 11:25:31 -0700 (PDT) Date: Tue, 23 Mar 2021 11:25:17 -0700 In-Reply-To: <20210303175235.3308220-1-bgeffon@google.com> Message-Id: <20210323182520.2712101-1-bgeffon@google.com> Mime-Version: 1.0 References: <20210303175235.3308220-1-bgeffon@google.com> X-Mailer: git-send-email 2.31.0.291.g576ba9dcdaf-goog Subject: [PATCH v5 1/3] mm: Extend MREMAP_DONTUNMAP to non-anonymous mappings From: Brian Geffon To: Andrew Morton Cc: Axel Rasmussen , Lokesh Gidra , Mike Rapoport , Peter Xu , Hugh Dickins , "Michael S . Tsirkin" , Brian Geffon , linux-kernel@vger.kernel.org, linux-mm@kvack.org, Andy Lutomirski , Vlastimil Babka , Andrea Arcangeli , Sonny Rao , Minchan Kim , "Kirill A . Shutemov" , Dmitry Safonov , Michael Kerrisk , Alejandro Colomar Content-Type: text/plain; charset="UTF-8" X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 8A4DB600011F X-Stat-Signature: qrtfrsti3rdoayqwxak1zzxpaw7nfxb8 Received-SPF: none (flex--bgeffon.bounces.google.com>: No applicable sender policy available) receiver=imf09; identity=mailfrom; envelope-from="<3mzJaYAcKCHIRWUVVedWeeWbU.SecbYdkn-ccalQSa.ehW@flex--bgeffon.bounces.google.com>"; helo=mail-pf1-f201.google.com; client-ip=209.85.210.201 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1616523932-888533 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: Currently MREMAP_DONTUNMAP only accepts private anonymous mappings. This restriction was placed initially for simplicity and not because there exists a technical reason to do so. This change will widen the support to include any mappings which are not VM_DONTEXPAND or VM_PFNMAP. The primary use case is to support MREMAP_DONTUNMAP on mappings which may have been created from a memfd. This change will result in mremap(MREMAP_DONTUNMAP) returning -EINVAL if VM_DONTEXPAND or VM_PFNMAP mappings are specified. 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/ Signed-off-by: Brian Geffon Acked-by: Hugh Dickins Tested-by: Lokesh Gidra --- mm/mremap.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mm/mremap.c b/mm/mremap.c index ec8f840399ed..db5b8b28c2dd 100644 --- a/mm/mremap.c +++ b/mm/mremap.c @@ -653,8 +653,8 @@ 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->vm_flags & (VM_DONTEXPAND | VM_PFNMAP))) return ERR_PTR(-EINVAL); if (is_vm_hugetlb_page(vma)) -- 2.31.0.291.g576ba9dcdaf-goog