From nobody Sat Feb 7 18:21:00 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 B67B733E369 for ; Mon, 12 Jan 2026 08:32:38 +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=1768206762; cv=none; b=EEsZ8ITRzchOAK72wdF90GzqFnl9wCfE3M0MBQKzTNW65kFhcus8LvrsTf1cHBUSCUBrMPL/gzjMFB5WPqby2KvkSHmWunrol/u2GyDegAhbg9z5LARJxwUtDijPDPJek1WA2Pk7lk7xG+jv47Lkp5DmbMW25Z6ahOhYrWOucMk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768206762; c=relaxed/simple; bh=Q46fXj2SD1mwGxz9BvPdoQwlOsP44emz+A8TmYc+Bgk=; h=Date:Mime-Version:Message-ID:Subject:From:To:Cc:Content-Type; b=aq0qqVxRfngbrbf2HVT8VY40/64Y013zUCXlPbdTos1PMFuYq+ZVF5E+1Otbk/YEcFczQ9v9wZbBZdPjMfJdCWofd76f1titEzt2FqyRnBT5zYjOdzPcB17nPIfHK0aoJd1RUEK7F3K31G/L0GxwQvlsdMnjgo0nZDsmGTnfKsE= 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=dzZ1BK5c; 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="dzZ1BK5c" Received: by mail-ej1-f73.google.com with SMTP id a640c23a62f3a-b8711b467f3so110126266b.1 for ; Mon, 12 Jan 2026 00:32:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1768206757; x=1768811557; darn=vger.kernel.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=mOzRL6yPoMhE1PRN8zqbHjwDhaDfkx12ZotLhBVpiKk=; b=dzZ1BK5cBoY24q4F2LzXhnS2a/kiF21m8LDCkq7CrJ8U/Cm82YPCYnR0PaqRETODrq IYjQpmiP7iyLAUijgfpAAbbcCSoq0hem8JWgmOwfhvgrx5N1DVGq69gtfCa71G7A0YER vHYv9Iscq6kv09E7Zgh8+UBlF+xKG9C5BrEpbdqLP4HRc/SvymN2psVoNK4ebx86F1D9 zEqWrzz5w8tW9kVF6U4CLxtEv0jjDRCTbK7bCKMnTU8UQE4EYivSiFQTHefvrBNp8mim C2tdCD7d87aP7F27GbbgRQyh40kAjRwu3NLBIj6loIkmknaQWLdXk0kqoTCQI5WqFkvH K8yg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1768206757; x=1768811557; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=mOzRL6yPoMhE1PRN8zqbHjwDhaDfkx12ZotLhBVpiKk=; b=dPlQbuiNzwmS3T71BhDA3tu1YaDNW3lXZ2yg0jBVezGVoAp+pXS+X40VMJZNfMqOZ3 D8W5uJB1qh1R62IZD0uVh+mIR9Y5UmbgdVB91OimcujXs35XzhRYQJchYG//yFugx3TE e/ORSUsl9tsm0x6ZMqgViVe2Ii4ydFmXZfN2bqKUs3viDQ5qSfWrt1BCLNKWv/Ijec7F ykp5qGTVcgWeu93HbU63M3xC2Yn9jouQwsWY0LNX2F3lgbZsWfmjvRLFBRmBYOBDRlG5 NpDttRHYZVFaojZ2Bd6KzarXAbWXOwbNj0odGtdyVrxG7sG94gOaG6jPERHVVwnKmDdy 7B+g== X-Forwarded-Encrypted: i=1; AJvYcCXvNbJI4r14xyAmH9dpBNXlOHuMBf5PsxeMa2hWnMMNXMf075QcviEq6OC+sIf4E+mJne7/x2ejh2KuVpg=@vger.kernel.org X-Gm-Message-State: AOJu0YzDKqZDoxR0+edjB7WQt2aiJMtGRaAG7HYHRKTrPXmNX2s7nxn6 LOBWbnVpsss6ul37bd5frRgWFwUlFLWQoIROwRwyVx2LezJ4QUgZNSv1ZM/EeNC6tzZQGqFb7Wn EQgFyUA== X-Google-Smtp-Source: AGHT+IFZplbY/wXNW7zYEdPSXNWEpmqz2W80lxD4QR3CjC/LSBJ8MI19HH7PwIMLbIFg+O6RSaMH8FhNBqI= X-Received: from ejcsr15.prod.google.com ([2002:a17:907:398f:b0:b87:1c45:66e1]) (user=lrizzo job=prod-delivery.src-stubby-dispatcher) by 2002:a17:906:ef0c:b0:b71:ea7c:e501 with SMTP id a640c23a62f3a-b8444c593c2mr2010829366b.4.1768206757133; Mon, 12 Jan 2026 00:32:37 -0800 (PST) Date: Mon, 12 Jan 2026 08:32:33 +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: <20260112083234.2665832-1-lrizzo@google.com> Subject: [PATCH v2] genirq: move clear of kstat_irqs to free_desc() From: Luigi Rizzo To: tglx@linutronix.de, maz@kernel.org, rizzo.unipi@gmail.com 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 | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/kernel/irq/irqdesc.c b/kernel/irq/irqdesc.c index f8e4e13dbe339..ec963174e7e27 100644 --- a/kernel/irq/irqdesc.c +++ b/kernel/irq/irqdesc.c @@ -115,8 +115,6 @@ static inline void free_masks(struct irq_desc *desc) { } static void desc_set_defaults(unsigned int irq, struct irq_desc *desc, int= node, const struct cpumask *affinity, struct module *owner) { - int cpu; - desc->irq_common_data.handler_data =3D NULL; desc->irq_common_data.msi_desc =3D NULL; =20 @@ -134,8 +132,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 @@ -621,9 +617,13 @@ EXPORT_SYMBOL(irq_to_desc); static void free_desc(unsigned int irq) { struct irq_desc *desc =3D irq_to_desc(irq); + int cpu; =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