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: 198188 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp2723212dyb; Wed, 7 Feb 2024 22:34:19 -0800 (PST) X-Google-Smtp-Source: AGHT+IHFxP+eJhXqcizM0vd/Ddv9oYN/jU4N07aMWCJUVsgzakvfGjgOgTtRUO8jRVu0bXY9ruDa X-Received: by 2002:a17:90a:69a7:b0:296:2035:a3c2 with SMTP id s36-20020a17090a69a700b002962035a3c2mr5194209pjj.36.1707374059804; Wed, 07 Feb 2024 22:34:19 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707374059; cv=pass; d=google.com; s=arc-20160816; b=L/rTyTs/xiLGpgUmLKT72T2CvnDOsC3cC63CtLSgKrdSJJkJIFjXLHgW9gbZKIk2iG Uiko9lD0oVrf3WDu7I9NLdP+HXIfb4RNqtL2eipiTBp74WxmybBvca4wfnczVcJQ+1pU bj9RkFQuM3nT3fCvMC5QEfuxlnr1EDj2tZx9lci0+nQQn4OT5ve2Qo8HS00AGcxkzjoF EYQ785z/z5taYYM2sJHd36r2mO/2qN8Zj1i9FZFhGHXhI5VqpljBzudaral7K+LacSmG 1d50LI4WNYdMRresU1Y/6qH5GI7F9krVJ8RpAkKQOmk6oToBWs19RgWHk6hn+PoN9pkp SbwQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-unsubscribe:list-subscribe:list-id:precedence:references :in-reply-to:message-id:date:subject:cc:to:from; bh=deHIYqkuaMMowWAwSsScVOmIndLCnwrqbZwxQiYz+QA=; fh=GNy1Kv/+EHwmxzfXFVoJLZzo4kNLgyzsw4hqhLBmTWU=; b=CLZ7rgF3V8ZvFG7o2SSN/GCnLvykn11g/wO50nLoLNFXkB7RSNQo4Y5DCHjPgRCTg6 zhePXVU+b44BcRhSn4iI2+JaQmsC1fnpBGSUpsjRQJNCeuXzixyfCdLc1vEqqXMkXtdP iYMrN/7CieNsh3BiOfw9DNFn9lD7oLNGcHUiwafp4hjfh3u4M4Vm8nHhm2dDAh8rujUc jYqVYC2l6y88m204DUYvi8cyI9BCu2FSLnxtdsesB0Q1Vb6bcSuB9SIcZ3GlBHKxVSW8 VNAdcuJENd8CWUiEGWLgcSAa5f1RsS1tgHvuvZDmMP4h7D/DG+u4luCbWA369xGkdiK4 ff+g==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=sk.com); spf=pass (google.com: domain of linux-kernel+bounces-57516-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-57516-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=2; AJvYcCVUn3gQgjDA0doOxtP6pGoB9H2zJfMNTf9bsYqZcoWGVkCZtAw064Cta6lHwfT9R8IFYShdzSTEqTXDYaWqijHaz7YD2A== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id fw4-20020a17090b128400b002969bca1b53si683136pjb.96.2024.02.07.22.34.19 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Feb 2024 22:34:19 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-57516-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=sk.com); spf=pass (google.com: domain of linux-kernel+bounces-57516-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-57516-ouuuleilei=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id D8E9F288AC0 for ; Thu, 8 Feb 2024 06:27:44 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9FF856A02C; Thu, 8 Feb 2024 06:26:31 +0000 (UTC) Received: from invmail4.hynix.com (exvmail4.hynix.com [166.125.252.92]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5C41967E63 for ; Thu, 8 Feb 2024 06:26:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=166.125.252.92 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707373589; cv=none; b=nb/ntcPThuvVqQW/mzTvIwqzETrKUmupoZKpKVLS9D0/JiQU5hRbAiKaEVm7iseuj57n7Y1dXJ+WZkqvEUX8SzffZDOJRM8D63Vi1/4ILLHVgMapH6U56znU8/1/d6BgKQqhsFTBM7nflQIe77ndcETdsjTAIml3SX2Cg7RMVKE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707373589; c=relaxed/simple; bh=WHuF8WryLfu8JX/60dlBPk8CVS136b4yvUfGBE1UZcQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References; b=OK3zgtJ3BccpqgH2HrGdDLM/PrumDhJ81/JmoGOz8Dyo7fz8kcyhxMXYB4ZD1C7VSmsk7bHADqhCCcrDPRDDCl3ne8gYxOjgR6+HO6fSsnmD880FA083zNki9ECPc9yZn9B0ZISCG4PBcfuC//HoWIPEbfIYS6UCvg7titiJzXM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=sk.com; spf=pass smtp.mailfrom=sk.com; arc=none smtp.client-ip=166.125.252.92 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=sk.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=sk.com 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: H4sIAAAAAAAAA+NgFvrALMWRmVeSWpSXmKPExsXC9ZZnoS53yZFUg6bNAhZz1q9hs/i84R+b xYsN7YwWX9f/YrZ4+qmPxeLyrjlsFvfW/Ge1OL9rLavFjqX7mCwuHVjAZHF910NGi+O9B5gs 5t/7zGaxedNUZovjU6YyWvz+AdRxctZkFgdBj++tfSweO2fdZfdYsKnUY/MKLY/Fe14yeWxa 1cnmsenTJHaPd+fOsXucmPGbxWPeyUCP9/uusnls/WXn0Tj1GpvH501yHu/mv2UL4I/isklJ zcksSy3St0vgyvg6z6nguHTFh087GBsYH4h1MXJySAiYSHx+9JcFxu75PZURxGYTUJe4ceMn M4gtImAmcbD1D3sXIxcHs8BHJonV3zvAGoQFEiT6zyxkBbFZBFQlmv90gDXzCphKzN2xkhFi qLzE6g0HwAZxAg3aue0UWL0QUM2L2ZPZQIZKCPxnk5jbv50dokFS4uCKGywTGHkXMDKsYhTK zCvLTczMMdHLqMzLrNBLzs/dxAiMh2W1f6J3MH66EHyIUYCDUYmH90T54VQh1sSy4srcQ4wS HM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bcy9nL9jG3xyUpr0FGe PZ/PNfi0/oxJHG86vXQbTZRYijMSDbWYi4oTAeOGLtNqAgAA X-CFilter-Loop: Reflected Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790311461966243436 X-GMAIL-MSGID: 1790311461966243436 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;