From patchwork Mon Feb 26 03:06:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Byungchul Park X-Patchwork-Id: 13571187 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 9B37DC47DD9 for ; Mon, 26 Feb 2024 03:06:37 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A796D6B0146; Sun, 25 Feb 2024 22:06:33 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id A29676B0148; Sun, 25 Feb 2024 22:06:33 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8C83B6B0149; Sun, 25 Feb 2024 22:06:33 -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 70D916B0146 for ; Sun, 25 Feb 2024 22:06:33 -0500 (EST) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 4C784C06C6 for ; Mon, 26 Feb 2024 03:06:33 +0000 (UTC) X-FDA: 81832467066.23.2885B32 Received: from invmail4.hynix.com (exvmail4.skhynix.com [166.125.252.92]) by imf01.hostedemail.com (Postfix) with ESMTP id 8A98340005 for ; Mon, 26 Feb 2024 03:06:31 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=none; spf=pass (imf01.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=1708916791; 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=HPy/9qEA10DFpzl9azLs/Q1QCYJ178mgmdZA6S8Fw+fp90RykPA2SOjHQkdtZYXMxbNrk+ peGVTqncBE+LeESnI4xvb7JV/1QAdwwcpfBK5F6h411sJt+wpWUkg/qO6Et7xOW2EsuzYx gwbfVWPjxYgEQgkSB/cUa9Pjc9Xwk+o= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1708916791; a=rsa-sha256; cv=none; b=bi/aQrX6VmhZm+1p9+g56rBn4YD5SKwFx1Wjlkdn6r+4da8q2LdmnonIr/sVbOHSxez5ZS 7QUxs9ONFf+rXQK9rISarSj60m0pBx6ExhcNGeQSTpE9qirw2iZwvJoSXbXr8nD14x/ugw te9XDLf2x3ZJL9zet2K5F1HdjGC746w= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=none; spf=pass (imf01.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-32-65dc002f6be1 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, 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: [RESEND PATCH v8 3/8] mm/rmap: Recognize read-only TLB entries during batched TLB flush Date: Mon, 26 Feb 2024 12:06:08 +0900 Message-Id: <20240226030613.22366-4-byungchul@sk.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240226030613.22366-1-byungchul@sk.com> References: <20240226030613.22366-1-byungchul@sk.com> X-Brightmail-Tracker: H4sIAAAAAA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ErvHu3Pn2D1OzPjN4jHvZKDH+31X2TwWv/jA5LH1l51H49RrbB6fN8kF8Edx2aSk 5mSWpRbp2yVwZXyd51RwXLriw6cdjA2MD8S6GDk5JARMJM68/M0IYrMJqEvcuPGTGcQWETCT ONj6hx3EZha4yyRxoJ8NxBYWSJB4OG0eE4jNIqAqcfgMRD2vgKnE4QkLWSFmykus3nAAKM7B wQk05/1/Q5CwEFDJ396rjBMYuRYwMqxiFMnMK8tNzMwx1SvOzqjMy6zQS87P3cQIDOJltX8m 7mD8ctn9EKMAB6MSD++CD7dThVgTy4orcw8xSnAwK4nwhsvcTBXiTUmsrEotyo8vKs1JLT7E KM3BoiTO6xWemiAkkJ5YkpqdmlqQWgSTZeLglGpgDLfQf3L+fFbP6oyusxLzttvzPdJcJr97 ScDHgA/qEcmONkwr7/z9cOH7/fm1pZfvz/sgFbvYeTG3S/t1QbmXp82FA56ceN7pYWzxU3fH /6YgsQkdSlmvwkVXvJ8iMtPoStaDkj7+locqHgmzLln5O58/HNJVepZVq0Q2YNnvJ8/cDc5M Wqv7U4mlOCPRUIu5qDgRANgmFc1eAgAA X-CFilter-Loop: Reflected X-Rspamd-Queue-Id: 8A98340005 X-Rspam-User: X-Stat-Signature: s198urannygcrkrjb5m7386k4hetu7ns X-Rspamd-Server: rspam03 X-HE-Tag: 1708916791-520159 X-HE-Meta: U2FsdGVkX1+ymFloTNiKXCkYvn8QftL//Xq6KrYHg6Hm+oW/IN1vEBoG65HT/mvuubf1lC6m5pdMzrMuf8qHenZlMTOk4GDiAl2f77FgFG7BsoOwN4HsRy4wRwVh+n9Qo2GFiqsjJf3chgYOwz0WJmpv9+G0wmqBmoph4hpFrgPyJN8jXcpiNJ3YzJ42mjJJs6nb4UYxGIQWdNI1+D6TRQXGLq0udCOhe0k3esJLNaTk+/S/TRpVwB36DomggfFpOvasDcchIpg4vAPuWxF0wR6S5B2Wy/PQZPKxoHuvOTFazsJkvcJ+p/FFoLL+dstqKqu6WrXylJptSPNDdMji5MZ/q9Ajv0GN5PDHuqTZtbiv3GYl0UX19M9BrHwIf9lVNG4CfJ8RLSqSTqc++PkxKWqJmeUgNVirqT4ODl+aHjTmoSQ3Zh2cJbinztuKebWPAKMT2rXOskFPhOYrX0Y69oi0N71hhmSFbE6ExnTVxwIx5NGfsx+tC5T1g3eLrrkLMI6iGq/x+tNT6chYUI6AUcKiTElGrJzAqmx8kEpBvEVsG93vrtVJTuNzY8GHCxFRQPJvb0yA135bDC3SfQHXUMUfSJgmLvgjIBya/708nHYPUwp/TS6jCS2rg4Xj7jRI36UggVejKONkwIGzWfYbxbLXfb5DxPtpNngi1HzeNvjpAbnTx5l5gowNEREOgY9l4cjtpFLkda5FArJMEcrfgg== 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;