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.1 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,NICE_REPLY_A, 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 2E904C07E95 for ; Tue, 20 Jul 2021 12:27:42 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id D007E6120F for ; Tue, 20 Jul 2021 12:27:41 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D007E6120F Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 8B7116B00A6; Tue, 20 Jul 2021 08:27:42 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 88F938D0003; Tue, 20 Jul 2021 08:27:42 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 72F7F8D0002; Tue, 20 Jul 2021 08:27:42 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0193.hostedemail.com [216.40.44.193]) by kanga.kvack.org (Postfix) with ESMTP id 464C06B00A6 for ; Tue, 20 Jul 2021 08:27:42 -0400 (EDT) Received: from smtpin05.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id B6DDF185072E7 for ; Tue, 20 Jul 2021 12:27:40 +0000 (UTC) X-FDA: 78382892280.05.AAFC48A Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by imf12.hostedemail.com (Postfix) with ESMTP id 438EE10000A5 for ; Tue, 20 Jul 2021 12:27:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1626784059; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=zCBYtfj3pc7JRRIL/IaPTOryD+0TCF0beNILXobu+EQ=; b=B2zokSnujQu9C2kkGsxOBc3vbu4xrOGnrr2OETaD95LQvNNtT9UpQCwGwi17s1IfI9OmWk NJ2NW1bEbbud3cc/+tCPRVBh3XOAx03Nj051wDFwXzoVi9NGCMfbVO2dcDhtjCSlxqFjMV qxMnK04xYWhtPq7tBcq2dHmlIYLbE2k= Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-175-jvVvhi1fOyeYG7TV-_EUrA-1; Tue, 20 Jul 2021 08:27:36 -0400 X-MC-Unique: jvVvhi1fOyeYG7TV-_EUrA-1 Received: by mail-wr1-f72.google.com with SMTP id k3-20020a5d52430000b0290138092aea94so10263234wrc.20 for ; Tue, 20 Jul 2021 05:27:36 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:to:cc:references:from:organization:subject :message-id:date:user-agent:mime-version:in-reply-to :content-language:content-transfer-encoding; bh=zCBYtfj3pc7JRRIL/IaPTOryD+0TCF0beNILXobu+EQ=; b=VB4VRXOvWziUJmeWPujXjuO7ThlBkdSkonqSZvdD6gvaLASwRnLhMcQseYglTv7G0v zGK4IJNF+CjM+4+S8+8SakUzMOhliCebuETaftyKj2NwsMz6LTcVQDa62bCm4n3AAWSk AVAVZrJZADuqqIWrD0qwkoQok3V+9uayZRPlbabcJQfCPjtzNY9GkZa4yHTd+Ory/Ouh 61AhpArqMp8j+4IBh4kSQpMcoigeJYNYCVxYFillffYm0C+T/pnwJWGZr4cFhaFC6Y7+ sckYl6qJctgWDPOuVx2j7K0UI66aYbpPSRDVp/PZQlkVJZSMdJWrmHvzBCDz//S+8c9z xwXw== X-Gm-Message-State: AOAM532FtPX55XJyugsZ2iGAme2A2BRWXyO1GTfI7WlVbWcmaJ/KLAAq 1ztJGTNT8aEj4osng6JQ8HHo5AspUNiVTqYvFjNUnkBASSmIR3ABCbkd8EzRJKHdHFbOcJ6c4bx ICQBgTw74I4Q= X-Received: by 2002:a1c:a58b:: with SMTP id o133mr31337041wme.160.1626784055328; Tue, 20 Jul 2021 05:27:35 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwoPErq8AXD17LnoOsMyHSaZoJQm3mECPqj4xPN3ZZWvqxj4dMX0J82Hf5UO8v+9IfOkYrapg== X-Received: by 2002:a1c:a58b:: with SMTP id o133mr31337020wme.160.1626784055158; Tue, 20 Jul 2021 05:27:35 -0700 (PDT) Received: from ?IPv6:2003:d8:2f0a:7f00:fad7:3bc9:69d:31f? (p200300d82f0a7f00fad73bc9069d031f.dip0.t-ipconnect.de. [2003:d8:2f0a:7f00:fad7:3bc9:69d:31f]) by smtp.gmail.com with ESMTPSA id z13sm24131277wro.79.2021.07.20.05.27.34 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 20 Jul 2021 05:27:34 -0700 (PDT) To: Peter Collingbourne , John Hubbard , Matthew Wilcox , "Kirill A . Shutemov" , Andrew Morton , Catalin Marinas , Evgenii Stepanov Cc: Jann Horn , Linux ARM , linux-mm@kvack.org, kernel test robot , Linux API , linux-doc@vger.kernel.org References: <20210717025757.3945742-1-pcc@google.com> From: David Hildenbrand Organization: Red Hat Subject: Re: [PATCH v5] mm: introduce reference pages Message-ID: <5487f28a-0a12-0789-4014-749de7fb9259@redhat.com> Date: Tue, 20 Jul 2021 14:27:33 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.11.0 MIME-Version: 1.0 In-Reply-To: <20210717025757.3945742-1-pcc@google.com> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=B2zokSnu; spf=none (imf12.hostedemail.com: domain of david@redhat.com has no SPF policy when checking 216.205.24.124) smtp.mailfrom=david@redhat.com; dmarc=pass (policy=none) header.from=redhat.com X-Rspamd-Server: rspam05 X-Stat-Signature: oqc3amm4u4kob9maczth4zzx8eh1fp3k X-Rspamd-Queue-Id: 438EE10000A5 X-HE-Tag: 1626784060-34674 Content-Transfer-Encoding: quoted-printable 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 17.07.21 04:57, Peter Collingbourne wrote: > Introduce a new syscall, refpage_create, which returns a file > descriptor which may be mapped using mmap. Such a mapping is 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 > contents are specified using an argument to refpage_create. 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. I'm wondering, does the target use case really require the COW=20 optimization like we have for the shared zeropage? If we'd avoid having a reference page at all and only store the pattern,=20 we could significantly reduce the memory consumption when using a lot of=20 reference pages, especially per process multiple ones. I'm asking=20 because ... >=20 > 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: >=20 > - 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. ... I assume the first *sane* access to such a page is a write, and not=20 a read. >=20 > - 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= . ... and here as well. Having a first access being a read sound more like an actual BUG (e.g.,=20 detect and mitigate bugs), which doesn't scream for needing a=20 performance improvement or sacrificing a whole (unmovable/unswappable)=20 reference page. So, what would you lose when not populating a real reference pages at=20 all and instead only populating the pattern when populating a fresh=20 page? (and populating a fresh page even on read faults) --=20 Thanks, David / dhildenb