From patchwork Fri Sep 30 14:19:24 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 12995512 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 C1C5AC433F5 for ; Fri, 30 Sep 2022 14:19:52 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CD9F28D0001; Fri, 30 Sep 2022 10:19:51 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C62A56B0073; Fri, 30 Sep 2022 10:19:51 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B02558D0001; Fri, 30 Sep 2022 10:19:51 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 9ADCB6B0072 for ; Fri, 30 Sep 2022 10:19:51 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 6DDB41A044F for ; Fri, 30 Sep 2022 14:19:51 +0000 (UTC) X-FDA: 79968960582.19.63D58EF 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 12750180010 for ; Fri, 30 Sep 2022 14:19:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1664547589; 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=eksXkTT4hqG/3veGcAG1lXhndJ/4JYD7d1ML/eQwqI0=; b=ROt3wsSubHEuqDx+EdV8tVJalSUbNKXaXEMWudfairjOT/Qz7Ki6DlhjlGj4LxWFMQmrD7 GU9b6d4niqsbbKNTqC0IXz68NYOr9gBI+soR34E9jWqN5Wc2wg757GWiWQFyC3f33oSej4 1tkZg20Z6AeptN6bhJ7RdVOXdFfwOyc= 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-264-WVKMxLXMOA-eW7lYh1eiHA-1; Fri, 30 Sep 2022 10:19:46 -0400 X-MC-Unique: WVKMxLXMOA-eW7lYh1eiHA-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 765C3101A528; Fri, 30 Sep 2022 14:19:45 +0000 (UTC) Received: from t480s.redhat.com (unknown [10.39.194.187]) by smtp.corp.redhat.com (Postfix) with ESMTP id E6DCF1121315; Fri, 30 Sep 2022 14:19:32 +0000 (UTC) From: David Hildenbrand To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, linux-kselftest@vger.kernel.org, David Hildenbrand , Andrew Morton , Shuah Khan , Hugh Dickins , Vlastimil Babka , Peter Xu , Andrea Arcangeli , "Matthew Wilcox (Oracle)" , Jason Gunthorpe , John Hubbard Subject: [PATCH v1 0/7] mm/ksm: break_ksm() cleanups and fixes Date: Fri, 30 Sep 2022 16:19:24 +0200 Message-Id: <20220930141931.174362-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=ROt3wsSu; 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=1664547590; a=rsa-sha256; cv=none; b=kd4gmGZaUwrI5EcizdZnLQW4qWQaQkIfeut5AT/5ljv6Tse1Xp22PYw9YRYwEzzAGRJRX2 fsOvkxXl1pK2VVHEekbd1/xaulEojd3Ys9c4/19hWz+ertF1eHlNMVBsKxIck8zOkAOaBH oVj5Qw7RTWFGhejT3X1RD2dXVAqFd1k= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1664547590; 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=eksXkTT4hqG/3veGcAG1lXhndJ/4JYD7d1ML/eQwqI0=; b=y5MFUWpXAdGpKOrUoUJxcYBVy+RWjHSj+QoFgmIWRHzlZ7UiQDpoFIc8BUgqqiUgbmMkkR RBAykzVDq1TNoaK1ND0gp9j1HebIrSwIx4OCwAyehkpmqZqRwMocPylyxFmDGhv/ntJUAT iQdeJXjGKM78IQxMRVBU24bjIOIqC3g= X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 12750180010 X-Rspam-User: Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=ROt3wsSu; 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: dir8xb3nz61s7zh7arguuauz3e3y4rfw X-HE-Tag: 1664547589-459555 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. 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 ~8% -- 9% (old: ~5250 MiB/s, new: ~4800 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 David Hildenbrand (7): 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 mm/ksm: fix KSM COW breaking with userfaultfd-wp via FAULT_FLAG_UNSHARE 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 | 3 + mm/gup.c | 55 ++----------- mm/huge_memory.c | 2 +- mm/ksm.c | 103 +++++++++++++++++++------ mm/memory.c | 9 +-- mm/pagewalk.c | 27 +++++++ tools/testing/selftests/vm/ksm_tests.c | 76 +++++++++++++++++- 9 files changed, 192 insertions(+), 87 deletions(-)