From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f44.google.com (mail-wm1-f44.google.com [209.85.128.44]) (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 5B33921767D for ; Mon, 23 Mar 2026 01:39:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.44 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774229948; cv=none; b=HOTYMKHdNmlHXjvHR5tNEwrP1askaNQG7Rg9ZZoXTNTuvNSVUNV3S65Wy/ZNUaQ/Oj/ZEDj/F2iKJNmbzSbQ2cWmvtUnLJ9NsTjvfttQ4vvWQcpcH+zjLqkQs6yh1tycg4dH0XGq0h1PPT3xo30HpKMnF7y8rNnl/Lax+sEIIZQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774229948; c=relaxed/simple; bh=LP43m2vrYbc6eNyf45r358bFagwBROvvSzHeenJ7Pu8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type:Content-Disposition; b=a7onvHUMuQAGUVhqB8IHC1VBLzvTBToY4JTOxD/TUvgNwGxCox7TnT+NtM8rA8/EODX50tlJnoGU3d1C+ltNuU0doQTB4fU1HE6rnBgmz+i7dbrZbX9bR73LZTFwi9FsEmwfpbiTImWBC5X9KoyCr6zRW0w0IbEU3NtmnPQTCGI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=XnG72a2e; arc=none smtp.client-ip=209.85.128.44 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="XnG72a2e" Received: by mail-wm1-f44.google.com with SMTP id 5b1f17b1804b1-4852a9c6309so19243075e9.0 for ; Sun, 22 Mar 2026 18:39:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1774229945; x=1774834745; darn=vger.kernel.org; h=content-transfer-encoding:content-disposition:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from:from:to :cc:subject:date:message-id:reply-to; bh=Fx2cmrzWqJT91Br9jsPMyIKQu88+WNBdQ+o5h791kHo=; b=XnG72a2e4X/qc4AOzoSwfB/N3gnRqBUjGq2u+/q8drSs/wyeWpZgNNhuX3fh/bjY1s h/k8ZABvXYlDpSs+zXl+FClQsLoX/mfGcV/d4p/o+52JlSsmEeiXkI7239MrzlCck6zF fqfWGcCzIXb9FUCfGdohQIFPhdlgGchCljf/TNvZw0KCXZJHCIa9ipzVcAuOcW3Fgmc9 baZtakKQEXYHG73u+x6vrx3gAmtknp6R3y1QS2jEkMOg7GqPDm3nqsJA9x5aWW/eeW4J QW5nR/Cmu6rL9mkoXsG5Jg0xJ8VRegHf7lGuux7fnoD9WELU8YIemzkuUHGvYQ7MtIKe Cncw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774229945; x=1774834745; h=content-transfer-encoding:content-disposition: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=Fx2cmrzWqJT91Br9jsPMyIKQu88+WNBdQ+o5h791kHo=; b=UYqX+vG4Y1j9RzmfGVcNUw2/SnQ6rv04qwlRfJgqZDkrqJuG+3zAnRJqQrtnSOgDLz x95yDHJL3+Lm0Kp4iSdWGPvPXDscOkJrVxkZiaMvqob/qBfWw/COZVf+bidM9+DKDFip /cZdu7PRxMCRFWYc6L1SXBIw8e1VMtbk1lJEAwZATQl4gyJIfaoX0B2rnDNQ0ffBVbvL VbESYIDIHMK5E3rDHfcQdUPC7qmnEOl21MtES6xzRpG20yD4R52jVN5P1s2xxPHkgm1Q 4skYaEK6vAlavhBwFJ05FvRRsZxVYuVXzTPUo7t7LYgsPVXtUEaFGA3QlQNGUH7/JFE+ PuPw== X-Forwarded-Encrypted: i=1; AJvYcCUSdzGTJ6llRS3TR88HnJDbK/2VTRkTDF+OtqixYsz0tffgQSaxqSgBuVOl/MZShpx5BU5q0rV72Hchmu0=@vger.kernel.org X-Gm-Message-State: AOJu0YwSOyv/M3v72pYYeotyOm3lFhTan7kPcumlCxDwV3zSAmspQ6/K PmLsd4pq3rWme10V4GgvH7wBLJlRriqffHNdYxY/I2O/Qe0OxDZRpvTm X-Gm-Gg: ATEYQzxV6j+GOXBg9Z0zI8tqRcuyEjBgGfLL9CXtP2LQ8Oy+HrB4fxHw5ZYNbKn5HWC 8dmML66e4C6vfFvpOopMHNW8Gl+Ftlhqi7RCXax4cA0T4NpvxtJzLt8j77skUeKI6EXzgJYwwd5 vE6VSqqIHzn26PFSMHRUPryVp4QbXW1BN3mShPtDKrF+Z+IfHooSrf2M0WlXoKiD1NtCMU3TV6B IhncPiKnZd5jTpDijlAHKzkTUrUXnwa6hrSYadXzoKda1NwoZtyHfu9ApbOqXXhKZNz5xQj7lKX cVNTeO8QB8uitqltQNIJ1EICqsX40MXyHTJTKcz3gAS+6/LIPwx1godUm2ljOXweA0HT6ljo1jn VcRabMnLOfBhNXU70WBRANojTjnsvg5HKu1W9nIvS1Z+4DWKoT3dqRijFrgFl5Da9cYxtphyUoA /O+kgy/bgzaxPclvZJ/qXTxq06x6mpT8wFoaU= X-Received: by 2002:a05:600c:8b24:b0:485:3dfc:57c with SMTP id 5b1f17b1804b1-486fee0fcf6mr148878665e9.21.1774229944373; Sun, 22 Mar 2026 18:39:04 -0700 (PDT) Received: from WindFlash.powerhub ([2a0a:ef40:1b2a:fa01:9944:6a8c:dc37:eba5]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-43b644bdaf8sm29704360f8f.13.2026.03.22.18.39.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 22 Mar 2026 18:39:03 -0700 (PDT) From: Leonardo Bras To: Frederic Weisbecker Cc: Leonardo Bras , Marcelo Tosatti , linux-kernel@vger.kernel.org, linux-mm@kvack.org, Johannes Weiner , Michal Hocko , Roman Gushchin , Shakeel Butt , Muchun Song , Andrew Morton , Christoph Lameter , Pekka Enberg , David Rientjes , Joonsoo Kim , Vlastimil Babka , Hyeonggon Yoo <42.hyeyoo@gmail.com>, Thomas Gleixner , Waiman Long , Boqun Feun Subject: Re: [PATCH v2 2/5] Introducing qpw_lock() and per-cpu queue & flush work Date: Sun, 22 Mar 2026 22:38:56 -0300 Message-ID: X-Mailer: git-send-email 2.53.0 In-Reply-To: References: <20260302154945.143996316@redhat.com> <20260302155105.214878062@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit On Tue, Mar 17, 2026 at 02:33:50PM +0100, Frederic Weisbecker wrote: > Le Sun, Mar 15, 2026 at 03:10:27PM -0300, Leonardo Bras a écrit : > > On Fri, Mar 13, 2026 at 10:55:47PM +0100, Frederic Weisbecker wrote: > > > I find this part of the semantic a bit weird. If we eventually queue > > > the work, why do we care about doing a local_lock() locally ? > > > > (Sorry, not sure if I was able to understand the question.) > > > > Local locks make sure a per-cpu procedure happens on the same CPU from > > start to end. Using migrate_disable & using per-cpu spinlocks on RT and > > doing preempt_disable in non_RT. > > > > Most of the cases happen to have the work done in the local cpu, and just > > a few procedures happen to be queued remotely, such as remote cache > > draining. > > > > Even with the new 'local_qpw_lock()' which is faster for cases we are sure > > to have local usages, on qpw=0 we have to make qpw_lock() a local_lock as > > well, as the cpu receiving the scheduled work needs to make sure to run it > > all without moving to a different cpu. > > But queue_work_on() already makes sure the work doesn't move to a different CPU > (provided hotplug is correctly handled for the work). > > Looks like we are both confused, so let's take a practical example. Suppose > CPU 0 queues a work to CPU 1 which sets a per-cpu variable named A to the value > "1". We want to guarantee that further reads of that per-cpu value by CPU 1 > see the new value. With qpw=1, it looks like this: > > CPU 0 CPU 1 > ----- ----- > > qpw_lock(CPU 1) > spin_lock(&QPW_CPU1) > qpw_queue_for(write_A, 1) > write_A() > A1 = per_cpu_ptr(&A, 1) > *A1 = 1 > qpw_unlock(CPU 1) > spin_unlock(&QPW_CPU1) > read_A() > qpw_lock(CPU 1) > spin_lock(&QPW_CPU1) > r0 = __this_cpu_read(&A) > qpw_unlock(CPU 1) > spin_unlock(&QPW_CPU1) > > > CPU 0 took the spinlock while writing to A, so CPU 1 is guaranteed to further > observe the new value because it takes the same spinlock (r0 == 1) > Here, if we are in CPU0 we should never take the qpw_lock(CPU1) unless we are inside queue_percpu_work_on(). Maybe I am not getting your use case :/ Also, I don't see a case where we would need to call queue_percpu_work_on() inside a qpw_lock(). This could be dangerous as it could be the case in another cpu and cause a deadlock: CPU 0 CPU 1 qpw_lock(0) qpw_lock(1) ... ... queue_percpu_work_on() queue_percpu_work_on() qpw_lock(1) qpw_lock(0) > Now look at the qpw=0 case: > > CPU 0 CPU 1 > ----- ----- > > qpw_lock(CPU 1) > local_lock(&QPW_CPU0) > qpw_queue_for(write_A, 1) > queue_work_on(write_A, CPU 1) > qpw_unlock(CPU 1) > local_unlock(&QPW_CPU0) > // workqueue > write_A() > qpw_lock(CPU 1) > local_lock(&QPW_CPU1) > A1 = per_cpu_ptr(&A, 1) > *A1 = 1 > qpw_unlock(CPU 1) > local_unlock(&QPW_CPU1) > > read_A() > qpw_lock(CPU 1) > local_lock(&QPW_CPU1) > r0 = __this_cpu_read(&A) > qpw_unlock(CPU 1) > local_unlock(&QPW_CPU1) > > Here CPU 0 queues the work on CPU 1 which writes and reads the new value > (r0 == 1). local_lock() / preempt_disable() makes sure the CPU doesn't change. > > But what is the point in doing local_lock(&QPW_CPU0) on CPU 0 ? I can't see the case where one would need to hold the qpw_lock while calling queue_percpu_work_on(). Holding the qpw_lock() (as is the case of local_lock()) should be done only when one is working on data particular to that cpu structures. Queuing work on other CPU while touching this cpu data is unexpected to me. > > > > > > > > > > @@ -2840,6 +2840,16 @@ Kernel parameters > > > > > > > > The format of is described above. > > > > > > > > + qpw= [KNL,SMP] Select a behavior on per-CPU resource sharing > > > > + and remote interference mechanism on a kernel built with > > > > + CONFIG_QPW. > > > > + Format: { "0" | "1" } > > > > + 0 - local_lock() + queue_work_on(remote_cpu) > > > > + 1 - spin_lock() for both local and remote operations > > > > + > > > > + Selecting 1 may be interesting for systems that want > > > > + to avoid interruption & context switches from IPIs. > > > > > > Like Vlastimil suggested, it would be better to just have it off by default > > > and turn it on only if nohz_full= is passed. Then we can consider introducing > > > the parameter later if the need arise. > > > > I agree with having it enabled with isolcpus/nohz_full, but I would > > recommend having this option anyway, as the user could disable qpw if > > wanted, or enable outside isolcpu scenarios for any reason. > > Do you know any such users? Or suspect a potential usecase? If not we can still > add that option later. It's probably better than sticking with a useless > parameter that we'll have to maintain forever. Out of my head, I can think only on HPC scenario where user wants to make use of the regular/RT scheduler for many small workloads, but doesn't like the impact of IPI on those cases. Such systems that explore memory at it's limit will also benefit from those, for example, if cache gets drained remotely very often. None of those necessarily will need to or benefit from isolcpus, and may want to just use the kernel scheduler policies. > > > > > +#define qpw_lockdep_assert_held(lock) \ > > > > + lockdep_assert_held(lock) > > > > + > > > > +#define queue_percpu_work_on(c, wq, qpw) \ > > > > + queue_work_on(c, wq, &(qpw)->work) > > > > > > qpw_queue_work_on() ? > > > > > > Perhaps even better would be qpw_queue_work_for(), leaving some room for > > > mystery about where/how the work will be executed :-) > > > > > > > QPW comes from Queue PerCPU Work > > Having it called qpw_queue_work_{on,for}() would be repetitve > > Well, qpw_ just becomes the name of the subsystem and its prefix for APIs. > For example qpw_lock() doesn't mean that we queue and lock, it only means we lock. > Locks for queue'ing per-cpu work. :D > > But having qpw_on() or qpw_for() would be misleading :) > > > > That's why I went with queue_percpu_work_on() based on how we have the > > original function (queue_work_on) being called. > > That's much more misleading at it doesn't refer to qpw at all and it only > suggest that it's a queueing a per-cpu workqueue. > Humm, maybe qpw_queue_for/on()? Or maybe change the name of the API for pw: pw_lock()/unlock pw_queue(); pw_flush() and so on? That way it stays true to what means :) > > > Perhaps that too should just be selected automatically by CONFIG_NO_HZ_FULL and if > > > the need arise in the future, make it visible to the user? > > > > > > > I think it would be good to have this, and let whoever is building have the > > chance to disable QPW if it doesn't work well for their machines or > > workload, without having to add a new boot parameter to continue have > > their stuff working as always after a kernel update. > > > > But that is open to discussion :) > > Ok I guess we can stick with the Kconfig at least in the beginning. > > Thanks. > > -- > Frederic Weisbecker > SUSE Labs Thanks! Leo