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: 13028904 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 D8CBFC433FE for ; Wed, 2 Nov 2022 19:12:20 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 445348E0002; Wed, 2 Nov 2022 15:12:20 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3F57D8E0001; Wed, 2 Nov 2022 15:12:20 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2E4558E0002; Wed, 2 Nov 2022 15:12:20 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 18A628E0001 for ; Wed, 2 Nov 2022 15:12:20 -0400 (EDT) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id E027A406F6 for ; Wed, 2 Nov 2022 19:12:19 +0000 (UTC) X-FDA: 80089447998.08.B455EC9 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf20.hostedemail.com (Postfix) with ESMTP id 949521C0002 for ; Wed, 2 Nov 2022 19:12:18 +0000 (UTC) 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 ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Q4aD3Klz; spf=pass (imf20.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1667416338; a=rsa-sha256; cv=none; b=yVkMVDobfoVxu6lapIiknJobRQAOhC5lGpM+VzeNBF+7CtnA9K41wNbXHTdeNT/lzLiEEO yjKJaqKjKyNvPRfyVbX9nUlQdv8lGVqgpsQMo/6ArPwIXMPvQNXnKs863iMRgcRXd1WJCq YbuKvYk4L+Mr8TSBxE/ObWVhsCHvi64= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1667416338; 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=VER05fjf0NohBVPF35ToVp+oJ6fxGSpDkuoi/f3w0wA=; b=yD4FuqDPKnk/1MkOg/v85YQZ8oK5cqbjeznpirC8WXA07Ye21UoKqM/LyT8SJrX3PKoA1J cUz8qDga11+qAZMHICBns5jvk0acYQ0DZK1x/o/upDf/GRi2Qoj9smNc+abgFzg0P643Ik 5FUmW56Hb+0pAL++IZ+Ea1lbphcEXL4= X-Stat-Signature: 6mktw66cgb5rgb1c16frwn13wpqawa6d X-Rspamd-Queue-Id: 949521C0002 X-Rspam-User: Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Q4aD3Klz; spf=pass (imf20.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@redhat.com; dmarc=pass (policy=none) header.from=redhat.com X-Rspamd-Server: rspam01 X-HE-Tag: 1667416338-658117 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 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(-)