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: H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BplKPzSu0PBbv 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;