Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp3399836pxk; Mon, 5 Oct 2020 08:44:15 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyO+5IYLTMLy+YLMEVVis1TOeeyWwtUlma293mElucFdbBLPqlg+g7wgUXlejBfA8NZSmDq X-Received: by 2002:a17:907:20e7:: with SMTP id rh7mr295930ejb.515.1601912654977; Mon, 05 Oct 2020 08:44:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1601912654; cv=none; d=google.com; s=arc-20160816; b=IvaoTVsBv+Y0uMs/6KnjtbxNKyxPaq2KgOYpYFKPQmASJNGCy4ZIK4mT+O5YlUY2Lq WvNLCjKd2jmv/ktnU5MuP5UW56f1BQV3YxRhsfkOz6Jci1cCyKDW1VF53MjwFbZLp1KX 6Jk/htL/YUZAuHyfG86r7g7Bz0fv3SqXXzXicS9A5rTUa9mQQnQz3TKM+/6kTp1sxd6x //HouGiBsWGVTUPOTF4gGYLn/+6k8e95Sjt/6xkRfOTFfnnCG3/KYxnI5YABg2zj13xS yzeM8ZkCpam2UfRTceLLHpYtY8fds9NnyuoAwMKSZiszhr+co0tU7+OcNSFrDN6ixZco jjXg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:to:content-transfer-encoding:cc:from:subject :mime-version:message-id:date:sender:dkim-signature; bh=roRRmpnOQfqBgouvFdnsiNMWHoFG1to3sn9HMTXsuVQ=; b=TS+AvDgZiLlDixnsAY+AzQPHCiq/vZwKGnQSsE/YqHnOVDNYmQmBrLTg3AsQNq4Un6 oOmi73YQspwVZGMcFVzupk/ZoCGmyAhBrOewI4Ph83r8K2NZzuxS1L4EqteAUeJQKy/C RuHxgla2RiLFIThyt4xV5Ne2UT9cn8agtbSUUdn6kaPyW4Ah0FPdPnpuJ8C9eyGBXrnL YiXJbluJJa+Q2O0Zav+lVBXGo6HKaCNDR1v7A75gL216/DdWHfLY5ZXDe6UlG+KlqVIu cSUnbgHSVceIxycrTKdVj6uhh/HiHOxFKGGW2p0AB0vb2pV8D6T5m/uTDsIpRWR4H+JK S61A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b="ISCc2/Q+"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id t15si8336978ejx.450.2020.10.05.08.43.51; Mon, 05 Oct 2020 08:44:14 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b="ISCc2/Q+"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728759AbgJEPk3 (ORCPT + 99 others); Mon, 5 Oct 2020 11:40:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50508 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728754AbgJEPkX (ORCPT ); Mon, 5 Oct 2020 11:40:23 -0400 Received: from mail-qk1-x749.google.com (mail-qk1-x749.google.com [IPv6:2607:f8b0:4864:20::749]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 03597C0613A7 for ; Mon, 5 Oct 2020 08:40:22 -0700 (PDT) Received: by mail-qk1-x749.google.com with SMTP id y17so6951290qky.0 for ; Mon, 05 Oct 2020 08:40:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:message-id:mime-version:subject:from:cc :content-transfer-encoding; bh=roRRmpnOQfqBgouvFdnsiNMWHoFG1to3sn9HMTXsuVQ=; b=ISCc2/Q+3RqQHnmu/kT5NtbJpNZ7wC8V64UlYxth0OYKIluZdxX7K1qgddenEuyZkZ Wc8U6+kyTzsPPNyB+D9cDFo3M4s3lBLOfMlJJxYiV4Ltu9WPKkx8LeCnf3CGMyu8pe24 QIGKxtMSedAWRhEGXxS0Czaq2oiy71ShEVY7Ny+oG2nkFMpoiSWHyoAzbffu/G8vt1qm eXe1gnFdmR2B0WLUvrfX5yF+c/CGo5F5OCtcPRN88pnNiyl4nNnJeDRa7KIyr/t/xLbn r+McOy57d3h71tj/brwaYwm0tHmetXO0th1kYsTBVqPc0WeiLDFOn5mbQ/vuX5IbqSp1 CFqw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:message-id:mime-version:subject:from :cc:content-transfer-encoding; bh=roRRmpnOQfqBgouvFdnsiNMWHoFG1to3sn9HMTXsuVQ=; b=h8EJk0hpNyYi+pPc5YwOkDWS83BRJNrGoRqJ+HY9shCtrKiBBL3f/CVhMHUpmV2gry XDTfi7lIkhNEXH78GWgWSBSDXk5henkBwnL3MzHE5+xOOAHEMQkffSE18ghDZV19J9Wi nw9Gmrei2JAXJpfDqEVf3Xp9bSj9atoe9HTo1C7ir8bpDh80kORZJIC93hCkFbaKU3RI huxGgCf/ssTueYtyHy77KCck+mGVRKAMlAPtL6vjez934IlIQbam9BmEejljBWvCZwpW 4YsbNa8MmLjJ9cVrp2neCFGWIkVs599ShtIHFX2cVIau4XDcPoIORMuu/yBy6PYtCUzI +CmA== X-Gm-Message-State: AOAM532/6iPjO0ug7L0qZaoHOCpD96zOhKEUaLJr3ilWsftvLE1zW361 m5dTCYOO3izfA/Ia46qmXvhl4gc8ONMAMS9tHg== Sender: "kaleshsingh via sendgmr" X-Received: from kaleshsingh.c.googlers.com ([fda3:e722:ac3:10:14:4d90:c0a8:2145]) (user=kaleshsingh job=sendgmr) by 2002:ad4:58c7:: with SMTP id dh7mr278895qvb.20.1601912420924; Mon, 05 Oct 2020 08:40:20 -0700 (PDT) Date: Mon, 5 Oct 2020 15:40:03 +0000 Message-Id: <20201005154017.474722-1-kaleshsingh@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.28.0.806.g8561365e88-goog Subject: [PATCH v3 0/5] Speed up mremap on large regions From: Kalesh Singh Cc: surenb@google.com, minchan@google.com, joelaf@google.com, lokeshgidra@google.com, kaleshsingh@google.com, kernel-team@android.com, Catalin Marinas , Will Deacon , Thomas Gleixner , Ingo Molnar , Borislav Petkov , x86@kernel.org, "H. Peter Anvin" , Andrew Morton , Shuah Khan , "Aneesh Kumar K.V" , Kees Cook , Peter Zijlstra , Masahiro Yamada , Sami Tolvanen , Arnd Bergmann , Krzysztof Kozlowski , Frederic Weisbecker , Hassan Naveed , Christian Brauner , Mark Rutland , Mark Brown , Mike Rapoport , Gavin Shan , Jia He , Zhenyu Ye , John Hubbard , Sandipan Das , Thiago Jung Bauermann , "Kirill A. Shutemov" , Ram Pai , Ralph Campbell , Dave Hansen , Mina Almasry , Brian Geffon , Masami Hiramatsu , Jason Gunthorpe , SeongJae Park , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mm@kvack.org, linux-kselftest@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable To: unlisted-recipients:; (no To-header on input) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This version 3 of the mremap speed up patches previously posted at: v1 - https://lore.kernel.org/r/20200930222130.4175584-1-kaleshsingh@google.= com v2 - https://lore.kernel.org/r/20201002162101.665549-1-kaleshsingh@google.c= om mremap time can be optimized by moving entries at the PMD/PUD level if the source and destination addresses are PMD/PUD-aligned and PMD/PUD-sized. Enable moving at the PMD and PUD levels on arm64 and x86. Other architectures where this type of move is supported and known to be safe can also opt-in to these optimizations by enabling HAVE_MOVE_PMD and HAVE_MOVE_PUD. Observed Performance Improvements for remapping a PUD-aligned 1GB-sized region on x86 and arm64: - HAVE_MOVE_PMD is already enabled on x86 : N/A - Enabling HAVE_MOVE_PUD on x86 : ~13x speed up - Enabling HAVE_MOVE_PMD on arm64 : ~ 8x speed up - Enabling HAVE_MOVE_PUD on arm64 : ~19x speed up Altogether, HAVE_MOVE_PMD and HAVE_MOVE_PUD give a total of ~150x speed up on arm64. Changes in v2: - Reduce mremap_test time by only validating a configurable threshold of the remapped region, as per John. - Use a random pattern for mremap validation. Provide pattern seed in test output, as per John. - Moved set_pud_at() to separate patch, per Kirill. - Use switch() instead of ifs in move_pgt_entry(), per Kirill. - Update commit message with description of Android garbage collector use case for HAVE_MOVE_PUD, as per Joel. - Fix build test error reported by kernel test robot in [1]. Changes in v3: - Make lines 80 cols or less where they don=E2=80=99t need to be longer, per John. - Removed unused PATTERN_SIZE in mremap_test - Added Reviewed-by tag for patch 1/5 (mremap kselftest patch). - Use switch() instead of ifs in get_extent(), per Kirill - Add BUILD_BUG() is get_extent() default case. - Move get_old_pud() and alloc_new_pud() out of #ifdef CONFIG_HAVE_MOVE_PUD, per Kirill. - Have get_old_pmd() and alloc_new_pmd() use get_old_pud() and alloc_old_pud(), per Kirill. - Replace #ifdef CONFIG_HAVE_MOVE_PMD / PUD in move_page_tables() with IS_ENABLED(CONFIG_HAVE_MOVE_PMD / PUD), per Kirill. - Fold Add set_pud_at() patch into patch 4/5, per Kirill. [1] https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org/thread/CKP= GL4FH4NG7TGH2CVYX2UX76L25BTA3/ Kalesh Singh (5): kselftests: vm: Add mremap tests arm64: mremap speedup - Enable HAVE_MOVE_PMD mm: Speedup mremap on 1GB or larger regions arm64: mremap speedup - Enable HAVE_MOVE_PUD x86: mremap speedup - Enable HAVE_MOVE_PUD arch/Kconfig | 7 + arch/arm64/Kconfig | 2 + arch/arm64/include/asm/pgtable.h | 1 + arch/x86/Kconfig | 1 + mm/mremap.c | 230 ++++++++++++--- tools/testing/selftests/vm/.gitignore | 1 + tools/testing/selftests/vm/Makefile | 1 + tools/testing/selftests/vm/mremap_test.c | 344 +++++++++++++++++++++++ tools/testing/selftests/vm/run_vmtests | 11 + 9 files changed, 558 insertions(+), 40 deletions(-) create mode 100644 tools/testing/selftests/vm/mremap_test.c base-commit: 549738f15da0e5a00275977623be199fbbf7df50 --=20 2.28.0.806.g8561365e88-goog