From patchwork Thu Jul 27 14:18:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ryan Roberts X-Patchwork-Id: 13330158 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 D6C2FC41513 for ; Thu, 27 Jul 2023 14:18:54 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D8C5D6B0071; Thu, 27 Jul 2023 10:18:53 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D3BD26B0074; Thu, 27 Jul 2023 10:18:53 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C51696B0075; Thu, 27 Jul 2023 10:18:53 -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 B45D96B0071 for ; Thu, 27 Jul 2023 10:18:53 -0400 (EDT) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 7F00A1210D8 for ; Thu, 27 Jul 2023 14:18:53 +0000 (UTC) X-FDA: 81057598146.23.1F40FD6 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf18.hostedemail.com (Postfix) with ESMTP id 876551C001F for ; Thu, 27 Jul 2023 14:18:50 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=arm.com; spf=pass (imf18.hostedemail.com: domain of ryan.roberts@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=ryan.roberts@arm.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1690467531; 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; bh=yVrovolLhdoIDypqzxVEphfZDq1TAN7hgj47sjdxDGs=; b=u4YWN7k7biPr2kedT+hayRE1rdTJa9Pq/iHNrTbMlfQt8UnrxJuHX/NCWo+dh2HS++HbuD /8Z54rBtgV26FNpBTGRoOBUatMjW3IsSm9K7nz/Y/tSzi6MYT4XeZvrxy6XKVx1sg7vGjK 7Vuyqi0MOu8H5m8ypLDMr4tsZjDQSWM= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=arm.com; spf=pass (imf18.hostedemail.com: domain of ryan.roberts@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=ryan.roberts@arm.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1690467531; a=rsa-sha256; cv=none; b=7EU/b3kG4qzhYQnDnG1Pk9hyzr7ah7CRb5sTCGIJsqm+csndsaIyHGZ8lk1tte3r3RdGTt CoFtI8ilkXeUh8XHpq8wt+Ew2DhlUQL+g1qjRwMNSgfzPuF2HxQa16tUGIZuMqKQvtwBc/ U7HvmDruPHU3BzaIdRryi61ewceylFs= Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 6415AD75; Thu, 27 Jul 2023 07:19:32 -0700 (PDT) Received: from e125769.cambridge.arm.com (e125769.cambridge.arm.com [10.1.196.26]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 5D6A73F6C4; Thu, 27 Jul 2023 07:18:47 -0700 (PDT) From: Ryan Roberts To: Andrew Morton , Matthew Wilcox , Yin Fengwei , David Hildenbrand , Yu Zhao , Yang Shi , "Huang, Ying" , Zi Yan , Nathan Chancellor , Alexander Gordeev , Gerald Schaefer Cc: Ryan Roberts , linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH v4 0/3] Optimize large folio interaction with deferred split Date: Thu, 27 Jul 2023 15:18:34 +0100 Message-Id: <20230727141837.3386072-1-ryan.roberts@arm.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-Rspamd-Queue-Id: 876551C001F X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: wijza9zzydnorexnw1acuuew1i7q9srh X-HE-Tag: 1690467530-907792 X-HE-Meta: U2FsdGVkX18bA7pPu1tgU4dL6yH9S+kNT7/F9X9f/ZuZTzPtS5Rs2dAm+MCrWPylav4HFi8qoUOaNeLVAl7nmTgGnaXK3S5KBQVnJGtbV386WjwJqqXnal5mMartYNaZN57t49Jxo5Rz2UxwAbbxaye+gw4JUKHhQEK2qWVjna/Ag7zGbLJr+xn/hv4bdFpXEucM1MNkAVf/h1UHVfgyA/H5KzvP/qwVAfRmxNQU+rohybzzjQ05t38WgQdotBKOTiuXffkzg7WP95SfLrGmE4z43wNiFOJuPZWLABN0r3KhMYLFGJSlJfeM494xga7BaaDSq+RHvnL1cgUWsxTM6u3HZf7TJ1NLdBlTWR/Y4kOfVB8BVFAJ6ZeefOWWHlG1l5ArSzQQYlMLdJKtweqb4sdHZa42emAwg8JoX6YBjWE8QtLmfxMojDaGCGUt6LsrM+tLdsv77zb2j9P5gj86/UBqZRaimNXIMdqnYpyWwYxcqJCGvRXoWPGTzutlhCgRi4gFP7F2ShEaiTboRISCHZRM9Yxk+Y/6/p9IVKIc4cnRUICEVeRD+udIMzm6EgLwLcR+Kxhf20wldWXZ86iY8yuRFFzOzSRFY5rSxGER/4qeb0I7ZI9Y+GrUZqyB0GEKPH2cWN9McAOTaAeWFzqtcUnYCiUW/RzMddmggk4yYO1feQMxnlTPeG9Mb6VfjEFmcMgQI04ZxH6UCVe+gaYNQn9VN2zjX4i0Sj9q2aYyqLxS7n6w4pzsut8+8B5Ufm9gFy1E4rw77d5pS3+Ed8Xq/8RL9+Mxu0OMD0W93F6CPfJhqOco7TRs4VaJr7sT9TGSuQ0hj1/XDBB/ugNJxTHBIOznlAPEhzvavI2QTwCDKnQoMZRv76o6yNmWkTxTwkmmX6pRfp3Iij623uMIxkl2okbdzHJr/MjirPC7g9LaUGdnXfcfiINuLJ2ugusDY6c6VwwJXwzPAHp+Eslz0eU ufPloRjG xrLoiKQkij9NGzJUownoB3ffXnmoQpejqkJeVDPnvESirPmGUilEXAcIOk83KJesDBNrgruMZ5y0sNyXG6R+suiKnZMi3jtOHv2EMTHrVL0RzIR1ddUf/OSGeOU5Y5ML0zx05O3xBHR1Zt9e1/uq5KLbINxgYKnNZwXdh0MbD1fFBJm9lPyqUmf5iGvsq/K8RioBccrmbAbCCwfnfCQy46VuNpTqvQS5eZiLP 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: Hi All, This is v4 of a small series in support of my work to enable the use of large folios for anonymous memory (known as "FLEXIBLE_THP" or "LARGE_ANON_FOLIO") [5]. It first makes it possible to add large, non-pmd-mappable folios to the deferred split queue. Then it modifies zap_pte_range() to batch-remove spans of physically contiguous pages from the rmap, which means that in the common case, we elide the need to ever put the folio on the deferred split queue, thus reducing lock contention and improving performance. This becomes more visible once we have lots of large anonymous folios in the system, and Huang Ying has suggested solving this needs to be a prerequisit for merging the main FLEXIBLE_THP/LARGE_ANON_FOLIO work. The series applies on top of v6.5-rc3 and a branch is available at [4]. NOTE: v3 is currently in mm-unstable and has a bug that affects s390, which this version fixes. Changes since v3 [3] -------------------- - Fixed bug reported on s390 [6] - Since s390 enables MMU_GATHER_NO_GATHER, __tlb_remove_page() causes a ref to be dropped on the page, but we were still using the page after that function call. - Fix by using folio_get()/folio_put() to guarrantee lifetime of page - Thanks to Nathan Chancellor for the bug report and helping me get set up with s390! - Don't use batch path if folio is not large Changes since v2 [2] -------------------- - patch 2: Reworked at Yu Zhou's request to reduce duplicated code. - page_remove_rmap() now forwards to folio_remove_rmap_range() for the !compound (PMD mapped) case. - Both page_remove_rmap() and folio_remove_rmap_range() share common epilogue via new helper function __remove_rmap_finish(). - As a result of the changes, I've removed the previous Reviewed-bys. - other 2 patches are unchanged. Changes since v1 [1] -------------------- - patch 2: Modified doc comment for folio_remove_rmap_range() - patch 2: Hoisted _nr_pages_mapped manipulation out of page loop so its now modified once per folio_remove_rmap_range() call. - patch 2: Added check that page range is fully contained by folio in folio_remove_rmap_range() - patch 2: Fixed some nits raised by Huang, Ying for folio_remove_rmap_range() - patch 3: Support batch-zap of all anon pages, not just those in anon vmas - patch 3: Renamed various functions to make their use clear - patch 3: Various minor refactoring/cleanups - Added Reviewed-By tags - thanks! [1] https://lore.kernel.org/linux-mm/20230717143110.260162-1-ryan.roberts@arm.com/ [2] https://lore.kernel.org/linux-mm/20230719135450.545227-1-ryan.roberts@arm.com/ [3] https://lore.kernel.org/linux-mm/20230720112955.643283-1-ryan.roberts@arm.com/ [4] https://gitlab.arm.com/linux-arm/linux-rr/-/tree/features/granule_perf/deferredsplit-lkml_v4 [5] https://lore.kernel.org/linux-mm/20230714160407.4142030-1-ryan.roberts@arm.com/ [6] https://lore.kernel.org/linux-mm/20230726161942.GA1123863@dev-arch.thelio-3990X/ Thanks, Ryan Ryan Roberts (3): mm: Allow deferred splitting of arbitrary large anon folios mm: Implement folio_remove_rmap_range() mm: Batch-zap large anonymous folio PTE mappings include/linux/rmap.h | 2 + mm/memory.c | 132 +++++++++++++++++++++++++++++++++++++++++++ mm/rmap.c | 125 ++++++++++++++++++++++++++++++---------- 3 files changed, 229 insertions(+), 30 deletions(-) --- 2.25.1