From mboxrd@z Thu Jan 1 00:00:00 1970 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 C887AC47422 for ; Mon, 15 Jan 2024 08:20:10 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 36E826B0095; Mon, 15 Jan 2024 03:20:10 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 2CF166B0099; Mon, 15 Jan 2024 03:20:10 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0DE136B0095; Mon, 15 Jan 2024 03:20:10 -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 E6C756B0095 for ; Mon, 15 Jan 2024 03:20:09 -0500 (EST) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id BD4F380821 for ; Mon, 15 Jan 2024 08:20:09 +0000 (UTC) X-FDA: 81680847738.06.0F48A7C Received: from invmail4.hynix.com (exvmail4.skhynix.com [166.125.252.92]) by imf02.hostedemail.com (Postfix) with ESMTP id DE3BA80011 for ; Mon, 15 Jan 2024 08:20:07 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf02.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=1705306808; 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:references; bh=Hmwc+GcIPpP7pzuundLoC17RHpp/lrN58qEILN4zvYc=; b=DoF8d8HHtRYuObdKPfea/Mlc8u7CvC+MqmYVpwd0gMYPX+vLwZhFog9QfXYzDNM/ZE7UQd dPQpY/9hEcn7fZzc7JMAAmK1JzFpolm2p58wWeuOZlTY7SMEsezas2NiK4KofTwfaapZFB iIF7D+gwTyZGoqQpKyGvv7oqBQQ/XvE= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf02.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=1705306808; a=rsa-sha256; cv=none; b=MG1UVh+oQdTEHjXQm234Q4OQU0xq3+WYL1FkGGxkYE98wBN0VeT1X8G2cI6qaxW8Zc9g/S rRGprHhEfJ816ve0417BEJXPsPWjLFqqcNcAjJdG/FPuFsPKC40COM1sCinzuqQlt6NZhC d7ga2L9CurCGvmpycpg/K89PRiUoqGA= X-AuditID: a67dfc5b-d85ff70000001748-70-65a4eab4c743 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 v6 0/7] Reduce TLB flushes by 94% by improving folio migration Date: Mon, 15 Jan 2024 17:19:46 +0900 Message-Id: <20240115081953.2521-1-byungchul@sk.com> X-Mailer: git-send-email 2.17.1 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrBLMWRmVeSWpSXmKPExsXC9ZZnoe6WV0tSDWb857SYs34Nm8XnDf/Y LF5saGe0+Lr+F7PF0099LBaXd81hs7i35j+rxflda1ktdizdx2Rx6cACJovrux4yWhzvPcBk Mf/eZzaLzZumMlscnzKV0eL3D6COk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ejUIoBCQgEECUY9vjKBYoBCQgN EDQYmoj4AooBCQgYEB8Yq7DAA5ABCKABAKoBFGludm1haWw1LnNraHluaXguY29tsgEGCgSm ffyRuAH000fCARAIASIMDfj9o2USBWF2c3ltwgEYCAMiFA173KRlEg1kYXl6ZXJvX3J1bGVz wgEbCAQiFw1KV2VgEhBnYXRla2VlcGVyX3J1bGVzwgECCAkagAFiNwb4xjxd+MxzjdvSwkot 7+UbekBkQPEOn2wwTJSVHR5J2E/cUfDXUIn3yI2bQzD+pKNSnd/5v+1ObvNjBakGkyqvzcsw XzbkQEsEeY0YffYH4O1FTtdLH0mP/4HqS8EAO9MV4O6R1uvmG4lfc29FufaOphfnuvOyMCW/ cgsQvCIEc2hhMSoDcnNhw3hrcVICAAA= X-CFilter-Loop: Reflected X-Rspamd-Queue-Id: DE3BA80011 X-Rspam-User: X-Rspamd-Server: rspam02 X-Stat-Signature: nf8xgygw6co6rp6cx3z1u8fwh8ko8s3d X-HE-Tag: 1705306807-766316 X-HE-Meta: U2FsdGVkX1/2ipphE20tvigOa4RCFQH9PKfum+gZGuY5c1gdtRVYJDl1J/jU2HqzEGeW+7/U7fAwI0x5sIVHRZpQuwLoXf3rI9MYLvfaO/6/cNrqPl3raOnVnDGrA8tQWRe0drHHnlQjnXL5nkghSENw1Cl5JSzoLaNXBCiD6SzZ90cXZJB+B/BWVoN/LR4o+XX95fBWMBxv8UAKbfqL8ESl0T7l9A6ryU8r2DEYBQbUPu2ygRxE4iwQRj8//yiE1cuE3xQFEMH59NwTbfIaKmx+qYEMAF63dFmp0lidnUhoAi2NEMPGmdUJniM91hUo651SrkP5cRDYiRCtvQ5zOtP3WowGPfMNVjG9N3sc/NhuQNX4vTJPvwCdR33Afg166rVgKSNUn9ESAV2wBx8odNv8btoRiJMgzAcSy2DKuo5eZfmu5F8ZIY7IXTD4RhEXftreM7f5qmEIDXN/zdPhaZ2+yVK2+pnGSIqRXFrP61stSMnQJNTTYfRcAjwLgLj0B9JR1EDHJtx6OPPRKfkXRXnspyyXJoWzzijJU8VI80dLxfVWOcbGtMM7+XkzdpfI8iA+bwFFeEoxkix4D7eppr8dSP46Frs/2158g5IeIp8o/Zd5lW8FkBdt/fqrP5H582a15+gZkDriPlDlltt0lqzIVDKmOG37ncTUjd/xspNZQF4tYDA4Z83344gPEzMdjpJSA+wsfbSFpM7D/rTs4MQ+XEp6reUcvxPxBGive7wCz7P0BEl38QwunpSRWjSR08ZJGyr2AA0q9SDhWXBA1Lyc1kONLuaZ1kM2csLssbkoBuMHr0on1N9Apm2DOYg5FuVyf9JltW4jmTi8dL9qwfPG7f2HE3Z2cD7FSEAkPTyUlPMWksHhw+ZClDr7qzN3C0uDAQA2jjOCXj1ZxBOjLlnrknooMwmeviPRDk7w5HuJF96dVKV5Em5fcMkspqa/rqeGbQ4x90VCkoZffcq lbpPmo80 tlnPFpobjEEJ5dh+arEIYXACN5CAsH1pK0oADI3/xB+TYa0PXd1AurQSYlA== 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: I'm sorry for the spam-like consecutive posting. I introduced build errors in v5, in case of CONFIG_MIGRATION disabled or CONFIG_HWPOISON_INJECT moduled. I'm reposting the fixed version. --->8--- Hi everyone, While I'm working with CXL memory, I have been facing migration overhead esp. TLB shootdown on promotion or demotion between different tiers. Yeah.. most TLB shootdowns on migration through hinting fault can be avoided thanks to Huang Ying's work, commit 4d4b6d66db ("mm,unmap: avoid flushing TLB in batch if PTE is inaccessible"). See the following link: https://lore.kernel.org/lkml/20231115025755.GA29979@system.software.com/ However, it's only for ones using hinting fault. I thought it'd be much better if we have a general mechanism to reduce the number of TLB flushes and TLB misses, that we can apply to any type of migration. I tried it only for tiering migration for now tho. I'm suggesting a mechanism to reduce TLB flushes by keeping source and destination of folios participated in the migrations until all TLB flushes required are done, only if those folios are not mapped with write permission PTE entries at all. I worked Based on v6.7. I saw the number of iTLB full flush was reduced by 94%, iTLB miss was reduced by 45.5% and the total runtime was reduced by 3.5% with the workload I tested with, XSBench. However, I believe that it would help more with other ones or any real ones. It'd be appreciated to let me know if I'm missing something. Byungchul --- Changes from v5: 1. Fix build errors in case of CONFIG_MIGRATION disabled or CONFIG_HWPOISON_INJECT moduled. (feedbacked by kernel test bot and Raymond Jay Golo) 2. Organize migrc code with two kconfigs, CONFIG_MIGRATION and CONFIG_ARCH_WANT_BATCHED_UNMAP_TLB_FLUSH. Changes from v4: 1. Rebase on v6.7. 2. Fix build errors in arm64 that is doing nothing for TLB flush but has CONFIG_ARCH_WANT_BATCHED_UNMAP_TLB_FLUSH. (reported by kernel test robot) 3. Don't use any page flag. So the system would give up migrc mechanism more often but it's okay. The final improvement is good enough. 4. Instead, optimize full TLB flush(arch_tlbbatch_flush()) by avoiding redundant CPUs from TLB flush. Changes from v3: 1. Don't use the kconfig, CONFIG_MIGRC, and remove sysctl knob, migrc_enable. (feedbacked by Nadav) 2. Remove the optimization skipping CPUs that have already performed TLB flushes needed by any reason when performing TLB flushes by migrc because I can't tell the performance difference between w/ the optimization and w/o that. (feedbacked by Nadav) 3. Minimize arch-specific code. While at it, move all the migrc declarations and inline functions from include/linux/mm.h to mm/internal.h (feedbacked by Dave Hansen, Nadav) 4. Separate a part making migrc paused when the system is in high memory pressure to another patch. (feedbacked by Nadav) 5. Rename: a. arch_tlbbatch_clean() to arch_tlbbatch_clear(), b. tlb_ubc_nowr to tlb_ubc_ro, c. migrc_try_flush_free_folios() to migrc_flush_free_folios(), d. migrc_stop to migrc_pause. (feedbacked by Nadav) 6. Use ->lru list_head instead of introducing a new llist_head. (feedbacked by Nadav) 7. Use non-atomic operations of page-flag when it's safe. (feedbacked by Nadav) 8. Use stack instead of keeping a pointer of 'struct migrc_req' in struct task, which is for manipulating it locally. (feedbacked by Nadav) 9. Replace a lot of simple functions to inline functions placed in a header, mm/internal.h. (feedbacked by Nadav) 10. Add additional sufficient comments. (feedbacked by Nadav) 11. Remove a lot of wrapper functions. (feedbacked by Nadav) Changes from RFC v2: 1. Remove additional occupation in struct page. To do that, unioned with lru field for migrc's list and added a page flag. I know page flag is a thing that we don't like to add but no choice because migrc should distinguish folios under migrc's control from others. Instead, I force migrc to be used only on 64 bit system to mitigate you guys from getting angry. 2. Remove meaningless internal object allocator that I introduced to minimize impact onto the system. However, a ton of tests showed there was no difference. 3. Stop migrc from working when the system is in high memory pressure like about to perform direct reclaim. At the condition where the swap mechanism is heavily used, I found the system suffered from regression without this control. 4. Exclude folios that pte_dirty() == true from migrc's interest so that migrc can work simpler. 5. Combine several patches that work tightly coupled to one. 6. Add sufficient comments for better review. 7. Manage migrc's request in per-node manner (from globally). 8. Add TLB miss improvement in commit message. 9. Test with more CPUs(4 -> 16) to see bigger improvement. Changes from RFC: 1. Fix a bug triggered when a destination folio at the previous migration becomes a source folio at the next migration, before the folio gets handled properly so that the folio can play with another migration. There was inconsistency in the folio's state. Fixed it. 2. Split the patch set into more pieces so that the folks can review better. (Feedbacked by Nadav Amit) 3. Fix a wrong usage of barrier e.g. smp_mb__after_atomic(). (Feedbacked by Nadav Amit) 4. Tried to add sufficient comments to explain the patch set better. (Feedbacked by Nadav Amit) Byungchul Park (7): x86/tlb: Add APIs manipulating tlb batch's arch data arm64: tlbflush: Add APIs manipulating tlb batch's arch data mm/rmap: Recognize read-only TLB entries during batched TLB flush mm: Separate move/undo doing on folio list from migrate_pages_batch() mm: Add APIs to free a folio directly to the buddy bypassing pcp mm: Defer TLB flush by keeping both src and dst folios at migration mm: Pause migrc mechanism at high memory pressure arch/arm64/include/asm/tlbflush.h | 19 ++ arch/x86/include/asm/tlbflush.h | 18 ++ arch/x86/mm/tlb.c | 4 + include/linux/mm.h | 31 +++ include/linux/mmzone.h | 7 + include/linux/sched.h | 9 + mm/internal.h | 74 ++++++ mm/memory.c | 8 + mm/migrate.c | 411 ++++++++++++++++++++++++++---- mm/page_alloc.c | 34 ++- mm/rmap.c | 37 ++- mm/swap.c | 7 + 12 files changed, 602 insertions(+), 57 deletions(-) base-commit: 0dd3ee31125508cd67f7e7172247f05b7fd1753a -- 2.17.1