From patchwork Tue Nov 8 17:46:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 13036632 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 7068FC4321E for ; Tue, 8 Nov 2022 17:47:12 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CAE226B0075; Tue, 8 Nov 2022 12:47:11 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id C2A318E0002; Tue, 8 Nov 2022 12:47:11 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AA33A6B0075; Tue, 8 Nov 2022 12:47:11 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 9BE026B0073 for ; Tue, 8 Nov 2022 12:47:11 -0500 (EST) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 387C2121088 for ; Tue, 8 Nov 2022 17:47:11 +0000 (UTC) X-FDA: 80111006262.05.BE0625A Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf30.hostedemail.com (Postfix) with ESMTP id E085480006 for ; Tue, 8 Nov 2022 17:47:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1667929629; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=ZHIUqQjgTcrrLQjjH6jvIopGCgDdzoOnD2NdhMSGVIY=; b=SeYjbLWhl4Fht2IEqEVmolUsNr3QYP6yp4e4ddm/mnixqu50++uO84pSd7DU+QUcBksz6k pwoXK7abIjBpevXsEKG0xmRiTANB6E8QIjwIdbr5t/I2xjkvZyI/dmnjStu52X2aum5uSA gYWkdku0qZctP8THJd4y3UjXYMiXsNU= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-392-mHodWVn8NdeSar_igPbYsg-1; Tue, 08 Nov 2022 12:46:58 -0500 X-MC-Unique: mHodWVn8NdeSar_igPbYsg-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 5F17B382F649; Tue, 8 Nov 2022 17:46:57 +0000 (UTC) Received: from t480s.fritz.box (unknown [10.39.194.18]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8E65DC15BB5; Tue, 8 Nov 2022 17:46:53 +0000 (UTC) From: David Hildenbrand To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, linuxppc-dev@lists.ozlabs.org, David Hildenbrand , Linus Torvalds , Andrew Morton , Mel Gorman , Dave Chinner , Nadav Amit , Peter Xu , Andrea Arcangeli , Hugh Dickins , Vlastimil Babka , Michael Ellerman , Nicholas Piggin , Mike Rapoport , Anshuman Khandual Subject: [PATCH v2 0/7] mm/autonuma: replace savedwrite infrastructure Date: Tue, 8 Nov 2022 18:46:45 +0100 Message-Id: <20221108174652.198904-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1667929629; a=rsa-sha256; cv=none; b=p4xqbIIKx+eIZWbnIYM9hta/KLT9yvuip0JQ/auEnYnCS/UdL2zKLsqSGEYOtmc0YWzrmQ nwOQ1sgN6/9SDOzMeGvI4jvd7OgsvAWWsbtzKPmfC19ZsX457LQTatbluYot2dIxTNZTho ZBd3Ajm/nBIoP1yiR49uPK/42/loHwo= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=SeYjbLWh; spf=pass (imf30.hostedemail.com: domain of david@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=david@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1667929629; 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-transfer-encoding:content-transfer-encoding: in-reply-to:references:dkim-signature; bh=ZHIUqQjgTcrrLQjjH6jvIopGCgDdzoOnD2NdhMSGVIY=; b=DatXd9UtAjnL3C/fWlz40Iu1wxsEFq+tTPbz/DW1JBmEmfpdJr3wlmqbsmlIAj0RdRD0pX KAaJbqNl2CyR8fQCnHlQTCy07t4qsvnLAtjLziQWj7+O/axJ+s3wJQcJZapvqaZCPtMjAI IWncx5ycrvTFI/8LItrMPBGCPjGAowk= Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=SeYjbLWh; spf=pass (imf30.hostedemail.com: domain of david@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=david@redhat.com; dmarc=pass (policy=none) header.from=redhat.com X-Rspamd-Server: rspam12 X-Rspam-User: X-Stat-Signature: m85qxcoa5osjwq9yjb5kd5kf34c8rnec X-Rspamd-Queue-Id: E085480006 X-HE-Tag: 1667929629-512017 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: This series is based on mm-unstable. As discussed in my talk at LPC, we can reuse the same mechanism for deciding whether to map a pte writable when upgrading permissions via mprotect() -- e.g., PROT_READ -> PROT_READ|PROT_WRITE -- to replace the savedwrite infrastructure used for NUMA hinting faults (e.g., PROT_NONE -> PROT_READ|PROT_WRITE). Instead of maintaining previous write permissions for a pte/pmd, we re-determine if the pte/pmd can be writable. The big benefit is that we have a common logic for deciding whether we can map a pte/pmd writable on protection changes. For private mappings, there should be no difference -- from what I understand, that is what autonuma benchmarks care about. I ran autonumabench for v1 on a system with 2 NUMA nodes, 96 GiB each via: perf stat --null --repeat 10 The numa01 benchmark is quite noisy in my environment and I failed to reduce the noise so far. numa01: mm-unstable: 146.88 +- 6.54 seconds time elapsed ( +- 4.45% ) mm-unstable++: 147.45 +- 13.39 seconds time elapsed ( +- 9.08% ) numa02: mm-unstable: 16.0300 +- 0.0624 seconds time elapsed ( +- 0.39% ) mm-unstable++: 16.1281 +- 0.0945 seconds time elapsed ( +- 0.59% ) It is worth noting that for shared writable mappings that require writenotify, we will only avoid write faults if the pte/pmd is dirty (inherited from the older mprotect logic). If we ever care about optimizing that further, we'd need a different mechanism to identify whether the FS still needs to get notified on the next write access. In any case, such an optimiztion will then not be autonuma-specific, but mprotect() permission upgrades would similarly benefit from it. Cc: Linus Torvalds Cc: Andrew Morton Cc: Mel Gorman Cc: Dave Chinner Cc: Nadav Amit Cc: Peter Xu Cc: Andrea Arcangeli Cc: Hugh Dickins Cc: Vlastimil Babka Cc: Michael Ellerman Cc: Nicholas Piggin Cc: Mike Rapoport Cc: Anshuman Khandual v1 -> v2: * "mm/mprotect: factor out check whether manual PTE write upgrades are required" -> Added * "mm/autonuma: use can_change_(pte|pmd)_writable() to replace savedwrite" -> Simplify and don't opimize for failed migration -> Update patch description RFC -> v1: * "mm/mprotect: allow clean exclusive anon pages to be writable" -> Move comment change to patch #2 * "mm/mprotect: minor can_change_pte_writable() cleanups" -> Adjust comments * "mm/huge_memory: try avoiding write faults when changing PMD protection" -> Fix wrong check * "selftests/vm: anon_cow: add mprotect() optimiation tests" -> Add basic tests for the mprotect() optimization David Hildenbrand (6): mm/mprotect: minor can_change_pte_writable() cleanups mm/huge_memory: try avoiding write faults when changing PMD protection mm/mprotect: factor out check whether manual PTE write upgrades are required mm/autonuma: use can_change_(pte|pmd)_writable() to replace savedwrite mm: remove unused savedwrite infrastructure selftests/vm: anon_cow: add mprotect() optimization tests Nadav Amit (1): mm/mprotect: allow clean exclusive anon pages to be writable arch/powerpc/include/asm/book3s/64/pgtable.h | 80 +------------------- arch/powerpc/kvm/book3s_hv_rm_mmu.c | 2 +- include/linux/mm.h | 18 ++++- include/linux/pgtable.h | 24 ------ mm/debug_vm_pgtable.c | 32 -------- mm/huge_memory.c | 64 ++++++++++++---- mm/ksm.c | 9 +-- mm/memory.c | 16 +++- mm/mprotect.c | 50 ++++++------ tools/testing/selftests/vm/anon_cow.c | 49 +++++++++++- 10 files changed, 158 insertions(+), 186 deletions(-)