From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=91.218.175.41 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796020683; b=xYYatY8f6oN92sL64+A5s7+TumnYfjwJGC05T5DPn3dYnijInbkiH/xXxEx7XnwZotmV gM1lh5UFd8S7GYMduwM6/IXVLdlrZTxbU8avFQqh9wr/iSTANkNp6HfIsI1PvjTSZ7lDG OXm8XpNEaptp455XKc7cJ66/nSPK8O5Z7TGA/ReYImaRo0NM8gM1YV3NLTUWCER57v2EZ 8kjSEQQVMYxS0oFmPDZzL7o7bJv16ALaDesa/UxybA+uMjZhl47SNdhe9fegdIVi34wwu enDZRDm6blDEvOT+GdXU9OmTFwIF4nA1Ibq+4WXANgD3EZ4TwFzNnMoLSQ5jWCag1ww== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796020683; h=DMARC-Filter:X-Envelope-To:DKIM-Signature:X-Envelope-To:Received: X-Mizu-Trace-ID:X-Migadu-Flow:From:Date:Subject:MIME-Version: Content-Type:Content-Transfer-Encoding:Message-Id:X-B4-Tracking:To:Cc: X-Mailer; bh=KtlKmd+Nb+QClUKjbFpd75qJCi2+iA4jWtz92WDKyIg=; b=2xS0RTWUtSccbrUXYDTYbyoCjq6ey9PHCE44P8XvNLhQaca8yrGzXUdwbOvD4PvLwUrg bgRn8+csDSLLexoprtcU9UjZrXupAEyPwuLL/9yY3SDYNO83ChhanC9ZcLB7QQQgkaCA6 AolTbqZ8dQd6qk2lPfwdx5XTuwe34X8PT4z/vZsC4QC18tL1zxucKyB/TfsYNBwV7+ES6 avzf4jzKuwqsev0S2zGkK+VEWFgnoIqhqLPjRBPBri+JFiwy2INXGxVEtQtUjb6KYZde6 0Lt0VkF8Y0rgnAIPB/wsQ0R0/LuK7FZYL18qfkbcxSFYokLnfoJgNZl187u86ZkRJCA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b="WpfN03M/"; arc=none smtp.remote-ip=91.218.175.41 Received: from mta0.migadu.com (out-41.mta0.migadu.com [91.218.175.41]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 04830606A320 for ; Mon, 30 Nov 2026 06:38:02 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 04830606A320 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=WpfN03M/ X-Envelope-To: linux-kernel@vger.kernel.org DKIM-Signature: a=rsa-sha256; bh=1+FVYB5+DU6fEC3lmCkDU2eS/DjfiIzUxM4MzWyH0xs=; c=simple/simple; d=linux.dev; h=from:to:subject:date:message-id:mime-version:content-type; s=key1; t=1796020680; v=1; x=1796625480; b=WpfN03M/4HCDlurWIhk37GdSzx4dsIcGtcx+4iRUhJWayb+o1/4Z1z5dZVd7XalqG0K6j/qQ +SrZ5DTmoZ8GjhLwH2V0fcyd/+5WJXL9JCt+ty7AAwHx3P2BfI20Ta3zgzHvX0oWBf403wDYKVf QyHPPrAnrqtCHIjQeNW6B0ks= X-Envelope-To: linux-kernel@vger.kernel.org Received: by smtp.migadu.com with ESMTPS id 7b79a2873375582a; Mon, 30 Nov 2026 06:38:00 +0000 X-Mizu-Trace-ID: 7b79a2873375582a X-Migadu-Flow: FLOW_OUT From: Qiliang Yuan Date: Mon, 30 Nov 2026 01:37:51 -0500 Subject: [PATCH] mm/memory_hotplug: return early from try_online_node() for online nodes X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20261130-feat-memhp-try-online-node-v1-1-b65dd4a9af92@linux.dev> X-B4-Tracking: v=1; b=H4sIAL4ZDWsC/x3MQQqDMBAF0KvIrDtgNETSq5QuxPzUAZ1IImIR7 97Q5du8iwqyoNCzuSjjkCJJK8yjoWke9QOWUE1d2zlj+pYjxp1XrPPGe/5y0kUUrCmArfPe2zj 01k5Ugy0jyvnPX+/7/gGIpTCtbAAAAA== To: David Hildenbrand , Oscar Salvador , Andrew Morton Cc: linux-mm@kvack.org, linux-cxl@vger.kernel.org, linux-kernel@vger.kernel.org, Qiliang Yuan X-Mailer: b4 0.13.0 cpu_up() calls try_online_node() for the node of every CPU it brings up, so that a CPU on a memoryless node that is not online yet gets its node onlined first. try_online_node() takes mem_hotplug_lock for write with mem_hotplug_begin() before it checks whether the node is online. mem_hotplug_lock is a percpu rwsem, and taking it for write waits for an RCU grace period unless another writer released it shortly before. Bringing a CPU online through sysfs, as done when hot-adding vCPUs to a VM, therefore waits for a grace period although the node of the CPU is almost always online already. Check node_online() before taking the lock. A node with present CPUs is never offlined, see try_offline_node(), so the node of the CPU being brought up cannot go offline concurrently. Onlining CPUs of a 32-vCPU VM through sysfs, base and patched kernels alternating over 4 rounds of 5 runs, median of the 20 runs and interquartile range in parentheses; "single" onlines one CPU 0.3 s after taking it offline, "16 in a row" onlines CPUs 16-31 back to back: case before (ms) after (ms) change single 24.8 (24.2-25.9) 16.7 (15.9-17.3) -33% 16 in a row 143.1 (139.8-147.2) 130.0 (127.3-133.7) -9% Signed-off-by: Qiliang Yuan --- mm/memory_hotplug.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c index 944ea6fd88562..eb50d6e0fe48d 100644 --- a/mm/memory_hotplug.c +++ b/mm/memory_hotplug.c @@ -1299,6 +1299,14 @@ int try_online_node(int nid) { int ret; + /* + * A node with present CPUs is never offlined, see try_offline_node(). + * Skip mem_hotplug_begin(), which waits for an RCU grace period, when + * the node is already online. + */ + if (node_online(nid)) + return 0; + mem_hotplug_begin(); ret = __try_online_node(nid, true); mem_hotplug_done(); --- base-commit: 2fffa854b7babdaf17e9722636015dacd205039f change-id: 20261130-feat-memhp-try-online-node-469994f7344c Best regards, -- Qiliang Yuan