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=-5.5 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_SANE_1 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 B91A7C433DF for ; Mon, 3 Aug 2020 12:01:58 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 2DCE320678 for ; Mon, 3 Aug 2020 12:01:58 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2DCE320678 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=arm.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 6907C8D00E9; Mon, 3 Aug 2020 08:01:58 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6421E8D0081; Mon, 3 Aug 2020 08:01:58 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 557258D00E9; Mon, 3 Aug 2020 08:01:58 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0109.hostedemail.com [216.40.44.109]) by kanga.kvack.org (Postfix) with ESMTP id 3F2978D0081 for ; Mon, 3 Aug 2020 08:01:58 -0400 (EDT) Received: from smtpin01.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id AA2893627 for ; Mon, 3 Aug 2020 12:01:57 +0000 (UTC) X-FDA: 77109118674.01.head67_4e0ba3926f9d Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin01.hostedemail.com (Postfix) with ESMTP id E18291004C7AA for ; Mon, 3 Aug 2020 12:01:39 +0000 (UTC) X-HE-Tag: head67_4e0ba3926f9d X-Filterd-Recvd-Size: 3991 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by imf30.hostedemail.com (Postfix) with ESMTP for ; Mon, 3 Aug 2020 12:01:39 +0000 (UTC) Received: from gaia (unknown [95.146.230.158]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 663C220678; Mon, 3 Aug 2020 12:01:36 +0000 (UTC) Date: Mon, 3 Aug 2020 13:01:34 +0100 From: Catalin Marinas To: "Kirill A. Shutemov" Cc: Peter Collingbourne , Andrew Morton , Evgenii Stepanov , linux-arm-kernel@lists.infradead.org, linux-mm@kvack.org Subject: Re: [PATCH] mm: introduce reference pages Message-ID: <20200803120134.GD6132@gaia> References: <20200731203241.50427-1-pcc@google.com> <20200803093259.ookknl4y7ee5hun7@box> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200803093259.ookknl4y7ee5hun7@box> User-Agent: Mutt/1.10.1 (2018-07-13) X-Rspamd-Queue-Id: E18291004C7AA 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 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. 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. -- Catalin