From patchwork Thu Feb 8 06:26: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: 13549357 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 62286C48260 for ; Thu, 8 Feb 2024 06:26:34 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1FBA66B009B; Thu, 8 Feb 2024 01:26:29 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id E2A1D6B009F; Thu, 8 Feb 2024 01:26:28 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C075D6B00A1; Thu, 8 Feb 2024 01:26:28 -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 8515C6B009E for ; Thu, 8 Feb 2024 01:26:28 -0500 (EST) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 45857C05C8 for ; Thu, 8 Feb 2024 06:26:28 +0000 (UTC) X-FDA: 81767652456.16.5E813D3 Received: from invmail4.hynix.com (exvmail4.skhynix.com [166.125.252.92]) by imf14.hostedemail.com (Postfix) with ESMTP id 5ADAB100010 for ; Thu, 8 Feb 2024 06:26:26 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=none; spf=pass (imf14.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=1707373586; 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=DJ3TTM3rHo7I5Ww6MPomCAfqZ46zBppxmjTTrmrNClNgy5gRVJ2azWPNdgF4hl1OLHKdi1 RoT1qBiizXr8fX5Yh0bfwFlweJJLOrxe7lfqwsNAeeEDKc3zCJNNBjMaij0Qu/11bHMbnp b17O4vZsMmy5qYe3zf9CiyGVnVP165k= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1707373586; a=rsa-sha256; cv=none; b=6rPDurBOPGHOmhiMC/0Al1S3loCFDjkqYXVpg48EdCI02x9UdHhL9Djt8B4wi9NUQg1qgb OuZxqnH83Q70eYPRY5cXTOsF4CZumqghFGaSQIpvgdlWMHncCS07iNC/FTmZlVwL06SyfC /Y7nspsQNOE+UTguWkTINTFLyjNnzTA= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=none; spf=pass (imf14.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-d85ff70000001748-7d-65c4740bc993 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: [RESEND PATCH v7 3/8] mm/rmap: Recognize read-only TLB entries during batched TLB flush Date: Thu, 8 Feb 2024 15:26:03 +0900 Message-Id: <20240208062608.44351-4-byungchul@sk.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240208062608.44351-1-byungchul@sk.com> References: <20240208062608.44351-1-byungchul@sk.com> X-Brightmail-Tracker: H4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plKPzSu0PBbv ecnksWlVJ5vHpk+T2D3enTvH7nFixm8Wj3knAz3e77vK5rH4xQcmj62/7Dwap15j8/i8Sc7j 3fy3bAECUVw2Kak5mWWpRfp2CVwZX+c5FRyXrvjwaQdjA+MDsS5GTg4JAROJnt9TGUFsNgF1 iRs3fjKD2CICZhIHW/+wdzFycTALfGSSWP29gwUkISyQINF/ZiEriM0ioCrR/KcDrJlXwFRi 7o6VjBBD5SVWbzgANogTaNDObafA6oWAal7Mnsw2gZFrASPDKkaRzLyy3MTMHFO94uyMyrzM Cr3k/NxNjMDgXlb7Z+IOxi+X3Q8xCnAwKvHwnig/nCrEmlhWXJl7iFGCg1lJhNdsx4FUId6U xMqq1KL8+KLSnNTiQ4zSHCxK4rxe4akJQgLpiSWp2ampBalFMFkmDk6pBsbT6Qs2PjP8zBge GnD61x6zpztS2dVYI/78MDKWPyPr0e73o/j8M9srfp8+2R5ee/PFGmZbs31Wwgsdznr/WiIf spbRtHRVS+M7d89Mn+bwqU9M7ex3fI70eij2oMR7bbU3R5PUlJvi3Bcy9nL9jG3xyUpr0FGe PZ/PNfi0/oxJHG86vXQbTZRYijMSDbWYi4oTAeOGLtNqAgAA X-CFilter-Loop: Reflected X-Stat-Signature: w3tgdht67w78ae5o5ffq4dpy8fgw1xxr X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: 5ADAB100010 X-Rspam-User: X-HE-Tag: 1707373586-920585 X-HE-Meta: U2FsdGVkX1+qYD/U8zRl7labyAfFk8sEZue76MtKt2ngBo+zQE2LJQUikoMRrdy5Y6db9lGqtlU9jgahLHjIFC/gWDVIr+u02C2xV78BTo2JNPWeqGkqsi65tXibErl8Kl+LcgdldNmFBNgotuaKtKUx6/MUPXj5VHpqaWelRtc+S5Ogtm6jfXnvYFIoXGmzIsU9Ym/EC2zNgo1m8ucxlkGIDxuYGbbEaPaItoFaz2kGV2hr3ebF+m6WG2rAWUsohc3vEsRWkJRVjc1nwZIzcDOXkaxZ1zLNckWBUFS0JuBh0aZhHnsKqX/zzqwJndPkJ9QnpKG/RC12b+5/2wbmCW8xH2g5gw/5q4Nrq0n4aUV62RwpVO2rQ9oqsJEBEYX53vT024IdcaQn/dzeFKzXoNvvges1+fKhbwOhTlbYcuf5ycBumIThS15vW5rJyRZR6nPmzwJ848WG+zbsk9fiof/L66KgsaFnx/81fdF/q9r516d1os2y4vC8DYplrAUjFX0Jmi0mNkykhc/wIQyZaAfUDbxyf5POI5uUXp1HbJU0OvKFcchrzZ78Cnn6dQc2pjGNT+9G9xw5sFsZmfWzjk8+vt+1eD5z4s/8qlReXHu9l1RfX5AC1jcH/EALZ3/ruQzgFmkLm9YAD8Be532a6b0jBNlWjrcmHS90tc7K8zsnfprbZA50t+MM3s9x6H7S5zBtHuSdZOt/cAzF3CLFEApYMx7h2AgIYgBTfkWLbC+CO8dYtb4DmW9cMQADGdT/ldxOo6D+CfxVN7gc47GVH9kR7FmToyzRY1S8T9FfWLnnU0WeZQgwwJVd446/l1A6a7XxZwYrhpZkbnjRQMtjsWWaUjniiuGe12/p/9ZBj5ZkMEincnxjtnqbsglnqLNL5Anr84kf3n2jzNlS2xeaHLEfpjH8p8xAlxc8u54wEktmFzRqIM8KsSJk4W5cPWdbvbb+sbI13tPLbBfovhZ Znw== 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;