From patchwork Thu Jul 20 11:29:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ryan Roberts X-Patchwork-Id: 13320349 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 863E9EB64DD for ; Thu, 20 Jul 2023 11:30:12 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DE8A02800EE; Thu, 20 Jul 2023 07:30:11 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D991C28004C; Thu, 20 Jul 2023 07:30:11 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C60F42800EE; Thu, 20 Jul 2023 07:30:11 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id B3A1F28004C for ; Thu, 20 Jul 2023 07:30:11 -0400 (EDT) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 7E1D71C8D4C for ; Thu, 20 Jul 2023 11:30:11 +0000 (UTC) X-FDA: 81031771422.10.FEBE710 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf24.hostedemail.com (Postfix) with ESMTP id AAF81180017 for ; Thu, 20 Jul 2023 11:30:09 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=arm.com; spf=pass (imf24.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=1689852610; 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=VaQ0evAW+iMJ3X3MzxAmvzcl1mMF2PLKTnaX2OtDpBM=; b=Q6yOCw4xDwzPy7TvhZFut4GbTbDRc+IEpqL+rzUnMPTG7uvvuIAkPZww/NivQhoxpIJc4o jyQKfQOJEJtJJqLLhEHw7VmEMVXzamVraRI6fxFQ+9VV/K2y/47jRIOkx6ZDm108Agg2Ro g7c7978AS1c9/uwb/Eppk92DS2Py9MM= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=arm.com; spf=pass (imf24.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=1689852610; a=rsa-sha256; cv=none; b=YMZna/U4Xsf8tzMF8EVf3CFU6cVfaCB8tyDECZ7gjfaHoqpw6vc0VaVSqLQsmBXDwVrJFN 4tQ1zgqNFVSiZAbDslQmKzyAoJwDB4JytpPRHbOnlhjoE5w5KTPz9g9r1cflb3bC7q8/gX BwnUo9+K/q62P02EKQgITmArV3aMDa8= 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 BA0301FB; Thu, 20 Jul 2023 04:30:51 -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 D5E803F6C4; Thu, 20 Jul 2023 04:30:06 -0700 (PDT) From: Ryan Roberts To: Andrew Morton , Matthew Wilcox , Yin Fengwei , David Hildenbrand , Yu Zhao , Yang Shi , "Huang, Ying" , Zi Yan Cc: Ryan Roberts , linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH v3 0/3] Optimize large folio interaction with deferred split Date: Thu, 20 Jul 2023 12:29:52 +0100 Message-Id: <20230720112955.643283-1-ryan.roberts@arm.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: AAF81180017 X-Stat-Signature: 6eqpykchdrr3nwgf37qqjqxmiwraergo X-Rspam-User: X-HE-Tag: 1689852609-103069 X-HE-Meta: U2FsdGVkX19ahUkeCIuaMQ9k4DfLtsalXqO6zpuF+t84Zk1uYQsNYK5FAMRK00cVdV3wqY62kdiD9NlLmpZoftgoz+IwO4f7JGEXWlJ0XMmBPb4fCi4O1aa/Ae/6Y7qc/EZQQFgH9uQen6hkZuUV1dshTlpbj2MON6f2qQ1xijtsG28H440D45zLehl8E+CKTp+XxoVyNbLnoe9w7Nyn8Hk/ZZUloqexeBzVsA+6F4e5SIeoodBKtmN2LHFImMKtY7y1VSRRwRdg5F4Ldv3nwSzb0b2DvL76cbaC1uvpnLYOeL6FyqLWNyucv2ZChtEPh0yZfcce7TwNkiM/sesoW+P+N/TqcJwnJaGetWtqQj2eC9k8PyAFIr5saMRMWpNS2qxBG0yxVgXF7tgHCIhckHHo+PHcIlBpkGuaRBMfTAGwyXSzicPbXJd5rqTExQ0Uj7ATzdtzwwfj5fZIo1db3Ekfs2R2ZnZ9Sw3mrUgw5ntNR00CTeGd82CNIFenTXHtbu04L4uCY6Xk4Dh6eNbsWtXEqNBy9EqTyfIReqzAJwqrSvHM9ibKjGDaWjuyvt/Nt9tXJWUM+NfmdcSLReg3tws62cfVt+ly3gkUgB8ZiEpb3JKpAj1MfDmOoqbg8ZpGJSsA2879+youRv1ud6Hsny+bYxv4CgJY1MmLbflf9Chb6rW1HeFdI7WrVB6XuZnYJsNIL7Z/oL83vNSPy5Nfh2o80MIvxDwvYx/80pT5EeMHlFeRYSpKZw633CIJbPHu/vYTPxnVVu7RHQmwtCql7zPyqmii+K5dPpQWkL3dQdwPFN9jQTE+Y9OuX1+jvZLRmVNVBzP2ZFp5wywIMuH4vi/A+R9GG7Iev5yPAEg4xvc0rmr/GHcu0A55Wn0V+o3KmD6desMSoP+2HiNh+oVPvx0t7zm8nAHfocIdLjxXKK94VdC6YXk/BSjnvFlFyBu0USICQ+La7jZLqh7pGMC P/FNwGDT x1a2clcrkcduuIUWOAC39fZrI8CLtYti7wXw0CzLaGqkCsAvp/TJzhRhAWSGCFywrfJuvjBBHL8Z4aXTNTL4Bjye7+NYCRSB8wOLYZcVZS4ETVn2fIQOFR/D5k9mWi+0xlUrD/nPM/oI5fWeLTO3Nk631YOV8pUj84hOtdEGPEN6H2A0vMJ+o4ArNtVLi/OrMQR4c9zQe6jzJI/xC5pZQRO2bsg== 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, [Sending v3 to replace yesterday's v2 after Yu Zhou's feedback] This is v3 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") [1]. 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-rc2 and a branch is available at [2]. I don't have a full test run with the latest versions of all the patches on top of the latest baseline, so not posting results formally. I can get these if people feel they are neccessary though. But anecdotally, for the kernel compilation workload, this series reduces kernel time by ~4% and reduces real-time by ~0.4%, compared with [1]. Changes since v2 [3] -------------------- - 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 [4] -------------------- - 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/20230714160407.4142030-1-ryan.roberts@arm.com/ [2] https://gitlab.arm.com/linux-arm/linux-rr/-/tree/features/granule_perf/deferredsplit-lkml_v3 [3] https://lore.kernel.org/linux-mm/20230719135450.545227-1-ryan.roberts@arm.com/ [4] https://lore.kernel.org/linux-mm/20230717143110.260162-1-ryan.roberts@arm.com/ 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 | 120 +++++++++++++++++++++++++++++++++++++++++ mm/rmap.c | 125 ++++++++++++++++++++++++++++++++----------- 3 files changed, 217 insertions(+), 30 deletions(-) --- 2.25.1