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=-11.6 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=no 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 10CE1C433DF for ; Tue, 4 Aug 2020 00:50:46 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id EE170206D7 for ; Tue, 4 Aug 2020 00:50:45 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="l1azzeTL" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org EE170206D7 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 54ADD8D011C; Mon, 3 Aug 2020 20:50:45 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4FD7F8D0081; Mon, 3 Aug 2020 20:50:45 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3EB0B8D011C; Mon, 3 Aug 2020 20:50:45 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0117.hostedemail.com [216.40.44.117]) by kanga.kvack.org (Postfix) with ESMTP id 254458D0081 for ; Mon, 3 Aug 2020 20:50:45 -0400 (EDT) Received: from smtpin05.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id B305A3626 for ; Tue, 4 Aug 2020 00:50:44 +0000 (UTC) X-FDA: 77111056008.05.plant58_4a0aeb926fa2 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin05.hostedemail.com (Postfix) with ESMTP id 8B7661801E33F for ; Tue, 4 Aug 2020 00:50:44 +0000 (UTC) X-HE-Tag: plant58_4a0aeb926fa2 X-Filterd-Recvd-Size: 6197 Received: from mail-vk1-f195.google.com (mail-vk1-f195.google.com [209.85.221.195]) by imf18.hostedemail.com (Postfix) with ESMTP for ; Tue, 4 Aug 2020 00:50:44 +0000 (UTC) Received: by mail-vk1-f195.google.com with SMTP id b6so7342541vkb.6 for ; Mon, 03 Aug 2020 17:50:44 -0700 (PDT) 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=UYpP71Hmt67QOqtnBJa/efiXPfrM+3mz/tgNPKF1hyo=; b=l1azzeTLjYLscwfbj8yyrqdSUYJ1SQEJJOpdo3+lDiIUYR62At0MDut7OEacobnupt shchHh7AN9Q2axIpagR+zDjOe2E0mxe/8Lea7ja928lUPvQCj3SVlPBmji+W8bicLmXj 8g2wsPxRkQ4P4ixjKmzkHNkhn9MTWMMyzHRSv6mcW7pqJVoD+UhAyCW9iYFyEuwoI1Lb EWd7q2t6ebmOAFmQMN4N0GX/WxlRi5La4DoEaMbj4JSKBjRuZyBs+EWR7EU1lIIpR42k kmow+AfdmtJ653QAb7+udUnNg2HJ0uDln7Yxr6biZVlmuhEElfSuBwbX6Ex/2205Jn2o EEdw== 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=UYpP71Hmt67QOqtnBJa/efiXPfrM+3mz/tgNPKF1hyo=; b=NLDhSEW6q9Q38Fr6JEOb4Ve9+H4y2bjyoaNiD/BglD7PiTniGhR+RQdBRf7mjZbkjG q74nHRelL3OCbBxDvDC8/XNRweI797BqvaJj1GyIKrGSI3Xk67d4pTPF1fbwweEp0ksh +p6/uuUB3l2twRhI6rH3HdvkENA4LbF0hXU2iO4kZP98irMdUO6f6yxcVUXQKfnYytmV hyvtjWgc4aNMImrEmCpzPzHfwjTX+usvZuQWNZPTscbe1yY3oCHvXQzF/HJSWxQYHN5q FPS7RghmfEDgnvMUKsBLMJzmSI9+HSM9gzZFhd7kIS8jiEt4UYbyy6HeNyLxK6wXiXO0 hpYg== X-Gm-Message-State: AOAM532zb+rXAk1WBnwsZRjqzQsSM+tnljLbotKIDUV2rsuhy6qFhRwf qN1uirgR5BQkEmq0tJ/MMHJlxsVjorYMMP5dCvtXXw== X-Google-Smtp-Source: ABdhPJzUAjod9MOU1bkuHv6WaJJAW5h7jnIdEgZKg6FjWr2A3cjm2EelOb+zYnRTzddekT2HqL7Rd+ZS/EWJKB76QE8= X-Received: by 2002:a1f:5986:: with SMTP id n128mr13362943vkb.93.1596502243117; Mon, 03 Aug 2020 17:50:43 -0700 (PDT) MIME-Version: 1.0 References: <20200731203241.50427-1-pcc@google.com> <20200803093259.ookknl4y7ee5hun7@box> <20200803120134.GD6132@gaia> In-Reply-To: <20200803120134.GD6132@gaia> From: Peter Collingbourne Date: Mon, 3 Aug 2020 17:50:32 -0700 Message-ID: Subject: Re: [PATCH] mm: introduce reference pages To: Catalin Marinas Cc: "Kirill A. Shutemov" , Andrew Morton , Evgenii Stepanov , Linux ARM , linux-mm@kvack.org Content-Type: text/plain; charset="UTF-8" X-Rspamd-Queue-Id: 8B7661801E33F X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam03 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 Mon, Aug 3, 2020 at 5:01 AM Catalin Marinas wrote: > > On Mon, Aug 03, 2020 at 12:32:59PM +0300, Kirill A. Shutemov wrote: > > On Fri, Jul 31, 2020 at 01:32:41PM -0700, Peter Collingbourne wrote: > > > Introduce a new mmap flag, MAP_REFPAGE, that creates a mapping similar > > > to an anonymous mapping, but instead of clean pages being backed by the > > > zero page, they are instead backed by a so-called reference page, whose > > > address is specified using the offset argument to mmap. Loads from > > > the mapping will load directly from the reference page, and initial > > > stores to the mapping will copy-on-write from the reference page. > > > > > > Reference pages are useful in circumstances where anonymous mappings > > > combined with manual stores to memory would impose undesirable costs, > > > either in terms of performance or RSS. Use cases are focused on heap > > > allocators and include: > > > > > > - Pattern initialization for the heap. This is where malloc(3) gives > > > you memory whose contents are filled with a non-zero pattern > > > byte, in order to help detect and mitigate bugs involving use > > > of uninitialized memory. Typically this is implemented by having > > > the allocator memset the allocation with the pattern byte before > > > returning it to the user, but for large allocations this can result > > > in a significant increase in RSS, especially for allocations that > > > are used sparsely. Even for dense allocations there is a needless > > > impact to startup performance when it may be better to amortize it > > > throughout the program. By creating allocations using a reference > > > page filled with the pattern byte, we can avoid these costs. > > > > > > - Pre-tagged heap memory. Memory tagging [1] is an upcoming ARMv8.5 > > > feature which allows for memory to be tagged in order to detect > > > certain kinds of memory errors with low overhead. In order to set > > > up an allocation to allow memory errors to be detected, the entire > > > allocation needs to have the same tag. The issue here is similar to > > > pattern initialization in the sense that large tagged allocations > > > will be expensive if the tagging is done up front. The idea is that > > > the allocator would create reference pages with each of the possible > > > memory tags, and use those reference pages for the large allocations. > > > > Looks like it's wrong layer to implement the functionality. Just have a > > special fd that would return the same page for all vm_ops->fault and map > > the fd with normal mmap(MAP_PRIVATE, fd). It will get you what you want > > without touching core-mm. Thanks, I like this idea. I will try to implement it. > I think this would work even for the arm64 MTE (though I haven't tried): > use memfd_create() to get such file descriptor, mmap() it as MAP_SHARED > to populate the initial pattern, mmap() it as MAP_PRIVATE for any > subsequent mapping that needs to be copied-on-write. That would require a separate mmap() (i.e. separate VMA) for each page, no? That sounds like it could be expensive both in terms of VMAs and the number of mmap syscalls required (i.e. N/PAGE_SIZE). You could decrease these costs by increasing the size of the memfd files to more than a page, but that would also increase the amount of memory required for the reference pages. Peter