From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pg1-f173.google.com (mail-pg1-f173.google.com [209.85.215.173]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 01C8520B7ED for ; Sat, 13 Dec 2025 08:01:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.173 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765612895; cv=none; b=IL2yna1Kekh98JrbLYAq0jK5eleXyKFnrDTQikkT2zrrRiKi8IeVgcxWqBJMO+ovC0e1Z3h0Tuy69rW6UAOWTdjIho9Af2q7k6asFX1TuobrWpu62IRryDpfk3wN8nXarrjk3oErTAMoTwpYYyAWCAD9lYGgnTKshgY4GUukuJw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765612895; c=relaxed/simple; bh=jXDGWyRXrmBErkv9sVlwDZo5kqTeYEl2XPZA8Y4KEZ4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=tZ78zEbH7xajD0RLD1uHf8xxKbWVG2aGNkm9nuler/CLro3VLlQ5ysrA8x9ajy8S0dAhzWgbMhwFemoNYpNwz3WcMjnRj+00chXIFjZ6IOdtNgfXDkvNYbK6fjIkOzhAFyMvodYeXTGure+6tqMWX0sdjr4jYWzVOkpR9ZLbnlk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.215.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pg1-f173.google.com with SMTP id 41be03b00d2f7-bcfd82f55ebso819981a12.1 for ; Sat, 13 Dec 2025 00:01:33 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1765612893; x=1766217693; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=6zyZqpXGOD7PQXCX/qi8XAI4ssAYS91zNYfhBfwbL38=; b=TxZWCLeKkDExrYjTdF6N5Qdv5Ap+5cjG6loNtUvfvzXw8bFciSPf01GoJdNXnBsyaO RhaAE2JUQ2TnJ+/Q77cPAJPhOwm8Yu1Y4NMMydHIapGuZGald6dfpo7o+U8F4ZoMHg5j 2VWeP4g2qsUGE5hmzmD+Oemt62GPathf0F7Ns03viniSEKSfssydlHUpqRVJgbAc0wCV NIrdLO8zfaKe50Jw6mfh5tAnFRcLVM6EGYiDPKgKa4MAN3UBt3/ANIqMW/2xDSLY4hyw yB/p/CXZ4RxyIxgA4W4CrcfDDGlmC0mI0Jm/CqG6JTO+iOPQept2DzRdtDFKz0teUcpW U8zA== X-Forwarded-Encrypted: i=1; AJvYcCWW3APcEfY3jcFIi4kQ7FF2s+8BQ7PXFsLR5hf7/MjgULhOkYTT+KGMgp89t4yc+OxN1e5a+p6UGNjXlCU=@vger.kernel.org X-Gm-Message-State: AOJu0Ywhizq0K3mOhwF8Ej2Nq02uSbZDlkTGerNu+x+YODYrHUYsV3oS RmajshAoM0y+h/GHT4eBqTvkLL6NRfjTa/M4CcR0whdFZfg6Utk4L3gd X-Gm-Gg: AY/fxX5NO+JMsaO1yuHNZ55fW6O0JVlAC/HW5WOWJPRpR4NgIy3BcxOsukW2o9B+4dW zTZmUNx19YucWtAGhPisGrJ4XzjlOFomo5+41CpuiOuxOjwKg0txMLsa3a5hdY0MgPL9/sm/i9w OvnmfgUjiT4PWrbt/nswdAGckcdDnDFfeNYl1WO1p7irecBv6PnBBut3aaZAI0zDwPAb4c55uZ7 OdlNeTO4mWFqBHsswwmrnz8Samvx9SMLLR+AdgXdhSD9f8N2z0u48sHA3BVflb2xcZi9jlkpmGd 1/Ht9kXeSUPqHBEBdQQNr4RTE9JAv7sGRBDNIX7KmmzJl/BWtEzM5xU6/wavULOrCftwSlI654f memXvQgVu7F94N6uTuPp5a1H5xpNVEScRO369xKvB81JMmpWg41J1TR3tOT50xdLH/A+l2Xq0+X Iau3wVAkZLS/wwIBNkkbUZIlInAkjS4kKiFhl+ X-Google-Smtp-Source: AGHT+IEvzQW8UzoOcTZBNcUeKF5AlG/hKLmPQTyZebSEYXQtt07g7PJxjlFHqOPOoSkuSiaptW4vAg== X-Received: by 2002:a17:903:2ec3:b0:295:4d97:84f9 with SMTP id d9443c01a7336-29f24eea3b8mr45731115ad.26.1765612893191; Sat, 13 Dec 2025 00:01:33 -0800 (PST) Received: from localhost.localdomain ([45.142.165.134]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-29f05287fa3sm53149155ad.5.2025.12.13.00.01.23 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Sat, 13 Dec 2025 00:01:32 -0800 (PST) From: Lance Yang To: akpm@linux-foundation.org Cc: will@kernel.org, aneesh.kumar@kernel.org, npiggin@gmail.com, peterz@infradead.org, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, x86@kernel.org, hpa@zytor.com, arnd@arndb.de, david@kernel.org, lorenzo.stoakes@oracle.com, ziy@nvidia.com, baolin.wang@linux.alibaba.com, Liam.Howlett@oracle.com, npache@redhat.com, ryan.roberts@arm.com, dev.jain@arm.com, baohua@kernel.org, ioworker0@gmail.com, shy828301@gmail.com, riel@surriel.com, jannh@google.com, linux-arch@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Lance Yang Subject: [PATCH RFC 3/3] mm/khugepaged: skip redundant IPI in collapse_huge_page() Date: Sat, 13 Dec 2025 16:00:25 +0800 Message-ID: <20251213080038.10917-4-lance.yang@linux.dev> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20251213080038.10917-1-lance.yang@linux.dev> References: <20251213080038.10917-1-lance.yang@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Lance Yang Similar to the hugetlb PMD unsharing optimization, skip the second IPI in collapse_huge_page() when the TLB flush already provides necessary synchronization. Before commit a37259732a7d ("x86/mm: Make MMU_GATHER_RCU_TABLE_FREE unconditional"), bare metal x86 didn't enable MMU_GATHER_RCU_TABLE_FREE. In that configuration, tlb_remove_table_sync_one() was a NOP. GUP-fast synchronization relied on IRQ disabling, which blocks TLB flush IPIs. When Rik made MMU_GATHER_RCU_TABLE_FREE unconditional to support AMD's INVLPGB, all x86 systems started sending the second IPI. However, on native x86 this is redundant: - pmdp_collapse_flush() calls flush_tlb_range(), sending IPIs to all CPUs to invalidate TLB entries - GUP-fast runs with IRQs disabled, so when the flush IPI completes, any concurrent GUP-fast must have finished - tlb_remove_table_sync_one() provides no additional synchronization On x86, skip the second IPI when running native (without paravirt) and without INVLPGB. For paravirt with non-native flush_tlb_multi and for INVLPGB, conservatively keep both IPIs. Use tlb_table_flush_implies_ipi_broadcast(), consistent with the hugetlb optimization. Suggested-by: David Hildenbrand (Red Hat) Signed-off-by: Lance Yang --- mm/khugepaged.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/mm/khugepaged.c b/mm/khugepaged.c index 97d1b2824386..06ea793a8190 100644 --- a/mm/khugepaged.c +++ b/mm/khugepaged.c @@ -1178,7 +1178,12 @@ static int collapse_huge_page(struct mm_struct *mm, unsigned long address, _pmd = pmdp_collapse_flush(vma, address, pmd); spin_unlock(pmd_ptl); mmu_notifier_invalidate_range_end(&range); - tlb_remove_table_sync_one(); + /* + * Skip the second IPI if the TLB flush above already synchronized + * with concurrent GUP-fast via broadcast IPIs. + */ + if (!tlb_table_flush_implies_ipi_broadcast()) + tlb_remove_table_sync_one(); pte = pte_offset_map_lock(mm, &_pmd, address, &pte_ptl); if (pte) { -- 2.49.0