Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp7472844imu; Thu, 31 Jan 2019 10:39:13 -0800 (PST) X-Google-Smtp-Source: ALg8bN5cFoopo+jZkSUE//1B1cWYpi9hEN80i9nElImo2MlKhRqpW2xHcF6IDAfMklWsM8Am5eRC X-Received: by 2002:a17:902:9887:: with SMTP id s7mr34995316plp.199.1548959953672; Thu, 31 Jan 2019 10:39:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548959953; cv=none; d=google.com; s=arc-20160816; b=uzUsYu0dLRuhEX0P8TbqiEBMCOLn2uxcs3DsaA9D5oe5IxwbX4AbBwwoTRiqxNCb/Q po8QkmfG1u9M/oUJNGh5/Y6FT9K9aDEfCvyCRCI7oRuN7siZe0XZoFkE8zp5Vf4SX4Y3 tCIgOPrj6z4HlTBbMY72uoxe48uVv1cfBvfMSiEr2JzzhOdn3xOjBk4k9+sXeZ4xmsVS phBoJTX45se0dlEsKdNG68lfHepKBoXSK/HKIV121KDEbbKtPNc1lqw2AfqdWmdk7QUN MyF4bDL/6qEyVRet1LgKN8edfBih4TYqta9an5g6SQQKmX/52mgmkE5ipQY3kN3MYHvr M5GA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=KPWKir/sq0x95e20bcJglMpomUWDLhIE9o/JOfqXUGI=; b=nLXh8Tplxb2Ly1oOgic6ZVFTWPWD/9ICUZvlWUBp6xBwXHPIHKwAx5HwgWcdlzY5lQ rk8VP25Jd36ts3i4yoKEuGmDhC2XHZoAEQqWnXh40P6yEX4moZsIQm0GWKCzyvNh7blS h5Piw4TEWazx23G97oxRQ7xhLobVN7fQ3Zbkf6vmKpH3VS5cfvL/ryB8RDcx7WiRp15W jmB0zyl2Dbw0fH9d57zGjPnYvDRESmgDhG1yyaplCG4vz3ty3/N1t6/au6xv441Xa9NM 0/FvvSerY9iiLVmetnooKb49JaIzXtvTFfNwOF4ZxRYSftY+DVmsmfi4+qG9bmj4AykB 4c1Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y10si4313983pgp.348.2019.01.31.10.38.58; Thu, 31 Jan 2019 10:39:13 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727837AbfAaShQ (ORCPT + 99 others); Thu, 31 Jan 2019 13:37:16 -0500 Received: from mx1.redhat.com ([209.132.183.28]:55440 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725777AbfAaShQ (ORCPT ); Thu, 31 Jan 2019 13:37:16 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8EEC4CCB60; Thu, 31 Jan 2019 18:37:15 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.20.6.236]) by smtp.corp.redhat.com (Postfix) with ESMTP id BBCCD19492; Thu, 31 Jan 2019 18:37:13 +0000 (UTC) From: jglisse@redhat.com To: linux-mm@kvack.org Cc: linux-kernel@vger.kernel.org, =?UTF-8?q?J=C3=A9r=C3=B4me=20Glisse?= , Andrea Arcangeli , Peter Xu , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Andrew Morton , Matthew Wilcox , Paolo Bonzini , =?UTF-8?q?Radim=20Kr=C4=8Dm=C3=A1=C5=99?= , Michal Hocko , kvm@vger.kernel.org Subject: [RFC PATCH 0/4] Restore change_pte optimization to its former glory Date: Thu, 31 Jan 2019 13:37:02 -0500 Message-Id: <20190131183706.20980-1-jglisse@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Thu, 31 Jan 2019 18:37:15 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Jérôme Glisse This patchset is on top of my patchset to add context information to mmu notifier [1] you can find a branch with everything [2]. I have not tested it but i wanted to get the discussion started. I believe it is correct but i am not sure what kind of kvm test i can run to exercise this. The idea is that since kvm will invalidate the secondary MMUs within invalidate_range callback then the change_pte() optimization is lost. With this patchset everytime core mm is using set_pte_at_notify() and thus change_pte() get calls then we can ignore the invalidate_range callback altogether and only rely on change_pte callback. Note that this is only valid when either going from a read and write pte to a read only pte with same pfn, or from a read only pte to a read and write pte with different pfn. The other side of the story is that the primary mmu pte is clear with ptep_clear_flush_notify before the call to change_pte. Also with the mmu notifier context information [1] you can further optimize other cases like mprotect or write protect when forking. You can use the new context information to infer that the invalidation is for read only update of the primary mmu and update the secondary mmu accordingly instead of clearing it and forcing fault even for read access. I do not know if that is an optimization that would bear any fruit for kvm. It does help for device driver. You can also optimize the soft dirty update. Cheers, Jérôme [1] https://lore.kernel.org/linux-fsdevel/20190123222315.1122-1-jglisse@redhat.com/T/#m69e8f589240e18acbf196a1c8aa1d6fc97bd3565 [2] https://cgit.freedesktop.org/~glisse/linux/log/?h=kvm-restore-change_pte Cc: Andrea Arcangeli Cc: Peter Xu Cc: Peter Zijlstra Cc: Ingo Molnar Cc: Arnaldo Carvalho de Melo Cc: Alexander Shishkin Cc: Jiri Olsa Cc: Namhyung Kim Cc: Andrew Morton Cc: Matthew Wilcox Cc: Paolo Bonzini Cc: Radim Krčmář Cc: Michal Hocko Cc: kvm@vger.kernel.org Jérôme Glisse (4): uprobes: use set_pte_at() not set_pte_at_notify() mm/mmu_notifier: use unsigned for event field in range struct mm/mmu_notifier: set MMU_NOTIFIER_USE_CHANGE_PTE flag where appropriate kvm/mmu_notifier: re-enable the change_pte() optimization. include/linux/mmu_notifier.h | 21 +++++++++++++++++++-- kernel/events/uprobes.c | 3 +-- mm/ksm.c | 6 ++++-- mm/memory.c | 3 ++- virt/kvm/kvm_main.c | 16 ++++++++++++++++ 5 files changed, 42 insertions(+), 7 deletions(-) -- 2.17.1