From patchwork Mon Jan 15 08:19:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Byungchul Park X-Patchwork-Id: 13519382 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 2856FC47258 for ; Mon, 15 Jan 2024 08:20:15 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4CB136B0099; Mon, 15 Jan 2024 03:20:12 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 408176B009A; Mon, 15 Jan 2024 03:20:12 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 27FDE6B009B; Mon, 15 Jan 2024 03:20:12 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 187E66B0099 for ; Mon, 15 Jan 2024 03:20:12 -0500 (EST) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id DF497407FF for ; Mon, 15 Jan 2024 08:20:11 +0000 (UTC) X-FDA: 81680847822.25.F2B45CC Received: from invmail4.hynix.com (exvmail4.skhynix.com [166.125.252.92]) by imf02.hostedemail.com (Postfix) with ESMTP id 075F380011 for ; Mon, 15 Jan 2024 08:20:09 +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=1705306810; 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=u7GY04k7TA88lgkG872ExUI0fAlPeafJt1nrODFX7uXW+W0bwko6nvKiZcY6Okw9cudl4i qyz991gn6i+62Y5763GNRtsNApN0Uc+wZauBhXNzke02rY4Jemv3cxj9W+bIlf0vffLO2p 2COJ89QNGJhLi+ETmaDZsI0oyV9+XUw= 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=1705306810; a=rsa-sha256; cv=none; b=5QAwkGG20IaJmGyk3+y/9PSCV0GW6BEH7oHgk4FiGFIF+Plt+2k+6Ncwg3XZFvWiYYWvCy TooCF6g+qveUjJbQueMf/Zsq9mKXdMmfAYu8pDSF9ZXJ4EvrvkzGc9Mu4v3r56WaLvYCdQ hC11KPInhrLXAE0xC5VM0gobGsIsbSU= X-AuditID: a67dfc5b-d85ff70000001748-7f-65a4eab48a36 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 3/7] mm/rmap: Recognize read-only TLB entries during batched TLB flush Date: Mon, 15 Jan 2024 17:19:49 +0900 Message-Id: <20240115081953.2521-4-byungchul@sk.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240115081953.2521-1-byungchul@sk.com> References: <20240115081953.2521-1-byungchul@sk.com> X-Brightmail-Tracker: H4sIAAAAAAAAA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8msXu8O3eO3ePEjN8sHvNOBnq833eVzWPxiw9MHlt/2Xk0Tr3G5vF5k5zH u/lv2QIEorhsUlJzMstSi/TtErgyvs5zKjguXfHh0w7GBsYHYl2MnBwSAiYS146tYwSx2QTU JW7c+MkMYosImEkcbP3D3sXIxcEs8JFJYvX3DhaQhLBApETDir1gDSwCqhLHNr8Ba+AFGrRt 6wxWiKHyEqs3HACLcwqYSrz7eJwdxBYCqmm5u451AiPXAkaGVYwimXlluYmZOaZ6xdkZlXmZ FXrJ+bmbGIHBvaz2z8QdjF8uux9iFOBgVOLh/fF3caoQa2JZcWXuIUYJDmYlEd7qO0tShXhT EiurUovy44tKc1KLDzFKc7AoifN6hacmCAmkJ5akZqemFqQWwWSZODilGhgbr0o4HFm85Kfq gQu/F6bd3ZnyYU7heQ/jhRv+XX/i9v7Dyplc1+Z/TvJpuKbSkDZ5h9VL/718xgfjHHtifQ5k /o0IP6rZ99dde3+x3I05j08dDlsUkhimK2t0VpypRvMU37q+NBd37ZSGyGMPb7tXfjdXm3BL WPDfoRmnyy+5T75r/Gu++ywtJZbijERDLeai4kQAJQwUJmoCAAA= X-CFilter-Loop: Reflected X-Rspamd-Queue-Id: 075F380011 X-Rspam-User: X-Rspamd-Server: rspam02 X-Stat-Signature: burdypz3bhwru95wdjzcthpp68o9xktx X-HE-Tag: 1705306809-382790 X-HE-Meta: U2FsdGVkX19fg5chTQu5cn1Xg6Xi0RUyJy5tQe8IccFOFUAQp/8l0V7w6bjoH3aHJf1E8s5+xk83eT7xWgFnyOJfSQuO5wGdZ1+Qt0ky4Yf6h2+ZJS7gHK5MOKgLyeDAvolBK/uuvkDM29LwvWj2xq0fNniZwKaa7LN8oBtzsUmfKAzY6averYlNmlFn4jBe8dS6fjY0FBYYWJ6eGqDz2I2n3yBsO3GullzOhPNX4ZVH94Ihmc+QUdC+vrS9bg7TucOeioS80auPEwF8uyIacF5c6aNo4AG4TxDOoLoCYdeRoW0+tebeVRac6M9zyyZ+rSshZhh1Z4fBlJ52bt2IYT4inmr/tWbHsVvexQYEoplwrC23bT781dvWLxqLrwiqzidnjHIH7obpTRd48eadxDnrwGSePPDU3mvuF5hZrYNs59zJlZwa9pvBV/MDBnXKfv/RsgEfLIHi1zPOvhZH4tvK9ctYTCkDfnmUfhm3QaVt6EUcQtjgtGPzNInjccwh4WGtvRiAKDZ658wksTDcpUWMvgbhog7H8rmA5c8/62G6QgOe/0F+JA/BF5whKGJeBXwjicnTB2oCJu9js/xEjrfQ7h0wXzwSKXX0iWStO5QZSDdk02wQuuTxaVLeFfhsWuwHa1Ezt3fSw4DgAr0wCx78DzaEAG+Tb0XgfGQDLWhGblfRuNTUxWF6DxxgAlG3lVSZU1j1uPGqFMgZataLiCpUQYZjESKeGKq3aKSWX5VLPlMXRHM5UooMzPvMTxf3f37bnIVECNcvym+vnODdY5V6Y55/Sk0oTl0v89aMF4BJ+KIFE/SfbTx0HE2s+f95KNi8Z0IktkhJmrmyKkQ4Whyc1GHZYdvn4/ux3+KhDP9n3HoRa0u62D9PU4rV8DuiHDQGOnVQAy/ZQrJ6U0exP2TFsm1AGeiDumYgjorx4t99xVFu2MQ20jfGnqurmWrp3e66bRapoxjIHTaMyvE Hzg== 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;