From nobody Sat Feb 7 17:48:35 2026 Received: from mail-ej1-f73.google.com (mail-ej1-f73.google.com [209.85.218.73]) (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 A70B5183CC3 for ; Sun, 11 Jan 2026 19:17:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.73 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768159072; cv=none; b=rqrWKdpg8fm9cHTOqe4Rf3YaKwYs8uRY3/YgBlCkUpeHWmHicliJaRcahMAivVXfmYjPksu0NzbVge24r8L1mIZKk1rmJmNiiDA8yihKjlikAeEFGJSA4Hl/wv1Tm3WzVPkvkPtuWMrzPFhUagGxqiU+84NwjC39oUVpDL3uSic= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768159072; c=relaxed/simple; bh=JubApuOJICS6n1s2hIwXnsivIihPjR/yPKP6TC76VcU=; h=Date:Mime-Version:Message-ID:Subject:From:To:Cc:Content-Type; b=akA69LdIbllEKLvleCJiwdr/7EElYEnMsOdwoeXDeCgIStgPPakEet4ds/vELFyHYMKOqnGhJM1miIlP/6eBIo+/AFpFXpacGFr2jViqEkRFCT2DMUU20rU6gq7JB16PnzsFbGNEI9+jlEoIrW6G+Gq9oblADw2qwvJwj1kYUGI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--lrizzo.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=XjYf22+f; arc=none smtp.client-ip=209.85.218.73 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--lrizzo.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="XjYf22+f" Received: by mail-ej1-f73.google.com with SMTP id a640c23a62f3a-b871ea8299dso11088166b.0 for ; Sun, 11 Jan 2026 11:17:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1768159069; x=1768763869; darn=vger.kernel.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=p5yMPcNCih0BSoXnmBtfMgcx/R4KckISTDbsz6OQrtk=; b=XjYf22+fGpJUv0PWFRyFyuaPcmuIAi3MBysJsBr+wUXlr4p600TZDO57NutJS7bGCR oteTOp/SN+Qpt1mIlOzDGz+6ntTvWK80p9bMpio9E1bTMg/NbzWBAvC/r9u8E1CrdDoI yC/vKgM5AWOpzq8oGNsvTMyzy6yNaONu1Z2G6Qfz6yva6MpPplns/ITVeN7RikNOUVg7 aBPfWI4NoWPwO+dX/iYdDME2qqvMLpCkDwdOitWhJJspktRc4tMSRFxE6aRDaXofd7H9 kMAOF8JOFaFSMB33XInfbd4YiVZjr1Vfp9Vwizv+t2EqO147BBoHEPCNEqnq74CYvmG4 usRg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1768159069; x=1768763869; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=p5yMPcNCih0BSoXnmBtfMgcx/R4KckISTDbsz6OQrtk=; b=XFSR2NdxN1eoCPatmvHRRtrFkTFP+C75NvbA7vGfj4grfhZdTne6VUZZOuuobhoNwX T4QkubJA1AKIUIiEkScVqXPVI8sOEhRBNIH+I8NnVC3gCH0PFPTUBaqQagUdaTz6eioC vARiwlgx9/aXO+ZUNDNt+1VWGi2RzTD46EpZ/q+DktX2kj1P3yqSMan7BZT/lYt9KJCx Q+5eyjq0im4rb5m/7wJsQYhl6t6S1FW/gmG6T66gZL6fn6l0uV3v6uNFm/sw+QkaE/GS 8/8FB+ziqtpzDYCIWQryMuhxNnzjSvwCbv4+U9L1FbEcaOoJMdS2bqPf50EbnsfUSpDi my1A== X-Forwarded-Encrypted: i=1; AJvYcCUs9/0qDlJC5FYjkZoYqXvO+njVL3xAQPQwVGDTkCn6TNYEo0BvW5rNNi4uIFXp/zeC36/jopi2ST+kHZw=@vger.kernel.org X-Gm-Message-State: AOJu0YxI8DC8nLNB5KPBh15at5ESXQ458dv0IwsGNp7WhycKEXAvNklq CGOOyE7RxXsT0aZ27HWDPC9Jvb0V6a0WSXEVht2fo7XTAwYu0OxrYoCzDa0LLiqvzERBJS7nxqk vCnI1cA== X-Google-Smtp-Source: AGHT+IHWKfFrbArcnCh1LfJVPIetsHQQwNtdhDFMG8mXfzVgfOj+YZVJsP3PisL9Nnso/RERn5DOtlLc7SU= X-Received: from ejcsr17.prod.google.com ([2002:a17:907:3991:b0:b72:41e4:7562]) (user=lrizzo job=prod-delivery.src-stubby-dispatcher) by 2002:a17:906:f5a3:b0:b87:e76:67b7 with SMTP id a640c23a62f3a-b870e766fb5mr240027866b.15.1768159069031; Sun, 11 Jan 2026 11:17:49 -0800 (PST) Date: Sun, 11 Jan 2026 19:17:10 +0000 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 X-Mailer: git-send-email 2.52.0.457.g6b5491de43-goog Message-ID: <20260111191710.1993867-1-lrizzo@google.com> Subject: [PATCH] genirq: move clear of kstat_irqs to free_desc() From: Luigi Rizzo To: tglx@linutronix.de, maz@kernel.org Cc: edumazet@google.com, linux-kernel@vger.kernel.org, Luigi Rizzo Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" desc_set_defaults() has a loop to clear the per-cpu counters kstats_irq. This is only needed in free_desc(), which is used with non-sparse IRQs so that the irq_desc can be recycled. For newly allocated irq_desc, the memory comes from alloc_percpu() and is already zeroed out. Move the loop to free_desc() to avoid wasting time unnecessarily. This is especially important on large servers with 100+ CPUs, because each write results in a cache miss, and the write buffer can only have so many outstanding transactions. Below is an example of cost on a host with 480 CPUs, taken with local_irq_save()/restore() around the code to avoid interference. Measurements taken with kstats https://github.com/luigirizzo/lr-cstats/tree/main/kstats BUCKET SAMPLES AVG TIME(ns) PERCENTILE 40 3 2432 0.000366 41 3 3000 0.000732 42 24 3241 0.003662 43 33 3971 0.007690 44 963 4742 0.125244 45 1071 5545 0.255981 46 494 6644 0.316284 47 352 7661 0.359252 48 816 9447 0.458862 49 2214 11493 0.729125 50 1440 13027 0.904907 51 428 15219 0.957153 52 275 18211 0.990722 53 69 21396 0.999145 54 4 26125 0.999633 55 1 28996 0.999755 56 2 37253 1.000000 Signed-off-by: Luigi Rizzo --- kernel/irq/irqdesc.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/kernel/irq/irqdesc.c b/kernel/irq/irqdesc.c index f8e4e13dbe339..fa1e3c7838aa7 100644 --- a/kernel/irq/irqdesc.c +++ b/kernel/irq/irqdesc.c @@ -134,8 +134,6 @@ static void desc_set_defaults(unsigned int irq, struct = irq_desc *desc, int node, desc->tot_count =3D 0; desc->name =3D NULL; desc->owner =3D owner; - for_each_possible_cpu(cpu) - *per_cpu_ptr(desc->kstat_irqs, cpu) =3D (struct irqstat) { }; desc_smp_init(desc, node, affinity); } =20 @@ -622,8 +620,11 @@ static void free_desc(unsigned int irq) { struct irq_desc *desc =3D irq_to_desc(irq); =20 - scoped_guard(raw_spinlock_irqsave, &desc->lock) + scoped_guard(raw_spinlock_irqsave, &desc->lock) { desc_set_defaults(irq, desc, irq_desc_get_node(desc), NULL, NULL); + for_each_possible_cpu(cpu) + *per_cpu_ptr(desc->kstat_irqs, cpu) =3D (struct irqstat) { }; + } delete_irq_desc(irq); } =20 --=20 2.52.0.457.g6b5491de43-goog