From patchwork Wed Nov 2 19:12:03 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 1051 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp92058wru; Wed, 2 Nov 2022 12:18:00 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6Jb3ut4Hh+Jg7dm+Ni1yPSw+brGUNr2Dh24FTKU8JKMpRfjbkolY4MWI0UIjWsIv0WgUO4 X-Received: by 2002:a17:902:cccd:b0:187:733:35d1 with SMTP id z13-20020a170902cccd00b00187073335d1mr24476645ple.26.1667416680312; Wed, 02 Nov 2022 12:18:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667416680; cv=none; d=google.com; s=arc-20160816; b=cyN1RsMhYTAXMvlCa04MT00NJMCh6+0t1MTOHQZVrgYjzsxuQS4i1Eh0Si5YSQFdvo cXEI4Lfsa4DEMFCbt+sbXLicAmakajMPUYjFxwtP0SYhnifn9MPcp4GqyD1SrEu/PQOa gNFA00XyyPZJyDru53a4zZYJaHUrZ/hZLAxbrruS/AmYjQC8FaP0aqaQ6n3Qh+CRlGQu jtddGcx55uc5Cw3gYkabbx11xruwn957lTa2f4vNEpeEhdF/qEM2bQ46RVuF/L7y1GZi EK0hb7lCSfmMDMW2wA6Voszpf52s29EFIpD+y7RYMAeJC72bvEwhL0vahCUtwNMF6TjD FHgQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=VER05fjf0NohBVPF35ToVp+oJ6fxGSpDkuoi/f3w0wA=; b=yXiJccVUQpiG/z4R5aaz/KvJYIOgsUI7pL4Z8z86ReUtIxbjclfMelrCpW1CYeYGFc Cdm9KbDXehqltpbWRf+YymzzVy7RcXnK92NtVxOCixCLk2I3lJJCnql0biKZrWuEQVoV Fg61PJ9AEuU7/BWTYdyc8x8flEe/1QcdL5FxG6AsSyVJAuqs/7Vu+PBI46dphsgoIb1M 5Ydm2xs99lVyUsqmS6v4hK+dNIg/T77H+31jb7fsi6lhF/cnai/D/ecJUkXvGI3H0Omm s4KS7V4TGUNKHqt+ax6iCM1HpHT94QVRN55fQqbBEU8rN5rzF080+9fjMDa1f0otNAv7 BYUw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Q4aD3Klz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l71-20020a63914a000000b0046eecbac482si17448833pge.415.2022.11.02.12.17.43; Wed, 02 Nov 2022 12:18:00 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Q4aD3Klz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230222AbiKBTNS (ORCPT + 99 others); Wed, 2 Nov 2022 15:13:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40966 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230106AbiKBTNP (ORCPT ); Wed, 2 Nov 2022 15:13:15 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B7C02C4D for ; Wed, 2 Nov 2022 12:12:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1667416338; 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=VER05fjf0NohBVPF35ToVp+oJ6fxGSpDkuoi/f3w0wA=; b=Q4aD3Klz4ZH5OqxOe4E0/PW+bFNMUnzfMW6yiMtFSUwJfwI9ypjil0mV5hiJy87YIYtm5s BWzq1YrKQSXWLV/qvJy0ikx8l8+mE7PZzq2WpYMg4/K2qQidBs1U0suOWklgFQ3U3615xR h5infTqPCo2PqsGEl1xfGkqn0eT2c6E= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-515-fHaa8UhcO6au98qUUN7h_g-1; Wed, 02 Nov 2022 15:12:15 -0400 X-MC-Unique: fHaa8UhcO6au98qUUN7h_g-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id F2C84185A79C; Wed, 2 Nov 2022 19:12:14 +0000 (UTC) Received: from t480s.fritz.box (unknown [10.39.192.243]) by smtp.corp.redhat.com (Postfix) with ESMTP id C136449BB60; Wed, 2 Nov 2022 19:12:10 +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 v1 0/6] mm/autonuma: replace savedwrite infrastructure Date: Wed, 2 Nov 2022 20:12:03 +0100 Message-Id: <20221102191209.289237-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.9 X-Spam-Status: No, score=-3.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1748413112892920532?= X-GMAIL-MSGID: =?utf-8?q?1748413112892920532?= 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 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 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 (5): mm/mprotect: minor can_change_pte_writable() cleanups mm/huge_memory: try avoiding write faults when changing PMD protection 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 | 2 + include/linux/pgtable.h | 24 ------ mm/debug_vm_pgtable.c | 32 -------- mm/huge_memory.c | 66 ++++++++++++---- mm/ksm.c | 9 +-- mm/memory.c | 19 ++++- mm/mprotect.c | 33 ++++---- tools/testing/selftests/vm/anon_cow.c | 49 +++++++++++- 10 files changed, 145 insertions(+), 171 deletions(-)