From patchwork Mon Feb 19 06:04:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Byungchul Park X-Patchwork-Id: 13562180 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 EDD36C5475B for ; Mon, 19 Feb 2024 06:04:26 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8ED866B008A; Mon, 19 Feb 2024 01:04:25 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 89D6D6B0089; Mon, 19 Feb 2024 01:04:25 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 660BC6B0088; Mon, 19 Feb 2024 01:04:25 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 454E96B0085 for ; Mon, 19 Feb 2024 01:04:25 -0500 (EST) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 1EB731C01AA for ; Mon, 19 Feb 2024 06:04:25 +0000 (UTC) X-FDA: 81807513690.27.74065C8 Received: from invmail4.hynix.com (exvmail4.hynix.com [166.125.252.92]) by imf18.hostedemail.com (Postfix) with ESMTP id 65EB21C0009 for ; Mon, 19 Feb 2024 06:04:22 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=none; spf=pass (imf18.hostedemail.com: domain of byungchul@sk.com designates 166.125.252.92 as permitted sender) smtp.mailfrom=byungchul@sk.com; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1708322663; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:content-type: content-transfer-encoding:in-reply-to:in-reply-to: references:references; bh=eRD1/8o+qtEOTAKMY7ucioDJJtMI3+WpTL+ASvHX4To=; b=d4/2KlhlVP/xl2N0Q2QCQ5z9UIvXuDpzbYCJqw6G8h7RGJrBbm06vbp+4IPCUHjD0CCXVp E/NwlmmNAEh1GWHEiOuN6ZfxCV9ToxGcyxGN/zeEf9OBWDezLf6MI8hZzmX5Y39S2G7ktE a0RDqrpqSk1RCRUGorr+FSQhpreIhic= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1708322663; a=rsa-sha256; cv=none; b=z7nSiZZ0mgxpntV/nhQImvXTVG3XVTwZ6xUAnALTvGoPpDxMpa1vMq0KHcKqTvZ/hAyzSo kuiyQBttZBRbvApo0kTQPWMGmX3x7N/gYOQhBOdAQrz+23Ovd+i4ULVtrd0RlOQVEC8QNa 60msAnDdJaxY3/+u1xOoS2pJQv7fgjY= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=none; spf=pass (imf18.hostedemail.com: domain of byungchul@sk.com designates 166.125.252.92 as permitted sender) smtp.mailfrom=byungchul@sk.com; dmarc=none X-AuditID: a67dfc5b-d6dff70000001748-bd-65d2ef615024 From: Byungchul Park To: linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: kernel_team@skhynix.com, akpm@linux-foundation.org, ying.huang@intel.com, namit@vmware.com, vernhao@tencent.com, mgorman@techsingularity.net, hughd@google.com, willy@infradead.org, david@redhat.com, peterz@infradead.org, luto@kernel.org, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, rjgolo@gmail.com Subject: [PATCH v8 1/8] x86/tlb: Add APIs manipulating tlb batch's arch data Date: Mon, 19 Feb 2024 15:04:00 +0900 Message-Id: <20240219060407.25254-2-byungchul@sk.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240219060407.25254-1-byungchul@sk.com> References: <20240219060407.25254-1-byungchul@sk.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrALMWRmVeSWpSXmKPExsXC9ZZnkW7i+0upBt8fqFrMWb+GzeLzhn9s Fi82tDNafF3/i9ni6ac+FovLu+awWdxb85/V4vyutawWO5buY7K4dGABk8X1XQ8ZLY73HmCy mH/vM5vF5k1TmS2OT5nKaPH7B1DHyVmTWRwEPb639rF47Jx1l91jwaZSj80rtDwW73nJ5LFp VSebx6ZPk9g93p07x+5xYsZvFo95JwM93u+7yuax9ZedR+PUa2wenzfJebyb/5YtgD+KyyYl NSezLLVI3y6BK+P27ZdMBav4Kpb8aGdrYJzG08XIySEhYCKx8vp0Nhj73PUDYDabgLrEjRs/ mUFsEQEziYOtf9i7GLk4mAU+Mkms/t7BApIQFvCRWHz/H5jNIqAq0T3zHROIzStgKnFq2gYW iKHyEqs3HAAaxMHBCTRo90EhkLAQUMmJq5OZQGZKCLSzS/y7s50Vol5S4uCKGywTGHkXMDKs YhTKzCvLTczMMdHLqMzLrNBLzs/dxAiMh2W1f6J3MH66EHyIUYCDUYmHN0PkUqoQa2JZcWXu IUYJDmYlEV73pgupQrwpiZVVqUX58UWlOanFhxilOViUxHmNvpWnCAmkJ5akZqemFqQWwWSZ ODilGhjl/X6+u7dnlu2ZRwY71ty++sdgFYPOt4qkaT4eF6ZceLywbZVx62wRNpHKr36577VM HOqfH5NYG3WYYcd2tT/x5VIPJ1n6X0ubFbeo7NPtlvVRm9JPy/fNcN6gnb434MgDB8XHt3kZ nl55pz61IK+E33KRjPr+6JxL+Q5XbjKXB5fUKl7bv++oEktxRqKhFnNRcSIAuMXYj4MCAAA= X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrOLMWRmVeSWpSXmKPExsXC5WfdrJv4/lKqwZevUhZz1q9hs/i84R+b xYsN7YwWX9f/YrZ4+qmPxeLw3JOsFpd3zWGzuLfmP6vF+V1rWS12LN3HZHHpwAImi+u7HjJa HO89wGQx/95nNovNm6YyWxyfMpXR4vcPoI6TsyazOAh5fG/tY/HYOesuu8eCTaUem1doeSze 85LJY9OqTjaPTZ8msXu8O3eO3ePEjN8sHvNOBnq833eVzWPxiw9MHlt/2Xk0Tr3G5vF5k5zH u/lv2QIEorhsUlJzMstSi/TtErgybt9+yVSwiq9iyY92tgbGaTxdjJwcEgImEueuH2ADsdkE 1CVu3PjJDGKLCJhJHGz9w97FyMXBLPCRSWL19w4WkISwgI/E4vv/wGwWAVWJ7pnvmEBsXgFT iVPTNrBADJWXWL3hANAgDg5OoEG7DwqBhIWASk5cncw0gZFrASPDKkaRzLyy3MTMHFO94uyM yrzMCr3k/NxNjMDgXlb7Z+IOxi+X3Q8xCnAwKvHwZohcShViTSwrrsw9xCjBwawkwuvedCFV iDclsbIqtSg/vqg0J7X4EKM0B4uSOK9XeGqCkEB6YklqdmpqQWoRTJaJg1OqgdHK2n/Sdu7V /xe/iok3ct0vt4ZJpKPoyqFNhhYaFd6TWU5/dn/l+ObD9QxrvaN3Z2S4VmhcMhZ8uNh1OZPF +tiAU83Hln/jTmg6bfLN66XQtfu7VkQd4vyxcIPwk+UvT1VHrNiVrfz8zdUHSuvnP128TV9B L1eKZX+k3f8PxRppdi5Vaz3SlfuUWIozEg21mIuKEwGcMv88agIAAA== X-CFilter-Loop: Reflected X-Stat-Signature: meg9nh391ji37zpqywim59ux4yx6ggzg X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: 65EB21C0009 X-Rspam-User: X-HE-Tag: 1708322662-991155 X-HE-Meta: U2FsdGVkX1/xYZq/j2Q9BGUTNwLbdbypm+P8nX0KAXBxNUJQcqd7WNaA0tyBmVLCSsPcXT4HbS1pJQR2vOenmNnTo8/vfVf1TEm3SLjadr6JBx2ReexIfHYRmPbfWWBQ1dzzICB4eLmGQ24qIc3HQ2Vls/r24Ui3Oainpas/Q/vsY6G1MoM7SqiRVWBXNPnUCAeL/L9kH34ptobG41h2N72vLB2EPxKiJCNXAOlO4nSedR2WUuJdARWEWUaOmt1vK3HiVIJ2HCU+qf47IMMxC+Od4WJyhWJffpvJOV0LnEw2p9CqlohZIdsit7flo3otKhJQiTBqeDgAfC/JLra8358xNXt4gaynRluuV2GbSQrSqoE6GZBQtfAfrPFeSlM8uO57GiOYg4+aMcM0lnWdoP6Qbcg15OiuRIJjPLBtYKk3WZJmroOy9thNgCAYVx5IKjFBoIeCHODlMoxKEqCzlGToMp4PfbJnb2mlM9lpJzHPqq2abfS0Q58O7Mb+U6aipLKZ71jC1iJ7vH8UKbOeAmd6Z89mebOkSPcHJl9Ih3F1qToIG7S79F8QrVdZYpvNvHdkeY3nnqPmmCuqIA1jUFIZ8daGoFvBLnkadErAqmUTCYJLESFbbw7hG51ScFaYxMosIrKvXZVnEepc4NDfmn0gOSe6ebtsf4K9fXS5I4moBGgrzvi8dY+7vWArmS2zrOPc/2yugDan50v8SbmLhw== 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: List-Subscribe: List-Unsubscribe: This is a preparation for migrc mechanism that needs to recognize read-only TLB entries during batched TLB flush by separating tlb batch's arch data into two, one is for read-only entries and the other is for writable ones, and merging those two when needed. Migrc also needs to optimize CPUs to flush by clearing ones that have already performed TLB flush needed. To support it, added APIs manipulating arch data for x86. Signed-off-by: Byungchul Park --- arch/x86/include/asm/tlbflush.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/arch/x86/include/asm/tlbflush.h b/arch/x86/include/asm/tlbflush.h index 25726893c6f4..fa7e16dbeb44 100644 --- a/arch/x86/include/asm/tlbflush.h +++ b/arch/x86/include/asm/tlbflush.h @@ -5,6 +5,7 @@ #include #include #include +#include #include #include @@ -293,6 +294,23 @@ static inline void arch_flush_tlb_batched_pending(struct mm_struct *mm) extern void arch_tlbbatch_flush(struct arch_tlbflush_unmap_batch *batch); +static inline void arch_tlbbatch_clear(struct arch_tlbflush_unmap_batch *batch) +{ + cpumask_clear(&batch->cpumask); +} + +static inline void arch_tlbbatch_fold(struct arch_tlbflush_unmap_batch *bdst, + struct arch_tlbflush_unmap_batch *bsrc) +{ + cpumask_or(&bdst->cpumask, &bdst->cpumask, &bsrc->cpumask); +} + +static inline bool arch_tlbbatch_done(struct arch_tlbflush_unmap_batch *bdst, + struct arch_tlbflush_unmap_batch *bsrc) +{ + return cpumask_andnot(&bdst->cpumask, &bdst->cpumask, &bsrc->cpumask); +} + static inline bool pte_flags_need_flush(unsigned long oldflags, unsigned long newflags, bool ignore_access) From patchwork Mon Feb 19 06:04:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Byungchul Park X-Patchwork-Id: 13562181 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 99995C48260 for ; Mon, 19 Feb 2024 06:04:29 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B417C6B0083; Mon, 19 Feb 2024 01:04:25 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id AFD6E6B0088; Mon, 19 Feb 2024 01:04:25 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8EB046B0085; Mon, 19 Feb 2024 01:04:25 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 757A76B0083 for ; Mon, 19 Feb 2024 01:04:25 -0500 (EST) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 54AA9A024D for ; Mon, 19 Feb 2024 06:04:25 +0000 (UTC) X-FDA: 81807513690.23.8A117C5 Received: from invmail4.hynix.com (exvmail4.hynix.com [166.125.252.92]) by imf05.hostedemail.com (Postfix) with ESMTP id 570CF100014 for ; Mon, 19 Feb 2024 06:04:21 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=none; spf=pass (imf05.hostedemail.com: domain of byungchul@sk.com designates 166.125.252.92 as permitted sender) smtp.mailfrom=byungchul@sk.com; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1708322663; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:content-type: content-transfer-encoding:in-reply-to:in-reply-to: references:references; bh=23+JjFD9uRPbyMWGqJTLiQYjg6Gkh8EQ/TB1jpahIpQ=; b=rYonxCbZxDq2E3J/xLF1liFh4Rf26OD42gkajSWQWAyNTLbhc9FvCUecNMR1aboGwccmDm qE8ainCezQng8g6wdq2CKLcCn5zZGOnJOcH95ZkopAUmCDBM30A7SkbHXbQOpSR68aY/LE TTQ8VWPTOR6mcmGywDuOHoeDc1PQKIU= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1708322663; a=rsa-sha256; cv=none; b=vP89KTj67qvTn8zlgcZ4C4Qu68kk4EO3gLeJx2ux+pFZplrr99vXzw+sSe+QKay4Ugp6HQ a1F6MgJtgr/CYy/YjYyGuJ5Yv/iuK+CHVVseENRifFKufU/WTjVyGWRPEtcagzoe0uYVlN k3biVLgph9OSk61Mi2sm/rNgl4mY8G8= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=none; spf=pass (imf05.hostedemail.com: domain of byungchul@sk.com designates 166.125.252.92 as permitted sender) smtp.mailfrom=byungchul@sk.com; dmarc=none X-AuditID: a67dfc5b-d6dff70000001748-c2-65d2ef61c11d From: Byungchul Park To: linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: kernel_team@skhynix.com, akpm@linux-foundation.org, ying.huang@intel.com, namit@vmware.com, vernhao@tencent.com, mgorman@techsingularity.net, hughd@google.com, willy@infradead.org, david@redhat.com, peterz@infradead.org, luto@kernel.org, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, rjgolo@gmail.com Subject: [PATCH v8 2/8] arm64: tlbflush: Add APIs manipulating tlb batch's arch data Date: Mon, 19 Feb 2024 15:04:01 +0900 Message-Id: <20240219060407.25254-3-byungchul@sk.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240219060407.25254-1-byungchul@sk.com> References: <20240219060407.25254-1-byungchul@sk.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrPLMWRmVeSWpSXmKPExsXC9ZZnkW7i+0upBhuf6lnMWb+GzeLzhn9s Fi82tDNafF3/i9ni6ac+FovLu+awWdxb85/V4vyutawWO5buY7K4dGABk8X1XQ8ZLY73HmCy mH/vM5vF5k1TmS2OT5nKaPH7B1DHyVmTWRwEPb639rF47Jx1l91jwaZSj80rtDwW73nJ5LFp VSebx6ZPk9g93p07x+5xYsZvFo95JwM93u+7yuax9ZedR+PUa2wenzfJebyb/5YtgD+KyyYl NSezLLVI3y6BK2NP30P2gtlcFZvet7M1MO7l6GLk5JAQMJH4dPspK4y95ORdJhCbTUBd4saN n8wgtoiAmcTB1j/sXYxcHMwCH5kkVn/vYAFJCAuESPT/PMUGYrMIqErMfbwHLM4rYCqxdhdE s4SAvMTqDQeAbA4OTqBBuw8KgYSFgEpOXJ3MBFHSzC7xZ3I2hC0pcXDFDZYJjLwLGBlWMQpl 5pXlJmbmmOhlVOZlVugl5+duYgRGw7LaP9E7GD9dCD7EKMDBqMTDmyFyKVWINbGsuDL3EKME B7OSCK9704VUId6UxMqq1KL8+KLSnNTiQ4zSHCxK4rxG38pThATSE0tSs1NTC1KLYLJMHJxS DYy1bcxrf3Of9latynp5JX5OwH8TP445ypzzMn6uEvv8pMn7oOe5WTtXMNhrMm1puKsSe0Ps ++oXUmdd1d4kf+NOkD9yoOXNxS9HFuu/fNb/ZbGv7sXjQmxLLkSZzD50UJ912TUmx+Z9a0MV zVX1vn/5PPPPZ2eWhviTMQf3vhA1OlBwdN5p3ZAZSizFGYmGWsxFxYkAZHZPDYICAAA= X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrOLMWRmVeSWpSXmKPExsXC5WfdrJv4/lKqwbw+BYs569ewWXze8I/N 4sWGdkaLr+t/MVs8/dTHYnF47klWi8u75rBZ3Fvzn9Xi/K61rBY7lu5jsrh0YAGTxfVdDxkt jvceYLKYf+8zm8XmTVOZLY5Pmcpo8fsHUMfJWZNZHIQ8vrf2sXjsnHWX3WPBplKPzSu0PBbv ecnksWlVJ5vHpk+T2D3enTvH7nFixm8Wj3knAz3e77vK5rH4xQcmj62/7Dwap15j8/i8Sc7j 3fy3bAECUVw2Kak5mWWpRfp2CVwZe/oeshfM5qrY9L6drYFxL0cXIyeHhICJxJKTd5lAbDYB dYkbN34yg9giAmYSB1v/sHcxcnEwC3xkklj9vYMFJCEsECLR//MUG4jNIqAqMffxHrA4r4Cp xNpdEM0SAvISqzccALI5ODiBBu0+KAQSFgIqOXF1MtMERq4FjAyrGEUy88pyEzNzTPWKszMq 8zIr9JLzczcxAoN7We2fiTsYv1x2P8QowMGoxMObIXIpVYg1say4MvcQowQHs5IIr3vThVQh 3pTEyqrUovz4otKc1OJDjNIcLErivF7hqQlCAumJJanZqakFqUUwWSYOTqkGRskSc8uF23zK TO9Y9P8PCgibwjbDKcaIebG+E+vNFGGO52H7Snq22SdZCeTnTHLJUNkZE6nTt327UoeyVST/ Q4vy3BnzOwPWBU96bZky69A7d6fP85y05u6t6bmTsVtOcknqevGPp31u17GWnxZ+n3lN+r3x xNaTrTuVHjTyy3oGfn3E4xCoxFKckWioxVxUnAgAtvSl22oCAAA= X-CFilter-Loop: Reflected X-Stat-Signature: 347jmstk1wfq8hggqyiat4o4tmbztyi5 X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: 570CF100014 X-Rspam-User: X-HE-Tag: 1708322661-503198 X-HE-Meta: U2FsdGVkX19lmXeK1RNxrxIFZEzPyguYVpdGmgdOy5mFr25uEQY0yT/0VkjSs63ze9hLe7s2tCqazsNlLTu17oWYohiSlE/VqTfMIbZz047zLQPkkkMtpd92f4KQ6hqrIeIhwsy9TrBeJuZoN/nTQHP8RWD7e0cOz3bmF9AmH+Z5fMGGJ1aKG4XDIn8jMFmm9VMiQXcqRTyCkIgZt6vIh8I+l+wI11HBYjsKydQ67Q8S88kEClwHlEuuo/qJY8fSMZoDS/PW8/fBuvL+LzZxTseFt84tZ7YGEDhYk6bmQf9CumKi5QzSWl1xuunxpZZHoaj0W7mpYXHHJMXPgiZcXbw7F8w4351/Sq8hGQ27k0znL3P5kM2m+FHj6qhAyBNCyZsKcKD2G8KiBwmZ7Gr9DqRGfPskLRzCjFRQI/aUW1QHLXFVMQK9umOXSH98aGLKs3BMB3+moODywqhBGyDtcrITBo6NDB8rTpfFVq6+dwTmQpCO4mJ3iKdujeSdPfwoxoTzZ0iWmdF5LZrY2D1UjUIDz5Kh6FPeP4zpNmgwiFH5N4GfPalTMbBsj0ACyixiv45JKHiIDKUryMv5hPv7IqRD2k6SlkQDLwaPpx17wjkOqg8YVoub6Xju/HaiCQ9tK63v0n0v0IJ/aT0Yj/pWyAZapPTofNC/Vy2t47RWXLOPSAx7HB5wlVAuJOC2gJF4SfVOGbhqLoctuCW8m8+CwatFHdjFF5emGTOlkuB9irkkZAEZc66WSt+r6vnPC7Fgz2/VrH2VXLfL/O29Bu/fdd2wRnqkOu9Ut5ndjH7DxpHiqXN5y4nIdzRt4LBk75Pau4iZLdhjjpb5tvd/MWvgSVSufbaWis1hIwqIM+Tvp0TxTF2COGjVoYdNe0yktzbrAgWfciwRqRy7OZRpN0AEZlZMcxYFMtTCOsvxz9rJGaaAtpuYyhatJlpy41YlPm7OGVNzG4BDVP3zSdIcIj5 TPw== 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: List-Subscribe: List-Unsubscribe: This is a preparation for migrc mechanism that requires to manipulate tlb batch's arch data. Even though arm64 does nothing with it, arch with CONFIG_ARCH_WANT_BATCHED_UNMAP_TLB_FLUSH should provide the APIs. Signed-off-by: Byungchul Park --- arch/arm64/include/asm/tlbflush.h | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/arch/arm64/include/asm/tlbflush.h b/arch/arm64/include/asm/tlbflush.h index bb2c2833a987..4f2094843e7a 100644 --- a/arch/arm64/include/asm/tlbflush.h +++ b/arch/arm64/include/asm/tlbflush.h @@ -328,6 +328,25 @@ static inline void arch_tlbbatch_flush(struct arch_tlbflush_unmap_batch *batch) dsb(ish); } +static inline void arch_tlbbatch_clear(struct arch_tlbflush_unmap_batch *batch) +{ + /* nothing to do */ +} + +static inline void arch_tlbbatch_fold(struct arch_tlbflush_unmap_batch *bdst, + struct arch_tlbflush_unmap_batch *bsrc) +{ + /* nothing to do */ +} + +static inline bool arch_tlbbatch_done(struct arch_tlbflush_unmap_batch *bdst, + struct arch_tlbflush_unmap_batch *bsrc) +{ + /* nothing to do */ + + return false; +} + /* * This is meant to avoid soft lock-ups on large TLB flushing ranges and not * necessarily a performance improvement. From patchwork Mon Feb 19 06:04:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Byungchul Park X-Patchwork-Id: 13562182 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 900AAC48BC3 for ; Mon, 19 Feb 2024 06:04:31 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4D4AB6B0089; Mon, 19 Feb 2024 01:04:27 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 459B36B0088; Mon, 19 Feb 2024 01:04:27 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 235788D0003; Mon, 19 Feb 2024 01:04:27 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 0D90C6B0085 for ; Mon, 19 Feb 2024 01:04:27 -0500 (EST) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id D4EE2A0263 for ; Mon, 19 Feb 2024 06:04:26 +0000 (UTC) X-FDA: 81807513732.13.E1B2DAE Received: from invmail4.hynix.com (exvmail4.hynix.com [166.125.252.92]) by imf08.hostedemail.com (Postfix) with ESMTP id E9D4D16000B for ; Mon, 19 Feb 2024 06:04:24 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf08.hostedemail.com: domain of byungchul@sk.com designates 166.125.252.92 as permitted sender) smtp.mailfrom=byungchul@sk.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1708322665; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:content-type: content-transfer-encoding:in-reply-to:in-reply-to: references:references; bh=deHIYqkuaMMowWAwSsScVOmIndLCnwrqbZwxQiYz+QA=; b=bzuPneF6/hoJiFEmiq5PXJpdE39ICzWVV1CtOpeFh8R1BrrWilWNmhf2K/G2R3i0nrIRXo cudi/UWY6zOOW24urZ9UgDdalOOw6N+Jf5BdKnpVYx+38tG16Rdi9Csv77CHDhObFyPJDs mWoFq9Mj+QriNvC4DsZdDvAwWefoVuA= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf08.hostedemail.com: domain of byungchul@sk.com designates 166.125.252.92 as permitted sender) smtp.mailfrom=byungchul@sk.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1708322665; a=rsa-sha256; cv=none; b=Rb94b7tpITQal0bdKL5Tuj0mGNPS3pW6YnXQX6ht2/xCnfydBKTxCOCPVgrl+o6Rfrd+Ph dyBkSpibnhJjZcKXmJJXYjja/SdK4KilWNUcgAcii+Jh05K80kCyICgrzFc11+OP3bnxdK MgVw0KHJ21Pw/gLjx/J65vTtBrCsoC8= X-AuditID: a67dfc5b-d6dff70000001748-c7-65d2ef6120f8 From: Byungchul Park To: linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: kernel_team@skhynix.com, akpm@linux-foundation.org, ying.huang@intel.com, namit@vmware.com, vernhao@tencent.com, mgorman@techsingularity.net, hughd@google.com, willy@infradead.org, david@redhat.com, peterz@infradead.org, luto@kernel.org, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, rjgolo@gmail.com Subject: [PATCH v8 3/8] mm/rmap: Recognize read-only TLB entries during batched TLB flush Date: Mon, 19 Feb 2024 15:04:02 +0900 Message-Id: <20240219060407.25254-4-byungchul@sk.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240219060407.25254-1-byungchul@sk.com> References: <20240219060407.25254-1-byungchul@sk.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrPLMWRmVeSWpSXmKPExsXC9ZZnkW7i+0upBhsW6lvMWb+GzeLzhn9s Fi82tDNafF3/i9ni6ac+FovLu+awWdxb85/V4vyutawWO5buY7K4dGABk8X1XQ8ZLY73HmCy mH/vM5vF5k1TmS2OT5nKaPH7B1DHyVmTWRwEPb639rF47Jx1l91jwaZSj80rtDwW73nJ5LFp VSebx6ZPk9g93p07x+5xYsZvFo95JwM93u+7yuax9ZedR+PUa2wenzfJebyb/5YtgD+KyyYl NSezLLVI3y6BK+PrPKeC49IVHz7tYGxgfCDWxcjJISFgIrHl3SQmGPv4yimsIDabgLrEjRs/ mUFsEQEziYOtf9i7GLk4mAU+Mkms/t7BApIQFoiUOLTpPJjNIqAq8fTlH7BmXgFTiRuf9kAN lZdYveEA0CAODk6gQbsPCoGEhYBKTlydzAQyU0KgmV3iyNE2Foh6SYmDK26wTGDkXcDIsIpR KDOvLDcxM8dEL6MyL7NCLzk/dxMjMBqW1f6J3sH46ULwIUYBDkYlHt4MkUupQqyJZcWVuYcY JTiYlUR43ZsupArxpiRWVqUW5ccXleakFh9ilOZgURLnNfpWniIkkJ5YkpqdmlqQWgSTZeLg lGpgjNytd05he82hCWc/NTn08igeecM5/fwcB7FbUsf2pPCW+HP1GyfoCsd1XXA40yVUV9h7 0ne6BdefOZUnI9jNcisFirZL2/ZbnuS1/iPOGbUo0qQyZyFXZPBx8xkf05Yv4t6mwyqqHCcs fjI2sWC1/5NPzjVvfW/a+8qmfzuVtUjcPPnxn3dKLMUZiYZazEXFiQD2/cjxggIAAA== X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrGLMWRmVeSWpSXmKPExsXC5WfdrJv4/lKqQfNKZYs569ewWXze8I/N 4sWGdkaLr+t/MVs8/dTHYnF47klWi8u75rBZ3Fvzn9Xi/K61rBY7lu5jsrh0YAGTxfVdDxkt jvceYLKYf+8zm8XmTVOZLY5Pmcpo8fsHUMfJWZNZHIQ8vrf2sXjsnHWX3WPBplKPzSu0PBbv ecnksWlVJ5vHpk+T2D3enTvH7nFixm8Wj3knAz3e77vK5rH4xQcmj62/7Dwap15j8/i8Sc7j 3fy3bAECUVw2Kak5mWWpRfp2CVwZX+c5FRyXrvjwaQdjA+MDsS5GTg4JAROJ4yunsILYbALq Ejdu/GQGsUUEzCQOtv5h72Lk4mAW+Mgksfp7BwtIQlggUuLQpvNgNouAqsTTl3/AmnkFTCVu fNrDBDFUXmL1hgNAgzg4OIEG7T4oBBIWAio5cXUy0wRGrgWMDKsYRTLzynITM3NM9YqzMyrz Miv0kvNzNzECQ3tZ7Z+JOxi/XHY/xCjAwajEw5shcilViDWxrLgy9xCjBAezkgive9OFVCHe lMTKqtSi/Pii0pzU4kOM0hwsSuK8XuGpCUIC6YklqdmpqQWpRTBZJg5OqQbG5swyM7PeKvlC BZMJuvN+7F/6aNG+y5VFn/fe63+0VGOC6RLGaxOauVS28YckLCgpFLU7GXu3oaZA9g3DA1lW pobWLS0neyb/byu+U51Y/u/k2TKfz2G3k2xWnBU+YF/kEVtxWfzns9+b+HQSTe7kzlWcav/l mOqHvrZaF4ZLZ1aFa/14sJRPiaU4I9FQi7moOBEANl9Y0GkCAAA= X-CFilter-Loop: Reflected X-Rspamd-Queue-Id: E9D4D16000B X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: x5c4ca34my65b5h3hqzcqfnx6sikyuws X-HE-Tag: 1708322664-985596 X-HE-Meta: U2FsdGVkX1+MKORPZV3AFhB+vHGlkxUp8TsT8361KYGjODWy933dOtYa5zW6XfYMQgJ1mbD2BfUfqcrRMOoh/+aJufODBd6rGWCCLHIFcD2q7e0HmBR/0nvfhnkgUbU8sBtgAOW2Dx7j3DKVpdLVgM/tqj9IuJ27eu9a9FdIJ0B/jNmoGvKBBbtNmezgf8LAm8WXzQDwn11m8+Nyy8cQyVeenmE/vE/du5eTtTuI2fVTITygCVJIKFwE6ql9LbQTqMt0pv1K9r4VoYqz8OD9RBDUtZN6QuWKzjHDMZ3OqNUBYHlCyc8NnBgVsy9pN3Jg4dGDwddZAvNIfFfsU1+PSVfiX1NxoKlLuFlK11QvG7FWLG2cPnNkN4LrPaB3dToGre+Oxrm3IscU5FALeE/CArPB04ggKtYqOMVexDnQhYBw6KNLHr/36cYB1E2pA8T5ygM/ccfdtqaO4RBP9cHrMfDl9kvisTrXSyPQgXssEbV/Rc+Of3uaB9iuaSykZAAUsLLhohlB20HDEy8JRUFSOYyousYS4IFAof/DjYcwV/mvNSTy7dIElR/v1RRjzeDRyKkiW/CerCxJHZ2b+42LHTbOReaRWkZp6L2b2E5gANjpEqnvYqeVu9crEf3S4tL519t9BS69VzhgefFsx5YgyEbLg3wmh5ujvPMr+HkHzMjUo4kuk+4IIb09fgjUswfAX8RAqs/u4fO57FchJ4mTi+Da506u0ikocQCV3OTgloCMVo7vIf+RY9KJtsv/AyDyhQT3jiiI7VMg0hRGQZ8Gke845IKEFjJ6/bi84hUzZcrn2IEmhPLdBvlDpX5PemdAeFNxx/DjBQVRGy/Mli1BOhJ3qHwXPeoriwFKwwPQbKPbhAv6CUyPBKwM7trdmzzyVdncj3/53fmjnucn4XfG83JRvsR+ZgnlbOXM4U/5ys8GFJ+kP5ZLyP5Gm1EFE12kwNGtBawwlwq84u8byUf b1w== 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: List-Subscribe: List-Unsubscribe: Functionally, no change. This is a preparation for migrc mechanism that requires to recognize read-only TLB entries and makes use of them to batch more aggressively. Plus, the newly introduced API, fold_ubc() will be used by migrc mechanism when manipulating tlb batch data. Signed-off-by: Byungchul Park --- include/linux/sched.h | 1 + mm/internal.h | 4 ++++ mm/rmap.c | 31 ++++++++++++++++++++++++++++++- 3 files changed, 35 insertions(+), 1 deletion(-) diff --git a/include/linux/sched.h b/include/linux/sched.h index 292c31697248..0317e7a65151 100644 --- a/include/linux/sched.h +++ b/include/linux/sched.h @@ -1328,6 +1328,7 @@ struct task_struct { #endif struct tlbflush_unmap_batch tlb_ubc; + struct tlbflush_unmap_batch tlb_ubc_ro; /* Cache last used pipe for splice(): */ struct pipe_inode_info *splice_pipe; diff --git a/mm/internal.h b/mm/internal.h index b61034bd50f5..b880f1e78700 100644 --- a/mm/internal.h +++ b/mm/internal.h @@ -923,6 +923,7 @@ extern struct workqueue_struct *mm_percpu_wq; void try_to_unmap_flush(void); void try_to_unmap_flush_dirty(void); void flush_tlb_batched_pending(struct mm_struct *mm); +void fold_ubc(struct tlbflush_unmap_batch *dst, struct tlbflush_unmap_batch *src); #else static inline void try_to_unmap_flush(void) { @@ -933,6 +934,9 @@ static inline void try_to_unmap_flush_dirty(void) static inline void flush_tlb_batched_pending(struct mm_struct *mm) { } +static inline void fold_ubc(struct tlbflush_unmap_batch *dst, struct tlbflush_unmap_batch *src) +{ +} #endif /* CONFIG_ARCH_WANT_BATCHED_UNMAP_TLB_FLUSH */ extern const struct trace_print_flags pageflag_names[]; diff --git a/mm/rmap.c b/mm/rmap.c index 7a27a2b41802..da36f23ff7b0 100644 --- a/mm/rmap.c +++ b/mm/rmap.c @@ -605,6 +605,28 @@ struct anon_vma *folio_lock_anon_vma_read(struct folio *folio, } #ifdef CONFIG_ARCH_WANT_BATCHED_UNMAP_TLB_FLUSH + +void fold_ubc(struct tlbflush_unmap_batch *dst, + struct tlbflush_unmap_batch *src) +{ + if (!src->flush_required) + return; + + /* + * Fold src to dst. + */ + arch_tlbbatch_fold(&dst->arch, &src->arch); + dst->writable = dst->writable || src->writable; + dst->flush_required = true; + + /* + * Reset src. + */ + arch_tlbbatch_clear(&src->arch); + src->flush_required = false; + src->writable = false; +} + /* * Flush TLB entries for recently unmapped pages from remote CPUs. It is * important if a PTE was dirty when it was unmapped that it's flushed @@ -614,7 +636,9 @@ struct anon_vma *folio_lock_anon_vma_read(struct folio *folio, void try_to_unmap_flush(void) { struct tlbflush_unmap_batch *tlb_ubc = ¤t->tlb_ubc; + struct tlbflush_unmap_batch *tlb_ubc_ro = ¤t->tlb_ubc_ro; + fold_ubc(tlb_ubc, tlb_ubc_ro); if (!tlb_ubc->flush_required) return; @@ -645,13 +669,18 @@ void try_to_unmap_flush_dirty(void) static void set_tlb_ubc_flush_pending(struct mm_struct *mm, pte_t pteval, unsigned long uaddr) { - struct tlbflush_unmap_batch *tlb_ubc = ¤t->tlb_ubc; + struct tlbflush_unmap_batch *tlb_ubc; int batch; bool writable = pte_dirty(pteval); if (!pte_accessible(mm, pteval)) return; + if (pte_write(pteval) || writable) + tlb_ubc = ¤t->tlb_ubc; + else + tlb_ubc = ¤t->tlb_ubc_ro; + arch_tlbbatch_add_pending(&tlb_ubc->arch, mm, uaddr); tlb_ubc->flush_required = true; From patchwork Mon Feb 19 06:04:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Byungchul Park X-Patchwork-Id: 13562183 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 B47D2C48260 for ; Mon, 19 Feb 2024 06:04:33 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B18466B0085; Mon, 19 Feb 2024 01:04:27 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 9FE1B6B0088; Mon, 19 Feb 2024 01:04:27 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 850CF6B008C; Mon, 19 Feb 2024 01:04:27 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 6F82F6B0085 for ; Mon, 19 Feb 2024 01:04:27 -0500 (EST) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 24085A0264 for ; Mon, 19 Feb 2024 06:04:27 +0000 (UTC) X-FDA: 81807513774.09.E98CF9C Received: from invmail4.hynix.com (exvmail4.hynix.com [166.125.252.92]) by imf18.hostedemail.com (Postfix) with ESMTP id 7262B1C0008 for ; Mon, 19 Feb 2024 06:04:25 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=none; spf=pass (imf18.hostedemail.com: domain of byungchul@sk.com designates 166.125.252.92 as permitted sender) smtp.mailfrom=byungchul@sk.com; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1708322665; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:content-type: content-transfer-encoding:in-reply-to:in-reply-to: references:references; bh=JD5mtfEWkRjuaUV9XVtob8Xf345yQ1B8wbzU19SAuqU=; b=gAXoIsH/Qc4SvmWQxerRZnv2/vjstz5yPaXXpO845A9h6Oho2opkAFBAIwN9fbG+C382UK E47zHUTibPAJCeE/f5bK255Q9bTvLKdmMSIPbnMpX67cLHpdYpHeB1RuKz5KeCkI4Gag72 /EeKNQrE31FnqXqa2WxfFlRZpolham4= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1708322665; a=rsa-sha256; cv=none; b=cFHKVswjHQ4WOG329bs+Ck5AADz8YPGGGcnog8oB2Ca40uRYmHW6T+gHeGPQN6Tp6wH5w5 Z/RtkE5dGIwM6dkfdaszoJpsZH5xOftugSKnxRtI8Q5CaJOvIE25gOv+PdYRdiB8/z8/hW wjagF57nZTgrDfs80A0WrZm8gyE6WFI= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=none; spf=pass (imf18.hostedemail.com: domain of byungchul@sk.com designates 166.125.252.92 as permitted sender) smtp.mailfrom=byungchul@sk.com; dmarc=none X-AuditID: a67dfc5b-d6dff70000001748-cc-65d2ef61944a From: Byungchul Park To: linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: kernel_team@skhynix.com, akpm@linux-foundation.org, ying.huang@intel.com, namit@vmware.com, vernhao@tencent.com, mgorman@techsingularity.net, hughd@google.com, willy@infradead.org, david@redhat.com, peterz@infradead.org, luto@kernel.org, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, rjgolo@gmail.com Subject: [PATCH v8 4/8] x86/tlb, mm/rmap: Separate arch_tlbbatch_clear() out of arch_tlbbatch_flush() Date: Mon, 19 Feb 2024 15:04:03 +0900 Message-Id: <20240219060407.25254-5-byungchul@sk.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240219060407.25254-1-byungchul@sk.com> References: <20240219060407.25254-1-byungchul@sk.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrPLMWRmVeSWpSXmKPExsXC9ZZnkW7i+0upBhdXGlrMWb+GzeLzhn9s Fi82tDNafF3/i9ni6ac+FovLu+awWdxb85/V4vyutawWO5buY7K4dGABk8X1XQ8ZLY73HmCy mH/vM5vF5k1TmS2OT5nKaPH7B1DHyVmTWRwEPb639rF47Jx1l91jwaZSj80rtDwW73nJ5LFp VSebx6ZPk9g93p07x+5xYsZvFo95JwM93u+7yuax9ZedR+PUa2wenzfJebyb/5YtgD+KyyYl NSezLLVI3y6BK+PonXtsBXM4K87/msrUwHiJvYuRk0NCwETi7IsPrDD2u5sXmUBsNgF1iRs3 fjKD2CICZhIHW/8A1XNxMAt8ZJJY/b2DBSQhLJAqseTLQcYuRg4OFgFVie6jASBhXgFTiWsL /jJCzJSXWL3hADNICSfQnN0HhUDCQkAlJ65OZgIZKSHQzi6xev9DNoh6SYmDK26wTGDkXcDI sIpRKDOvLDcxM8dEL6MyL7NCLzk/dxMjMBqW1f6J3sH46ULwIUYBDkYlHt4MkUupQqyJZcWV uYcYJTiYlUR43ZsupArxpiRWVqUW5ccXleakFh9ilOZgURLnNfpWniIkkJ5YkpqdmlqQWgST ZeLglGpg7JtfuuGLz+brTy4ZvSh3zA1hVL986oZJ59GJe7/9MdatcWnZMNF2I6/nRf98lu9S zscKu07WCGs876q67+m/V6J8qfWZNV5577uecKyZoSJwNNns8NVH9zdmKu/lPhlT+uf2ieye lGtWaaHBndzCBzvOTZs1x32l1urVM40OR3/vUVvXoVBTqcRSnJFoqMVcVJwIACyHJuuCAgAA X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrGLMWRmVeSWpSXmKPExsXC5WfdrJv4/lKqwZnVGhZz1q9hs/i84R+b xYsN7YwWX9f/YrZ4+qmPxeLw3JOsFpd3zWGzuLfmP6vF+V1rWS12LN3HZHHpwAImi+u7HjJa HO89wGQx/95nNovNm6YyWxyfMpXR4vcPoI6TsyazOAh5fG/tY/HYOesuu8eCTaUem1doeSze 85LJY9OqTjaPTZ8msXu8O3eO3ePEjN8sHvNOBnq833eVzWPxiw9MHlt/2Xk0Tr3G5vF5k5zH u/lv2QIEorhsUlJzMstSi/TtErgyjt65x1Ywh7Pi/K+pTA2Ml9i7GDk5JARMJN7dvMgEYrMJ qEvcuPGTGcQWETCTONj6B6iGi4NZ4COTxOrvHSwgCWGBVIklXw4ydjFycLAIqEp0Hw0ACfMK mEpcW/CXEWKmvMTqDQeYQUo4gebsPigEEhYCKjlxdTLTBEauBYwMqxhFMvPKchMzc0z1irMz KvMyK/SS83M3MQJDe1ntn4k7GL9cdj/EKMDBqMTDmyFyKVWINbGsuDL3EKMEB7OSCK9704VU Id6UxMqq1KL8+KLSnNTiQ4zSHCxK4rxe4akJQgLpiSWp2ampBalFMFkmDk6pBsamzamHwoue 9HD822LlxrN/Z4ZrsL3Y5t3pB2qLz2j/+F7t9vWkqnDkyweCp+Zc+u/TwOSztuTpkvsH7R/s qp94Y/+RJ0tLj31mOv0u5eQ9zbm9z/M5AkR5NV8W9s6Zvo5FIv7v9RxOyVV74zg4bDjsEhkm f4icdm7WlZfe4mdsb3q8Njv0ny9TiaU4I9FQi7moOBEAFcVlHGkCAAA= X-CFilter-Loop: Reflected X-Stat-Signature: gjeesc3ifosukoshby979m3389rbke3u X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: 7262B1C0008 X-Rspam-User: X-HE-Tag: 1708322665-517262 X-HE-Meta: U2FsdGVkX19azO8VVzBkymSB2g9rVNaEyG28hT/eo3VER0pOR5DoE9Fmqtg3AVJiGRjFDxX4kmeCRgqhaBs2GKdn3ypKwy56DfXS7ggCY+0SvW480ZEdU/yr5mQcdiUSQeXI2FTyBeEhKVRHlkfiRE73hAIuXNwZrDq8qUHGWcUNTK/ak7BbEgXZ0pFeEBbq8DAJlH4ygOzW55M5GZI3jDwkjUBcVglQIIqe4O+rFQCL99GwndiYQT98tyaMsqK0+tspq4cf9/tdCePecOO5pIdbPJsQ6wURR0zos8OSDANXlJcWagfz9pg19K9K87w1PpNEx5Fde0AQfHhJBgV0cBw2lgAfnBgRE+vJXuW6y3z0PTlDZov8YZeXAIAhqNV6fPgVP29aT2xB60NgWAzVdWwFIPtjAaA9t6mN1Ym9PwDECtHoduQ3ayR5dVIRUZgO8FR84jVntpL07Gz2SfUZTPA16NzROHkieF85gzM2BK7ONJfpmLgIj9gPt5WU+FzeFj1xvr6rS6qBKhh+Uho2+uHvA58P/8l9b2bmaZojTnZxh6TIig9XsdSFgzbJ6BhiJkWQhQNnV7ZZ4DDilDNdPcxJGDh1EEeTk0S0XEefekbPsQ+V1zoAdYCpniTUz66fp2bfirr+oj5/qNodoMNbA71sJAGFTvB4NhxOuMVJOmRQEBgEakV1Qnmt0y1O91nkQggqC2zec+0ID5lIf4OC4o7FwemAcIpKJMQ/go2/lA4kqhL0t1RjAz9/w4C3rOIR 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: List-Subscribe: List-Unsubscribe: This is a preparation for migrc mechanism that requires to avoid redundant TLB flushes by manipulating tlb batch's arch data after arch_tlbbatch_flush(). However, we cannot because the data is getting cleared inside arch_tlbbatch_flush(). So separated the part clearing the tlb batch's arch data out of arch_tlbbatch_flush(). Signed-off-by: Byungchul Park --- arch/x86/mm/tlb.c | 2 -- mm/rmap.c | 1 + 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c index 453ea95b667d..941f41df02f3 100644 --- a/arch/x86/mm/tlb.c +++ b/arch/x86/mm/tlb.c @@ -1268,8 +1268,6 @@ void arch_tlbbatch_flush(struct arch_tlbflush_unmap_batch *batch) local_irq_enable(); } - cpumask_clear(&batch->cpumask); - put_flush_tlb_info(); put_cpu(); } diff --git a/mm/rmap.c b/mm/rmap.c index da36f23ff7b0..b484d659d0c1 100644 --- a/mm/rmap.c +++ b/mm/rmap.c @@ -643,6 +643,7 @@ void try_to_unmap_flush(void) return; arch_tlbbatch_flush(&tlb_ubc->arch); + arch_tlbbatch_clear(&tlb_ubc->arch); tlb_ubc->flush_required = false; tlb_ubc->writable = false; } From patchwork Mon Feb 19 06:04:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Byungchul Park X-Patchwork-Id: 13562184 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 B87D8C5475B for ; Mon, 19 Feb 2024 06:04:35 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 19BD36B0088; Mon, 19 Feb 2024 01:04:28 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 14D206B008C; Mon, 19 Feb 2024 01:04:28 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D58F66B0093; Mon, 19 Feb 2024 01:04:27 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id B84226B008C for ; Mon, 19 Feb 2024 01:04:27 -0500 (EST) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 8C266140214 for ; Mon, 19 Feb 2024 06:04:27 +0000 (UTC) X-FDA: 81807513774.08.C26A9FF Received: from invmail4.hynix.com (exvmail4.hynix.com [166.125.252.92]) by imf05.hostedemail.com (Postfix) with ESMTP id A931F100013 for ; Mon, 19 Feb 2024 06:04:25 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=none; spf=pass (imf05.hostedemail.com: domain of byungchul@sk.com designates 166.125.252.92 as permitted sender) smtp.mailfrom=byungchul@sk.com; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1708322666; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:content-type: content-transfer-encoding:in-reply-to:in-reply-to: references:references; bh=hj/OU3wk3OzsqULfJnD2mvtgwTJyJb/ndDOd9gzDe6E=; b=Vy2+/PjXyAYJJZ2amubvZLjCJdf29oEJo0bBTs5lb3rd8IyHjoNTxGtv35wzowPtqpL4k7 P9Nz0QZYwcqVpyMQy3fCBcW0X/prsLDX3HKP7oIsfVKuahrtqKTaiN/8iUMWZmNvkwDddM MiuC1PU8Zo/Mpq6ttj1Ittpo/3SfVdk= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1708322666; a=rsa-sha256; cv=none; b=Zfx6xgiI8XAA+pOCDGYzimQ1GqEBJv1InQ0C7sZsTgcLQ1ca3aLCegeWyiJvXyRYJiO7lH piuhmCmMvZvqVxmpxsGC1SZy08nwtmRqKcF4i7luFy7oiSTv5TwomTnL1UZvXEx5SHeYG8 quMafk0Rk2NC668lzforN4xRpeNIEj4= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=none; spf=pass (imf05.hostedemail.com: domain of byungchul@sk.com designates 166.125.252.92 as permitted sender) smtp.mailfrom=byungchul@sk.com; dmarc=none X-AuditID: a67dfc5b-d6dff70000001748-d1-65d2ef61c8ab From: Byungchul Park To: linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: kernel_team@skhynix.com, akpm@linux-foundation.org, ying.huang@intel.com, namit@vmware.com, vernhao@tencent.com, mgorman@techsingularity.net, hughd@google.com, willy@infradead.org, david@redhat.com, peterz@infradead.org, luto@kernel.org, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, rjgolo@gmail.com Subject: [PATCH v8 5/8] mm: Separate move/undo doing on folio list from migrate_pages_batch() Date: Mon, 19 Feb 2024 15:04:04 +0900 Message-Id: <20240219060407.25254-6-byungchul@sk.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240219060407.25254-1-byungchul@sk.com> References: <20240219060407.25254-1-byungchul@sk.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrPLMWRmVeSWpSXmKPExsXC9ZZnkW7i+0upBneumFnMWb+GzeLzhn9s Fi82tDNafF3/i9ni6ac+FovLu+awWdxb85/V4vyutawWO5buY7K4dGABk8X1XQ8ZLY73HmCy mH/vM5vF5k1TmS2OT5nKaPH7B1DHyVmTWRwEPb639rF47Jx1l91jwaZSj80rtDwW73nJ5LFp VSebx6ZPk9g93p07x+5xYsZvFo95JwM93u+7yuax9ZedR+PUa2wenzfJebyb/5YtgD+KyyYl NSezLLVI3y6BK+PG+7vsBf06FYvmPGRvYFyp3MXIwSEhYCIxb5tEFyMnmLn7bBcLiM0moC5x 48ZPZhBbRMBM4mDrH/YuRi4OZoGPTBKrv3eAFQkLxEpc71zACmKzCKhKnHq3ixHE5hUwlTh9 awMzxFB5idUbDjCD7OIEGrT7oBBIWAio5MTVyUwgMyUEmtklNr/qY4eol5Q4uOIGywRG3gWM DKsYhTLzynITM3NM9DIq8zIr9JLzczcxAqNhWe2f6B2Mny4EH2IU4GBU4uHNELmUKsSaWFZc mXuIUYKDWUmE173pQqoQb0piZVVqUX58UWlOavEhRmkOFiVxXqNv5SlCAumJJanZqakFqUUw WSYOTqkGxnk8+/yOLvv+8I/xwn2Na/5d+PX8Rcjy+a2pRzo45Ga+ia0Vq9t8aFFxUXfPT+1w wVKRyS5nrvxxMlh53evaglbeyEAJ3XcP5tlrLL1rvFbwhs+95P3ieaYvu6PbXON8Tn4Ufjb3 d3tpyYSj4mvPnlbMfhmqGmO7pK9sk/fCgknPOXPYzmdffKbEUpyRaKjFXFScCADdv3sSggIA AA== X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrOLMWRmVeSWpSXmKPExsXC5WfdrJv4/lKqwYtv2hZz1q9hs/i84R+b xYsN7YwWX9f/YrZ4+qmPxeLw3JOsFpd3zWGzuLfmP6vF+V1rWS12LN3HZHHpwAImi+u7HjJa HO89wGQx/95nNovNm6YyWxyfMpXR4vcPoI6TsyazOAh5fG/tY/HYOesuu8eCTaUem1doeSze 85LJY9OqTjaPTZ8msXu8O3eO3ePEjN8sHvNOBnq833eVzWPxiw9MHlt/2Xk0Tr3G5vF5k5zH u/lv2QIEorhsUlJzMstSi/TtErgybry/y17Qr1OxaM5D9gbGlcpdjJwcEgImErvPdrGA2GwC 6hI3bvxkBrFFBMwkDrb+Ye9i5OJgFvjIJLH6ewdYkbBArMT1zgWsIDaLgKrEqXe7GEFsXgFT idO3NjBDDJWXWL3hAJDNwcEJNGj3QSGQsBBQyYmrk5kmMHItYGRYxSiSmVeWm5iZY6pXnJ1R mZdZoZecn7uJERjcy2r/TNzB+OWy+yFGAQ5GJR7eDJFLqUKsiWXFlbmHGCU4mJVEeN2bLqQK 8aYkVlalFuXHF5XmpBYfYpTmYFES5/UKT00QEkhPLEnNTk0tSC2CyTJxcEo1MKrtOJxvwGzp yX+xZLWE7D9HLoHUZLnZwks4zqZtzJT+8UBxU4+oQrrF+RWplt9f8eW8r5UpDf+y8uVNb9lY EWveK0qnFjWvst9o//e0/bpYszl/Mjv5met8+++vvx4y5/rCZO7Onklmrexhd95NC1U16bi4 /ldHSb1d8fud7bMPvyxK9VgXqMRSnJFoqMVcVJwIAEbpRQJqAgAA X-CFilter-Loop: Reflected X-Stat-Signature: oyi7dqkpx73wqusgagdmgtge9fa8jxf6 X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: A931F100013 X-Rspam-User: X-HE-Tag: 1708322665-266762 X-HE-Meta: U2FsdGVkX18MxchTvY7YpJXuReGti+LJu1STcGRhdHrL1O3zUkJJrc5ziauscZohStUv0s7pM/G0OuTYJ371iHnRvDiIEMpRMh6X5ef1ojwzziEhm0MyN+mK5jKIVAkqJjUfJKPmpB5tnZ+KsmkZdlN3N05Krdtn7GRxwimr3ovBoH5rxeMBfwHDetAZUDdhhgv4ZFJsSjY1BrD2azrG2szEs0lGXgISqM8KSpeG2z9AcJb7+k9CP7amjsNhQjDDCQdnEMPY5s/rS9c7FOpsdx9K/umPsgmRupUhqMlJgoXcBdYRQUrNchW7gJMHkYuny7RWA6NOdiO5c65QV39IEGAkHgLjVdeSurbt1xKGctLZPtMd2uPYeLUyd2KPg5IuS2UQGWsth0mfVVBlI162LuDraECXyRgl2o0uPa22m3Fv4Fgt1Bkp5zLiXJ/QC1H+JUSUIbmEHsQ7e2HiGOjcHojig+lFdMYJRVZCPsADrTdh8MXf7Dl7bivBeKi3yCSBmjJcTrMMi7/XPOmtEGQmgi46B5nyDa00Pn8buzn7CczloMY3Eh7tvASk5NJvgItRHZxwbI71nKG8OF2GaFGmAglpjtetrvEkaG4ig94+ImHthzupbIQTYCSmp9RkyKXpukV1F0nfB61TwbRAMSSz8pktNaISj8iEliANhbr0b3xW2CfIgoxrcJ5QjFlSaR2iB2NrZGtzqW0oG45E52iFoWqSFNdTj+DxTECku5WncfOBLYFjV5yXs2GRCDaylWacLoloCDxZaHAYGHJct8nSuWbmMfiLiMvZvyqROLJQrPcIiHzmJBMtePa66yz2hTKsPmdeG4Sc+DeKO528og/+HO/6wbr49GYYs5hqm9GmzsNC/7kZfqzAcKx8b/8Xm9Gb3zbIkd6nuj3YlsF6QL1j6p74cMQnIjd7fnu16mvok2LFQnqvY9j/WtZPzpixALN2BNaduyiwuqbdDQx/tal znFtXPWe qv9z+UEB3Yyhy65KQOew/CFe+R5MZSIF2jHCf 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: List-Subscribe: List-Unsubscribe: Functionally, no change. This is a preparation for migrc mechanism that requires to use separate folio lists for its own handling at migration. Refactored migrate_pages_batch() and separated move and undo parts operating on folio list, from migrate_pages_batch(). Signed-off-by: Byungchul Park --- mm/migrate.c | 134 +++++++++++++++++++++++++++++++-------------------- 1 file changed, 83 insertions(+), 51 deletions(-) diff --git a/mm/migrate.c b/mm/migrate.c index 397f2a6e34cb..bbe1ecef4956 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -1611,6 +1611,81 @@ static int migrate_hugetlbs(struct list_head *from, new_folio_t get_new_folio, return nr_failed; } +static void migrate_folios_move(struct list_head *src_folios, + struct list_head *dst_folios, + free_folio_t put_new_folio, unsigned long private, + enum migrate_mode mode, int reason, + struct list_head *ret_folios, + struct migrate_pages_stats *stats, + int *retry, int *thp_retry, int *nr_failed, + int *nr_retry_pages) +{ + struct folio *folio, *folio2, *dst, *dst2; + bool is_thp; + int nr_pages; + int rc; + + dst = list_first_entry(dst_folios, struct folio, lru); + dst2 = list_next_entry(dst, lru); + list_for_each_entry_safe(folio, folio2, src_folios, lru) { + is_thp = folio_test_large(folio) && folio_test_pmd_mappable(folio); + nr_pages = folio_nr_pages(folio); + + cond_resched(); + + rc = migrate_folio_move(put_new_folio, private, + folio, dst, mode, + reason, ret_folios); + /* + * The rules are: + * Success: folio will be freed + * -EAGAIN: stay on the unmap_folios list + * Other errno: put on ret_folios list + */ + switch(rc) { + case -EAGAIN: + *retry += 1; + *thp_retry += is_thp; + *nr_retry_pages += nr_pages; + break; + case MIGRATEPAGE_SUCCESS: + stats->nr_succeeded += nr_pages; + stats->nr_thp_succeeded += is_thp; + break; + default: + *nr_failed += 1; + stats->nr_thp_failed += is_thp; + stats->nr_failed_pages += nr_pages; + break; + } + dst = dst2; + dst2 = list_next_entry(dst, lru); + } +} + +static void migrate_folios_undo(struct list_head *src_folios, + struct list_head *dst_folios, + free_folio_t put_new_folio, unsigned long private, + struct list_head *ret_folios) +{ + struct folio *folio, *folio2, *dst, *dst2; + + dst = list_first_entry(dst_folios, struct folio, lru); + dst2 = list_next_entry(dst, lru); + list_for_each_entry_safe(folio, folio2, src_folios, lru) { + int old_page_state = 0; + struct anon_vma *anon_vma = NULL; + + __migrate_folio_extract(dst, &old_page_state, &anon_vma); + migrate_folio_undo_src(folio, old_page_state & PAGE_WAS_MAPPED, + anon_vma, true, ret_folios); + list_del(&dst->lru); + migrate_folio_undo_dst(dst, true, put_new_folio, private); + dst = dst2; + dst2 = list_next_entry(dst, lru); + } +} + /* * migrate_pages_batch() first unmaps folios in the from list as many as * possible, then move the unmapped folios. @@ -1633,7 +1708,7 @@ static int migrate_pages_batch(struct list_head *from, int pass = 0; bool is_thp = false; bool is_large = false; - struct folio *folio, *folio2, *dst = NULL, *dst2; + struct folio *folio, *folio2, *dst = NULL; int rc, rc_saved = 0, nr_pages; LIST_HEAD(unmap_folios); LIST_HEAD(dst_folios); @@ -1769,42 +1844,11 @@ static int migrate_pages_batch(struct list_head *from, thp_retry = 0; nr_retry_pages = 0; - dst = list_first_entry(&dst_folios, struct folio, lru); - dst2 = list_next_entry(dst, lru); - list_for_each_entry_safe(folio, folio2, &unmap_folios, lru) { - is_thp = folio_test_large(folio) && folio_test_pmd_mappable(folio); - nr_pages = folio_nr_pages(folio); - - cond_resched(); - - rc = migrate_folio_move(put_new_folio, private, - folio, dst, mode, - reason, ret_folios); - /* - * The rules are: - * Success: folio will be freed - * -EAGAIN: stay on the unmap_folios list - * Other errno: put on ret_folios list - */ - switch(rc) { - case -EAGAIN: - retry++; - thp_retry += is_thp; - nr_retry_pages += nr_pages; - break; - case MIGRATEPAGE_SUCCESS: - stats->nr_succeeded += nr_pages; - stats->nr_thp_succeeded += is_thp; - break; - default: - nr_failed++; - stats->nr_thp_failed += is_thp; - stats->nr_failed_pages += nr_pages; - break; - } - dst = dst2; - dst2 = list_next_entry(dst, lru); - } + /* Move the unmapped folios */ + migrate_folios_move(&unmap_folios, &dst_folios, + put_new_folio, private, mode, reason, + ret_folios, stats, &retry, &thp_retry, + &nr_failed, &nr_retry_pages); } nr_failed += retry; stats->nr_thp_failed += thp_retry; @@ -1813,20 +1857,8 @@ static int migrate_pages_batch(struct list_head *from, rc = rc_saved ? : nr_failed; out: /* Cleanup remaining folios */ - dst = list_first_entry(&dst_folios, struct folio, lru); - dst2 = list_next_entry(dst, lru); - list_for_each_entry_safe(folio, folio2, &unmap_folios, lru) { - int old_page_state = 0; - struct anon_vma *anon_vma = NULL; - - __migrate_folio_extract(dst, &old_page_state, &anon_vma); - migrate_folio_undo_src(folio, old_page_state & PAGE_WAS_MAPPED, - anon_vma, true, ret_folios); - list_del(&dst->lru); - migrate_folio_undo_dst(dst, true, put_new_folio, private); - dst = dst2; - dst2 = list_next_entry(dst, lru); - } + migrate_folios_undo(&unmap_folios, &dst_folios, + put_new_folio, private, ret_folios); return rc; } From patchwork Mon Feb 19 06:04:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Byungchul Park X-Patchwork-Id: 13562185 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 CA870C48BC3 for ; Mon, 19 Feb 2024 06:04:37 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 127168D0008; Mon, 19 Feb 2024 01:04:30 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 03E398D0007; Mon, 19 Feb 2024 01:04:29 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 988F68D0005; Mon, 19 Feb 2024 01:04:29 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 7DF258D0003 for ; Mon, 19 Feb 2024 01:04:29 -0500 (EST) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 449CB16020B for ; Mon, 19 Feb 2024 06:04:29 +0000 (UTC) X-FDA: 81807513858.01.4C69539 Received: from invmail4.hynix.com (exvmail4.hynix.com [166.125.252.92]) by imf08.hostedemail.com (Postfix) with ESMTP id 272D716000B for ; Mon, 19 Feb 2024 06:04:26 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf08.hostedemail.com: domain of byungchul@sk.com designates 166.125.252.92 as permitted sender) smtp.mailfrom=byungchul@sk.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1708322667; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:content-type: content-transfer-encoding:in-reply-to:in-reply-to: references:references; bh=sYa6ZVoMA5/dASQ+t66FETLgCEz/UfospKSHXnWzbLI=; b=oICuyKKYelD3Zj/ruwSFsipSABSHXyCjU5dYDKKSr9vequreUW4u2rzr6ndnZFydRL5nKz BAQjlS0XO4tmQygTP6JCUmAAI7OZzkCaxQTzb6x4pu6egy1QnzxHWBh0Q4MfuS67AKYS+3 0URxwnA3sLUCROhOY2cyBJZ4C7DTUaM= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf08.hostedemail.com: domain of byungchul@sk.com designates 166.125.252.92 as permitted sender) smtp.mailfrom=byungchul@sk.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1708322667; a=rsa-sha256; cv=none; b=eLq3d33PUkrT4WUR4SWG5wRKnXd4Zn9UcftjpUhwKMgAOptDo32bb0EVbEfjW/n6fokrP9 NiIyp/8p0LbTUzJCuTBb8ywJUi4mreD9kZaqKZ2mDvu72721qfxDM3XCBPiifhAewVma5A fkiTaxW93gXCgRUqr5w+g2TI5Mw4xxY= X-AuditID: a67dfc5b-d6dff70000001748-d6-65d2ef61a9e5 From: Byungchul Park To: linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: kernel_team@skhynix.com, akpm@linux-foundation.org, ying.huang@intel.com, namit@vmware.com, vernhao@tencent.com, mgorman@techsingularity.net, hughd@google.com, willy@infradead.org, david@redhat.com, peterz@infradead.org, luto@kernel.org, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, rjgolo@gmail.com Subject: [PATCH v8 6/8] mm: Add APIs to free a folio directly to the buddy bypassing pcp Date: Mon, 19 Feb 2024 15:04:05 +0900 Message-Id: <20240219060407.25254-7-byungchul@sk.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240219060407.25254-1-byungchul@sk.com> References: <20240219060407.25254-1-byungchul@sk.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrPLMWRmVeSWpSXmKPExsXC9ZZnkW7i+0upBouuWFjMWb+GzeLzhn9s Fi82tDNafF3/i9ni6ac+FovLu+awWdxb85/V4vyutawWO5buY7K4dGABk8X1XQ8ZLY73HmCy mH/vM5vF5k1TmS2OT5nKaPH7B1DHyVmTWRwEPb639rF47Jx1l91jwaZSj80rtDwW73nJ5LFp VSebx6ZPk9g93p07x+5xYsZvFo95JwM93u+7yuax9ZedR+PUa2wenzfJebyb/5YtgD+KyyYl NSezLLVI3y6BK+PU/UXsBddkK/6//cfawDhZoouRk0NCwERiwaOrzDD23CeX2EBsNgF1iRs3 foLFRQTMJA62/mHvYuTiYBb4yCSx+nsHC0hCWCBC4u69LUAJDg4WAVWJx5OCQMK8AqYSC/5+ YYKYKS+xesMBZpASTqA5uw8KgYSFgEpOXJ3MBDJSQqCdXeJO12qoGyQlDq64wTKBkXcBI8Mq RqHMvLLcxMwcE72MyrzMCr3k/NxNjMBoWFb7J3oH46cLwYcYBTgYlXh4M0QupQqxJpYVV+Ye YpTgYFYS4XVvupAqxJuSWFmVWpQfX1Sak1p8iFGag0VJnNfoW3mKkEB6YklqdmpqQWoRTJaJ g1OqgTHuwW3DhYWpH8t3zGNwaJe1WtX7ac7P6a+T27pFbyzj+MScWJbtknK4PuaooNij78eW xx5T1u5aqzi54+b2xvCJU0PLHr17O/26bNT/U2rSD768S72X4XH6SaTaTxexm836gvzTf828 ZlEWumj7xCtXuEuVkh7KP3sZkJCy/3u3+t/2vKb0bx5KLMUZiYZazEXFiQBUey43ggIAAA== X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrGLMWRmVeSWpSXmKPExsXC5WfdrJv4/lKqwdsDehZz1q9hs/i84R+b xYsN7YwWX9f/YrZ4+qmPxeLw3JOsFpd3zWGzuLfmP6vF+V1rWS12LN3HZHHpwAImi+u7HjJa HO89wGQx/95nNovNm6YyWxyfMpXR4vcPoI6TsyazOAh5fG/tY/HYOesuu8eCTaUem1doeSze 85LJY9OqTjaPTZ8msXu8O3eO3ePEjN8sHvNOBnq833eVzWPxiw9MHlt/2Xk0Tr3G5vF5k5zH u/lv2QIEorhsUlJzMstSi/TtErgyTt1fxF5wTbbi/9t/rA2MkyW6GDk5JARMJOY+ucQGYrMJ qEvcuPGTGcQWETCTONj6h72LkYuDWeAjk8Tq7x0sIAlhgQiJu/e2ACU4OFgEVCUeTwoCCfMK mEos+PuFCWKmvMTqDQeYQUo4gebsPigEEhYCKjlxdTLTBEauBYwMqxhFMvPKchMzc0z1irMz KvMyK/SS83M3MQJDe1ntn4k7GL9cdj/EKMDBqMTDmyFyKVWINbGsuDL3EKMEB7OSCK9704VU Id6UxMqq1KL8+KLSnNTiQ4zSHCxK4rxe4akJQgLpiSWp2ampBalFMFkmDk6pBkZO3uRjO9V9 duxKY4vpvCy18q6k+dy3AmbiM/O8rfsFLIVnOvBdkXFw2GOwZ5HNybOXn66N3X7liv/cuKk3 Flx8+rzbWPLtstWTJU9O+qy4dvZmRwGmZ3meGoIXhLUWGSR/3WGdF84jxvJodcFir0Um0u6O HXG3cxsDqn5bmdw8pnzNKtiFXUCJpTgj0VCLuag4EQD1ji3paQIAAA== X-CFilter-Loop: Reflected X-Rspamd-Queue-Id: 272D716000B X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: akdh9mqewgc4cuuodg7csusku7jafdsf X-HE-Tag: 1708322666-409486 X-HE-Meta: U2FsdGVkX18ea+izr0XKkWYO2nWCmufa9lMD5kTldvGAdHqCjw3z5NQ0ELiOanYYiwnDki2RCTm+h43cSwfEDswkQ5J+zB+ryVka7sXfEU1Fc/wYpHqx59PWO4p1gL8FZpiL+Xva68tXVQ7HlLQoTjTqSWP//u+NQHEpMYktfuBGO48co1YNWonOSqwDOwby04dVPJtu5fY3y0JXRKSPm/LdMMusY6Ug2TFANENy9WqEW9DCfRUV+1QtPaTcDAeWsxmt/pH18jMTviDlJ0e438TBbukyce0uekaR08yUVlHGvvS4aPlTrp7wr+uXPbH/wkvq+UYe2uF+RYaSefhbmmotyAOHO+L56vi8cPjc22SkbwCFXVRy/7BRTKwNAgY4WYINIPiXMpFk6BWDlMFIKB02UYaL1hXvD77nmgcVORxl7tvw92zmxXtB9F2BzQRARwp+g024RqHcKyH/JZOwQbqHFYzn1iJVlE9CaTEwDAB4YDSZq9sVvEGbltZRtVaWAaM0nsMiZ2f9bcqgOKSUKhSqZNEP8qY233+dblLn0iQqCrWYzxDB9jrkQqT0aDVXkES6jKjzEWn7XL/tucQ7i4Up9C2/DYEBWFbkze4K4mhwL2HN2cMBJd5GjsZHk5mD/BtLgFU1DlYIg8H0rXRqNPHLDHZD5NvpvZ8IHb/aqpr8GWDOztuV53wBomw81nCTiOz8i77tsubhM+E/QhFD7qQtTnkhshCE55sxH9hrXR8LiFzlcC/Z4+YuCAFrx+9Y8nqU4eu+Gdm+xp1c2DLMcsOesilrfgVzqtdP+haDwmfQN2SUSxmrVSCEnX9MdjmuIx1NnrwnyLt2SHu3fL48tuV9aWQdp46hH5TNprdT6rksQw9vuhdV1e1I8T6RrqIoJzjcKTKipKGPkWQjkj+NCcY2mOfQjFOrqPVWIjQ1Yj0PIy01tV+oJrAaUx+vSkZO9XDHafBS4RVLnKNaGE8 idfFZoJP ChCCOQGOysAF4AF5B9brYRALzWg== 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: List-Subscribe: List-Unsubscribe: This is a preparation for migrc mechanism that frees folios at a better time. The mechanism will defer the use of folio_put*() for source folios of migration, that are unlikely to be used and a group of folios will be freed at once at a later time. However, this will pollute pcp so as to inexpectedly free_pcppages_bulk() fresher folios and make pcp get unstable. To facilitate this new mechanism, an additional API has been added that allows folios under migrc's control to be freed directly to buddy bypassing pcp. Signed-off-by: Byungchul Park --- include/linux/mm.h | 23 +++++++++++++++++++++++ mm/internal.h | 1 + mm/page_alloc.c | 10 ++++++++++ mm/swap.c | 7 +++++++ 4 files changed, 41 insertions(+) diff --git a/include/linux/mm.h b/include/linux/mm.h index da5219b48d52..fc0581cce3a7 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -1284,6 +1284,7 @@ static inline struct folio *virt_to_folio(const void *x) } void __folio_put(struct folio *folio); +void __folio_put_small_nopcp(struct folio *folio); void put_pages_list(struct list_head *pages); @@ -1483,6 +1484,28 @@ static inline void folio_put(struct folio *folio) __folio_put(folio); } +/** + * folio_put_small_nopcp - Decrement the reference count on a folio. + * @folio: The folio. + * + * This is only for a single page folio to release directly to the buddy + * allocator bypassing pcp. + * + * If the folio's reference count reaches zero, the memory will be + * released back to the page allocator and may be used by another + * allocation immediately. Do not access the memory or the struct folio + * after calling folio_put_small_nopcp() unless you can be sure that it + * wasn't the last reference. + * + * Context: May be called in process or interrupt context, but not in NMI + * context. May be called while holding a spinlock. + */ +static inline void folio_put_small_nopcp(struct folio *folio) +{ + if (folio_put_testzero(folio)) + __folio_put_small_nopcp(folio); +} + /** * folio_put_refs - Reduce the reference count on a folio. * @folio: The folio. diff --git a/mm/internal.h b/mm/internal.h index b880f1e78700..3be8fd5604e8 100644 --- a/mm/internal.h +++ b/mm/internal.h @@ -451,6 +451,7 @@ extern int user_min_free_kbytes; extern void free_unref_page(struct page *page, unsigned int order); extern void free_unref_page_list(struct list_head *list); +extern void free_pages_nopcp(struct page *page, unsigned int order); extern void zone_pcp_reset(struct zone *zone); extern void zone_pcp_disable(struct zone *zone); diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 733732e7e0ba..21b8c8cd1673 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -565,6 +565,16 @@ static inline void free_the_page(struct page *page, unsigned int order) __free_pages_ok(page, order, FPI_NONE); } +void free_pages_nopcp(struct page *page, unsigned int order) +{ + /* + * This function will be used in case that the pages are too + * cold to keep in pcp e.g. migrc mechanism. So it'd better + * release the pages to the tail. + */ + __free_pages_ok(page, order, FPI_TO_TAIL); +} + /* * Higher-order pages are called "compound pages". They are structured thusly: * diff --git a/mm/swap.c b/mm/swap.c index cd8f0150ba3a..3f37496a1184 100644 --- a/mm/swap.c +++ b/mm/swap.c @@ -106,6 +106,13 @@ static void __folio_put_small(struct folio *folio) free_unref_page(&folio->page, 0); } +void __folio_put_small_nopcp(struct folio *folio) +{ + __page_cache_release(folio); + mem_cgroup_uncharge(folio); + free_pages_nopcp(&folio->page, 0); +} + static void __folio_put_large(struct folio *folio) { /* From patchwork Mon Feb 19 06:04:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Byungchul Park X-Patchwork-Id: 13562187 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 64F93C5475B for ; Mon, 19 Feb 2024 06:04:42 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8796B8D0003; Mon, 19 Feb 2024 01:04:30 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 76D168D0007; Mon, 19 Feb 2024 01:04:30 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 323068D0006; Mon, 19 Feb 2024 01:04:30 -0500 (EST) 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 B4ECD8D0003 for ; Mon, 19 Feb 2024 01:04:29 -0500 (EST) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 797E04023D for ; Mon, 19 Feb 2024 06:04:29 +0000 (UTC) X-FDA: 81807513858.22.DA411F5 Received: from invmail4.hynix.com (exvmail4.hynix.com [166.125.252.92]) by imf18.hostedemail.com (Postfix) with ESMTP id 897861C000A for ; Mon, 19 Feb 2024 06:04:27 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=none; spf=pass (imf18.hostedemail.com: domain of byungchul@sk.com designates 166.125.252.92 as permitted sender) smtp.mailfrom=byungchul@sk.com; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1708322668; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:content-type: content-transfer-encoding:in-reply-to:in-reply-to: references:references; bh=0Xe+86Sg3SvMdEShlZyUiGPZdigVYaGkrosOSTaTIuA=; b=2jgy00jTg4rCtSTanXjbATwFUlp+ktZhKBVbM70AFDzWQ49HUj5F8rowfoOMKsPlL77Ec7 gO8FXnPZj/33Gr9bk/KyT2l6KC6eORCTB8sYNZo1mAK3XDd+6ee7iO5mCkyF1QkxkC3oqi Y5+5afJ3yVI/murazX39H+X5RczyqCo= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1708322668; a=rsa-sha256; cv=none; b=wgvdxlMjJyFJ3ZxDX7DObc8R+LkWgqhd/hXUr5+hgpvfZrFvphkHV/74zn6ulWxEHN8/RD rmx4cvF1BlwrXBTt7EQZs1kulQcgS7R6I9vrm1Gm04xVCbSM6piP6FvggQO0htQSvvi9Jr 7gQM9/K69ifZJE2IFH3KjagXwvCsElo= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=none; spf=pass (imf18.hostedemail.com: domain of byungchul@sk.com designates 166.125.252.92 as permitted sender) smtp.mailfrom=byungchul@sk.com; dmarc=none X-AuditID: a67dfc5b-d6dff70000001748-dc-65d2ef61c3ba From: Byungchul Park To: linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: kernel_team@skhynix.com, akpm@linux-foundation.org, ying.huang@intel.com, namit@vmware.com, vernhao@tencent.com, mgorman@techsingularity.net, hughd@google.com, willy@infradead.org, david@redhat.com, peterz@infradead.org, luto@kernel.org, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, rjgolo@gmail.com Subject: [PATCH v8 7/8] mm: Defer TLB flush by keeping both src and dst folios at migration Date: Mon, 19 Feb 2024 15:04:06 +0900 Message-Id: <20240219060407.25254-8-byungchul@sk.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240219060407.25254-1-byungchul@sk.com> References: <20240219060407.25254-1-byungchul@sk.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrALMWRmVeSWpSXmKPExsXC9ZZnkW7S+0upBu1TmSzmrF/DZvF5wz82 ixcb2hktvq7/xWzx9FMfi8XlXXPYLO6t+c9qcX7XWlaLHUv3MVlcOrCAyeL6roeMFsd7DzBZ zL/3mc1i86apzBbHp0xltPj9A6jj5KzJLA6CHt9b+1g8ds66y+6xYFOpx+YVWh6L97xk8ti0 qpPNY9OnSewe786dY/c4MeM3i8e8k4Ee7/ddZfPY+svOo3HqNTaPz5vkPN7Nf8sWwB/FZZOS mpNZllqkb5fAlbH91wmWgtcrGStm/Q1tYFzfxtjFyMkhIWAise7TFbYuRg4we97uEpAwm4C6 xI0bP5lBbBEBM4mDrX/Yuxi5OJgFPjJJrP7ewQKSEBaIlmibfIIdxGYRUJU4/2MKmM0rYCrx /PxcFoj58hKrNxxgBpnPCTRo90EhkLAQUMmJq5OZQGZKCHSzS+w4N40dol5S4uCKGywTGHkX MDKsYhTKzCvLTczMMdHLqMzLrNBLzs/dxAiMh2W1f6J3MH66EHyIUYCDUYmHN0PkUqoQa2JZ cWXuIUYJDmYlEV73pgupQrwpiZVVqUX58UWlOanFhxilOViUxHmNvpWnCAmkJ5akZqemFqQW wWSZODilGhhlki7mKrxadd0s/2DUKskwRZb11onHzizeYbjM/O3jp/GsmqZpD1zP3VaKy1yt dfm/bNO10H2dmzI+td7Or99bIDvlR8cBaSanG1VSIbNdllQ/mJv7bZvChnO3Jmr885OaHZjO +HlH3ZyCLHuJuGdb/lnv417wMDmqKXSaeJz7ncovhsZzj9xVYinOSDTUYi4qTgQAanq46IMC AAA= X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrOLMWRmVeSWpSXmKPExsXC5WfdrJv4/lKqwan1RhZz1q9hs/i84R+b xYsN7YwWX9f/YrZ4+qmPxeLw3JOsFpd3zWGzuLfmP6vF+V1rWS12LN3HZHHpwAImi+u7HjJa HO89wGQx/95nNovNm6YyWxyfMpXR4vcPoI6TsyazOAh5fG/tY/HYOesuu8eCTaUem1doeSze 85LJY9OqTjaPTZ8msXu8O3eO3ePEjN8sHvNOBnq833eVzWPxiw9MHlt/2Xk0Tr3G5vF5k5zH u/lv2QIEorhsUlJzMstSi/TtErgytv86wVLweiVjxay/oQ2M69sYuxg5OCQETCTm7S7pYuTk YBNQl7hx4ycziC0iYCZxsPUPexcjFwezwEcmidXfO1hAEsIC0RJtk0+wg9gsAqoS539MAbN5 BUwlnp+fC1YjISAvsXrDAWaQ+ZxAg3YfFAIJCwGVnLg6mWkCI9cCRoZVjCKZeWW5iZk5pnrF 2RmVeZkVesn5uZsYgcG9rPbPxB2MXy67H2IU4GBU4uHNELmUKsSaWFZcmXuIUYKDWUmE173p QqoQb0piZVVqUX58UWlOavEhRmkOFiVxXq/w1AQhgfTEktTs1NSC1CKYLBMHp1QD42oP7wvZ /mkTd9+/ycd2d+9sM50jR/oaZFk/JiUv/Cl/4O3t+Xd9Fd4b3tqSfH9VYolayoe5cgd1Lt1Z 1MO7Xco0oJaDr0L79+v9TrGub/1z5j869kLk+Y3yqOpJcyKL9p4NU1z1vn+ixII5Z4p/R7or WdUGdca6vFr0N/nc5/367NNXPI1bxa3EUpyRaKjFXFScCAAxSKAMagIAAA== X-CFilter-Loop: Reflected X-Stat-Signature: 53bc3131msg3jhkgzbgbz58e647apg33 X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: 897861C000A X-Rspam-User: X-HE-Tag: 1708322667-970426 X-HE-Meta: U2FsdGVkX1+GgH+9TuyScDtGoTmBzJRt+RGQW82saAT7vuUN4NqeF5n3id0RcadOuyRHYOAnDtl9Q3a6p+9kyB/srPQVE+UVHZY6PEeWeVNCLwx4JQTrlgztjPdZF4Vegnr6vrZ+cD33Rf2shLjqREK8f4R5ELWG79STGtGoreRExQJQe9p+M0pPxKm3ZW4F/BqXoQvsumbxWqx4cN3po0dA9XLZ0YhK7s0yUXqpyMfCas7VTB9Z+F7q0krPKtiT30jZKItFHfjRHO1XA4ISb13mLcVv7Xubh0x88bOLd8ObzlNigx/+GeQbf4mcqdnS0l6mmC3KD42FABW3XWa7LAhNeE7RXeSUmN88NEA5lfMLgtETydeip/T4XnZrVfRI/sf/KYMzAWhOLbQFNH8XIUS3zC2HWzWxk+LYInvDbqr9xEkBD0f9X1EBP6zt5tGYYfXCIYkmxO5C69h417foXX+kPHGG1aZRFt6hdfQg4n/ooQ8EqULC/UGSjHEcb3rRPmyUdWsMGTCfhZ83Jup3YFp8nvfusBVhODIAqPenOsYuNxUD8bXufDzuA1Y/kX51awRlW/vo729CoxG6EO4X0H8YtcbWkjxXjZSGXDLlHfX3RNYmmcMkIX8aEqsZ9V1Xm5mgNnpbt2zwH/QfwCMTEA6ZCf6eNczDRdrXukEs665Ei3rykmTVihG69gDYQDyOZem0p18LLTEKhpw0XzvC5Q== 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: List-Subscribe: List-Unsubscribe: Implementation of MIGRC mechanism that stands for 'Migration Read Copy'. We always face the migration overhead at either promotion or demotion, while working with tiered memory e.g. CXL memory and found out TLB shootdown is a quite big one that is needed to get rid of if possible. Fortunately, TLB flush can be defered if both source and destination of folios during migration are kept until all TLB flushes required will have been done, of course, only if the target PTE entries have read-only permission, more precisely speaking, don't have write permission. Otherwise, no doubt the folio might get messed up. To achieve that: 1. For the folios that map only to non-writable TLB entries, prevent TLB flush at migration by keeping both source and destination folios, which will be handled later at a better time. 2. When any non-writable TLB entry changes to writable e.g. through fault handler, give up migrc mechanism so as to perform TLB flush required right away. The following evaluation using XSBench shows the improvement like: 1. itlb flush was reduced by 93.9%. 2. dtlb thread was reduced by 43.5%. 3. stlb flush was reduced by 24.9%. 4. dtlb store misses was reduced by 34.2%. 5. itlb load misses was reduced by 45.5%. 6. The runtime was reduced by 3.5%. --- The measurement result: Architecture - x86_64 QEMU - kvm enabled, host cpu Numa - 2 nodes (16 CPUs 1GB, no CPUs 8GB) Linux Kernel - v6.7, numa balancing tiering on, demotion enabled Benchmark - XSBench -p 100000000 (-p option makes the runtime longer) run 'perf stat' using events: 1) itlb.itlb_flush 2) tlb_flush.dtlb_thread 3) tlb_flush.stlb_any 4) dTLB-load-misses 5) dTLB-store-misses 6) iTLB-load-misses run 'cat /proc/vmstat' and pick: 1) numa_pages_migrated 2) pgmigrate_success 3) nr_tlb_remote_flush 4) nr_tlb_remote_flush_received 5) nr_tlb_local_flush_all 6) nr_tlb_local_flush_one BEFORE - mainline v6.7 ---------------------- $ perf stat -a \ -e itlb.itlb_flush \ -e tlb_flush.dtlb_thread \ -e tlb_flush.stlb_any \ -e dTLB-load-misses \ -e dTLB-store-misses \ -e iTLB-load-misses \ ./XSBench -p 100000000 Performance counter stats for 'system wide': 85647229 itlb.itlb_flush 480981504 tlb_flush.dtlb_thread 323937200 tlb_flush.stlb_any 238381632579 dTLB-load-misses 601514255 dTLB-store-misses 2974157461 iTLB-load-misses 2252.883892112 seconds time elapsed $ cat /proc/vmstat ... numa_pages_migrated 12790664 pgmigrate_success 26835314 nr_tlb_remote_flush 3031412 nr_tlb_remote_flush_received 45234862 nr_tlb_local_flush_all 216584 nr_tlb_local_flush_one 740940 ... AFTER - mainline v6.7 + migrc ----------------------------- $ perf stat -a \ -e itlb.itlb_flush \ -e tlb_flush.dtlb_thread \ -e tlb_flush.stlb_any \ -e dTLB-load-misses \ -e dTLB-store-misses \ -e iTLB-load-misses \ ./XSBench -p 100000000 Performance counter stats for 'system wide': 5240261 itlb.itlb_flush 271581774 tlb_flush.dtlb_thread 243149389 tlb_flush.stlb_any 234502983364 dTLB-load-misses 395673680 dTLB-store-misses 1620215163 iTLB-load-misses 2172.283436287 seconds time elapsed $ cat /proc/vmstat ... numa_pages_migrated 14897064 pgmigrate_success 30825530 nr_tlb_remote_flush 198290 nr_tlb_remote_flush_received 2820156 nr_tlb_local_flush_all 92048 nr_tlb_local_flush_one 741401 ... Signed-off-by: Byungchul Park --- include/linux/mmzone.h | 7 ++ include/linux/sched.h | 8 ++ mm/internal.h | 53 ++++++++ mm/memory.c | 8 ++ mm/migrate.c | 271 +++++++++++++++++++++++++++++++++++++++-- mm/page_alloc.c | 11 +- mm/rmap.c | 12 +- 7 files changed, 358 insertions(+), 12 deletions(-) diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h index 9db36e197712..492111cd1176 100644 --- a/include/linux/mmzone.h +++ b/include/linux/mmzone.h @@ -1002,6 +1002,13 @@ struct zone { /* Zone statistics */ atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS]; atomic_long_t vm_numa_event[NR_VM_NUMA_EVENT_ITEMS]; + +#if defined(CONFIG_MIGRATION) && defined(CONFIG_ARCH_WANT_BATCHED_UNMAP_TLB_FLUSH) + /* + * the number of folios pending for TLB flush in the zone + */ + atomic_t migrc_pending_nr; +#endif } ____cacheline_internodealigned_in_smp; enum pgdat_flags { diff --git a/include/linux/sched.h b/include/linux/sched.h index 0317e7a65151..d8c285309a8f 100644 --- a/include/linux/sched.h +++ b/include/linux/sched.h @@ -1330,6 +1330,14 @@ struct task_struct { struct tlbflush_unmap_batch tlb_ubc; struct tlbflush_unmap_batch tlb_ubc_ro; +#if defined(CONFIG_MIGRATION) && defined(CONFIG_ARCH_WANT_BATCHED_UNMAP_TLB_FLUSH) + /* + * whether all the mappings of a folio during unmap are read-only + * so that migrc can work on the folio + */ + bool can_migrc; +#endif + /* Cache last used pipe for splice(): */ struct pipe_inode_info *splice_pipe; diff --git a/mm/internal.h b/mm/internal.h index 3be8fd5604e8..ab02cb8306e2 100644 --- a/mm/internal.h +++ b/mm/internal.h @@ -1284,4 +1284,57 @@ static inline void shrinker_debugfs_remove(struct dentry *debugfs_entry, } #endif /* CONFIG_SHRINKER_DEBUG */ +#if defined(CONFIG_MIGRATION) && defined(CONFIG_ARCH_WANT_BATCHED_UNMAP_TLB_FLUSH) +/* + * Reset the indicator indicating there are no writable mappings at the + * beginning of every rmap traverse for unmap. Migrc can work only when + * all the mappings are read-only. + */ +static inline void can_migrc_init(void) +{ + current->can_migrc = true; +} + +/* + * Mark the folio is not applicable to migrc, once it found a writble or + * dirty pte during rmap traverse for unmap. + */ +static inline void can_migrc_fail(void) +{ + current->can_migrc = false; +} + +/* + * Check if all the mappings are read-only and read-only mappings even + * exist. + */ +static inline bool can_migrc_test(void) +{ + return current->can_migrc && current->tlb_ubc_ro.flush_required; +} + +/* + * Return the number of folios pending TLB flush that have yet to get + * freed in the zone. + */ +static inline int migrc_pending_nr_in_zone(struct zone *z) +{ + return atomic_read(&z->migrc_pending_nr); +} + +/* + * Perform TLB flush needed and free the folios under migrc's control. + */ +bool migrc_flush_free_folios(void); +void migrc_flush_start(void); +void migrc_flush_end(struct tlbflush_unmap_batch *batch); +#else /* CONFIG_MIGRATION && CONFIG_ARCH_WANT_BATCHED_UNMAP_TLB_FLUSH */ +static inline void can_migrc_init(void) {} +static inline void can_migrc_fail(void) {} +static inline bool can_migrc_test(void) { return false; } +static inline int migrc_pending_nr_in_zone(struct zone *z) { return 0; } +static inline bool migrc_flush_free_folios(void) { return false; } +static inline void migrc_flush_start(void) {} +static inline void migrc_flush_end(struct tlbflush_unmap_batch *batch) {} +#endif #endif /* __MM_INTERNAL_H */ diff --git a/mm/memory.c b/mm/memory.c index 6e0712d06cd4..e67de161da8b 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -3462,6 +3462,14 @@ static vm_fault_t do_wp_page(struct vm_fault *vmf) if (vmf->page) folio = page_folio(vmf->page); + /* + * The folio may or may not be one that is under migrc's control + * and about to change its permission from read-only to writable. + * Conservatively give up deferring TLB flush just in case. + */ + if (folio) + migrc_flush_free_folios(); + /* * Shared mapping: we are guaranteed to have VM_WRITE and * FAULT_FLAG_WRITE set at this point. diff --git a/mm/migrate.c b/mm/migrate.c index bbe1ecef4956..cbe5372f159e 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -57,6 +57,194 @@ #include "internal.h" +#ifdef CONFIG_ARCH_WANT_BATCHED_UNMAP_TLB_FLUSH +static struct tlbflush_unmap_batch migrc_ubc; +static LIST_HEAD(migrc_folios); +static DEFINE_SPINLOCK(migrc_lock); + +static void init_tlb_ubc(struct tlbflush_unmap_batch *ubc) +{ + arch_tlbbatch_clear(&ubc->arch); + ubc->flush_required = false; + ubc->writable = false; +} + +static void migrc_keep_folio(struct folio *f, struct list_head *h) +{ + list_move_tail(&f->lru, h); + folio_get(f); + atomic_inc(&folio_zone(f)->migrc_pending_nr); +} + +static void migrc_undo_folio(struct folio *f) +{ + list_del(&f->lru); + folio_put(f); + atomic_dec(&folio_zone(f)->migrc_pending_nr); +} + +static void migrc_release_folio(struct folio *f) +{ + folio_put_small_nopcp(f); + atomic_dec(&folio_zone(f)->migrc_pending_nr); +} + +/* + * Need to synchronize between TLB flush and managing pending CPUs in + * migrc_ubc. Take a look at the following scenario: + * + * CPU0 CPU1 + * ---- ---- + * TLB flush + * Unmap folios (needing TLB flush) + * Add pending CPUs to migrc_ubc + * Clear the CPUs from migrc_ubc + * + * The pending CPUs added in CPU1 should not be cleared from migrc_ubc + * in CPU0 because the TLB flush for migrc_ubc added in CPU1 has not + * been performed this turn. To avoid this, using 'migrc_flushing' + * variable, prevent adding pending CPUs to migrc_ubc and give up migrc + * mechanism if others are in the middle of TLB flush, like: + * + * CPU0 CPU1 + * ---- ---- + * migrc_flushing++ + * TLB flush + * Unmap folios (needing TLB flush) + * If migrc_flushing == 0: + * Add pending CPUs to migrc_ubc + * Else: <--- hit + * Give up migrc mechanism + * Clear the CPUs from migrc_ubc + * migrc_flush-- + * + * Only the following case would be allowed for migrc mechanism to work: + * + * CPU0 CPU1 + * ---- ---- + * Unmap folios (needing TLB flush) + * If migrc_flushing == 0: <--- hit + * Add pending CPUs to migrc_ubc + * Else: + * Give up migrc mechanism + * migrc_flushing++ + * TLB flush + * Clear the CPUs from migrc_ubc + * migrc_flush-- + */ +static int migrc_flushing; + +static bool migrc_add_pending_ubc(struct tlbflush_unmap_batch *ubc) +{ + struct tlbflush_unmap_batch *tlb_ubc = ¤t->tlb_ubc; + unsigned long flags; + + spin_lock_irqsave(&migrc_lock, flags); + if (migrc_flushing) { + spin_unlock_irqrestore(&migrc_lock, flags); + + /* + * Give up migrc mechanism. Just let TLB flush needed + * handled by try_to_unmap_flush() at the caller side. + */ + fold_ubc(tlb_ubc, ubc); + return false; + } + fold_ubc(&migrc_ubc, ubc); + spin_unlock_irqrestore(&migrc_lock, flags); + return true; +} + +static bool migrc_add_pending_folios(struct list_head *folios) +{ + unsigned long flags; + + spin_lock_irqsave(&migrc_lock, flags); + if (migrc_flushing) { + spin_unlock_irqrestore(&migrc_lock, flags); + + /* + * Give up migrc mechanism. The caller should perform + * TLB flush needed using migrc_flush_free_folios() and + * undo some on the folios e.g. restore folios' + * reference count increased by migrc and more. + */ + return false; + } + list_splice(folios, &migrc_folios); + spin_unlock_irqrestore(&migrc_lock, flags); + return true; +} + +void migrc_flush_start(void) +{ + unsigned long flags; + + spin_lock_irqsave(&migrc_lock, flags); + migrc_flushing++; + spin_unlock_irqrestore(&migrc_lock, flags); +} + +void migrc_flush_end(struct tlbflush_unmap_batch *batch) +{ + LIST_HEAD(folios); + struct folio *f, *f2; + unsigned long flags; + + spin_lock_irqsave(&migrc_lock, flags); + if (!arch_tlbbatch_done(&migrc_ubc.arch, &batch->arch)) { + list_splice_init(&migrc_folios, &folios); + migrc_ubc.flush_required = false; + migrc_ubc.writable = false; + } + migrc_flushing--; + spin_unlock_irqrestore(&migrc_lock, flags); + + list_for_each_entry_safe(f, f2, &folios, lru) + migrc_release_folio(f); +} + +bool migrc_flush_free_folios(void) +{ + struct tlbflush_unmap_batch *tlb_ubc = ¤t->tlb_ubc; + LIST_HEAD(folios); + struct folio *f, *f2; + unsigned long flags; + bool ret = true; + + spin_lock_irqsave(&migrc_lock, flags); + list_splice_init(&migrc_folios, &folios); + fold_ubc(tlb_ubc, &migrc_ubc); + spin_unlock_irqrestore(&migrc_lock, flags); + + if (list_empty(&folios)) + ret = false; + + try_to_unmap_flush(); + list_for_each_entry_safe(f, f2, &folios, lru) + migrc_release_folio(f); + return ret; +} +#else /* CONFIG_ARCH_WANT_BATCHED_UNMAP_TLB_FLUSH */ +static void init_tlb_ubc(struct tlbflush_unmap_batch *ubc) +{ +} +static void migrc_keep_folio(struct folio *f, struct list_head *h) +{ +} +static void migrc_undo_folio(struct folio *f) +{ +} +static bool migrc_add_pending_ubc(struct tlbflush_unmap_batch *ubc) +{ + return false; +} +static bool migrc_add_pending_folios(struct list_head *folios) +{ + return false; +} +#endif + bool isolate_movable_page(struct page *page, isolate_mode_t mode) { struct folio *folio = folio_get_nontail_page(page); @@ -1274,7 +1462,7 @@ static int migrate_folio_unmap(new_folio_t get_new_folio, static int migrate_folio_move(free_folio_t put_new_folio, unsigned long private, struct folio *src, struct folio *dst, enum migrate_mode mode, enum migrate_reason reason, - struct list_head *ret) + struct list_head *ret, struct list_head *move_succ) { int rc; int old_page_state = 0; @@ -1321,9 +1509,13 @@ static int migrate_folio_move(free_folio_t put_new_folio, unsigned long private, /* * A folio that has been migrated has all references removed - * and will be freed. + * and will be freed, unless it's under migrc's control. */ - list_del(&src->lru); + if (move_succ) + migrc_keep_folio(src, move_succ); + else + list_del(&src->lru); + /* Drop an anon_vma reference if we took one */ if (anon_vma) put_anon_vma(anon_vma); @@ -1618,7 +1810,7 @@ static void migrate_folios_move(struct list_head *src_folios, struct list_head *ret_folios, struct migrate_pages_stats *stats, int *retry, int *thp_retry, int *nr_failed, - int *nr_retry_pages) + int *nr_retry_pages, struct list_head *move_succ) { struct folio *folio, *folio2, *dst, *dst2; bool is_thp; @@ -1635,7 +1827,7 @@ static void migrate_folios_move(struct list_head *src_folios, rc = migrate_folio_move(put_new_folio, private, folio, dst, mode, - reason, ret_folios); + reason, ret_folios, move_succ); /* * The rules are: * Success: folio will be freed @@ -1712,17 +1904,34 @@ static int migrate_pages_batch(struct list_head *from, int rc, rc_saved = 0, nr_pages; LIST_HEAD(unmap_folios); LIST_HEAD(dst_folios); + LIST_HEAD(unmap_folios_migrc); + LIST_HEAD(dst_folios_migrc); + LIST_HEAD(move_succ); bool nosplit = (reason == MR_NUMA_MISPLACED); + struct tlbflush_unmap_batch pending_ubc; + struct tlbflush_unmap_batch *tlb_ubc = ¤t->tlb_ubc; + struct tlbflush_unmap_batch *tlb_ubc_ro = ¤t->tlb_ubc_ro; + bool do_migrc; + bool migrc_ubc_succ; VM_WARN_ON_ONCE(mode != MIGRATE_ASYNC && !list_empty(from) && !list_is_singular(from)); + /* + * Apply migrc only to numa migration for now. + */ + init_tlb_ubc(&pending_ubc); + do_migrc = IS_ENABLED(CONFIG_ARCH_WANT_BATCHED_UNMAP_TLB_FLUSH) && + (reason == MR_DEMOTION || reason == MR_NUMA_MISPLACED); + for (pass = 0; pass < nr_pass && retry; pass++) { retry = 0; thp_retry = 0; nr_retry_pages = 0; list_for_each_entry_safe(folio, folio2, from, lru) { + bool can_migrc; + is_large = folio_test_large(folio); is_thp = is_large && folio_test_pmd_mappable(folio); nr_pages = folio_nr_pages(folio); @@ -1752,9 +1961,12 @@ static int migrate_pages_batch(struct list_head *from, continue; } + can_migrc_init(); rc = migrate_folio_unmap(get_new_folio, put_new_folio, private, folio, &dst, mode, reason, ret_folios); + can_migrc = do_migrc && can_migrc_test() && !is_large; + /* * The rules are: * Success: folio will be freed @@ -1800,7 +2012,8 @@ static int migrate_pages_batch(struct list_head *from, /* nr_failed isn't updated for not used */ stats->nr_thp_failed += thp_retry; rc_saved = rc; - if (list_empty(&unmap_folios)) + if (list_empty(&unmap_folios) && + list_empty(&unmap_folios_migrc)) goto out; else goto move; @@ -1814,8 +2027,19 @@ static int migrate_pages_batch(struct list_head *from, stats->nr_thp_succeeded += is_thp; break; case MIGRATEPAGE_UNMAP: - list_move_tail(&folio->lru, &unmap_folios); - list_add_tail(&dst->lru, &dst_folios); + if (can_migrc) { + list_move_tail(&folio->lru, &unmap_folios_migrc); + list_add_tail(&dst->lru, &dst_folios_migrc); + + /* + * Gather ro batch data to add + * to migrc_ubc after unmap. + */ + fold_ubc(&pending_ubc, tlb_ubc_ro); + } else { + list_move_tail(&folio->lru, &unmap_folios); + list_add_tail(&dst->lru, &dst_folios); + } break; default: /* @@ -1829,12 +2053,19 @@ static int migrate_pages_batch(struct list_head *from, stats->nr_failed_pages += nr_pages; break; } + /* + * Done with the current folio. Fold the ro + * batch data gathered, to the normal batch. + */ + fold_ubc(tlb_ubc, tlb_ubc_ro); } } nr_failed += retry; stats->nr_thp_failed += thp_retry; stats->nr_failed_pages += nr_retry_pages; move: + /* Should be before try_to_unmap_flush() */ + migrc_ubc_succ = do_migrc && migrc_add_pending_ubc(&pending_ubc); /* Flush TLBs for all unmapped folios */ try_to_unmap_flush(); @@ -1848,7 +2079,27 @@ static int migrate_pages_batch(struct list_head *from, migrate_folios_move(&unmap_folios, &dst_folios, put_new_folio, private, mode, reason, ret_folios, stats, &retry, &thp_retry, - &nr_failed, &nr_retry_pages); + &nr_failed, &nr_retry_pages, NULL); + migrate_folios_move(&unmap_folios_migrc, &dst_folios_migrc, + put_new_folio, private, mode, reason, + ret_folios, stats, &retry, &thp_retry, + &nr_failed, &nr_retry_pages, migrc_ubc_succ ? + &move_succ : NULL); + } + + /* + * In case that migrc_add_pending_ubc() has been added + * successfully but migrc_add_pending_folios() does not. + */ + if (migrc_ubc_succ && !migrc_add_pending_folios(&move_succ)) { + migrc_flush_free_folios(); + + /* + * Undo src folios that have been successfully added to + * move_succ. + */ + list_for_each_entry_safe(folio, folio2, &move_succ, lru) + migrc_undo_folio(folio); } nr_failed += retry; stats->nr_thp_failed += thp_retry; @@ -1859,6 +2110,8 @@ static int migrate_pages_batch(struct list_head *from, /* Cleanup remaining folios */ migrate_folios_undo(&unmap_folios, &dst_folios, put_new_folio, private, ret_folios); + migrate_folios_undo(&unmap_folios_migrc, &dst_folios_migrc, + put_new_folio, private, ret_folios); return rc; } diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 21b8c8cd1673..6ef0c22b1109 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -2972,6 +2972,8 @@ bool __zone_watermark_ok(struct zone *z, unsigned int order, unsigned long mark, long min = mark; int o; + free_pages += migrc_pending_nr_in_zone(z); + /* free_pages may go negative - that's OK */ free_pages -= __zone_watermark_unusable_free(z, order, alloc_flags); @@ -3066,7 +3068,7 @@ static inline bool zone_watermark_fast(struct zone *z, unsigned int order, long usable_free; long reserved; - usable_free = free_pages; + usable_free = free_pages + migrc_pending_nr_in_zone(z); reserved = __zone_watermark_unusable_free(z, 0, alloc_flags); /* reserved may over estimate high-atomic reserves. */ @@ -3273,6 +3275,13 @@ get_page_from_freelist(gfp_t gfp_mask, unsigned int order, int alloc_flags, gfp_mask)) { int ret; + if (migrc_pending_nr_in_zone(zone) && + migrc_flush_free_folios() && + zone_watermark_fast(zone, order, mark, + ac->highest_zoneidx, + alloc_flags, gfp_mask)) + goto try_this_zone; + if (has_unaccepted_memory()) { if (try_to_accept_memory(zone, order)) goto try_this_zone; diff --git a/mm/rmap.c b/mm/rmap.c index b484d659d0c1..39ab0d64665a 100644 --- a/mm/rmap.c +++ b/mm/rmap.c @@ -642,7 +642,9 @@ void try_to_unmap_flush(void) if (!tlb_ubc->flush_required) return; + migrc_flush_start(); arch_tlbbatch_flush(&tlb_ubc->arch); + migrc_flush_end(tlb_ubc); arch_tlbbatch_clear(&tlb_ubc->arch); tlb_ubc->flush_required = false; tlb_ubc->writable = false; @@ -677,9 +679,15 @@ static void set_tlb_ubc_flush_pending(struct mm_struct *mm, pte_t pteval, if (!pte_accessible(mm, pteval)) return; - if (pte_write(pteval) || writable) + if (pte_write(pteval) || writable) { tlb_ubc = ¤t->tlb_ubc; - else + + /* + * Migrc cannot work with the folio, once it found a + * writable or dirty mapping on it. + */ + can_migrc_fail(); + } else tlb_ubc = ¤t->tlb_ubc_ro; arch_tlbbatch_add_pending(&tlb_ubc->arch, mm, uaddr); From patchwork Mon Feb 19 06:04:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Byungchul Park X-Patchwork-Id: 13562186 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 097F7C5475B for ; Mon, 19 Feb 2024 06:04:40 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 56C038D0005; Mon, 19 Feb 2024 01:04:30 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 51CDA8D0003; Mon, 19 Feb 2024 01:04:30 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 124918D0005; Mon, 19 Feb 2024 01:04:30 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id EC22E8D0006 for ; Mon, 19 Feb 2024 01:04:29 -0500 (EST) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id C35841201D7 for ; Mon, 19 Feb 2024 06:04:29 +0000 (UTC) X-FDA: 81807513858.20.EECE552 Received: from invmail4.hynix.com (exvmail4.hynix.com [166.125.252.92]) by imf05.hostedemail.com (Postfix) with ESMTP id DDEFD100008 for ; Mon, 19 Feb 2024 06:04:27 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=none; spf=pass (imf05.hostedemail.com: domain of byungchul@sk.com designates 166.125.252.92 as permitted sender) smtp.mailfrom=byungchul@sk.com; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1708322668; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:content-type: content-transfer-encoding:in-reply-to:in-reply-to: references:references; bh=z8N3K7cEzP29wp8OmV1x4SKhsG69RUNKzzZ3XrSlbEU=; b=cDd2MseRTLyC9jNvJ/Xx6nPeHwgQ59D4NOXREsXsYMsSU21M+1ZkPG4Em0qFH8VL8tWSQp C9Sfm53JYaHdICDIrlWQdj9X45T3Ruy+y2AtYMuZEPVn5e0/kiFuo+Nak2PRk6Q8BeB6wX ZF95DeoaZt7rjWnUQMne9xUqdnk79vg= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1708322668; a=rsa-sha256; cv=none; b=iJzjDC+1DnSz0ZZB9Z3qh1HRKUqhjfA60NFk9gQ7RaljZF+a29cdltNAu75P4Kml5hCr3y yofAXxYVVN/leR9fd3fWrp02QLAnI7skE40iRGL1CVuFfZY29XlzETBak0q2/fz/QBsliV CHMo8w85vqpgmSnH0Z/l5K+fWIQon4k= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=none; spf=pass (imf05.hostedemail.com: domain of byungchul@sk.com designates 166.125.252.92 as permitted sender) smtp.mailfrom=byungchul@sk.com; dmarc=none X-AuditID: a67dfc5b-d6dff70000001748-e1-65d2ef629e08 From: Byungchul Park To: linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: kernel_team@skhynix.com, akpm@linux-foundation.org, ying.huang@intel.com, namit@vmware.com, vernhao@tencent.com, mgorman@techsingularity.net, hughd@google.com, willy@infradead.org, david@redhat.com, peterz@infradead.org, luto@kernel.org, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, rjgolo@gmail.com Subject: [PATCH v8 8/8] mm: Pause migrc mechanism at high memory pressure Date: Mon, 19 Feb 2024 15:04:07 +0900 Message-Id: <20240219060407.25254-9-byungchul@sk.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240219060407.25254-1-byungchul@sk.com> References: <20240219060407.25254-1-byungchul@sk.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrHLMWRmVeSWpSXmKPExsXC9ZZnkW7S+0upBlOOc1rMWb+GzeLzhn9s Fi82tDNafF3/i9ni6ac+FovLu+awWdxb85/V4vyutawWO5buY7K4dGABk8X1XQ8ZLY73HmCy mH/vM5vF5k1TmS2OT5nKaPH7B1DHyVmTWRwEPb639rF47Jx1l91jwaZSj80rtDwW73nJ5LFp VSebx6ZPk9g93p07x+5xYsZvFo95JwM93u+7yuax9ZedR+PUa2wenzfJebyb/5YtgD+KyyYl NSezLLVI3y6BK6Or7T9bwVSVit+brBoY98t2MXJySAiYSLx6e5Adxn45exeYzSagLnHjxk9m EFtEwEziYOsfoDgXB7PARyaJ1d87WEASwgKeEnNn3wBKcHCwCKhKtPRbgIR5BUwlOjZfZ4KY KS+xesMBZpASTqA5uw8KgYSFgEpOXJ3MBDJSQuA/m8ShN7uYIeolJQ6uuMEygZF3ASPDKkah zLyy3MTMHBO9jMq8zAq95PzcTYzAWFhW+yd6B+OnC8GHGAU4GJV4eDNELqUKsSaWFVfmHmKU 4GBWEuF1b7qQKsSbklhZlVqUH19UmpNafIhRmoNFSZzX6Ft5ipBAemJJanZqakFqEUyWiYNT qoFx4R97/cSKU/zXXhgsmuN7Xom/Jcj/xTMZlzLvnVYuR8rE9T88kfVIS1HIuxrjH/z6AK9X s7DOphfLU70CGTXPaU4+WeeeFzX7++1ZLge4Ll6NNDm9xPAQt75V+zk+N+E6jWPHBJsqWH9Z SU7VvOigPPnnrf2RlZ9V3q2Z2HZZhOvW0xp3RXElluKMREMt5qLiRACIIbCQgQIAAA== X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrKLMWRmVeSWpSXmKPExsXC5WfdrJv4/lKqwcVmU4s569ewWXze8I/N 4sWGdkaLr+t/MVs8/dTHYnF47klWi8u75rBZ3Fvzn9Xi/K61rBY7lu5jsrh0YAGTxfVdDxkt jvceYLKYf+8zm8XmTVOZLY5Pmcpo8fsHUMfJWZNZHIQ8vrf2sXjsnHWX3WPBplKPzSu0PBbv ecnksWlVJ5vHpk+T2D3enTvH7nFixm8Wj3knAz3e77vK5rH4xQcmj62/7Dwap15j8/i8Sc7j 3fy3bAECUVw2Kak5mWWpRfp2CVwZXW3/2QqmqlT83mTVwLhftouRk0NCwETi5exd7CA2m4C6 xI0bP5lBbBEBM4mDrX+A4lwczAIfmSRWf+9gAUkIC3hKzJ19AyjBwcEioCrR0m8BEuYVMJXo 2HydCWKmvMTqDQeYQUo4gebsPigEEhYCKjlxdTLTBEauBYwMqxhFMvPKchMzc0z1irMzKvMy K/SS83M3MQIDe1ntn4k7GL9cdj/EKMDBqMTDmyFyKVWINbGsuDL3EKMEB7OSCK9704VUId6U xMqq1KL8+KLSnNTiQ4zSHCxK4rxe4akJQgLpiSWp2ampBalFMFkmDk6pBsa+qN/cuR+ZJxic q9auf2XEox5edC9pU3qJ7r87F+Lf/zBlkdu5rNZgSn74i1tHZ6ekWUv4Cd+zOuTPNvGstnnv ZnNGq5yIbCONxTrJLKW9SVtqfAN2rAted3qPQ0GKXU0Be7GD92GJfLPzt105PjzdrfWaXe1L QdvCPX9TVBYLHv+ntOKlthJLcUaioRZzUXEiALbAftxoAgAA X-CFilter-Loop: Reflected X-Stat-Signature: 3xinhcozxwf9rbkhbrjb8ea6g7it19jt X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: DDEFD100008 X-Rspam-User: X-HE-Tag: 1708322667-332064 X-HE-Meta: U2FsdGVkX1/zmtN1QHjCzMkeTmn3zXN0yLnQn0fEQsndXTiqQemX7fmlIi7FFoEwRmj1AuyiUAAthi88sbi6tku1OOguAuuGOxfhD4fZqTPqweix3/1wzKiKwXM66Umq/w0UfkiP+3htC/tzebBZ+lXqe4kAbmX7x9tSKO8OTB8RtRASS2zBBQxd2qJswrw18/NsvlAqTE79jZeVBF/JXNXXH3CXD4PPsDGI0QZ/k237p9dSZmeNyn5/pOZyha23xMB2CcuGbX1CyeYmIXWkRPA/o6nwlRxmbfqE5BqJ9nBuoU9yKttdKV9GZMpYslaamYSfKY4XZ44+oRTvHUxvw6BcOm7/1Iotg1yHS+0lqPMM0kKw+IXYPZppb6cWp2Hpk9kz/2SjDK5VGmGlDnIMP93O3447oNh/MytN5bfeCuvl0f6EiuKdRXeqX9af1vcMUFWou+sl3LBh//UY5HUebPDjGqsOPXIXlaltt3hfMnHDky2LU1GcBjlMIHBMQ75SPYxI/gPL8PNYn0FiqMXqsAWehwGvQd6iqWTjP/bVW/1J7+1ZJZEyi7+Pn9Vcmx6MNdrENVwIzZ1YTX75vnx48PWZKjge86SOqUJoeY19je/gJf4oZJ21UQZDto6FR/DmBNVn2/PYfa+yeehO2EnObBwZeOAMT9m27s+OSTGmynezK/w5Iyah8gHV+abCz6VlDJ15668kzzbjSTyHE8z8deJ1AQLSOijzi+1GZimwwguYrjKCP9dtpru6uSo1PlobJ1vGNwF44PA/CyvSqdL1MNW2SVm5m4HnS0bKQ8TajKwprhcfOFvMOjGLOJ5BU1LyyYksuqIEnCHvUx0N1nTit+vgVwalErJMbbHGBMWQixN2z0jIKdGIhK8xiIyXixeqR5RdBpqpX+SWbfu6GoadUE9P0Li2EcXhJWgZ+a9fx6RReZJ4BtZLI27YX9iLqAtSQcQsDlwDouCD7v+YvWJ u1Q== 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: List-Subscribe: List-Unsubscribe: Regression was observed when the system is in high memory pressure with swap on, where migrc might keep a number of folios in its pending queue, which possibly makes it worse. So temporarily prevented migrc from working on that condition. Signed-off-by: Byungchul Park --- mm/internal.h | 20 ++++++++++++++++++++ mm/migrate.c | 18 +++++++++++++++++- mm/page_alloc.c | 13 +++++++++++++ 3 files changed, 50 insertions(+), 1 deletion(-) diff --git a/mm/internal.h b/mm/internal.h index ab02cb8306e2..55781f879fb2 100644 --- a/mm/internal.h +++ b/mm/internal.h @@ -1285,6 +1285,8 @@ static inline void shrinker_debugfs_remove(struct dentry *debugfs_entry, #endif /* CONFIG_SHRINKER_DEBUG */ #if defined(CONFIG_MIGRATION) && defined(CONFIG_ARCH_WANT_BATCHED_UNMAP_TLB_FLUSH) +extern atomic_t migrc_pause_cnt; + /* * Reset the indicator indicating there are no writable mappings at the * beginning of every rmap traverse for unmap. Migrc can work only when @@ -1313,6 +1315,21 @@ static inline bool can_migrc_test(void) return current->can_migrc && current->tlb_ubc_ro.flush_required; } +static inline void migrc_pause(void) +{ + atomic_inc(&migrc_pause_cnt); +} + +static inline void migrc_resume(void) +{ + atomic_dec(&migrc_pause_cnt); +} + +static inline bool migrc_paused(void) +{ + return !!atomic_read(&migrc_pause_cnt); +} + /* * Return the number of folios pending TLB flush that have yet to get * freed in the zone. @@ -1332,6 +1349,9 @@ void migrc_flush_end(struct tlbflush_unmap_batch *batch); static inline void can_migrc_init(void) {} static inline void can_migrc_fail(void) {} static inline bool can_migrc_test(void) { return false; } +static inline void migrc_pause(void) {} +static inline void migrc_resume(void) {} +static inline bool migrc_paused(void) { return false; } static inline int migrc_pending_nr_in_zone(struct zone *z) { return 0; } static inline bool migrc_flush_free_folios(void) { return false; } static inline void migrc_flush_start(void) {} diff --git a/mm/migrate.c b/mm/migrate.c index cbe5372f159e..fbc8586ed735 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -62,6 +62,12 @@ static struct tlbflush_unmap_batch migrc_ubc; static LIST_HEAD(migrc_folios); static DEFINE_SPINLOCK(migrc_lock); +/* + * Increase on entry of handling high memory pressure e.g. direct + * reclaim, decrease on the exit. See __alloc_pages_slowpath(). + */ +atomic_t migrc_pause_cnt = ATOMIC_INIT(0); + static void init_tlb_ubc(struct tlbflush_unmap_batch *ubc) { arch_tlbbatch_clear(&ubc->arch); @@ -1922,7 +1928,8 @@ static int migrate_pages_batch(struct list_head *from, */ init_tlb_ubc(&pending_ubc); do_migrc = IS_ENABLED(CONFIG_ARCH_WANT_BATCHED_UNMAP_TLB_FLUSH) && - (reason == MR_DEMOTION || reason == MR_NUMA_MISPLACED); + (reason == MR_DEMOTION || reason == MR_NUMA_MISPLACED) && + !migrc_paused(); for (pass = 0; pass < nr_pass && retry; pass++) { retry = 0; @@ -1961,6 +1968,15 @@ static int migrate_pages_batch(struct list_head *from, continue; } + /* + * In case that the system is in high memory + * pressure, give up migrc mechanism this turn. + */ + if (unlikely(do_migrc && migrc_paused())) { + fold_ubc(tlb_ubc, &pending_ubc); + do_migrc = false; + } + can_migrc_init(); rc = migrate_folio_unmap(get_new_folio, put_new_folio, private, folio, &dst, mode, reason, diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 6ef0c22b1109..366777afce7f 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -4072,6 +4072,7 @@ __alloc_pages_slowpath(gfp_t gfp_mask, unsigned int order, unsigned int cpuset_mems_cookie; unsigned int zonelist_iter_cookie; int reserve_flags; + bool migrc_paused = false; restart: compaction_retries = 0; @@ -4203,6 +4204,16 @@ __alloc_pages_slowpath(gfp_t gfp_mask, unsigned int order, if (page) goto got_pg; + /* + * The system is in very high memory pressure. Pause migrc from + * expanding its pending queue temporarily. + */ + if (!migrc_paused) { + migrc_pause(); + migrc_paused = true; + migrc_flush_free_folios(); + } + /* Caller is not willing to reclaim, we can't balance anything */ if (!can_direct_reclaim) goto nopage; @@ -4330,6 +4341,8 @@ __alloc_pages_slowpath(gfp_t gfp_mask, unsigned int order, warn_alloc(gfp_mask, ac->nodemask, "page allocation failure: order:%u", order); got_pg: + if (migrc_paused) + migrc_resume(); return page; }