From patchwork Fri Oct 21 10:11:32 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 13014549 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 12C7CC4332F for ; Fri, 21 Oct 2022 10:12:27 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 730708E0003; Fri, 21 Oct 2022 06:12:27 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6B9148E0001; Fri, 21 Oct 2022 06:12:27 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 55B388E0003; Fri, 21 Oct 2022 06:12:27 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 45FE78E0001 for ; Fri, 21 Oct 2022 06:12:27 -0400 (EDT) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 0C426161288 for ; Fri, 21 Oct 2022 10:12:27 +0000 (UTC) X-FDA: 80044541934.18.22F14DC Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf06.hostedemail.com (Postfix) with ESMTP id B833218002F for ; Fri, 21 Oct 2022 10:12:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1666347146; 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=aghhJvVu2AzGZHMKahkE2d4moWkPJZMDtfGDcWTlxz0=; b=RXGnPtoPr1vFz0Cx6kBRtwUaQlzorMR0HHED9MmSSaFnDWrFKvMgb+LhVQPFpXjYfI5aCN Tw0h4YzyzzZL0IYgumfpzSpcnX/uwFBI+SVcCSXd8HHxwR8LdlDpemIxHezchnxrEXjpuS 1kiy4Ejdy92bOf7CEm+sEOP/jw49ipI= 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-542-X4wZcbWdNd6TO9gjx7dqew-1; Fri, 21 Oct 2022 06:12:23 -0400 X-MC-Unique: X4wZcbWdNd6TO9gjx7dqew-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id C7F8729ABA00; Fri, 21 Oct 2022 10:11:51 +0000 (UTC) Received: from t480s.fritz.box (unknown [10.39.193.99]) by smtp.corp.redhat.com (Postfix) with ESMTP id 69A9F40D298B; Fri, 21 Oct 2022 10:11:42 +0000 (UTC) From: David Hildenbrand To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, David Hildenbrand , Andrew Morton , Shuah Khan , Hugh Dickins , Vlastimil Babka , Peter Xu , Andrea Arcangeli , "Matthew Wilcox (Oracle)" , Jason Gunthorpe , John Hubbard Subject: [PATCH v2 0/9] mm/ksm: break_ksm() cleanups and fixes Date: Fri, 21 Oct 2022 12:11:32 +0200 Message-Id: <20221021101141.84170-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=RXGnPtoP; spf=pass (imf06.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-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1666347146; a=rsa-sha256; cv=none; b=uaY3lLAHWAcBIXIRcxoQiTrsM3xVbDpuZj5FwnxcE4HLZv6vB5lRo9yoFmT9q5HWPPMvMj 4LfdGf/hBEsU+vW9Ln9lR0PMCnhM46BnaeTZouj0o68qqKuE8vTXuaLg/TF9EQLhQ5SHC8 da9dKAH0/xvAssF7YECkiBDBbrgeoo8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1666347146; 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=aghhJvVu2AzGZHMKahkE2d4moWkPJZMDtfGDcWTlxz0=; b=ndMvzVMjcBIadCfZk5ECVQZCsPaEqz56hQxqkXy06efu7lQNrXT4RGJ0oWtjz/tQ9mhnQA YXPGwZGGnmni9LUvW9xPX4kbXINqlRSgUcsy7KeftDpfQJ1eina1rWRUVuYzYN8N2P6iFp KC05ygpytyLzwEHDt5c6WAONU77LZnQ= Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=RXGnPtoP; spf=pass (imf06.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-Stat-Signature: nxbkn1j8h9qz834zh6ag18b5z49zjfnj X-Rspamd-Queue-Id: B833218002F X-Rspamd-Server: rspam02 X-Rspam-User: X-HE-Tag: 1666347146-878707 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 cleans up and fixes break_ksm(). In summary, we no longer use fake write faults to break COW but instead FAULT_FLAG_UNSHARE. Further, we move away from using follow_page() --- that we can hopefully remove completely at one point --- and use new walk_page_range_vma() instead. Fortunately, we can get rid of VM_FAULT_WRITE and FOLL_MIGRATION in common code now. Extend the existing ksm tests by an unmerge benchmark, and a some new unmerge tests. Add a selftest to measure MADV_UNMERGEABLE performance. In my setup (AMD Ryzen 9 3900X), running the KSM selftest to test unmerge performance on 2 GiB (taskset 0x8 ./ksm_tests -D -s 2048), this results in a performance degradation of ~6% -- 7% (old: ~5250 MiB/s, new: ~4900 MiB/s). I don't think we particularly care for now, but it's good to be aware of the implication. Cc: Andrew Morton Cc: Shuah Khan Cc: Hugh Dickins Cc: Vlastimil Babka Cc: Peter Xu Cc: Andrea Arcangeli Cc: "Matthew Wilcox (Oracle)" Cc: Jason Gunthorpe Cc: John Hubbard v1 -> v2: * "selftests/vm: add KSM unmerge tests" -> Add new unmerge tests * "mm/ksm: fix KSM COW breaking with userfaultfd-wp via FAULT_FLAG_UNSHARE" -> Simplify patch description now that we have a selftest * "mm/pagewalk: don't trigger test_walk() in walk_page_vma()" -> Added * "mm/pagewalk: add walk_page_range_vma()" -> Don't call test_walk() * "mm/ksm: convert break_ksm() to use walk_page_range_vma()" -> Simplify and fix missing unlock, fix missing "static" David Hildenbrand (9): selftests/vm: add test to measure MADV_UNMERGEABLE performance mm/ksm: simplify break_ksm() to not rely on VM_FAULT_WRITE mm: remove VM_FAULT_WRITE selftests/vm: add KSM unmerge tests mm/ksm: fix KSM COW breaking with userfaultfd-wp via FAULT_FLAG_UNSHARE mm/pagewalk: don't trigger test_walk() in walk_page_vma() mm/pagewalk: add walk_page_range_vma() mm/ksm: convert break_ksm() to use walk_page_range_vma() mm/gup: remove FOLL_MIGRATION include/linux/mm.h | 1 - include/linux/mm_types.h | 3 - include/linux/pagewalk.h | 5 + mm/gup.c | 55 +--- mm/huge_memory.c | 2 +- mm/ksm.c | 78 +++-- mm/memory.c | 9 +- mm/pagewalk.c | 27 +- tools/testing/selftests/vm/Makefile | 2 + .../selftests/vm/ksm_functional_tests.c | 279 ++++++++++++++++++ tools/testing/selftests/vm/ksm_tests.c | 76 ++++- tools/testing/selftests/vm/run_vmtests.sh | 2 + tools/testing/selftests/vm/vm_util.c | 10 + tools/testing/selftests/vm/vm_util.h | 1 + 14 files changed, 456 insertions(+), 94 deletions(-) create mode 100644 tools/testing/selftests/vm/ksm_functional_tests.c base-commit: 9abf2313adc1ca1b6180c508c25f22f9395cc780