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,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,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 E16DDC433DF for ; Mon, 3 Aug 2020 12:03:14 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id A9B1920781 for ; Mon, 3 Aug 2020 12:03:14 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="pJImPtUu" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A9B1920781 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=arm.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References:Message-ID: Subject:To:From:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=31XKpe7mUxZNMD8I6PIJaMAR/4EHSVxmvaQ4dhEGj0s=; b=pJImPtUuAlFq8R9ZzZu/VrSBf ATbIA6ZXstfte6zq6DZ27OwLR6pCRDrUAaLNn2eQ82uioxLOQJCEPNelACyk31mjoRgY2gkJcNppv I+g7G2YKTbTkfXEodf4gOwkeExZqdHMnKBfKG6Hub1b5NYGocNNBfsRejH4g6Bki+2RXwcd3YDscS y58GTrp+BdnsBZleJPL0N8tJeXRJYGbnS2hHJC+zvc37PPNkIRM4XVMOCBha2wNNoKTgXHn/ATNRf 2Nt/1iyMzQY+vRCRFOASr2qnmiCOmqKZD3tHRtYXhu3KnwzcbH/lL4wa4Qxz43FJlNkETictRnBUx WZo2C1DLA==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1k2Z9x-0001bu-UT; Mon, 03 Aug 2020 12:01:41 +0000 Received: from mail.kernel.org ([198.145.29.99]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1k2Z9v-0001bT-1L for linux-arm-kernel@lists.infradead.org; Mon, 03 Aug 2020 12:01:39 +0000 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" 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-Disposition: inline In-Reply-To: <20200803093259.ookknl4y7ee5hun7@box> User-Agent: Mutt/1.10.1 (2018-07-13) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200803_080139_166227_3E3D37EB X-CRM114-Status: GOOD ( 26.49 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-mm@kvack.org, Andrew Morton , Peter Collingbourne , linux-arm-kernel@lists.infradead.org, Evgenii Stepanov Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel