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 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4DB37C77B76 for ; Mon, 17 Apr 2023 15:44:35 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8E2BD6B0071; Mon, 17 Apr 2023 11:44:34 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 891F76B0072; Mon, 17 Apr 2023 11:44:34 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 733848E0001; Mon, 17 Apr 2023 11:44:34 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 6538B6B0071 for ; Mon, 17 Apr 2023 11:44:34 -0400 (EDT) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 1C1191A0559 for ; Mon, 17 Apr 2023 15:44:34 +0000 (UTC) X-FDA: 80691305268.13.5750B22 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf16.hostedemail.com (Postfix) with ESMTP id DF7EA180028 for ; Mon, 17 Apr 2023 15:44:31 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="fhY/31NV"; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf16.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1681746272; h=from:from:sender: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:dkim-signature; bh=jSQrN8nbwOEspyIsO/hAq9pJ2iRjnpCaic4dIAFrx0w=; b=cIglOGrnYixt2qaD0GsQ68pGC8X3QwUBWTOIbxnwn487y9IzVVOWWV0FTY/75GyZ/InXGD BIo/6jmLVHWN0yr3MOFpP4VYXRyF8kGZSSfbbrOVEWR+5OITr4d5qyoH1S7lgVNdSDlWbM z62/jscrK+Mf/ilHobG2rqVP7gWQoD8= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="fhY/31NV"; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf16.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1681746272; a=rsa-sha256; cv=none; b=dlxvyxfU+ZTsY1VVwV7i1VFQrI0lzG0uC141gYuOlAmlcAMD0qCCumbxD9uw06aXoiRk1e u7XbV2b3PitU2pbp8IbxEIPijSqs2qfkaMK6a2TM8MetnlWlOVeUlCM5YOP+PE73/R6KAu nPqgtasrqUEVVqQps2D0sVaJxLg37CA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1681746271; 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=jSQrN8nbwOEspyIsO/hAq9pJ2iRjnpCaic4dIAFrx0w=; b=fhY/31NVfdzfOm94bo3lWciKhBOuB6e9Vg8e/ijgJXNMxlQhxrUlQcWeHSrWdewjxlVRZu M/Ba6iY5IeZ7OkCUiFo1d8NcxnxrIGyTBn7grMXwGuEt6BwPnC0RduzVrOTA9PGoM1frZK oN/6akZc1Ml6QvUEuzkfuW0i8ksd1cQ= Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-139-xU8tELasOIG2bZCFN-pCIw-1; Mon, 17 Apr 2023 11:44:28 -0400 X-MC-Unique: xU8tELasOIG2bZCFN-pCIw-1 Received: by mail-wr1-f71.google.com with SMTP id ffacd0b85a97d-2f831f6e175so787370f8f.2 for ; Mon, 17 Apr 2023 08:44:28 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681746267; x=1684338267; h=content-transfer-encoding:in-reply-to:organization:from:references :cc:to:content-language:subject:user-agent:mime-version:date :message-id:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=jSQrN8nbwOEspyIsO/hAq9pJ2iRjnpCaic4dIAFrx0w=; b=ZNRP8XMVBfMLoaNzGzwZ0DkXh2KSZaoCqrm+v09RURS5Fx+j7f0BMjJf/SsYHRUmFj 8aguBQs0yQmCiMrjYh5IHs58jghKFCjsV5/CMUfvtbq/H7HTngwbx7vWnY0b60OQjPHY 2R2UmFZD0zQrjhTxUIeVt7u2EXKnsU7+00OzFA4yHhMKfUNuwo+NKi+++tpNKv3O+dSG IHRahZBPn2qEL9l317orYCLOfj923g500pwREbIQf5PpBTBczbrmzotCZqY0WsGunBYk 6sUfyki/3D3jzMH3DjA6Fqg4FldnEuC3L1ZLZoj5tQ5HaGCgqvDAUfWodlbpn5zF4z1n DGyg== X-Gm-Message-State: AAQBX9cU03fMLQZCdpfdCjQLGMpbSZzeGtMQoiSL+PTvXXv1Qh6vh84b IeoeEMnOVmGEkWL9YUx4d2684Sa+37voRXPyaI7Tq2Ka9UrczLJ88z6pc/UGQQn8CIHzPUsj3Zx g28EQ5nHGsxg= X-Received: by 2002:adf:dc91:0:b0:2d9:81b2:322a with SMTP id r17-20020adfdc91000000b002d981b2322amr5799587wrj.55.1681746267450; Mon, 17 Apr 2023 08:44:27 -0700 (PDT) X-Google-Smtp-Source: AKy350a3mn8EDZgk9H4g/TXv5o8NcU1B69OGxLFZ0ubIrXzsCd9ACcFeE7xhAXzJ+IcR5mX2yteUGg== X-Received: by 2002:adf:dc91:0:b0:2d9:81b2:322a with SMTP id r17-20020adfdc91000000b002d981b2322amr5799570wrj.55.1681746267020; Mon, 17 Apr 2023 08:44:27 -0700 (PDT) Received: from [192.168.3.108] (p5b0c6d51.dip0.t-ipconnect.de. [91.12.109.81]) by smtp.gmail.com with ESMTPSA id n19-20020a1c7213000000b003ee58e8c971sm12209658wmc.14.2023.04.17.08.44.26 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 17 Apr 2023 08:44:26 -0700 (PDT) Message-ID: Date: Mon, 17 Apr 2023 17:44:25 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.9.1 Subject: Re: [RFC v2 PATCH 00/17] variable-order, large folios for anonymous memory To: Ryan Roberts , Andrew Morton , "Matthew Wilcox (Oracle)" , Yu Zhao , "Yin, Fengwei" Cc: linux-mm@kvack.org, linux-arm-kernel@lists.infradead.org References: <20230414130303.2345383-1-ryan.roberts@arm.com> <13969045-4e47-ae5d-73f4-dad40fe631be@arm.com> <568b5b73-f0e9-c385-f628-93e45825fb7b@redhat.com> From: David Hildenbrand Organization: Red Hat In-Reply-To: X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Rspamd-Queue-Id: DF7EA180028 X-Rspamd-Server: rspam09 X-Rspam-User: X-Stat-Signature: cztyegy85ab3uo83nen63se1dfz5sebm X-HE-Tag: 1681746271-96201 X-HE-Meta: U2FsdGVkX18s53HDuckjuL7P1Xa7r5g8XXVO0Ke6W53giZ6rqVsMCyCf+my6RgmL+tAWJu2WCJAMLQiqhpxRsbVRX+N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3DzhgpP+6AStUKoJsWLwNMx0YqIAjLh/pIpYRh+8yYLThKqjnsRSpgEsFGQCwDy8IF636dN5EW7tBfXAKyA7X1ObL3AF7jzVArMOaF9YlWkJfkWFT3hx/ZIpNak2BrvZ82RYxXIlnIHIXB4rCra6YDG3LXqkDjWYlhsZaT5+2HrEwawxwT0kHNugLp9W0dSwQjRhqmTE9r+a6m7oHK2iXo/lKXs4v1Mwf9n2j3giuuRz66aTw9 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: >>> >>>> >>>> Further, we have to be a bit careful regarding replacing ranges that are backed >>>> by different anon pages (for example, due to fork() deciding to copy some >>>> sub-pages of a PTE-mapped folio instead of sharing all sub-pages). >>> >>> I don't understand this statement; do you mean "different anon _folios_"? I am >>> scanning the page table to expand the region that I reuse/copy and as part of >>> that scan, make sure that I only cover a single folio. So I think I conform here >>> - the scan would give up once it gets to the hole. >> >> During fork(), what could happen (temporary detection of pinned page resulting >> in a copy) is something weird like: >> >> PTE 0: subpage0 of anon page #1 (maybe shared) >> PTE 1: subpage1 of anon page #1 (maybe shared >> PTE 2: anon page #2 (exclusive) >> PTE 3: subpage2 of anon page #1 (maybe shared > > Hmm... I can see how this could happen if you mremap PTE2 to PTE3, then mmap > something new in PTE2. But I don't see how it happens at fork. For PTE3, did you > mean subpage _3_? > Yes, fat fingers :) Thanks for paying attention! Above could be optimized by processing all consecutive PTEs at once: meaning, we check if the page maybe pinned only once, and then either copy all PTEs or share all PTEs. It's unlikely to happen in practice, I guess, though. >> >> Of course, any combination of above. >> >> Further, with mremap() we might get completely crazy layouts, randomly mapping >> sub-pages of anon pages, mixed with other sub-pages or base-page folios. >> >> Maybe it's all handled already by your code, just pointing out which kind of >> mess we might get :) > > Yep, this is already handled; the scan to expand the range ensures that all the > PTEs map to the expected contiguous pages in the same folio. Okay, great. > >> >>> >>>> >>>> >>>> So what should be safe is replacing all sub-pages of a folio that are marked >>>> "maybe shared" by a new folio under PT lock. However, I wonder if it's really >>>> worth the complexity. For THP we were happy so far to *not* optimize this, >>>> implying that maybe we shouldn't worry about optimizing the fork() case for now >>>> that heavily. >>> >>> I don't have the exact numbers to hand, but I'm pretty sure I remember enabling >>> large copies was contributing a measurable amount to the performance >>> improvement. (Certainly, the zero-page copy case, is definitely a big >>> contributer). I don't have access to the HW at the moment but can rerun later >>> with and without to double check. >> >> In which test exactly? Some micro-benchmark? > > The kernel compile benchmark that I quoted numbers for in the cover letter. I > have some trace points (not part of the submitted series) that tell me how many > mappings of each order we get for each code path. I'm pretty sure I remember all > of these 4 code paths contributing non-negligible amounts. Interesting! It would be great to see if there is an actual difference after patch #10 was applied without the other COW replacement. -- Thanks, David / dhildenb