[RFC PATCH 2/2] mm/mmu_gather: Avoid multiple page walk cache flush

From: Aneesh Kumar K.V
Date: Tue Dec 17 2019 - 02:19:08 EST


On tlb_finish_mmu() kernel does a tlb flush before mmu gather table invalidate.
The mmu gather table invalidate depending on kernel config also does another
TLBI. Avoid the later on tlb_finish_mmu().

Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@xxxxxxxxxxxxx>
---
mm/mmu_gather.c | 12 +++++++++---
1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/mm/mmu_gather.c b/mm/mmu_gather.c
index 7c1b8f67af7b..7e2bd43b9084 100644
--- a/mm/mmu_gather.c
+++ b/mm/mmu_gather.c
@@ -143,17 +143,23 @@ static void tlb_remove_table_rcu(struct rcu_head *head)
free_page((unsigned long)batch);
}

-static void tlb_table_flush(struct mmu_gather *tlb)
+static void __tlb_table_flush(struct mmu_gather *tlb, bool table_inval)
{
struct mmu_table_batch **batch = &tlb->batch;

if (*batch) {
- tlb_table_invalidate(tlb);
+ if (table_inval)
+ tlb_table_invalidate(tlb);
call_rcu(&(*batch)->rcu, tlb_remove_table_rcu);
*batch = NULL;
}
}

+static void tlb_table_flush(struct mmu_gather *tlb)
+{
+ __tlb_table_flush(tlb, true);
+}
+
void tlb_remove_table(struct mmu_gather *tlb, void *table)
{
struct mmu_table_batch **batch = &tlb->batch;
@@ -178,7 +184,7 @@ void tlb_remove_table(struct mmu_gather *tlb, void *table)
static void tlb_flush_mmu_free(struct mmu_gather *tlb)
{
#ifdef CONFIG_HAVE_RCU_TABLE_FREE
- tlb_table_flush(tlb);
+ __tlb_table_flush(tlb, false);
#endif
#ifndef CONFIG_HAVE_MMU_GATHER_NO_GATHER
tlb_batch_pages_flush(tlb);
--
2.23.0