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=-9.3 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,MAILING_LIST_MULTI, NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 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 4E33AC433E0 for ; Tue, 23 Mar 2021 19:04:39 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id D3EA061574 for ; Tue, 23 Mar 2021 19:04:38 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D3EA061574 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 62ED08D0016; Tue, 23 Mar 2021 15:04:38 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 5B6F86B0283; Tue, 23 Mar 2021 15:04:38 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3E3A28D0016; Tue, 23 Mar 2021 15:04:38 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0214.hostedemail.com [216.40.44.214]) by kanga.kvack.org (Postfix) with ESMTP id 1E31F6B0173 for ; Tue, 23 Mar 2021 15:04:38 -0400 (EDT) Received: from smtpin17.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id D872C8249980 for ; Tue, 23 Mar 2021 19:04:37 +0000 (UTC) X-FDA: 77952065394.17.03F9A1F Received: from mail-wm1-f46.google.com (mail-wm1-f46.google.com [209.85.128.46]) by imf01.hostedemail.com (Postfix) with ESMTP id EC4D95001526 for ; Tue, 23 Mar 2021 19:04:36 +0000 (UTC) Received: by mail-wm1-f46.google.com with SMTP id j4-20020a05600c4104b029010c62bc1e20so11459318wmi.3 for ; Tue, 23 Mar 2021 12:04:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=RbFpbq45kpggLm6Psx0owbwRXsYpSfJN7JgeqcP2Mu4=; b=UZKiqbd5+BBdc0NgTu+GUe/wC4bea0GtvB29FWI7Spj3k/dxu8QOO3dVhiIyeJMucF vQC8feWgvEa9X3J7SMPxAwT6My2YOBhRcWaJ0yiBDG71JxnDD8Hh53nv/GPFX/N/VLv7 jORi2aeofPCaEkYJT5x4PdkHS3eG0kBUdwfk5RqPLfGQpfiCQiZa2Uq12ZERjfBBu3Ty vThjutiV4MKI4efT85EHcLjz4bik64raZ063NTEN9k6h+7RnPiZukFM19+mXRKd7jNeL /ouBOF8Jqyovbt2ep53M/NOUW90gwGnJSod16lrWiQl16cT319HWHdSPDoCueq4hLT5P hb1Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=RbFpbq45kpggLm6Psx0owbwRXsYpSfJN7JgeqcP2Mu4=; b=ALx+YDvbEl/JJXuEVCc+1PlDk62YYyt31RE7BLecR3uPEeaB6oTD9fjssaxtKEQx89 Jr1ALRx5rMQVcnw3y2eYy9aJDetqebFBIKITud70Z2H4agKT1QHhUxMPo6vUdpRd13t5 Nu3nD0cssqk5tUo36Yf3vcxuksSaGHjvSDWDitsgZynQMRnY2SG65eWsfscfI45cvOu/ yjzOnoRDE3i+GgP2IzHHIcOy5mVgb3AUMmG+dsB9VeVdjZYKkQMPF8I3P1a6P/Lf+k8C b6rQxLkTWq4/299KS1GmLfa/MrwogCzcs801FL0r0Dyhs3pnxMiHRyaQXqFLvFb5HlIR fN7A== X-Gm-Message-State: AOAM532PhiRFlEzXnErEJtLlJvy0M9FZjwXI1rVpIDlY71R6I+L8YmJO DIQJ3W32nwblvMWrMg8nsb8= X-Google-Smtp-Source: ABdhPJxwi/mZg8TzTxJs26AM44HgpG1L47R7B6VUOtQ3vitadRNoKha3GN9uDw+lEk5ZSiOX+t9e+w== X-Received: by 2002:a1c:23c2:: with SMTP id j185mr4663665wmj.54.1616526276276; Tue, 23 Mar 2021 12:04:36 -0700 (PDT) Received: from ?IPv6:2a02:8084:e84:2480:228:f8ff:fe6f:83a8? ([2a02:8084:e84:2480:228:f8ff:fe6f:83a8]) by smtp.gmail.com with ESMTPSA id l9sm3194098wmq.2.2021.03.23.12.04.35 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 23 Mar 2021 12:04:35 -0700 (PDT) Subject: Re: [PATCH v5 1/3] mm: Extend MREMAP_DONTUNMAP to non-anonymous mappings To: Brian Geffon , Andrew Morton Cc: Axel Rasmussen , Lokesh Gidra , Mike Rapoport , Peter Xu , Hugh Dickins , "Michael S . Tsirkin" , 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 References: <20210303175235.3308220-1-bgeffon@google.com> <20210323182520.2712101-1-bgeffon@google.com> From: Dmitry Safonov <0x7f454c46@gmail.com> Message-ID: Date: Tue, 23 Mar 2021 19:04:34 +0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.8.1 MIME-Version: 1.0 In-Reply-To: <20210323182520.2712101-1-bgeffon@google.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: EC4D95001526 X-Stat-Signature: z1kte9up8o6btn316kqpkafb4dsojte4 Received-SPF: none (gmail.com>: No applicable sender policy available) receiver=imf01; identity=mailfrom; envelope-from="<0x7f454c46@gmail.com>"; helo=mail-wm1-f46.google.com; client-ip=209.85.128.46 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1616526276-836318 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 3/23/21 6:25 PM, Brian Geffon wrote: > 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. Pretty interesting idea :-) > > 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 Reviewed-by: Dmitry Safonov <0x7f454c46@gmail.com> Thanks, Dmitry