From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 58466372B32 for ; Mon, 18 May 2026 12:57:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779109037; cv=none; b=AmvwC5j7XUasBF1nxFx6W6e6JL783JmG+RDTgnbVJmIWLXIBIBs7tj9tbi7NrFdq3esDZV+1prY5OIpco/ZajawIoHuJrVaYXOWQcX5Udt7q0EfAa7FJYGvoUiPsaZHeJDJzgvO4Cj36IYyfwHTXl3WJbjS+Ebd/qmXRflvfLaE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779109037; c=relaxed/simple; bh=rNkyS5YAnNn6p5xcx5r6d9ZWQ4e1UaknwwRbnO+3CJ0=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=jsovO/SJZbmMjECcKRZ4bxyoCx1R4Hd35dccG3HTvdA9iDWr8/4mUta4TfPua3hSFJIGNyuv2Culb97uvYruKpR8l/SgZ4eotyEJQviBSzIdIst1iyDR1002rgJ21GSFE3ndiYYwMcPAdQvOrnnBJo2tsEWscblbQ27pxLelWH4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=nUCxd8Vw; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="nUCxd8Vw" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 83E83C2BCB7; Mon, 18 May 2026 12:57:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1779109036; bh=rNkyS5YAnNn6p5xcx5r6d9ZWQ4e1UaknwwRbnO+3CJ0=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=nUCxd8VwQsj8L3/bNXvb0cZFPzRv5KO5P0TxzrdIVDzeD1c6Kaq1epJdoDVQyxKKe AdFJU1PUz8x/U2ufACwmEBNjcX4a+gayx2KEy/zDXIPUbJMEJMA7xLZ6mTuma7Vmo/ oZVf3sadp3PB4haCsiyC4wKTHXJSVjtfrn6FUxW1BtwM29nIY/O7StXvvTj5uYFPD0 pU8PjArBzaIj8Hsm8nBiuTLB1JIjVoe7AJDNjuDzX8u+oRsrjf1jP9GnAuEt4o40rn DBrTaWQsYDYXQ5SksO6lWnZfesMReKBkZ1QRTlLiFg2Oa0hewpwP+MTbjReuZPvhb1 k8uEwpnomAZLw== Date: Mon, 18 May 2026 14:57:13 +0200 From: Frederic Weisbecker To: Marcelo Tosatti Cc: 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>, Leonardo Bras , Thomas Gleixner , Waiman Long , Boqun Feun Subject: Re: [PATCH v3 0/4] Introduce QPW for per-cpu operations (v3) Message-ID: References: <20260323175544.807534301@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 In-Reply-To: <20260323175544.807534301@redhat.com> Hi, Is there any plan to proceed with this patchset? Thanks. Le Mon, Mar 23, 2026 at 02:55:44PM -0300, Marcelo Tosatti a écrit : > The problem: > Some places in the kernel implement a parallel programming strategy > consisting on local_locks() for most of the work, and some rare remote > operations are scheduled on target cpu. This keeps cache bouncing low since > cacheline tends to be mostly local, and avoids the cost of locks in non-RT > kernels, even though the very few remote operations will be expensive due > to scheduling overhead. > > On the other hand, for RT workloads this can represent a problem: getting > an important workload scheduled out to deal with remote requests is > sure to introduce unexpected deadline misses. > > The idea: > Currently with PREEMPT_RT=y, local_locks() become per-cpu spinlocks. > In this case, instead of scheduling work on a remote cpu, it should > be safe to grab that remote cpu's per-cpu spinlock and run the required > work locally. That major cost, which is un/locking in every local function, > already happens in PREEMPT_RT. > > Also, there is no need to worry about extra cache bouncing: > The cacheline invalidation already happens due to schedule_work_on(). > > This will avoid schedule_work_on(), and thus avoid scheduling-out an > RT workload. > > Proposed solution: > A new interface called Queue PerCPU Work (QPW), which should replace > Work Queue in the above mentioned use case. > > If CONFIG_QPW=n this interfaces just wraps the current > local_locks + WorkQueue behavior, so no expected change in runtime. > > If CONFIG_QPW=y, and qpw kernel boot option =1, > queue_percpu_work_on(cpu,...) will lock that cpu's per-cpu structure > and perform work on it locally. This is possible because on > functions that can be used for performing remote work on remote > per-cpu structures, the local_lock (which is already > a this_cpu spinlock()), will be replaced by a qpw_spinlock(), which > is able to get the per_cpu spinlock() for the cpu passed as parameter. > > v2->v3: > - Use preempt_disable/preempt_enable on !CONFIG_PREEMPT_RT (Vlastimil Babka). > - Improve documentation to include local_qpw_lock on operations table > (Leonardo Bras). > - Enable qpw=1 automatically if CPU isolation is enabled (Vlastimil Babka). > > v1->v2: > - Introduce local_qpw_lock and unlock functions, move preempt_disable/ > preempt_enable to it (Leonardo Bras). This reduces performance > overhead of the patch. > - Documentation and changelog typo fixes (Leonardo Bras). > - Fix places where preempt_disable/preempt_enable was not being > correctly performed. > - Add performance measurements. > > RFC->v1: > > - Introduce CONFIG_QPW and qpw= kernel boot option to enable > remote spinlocking and execution even on !CONFIG_PREEMPT_RT > kernels (Leonardo Bras). > - Move buffer_head draining to separate workqueue (Marcelo Tosatti). > - Convert mlock per-CPU page lists to QPW (Marcelo Tosatti). > - Drop memcontrol convertion (as isolated CPUs are not targets > of queue_work_on anymore). > - Rebase SLUB against Vlastimil's slab/next. > - Add basic document for QPW (Waiman Long). > > The performance numbers, as measured by the following test program, > are as follows: > > CONFIG_PREEMPT_DYNAMIC=y > Unpatched kernel: 60 cycles > Patched kernel, CONFIG_QPW=n: 62 cycles > Patched kernel, CONFIG_QPW=y, qpw=0: 62 cycles > Patched kernel, CONFIG_QPW=y, qpw=1: 75 cycles > > CONFIG_PREEMPT_RT: > Unpatched kernel: 95 cycles > Patched kernel, CONFIG_QPW=y, qpw=0: 99 cycles > Patched kernel, CONFIG_QPW=y, qpw=1: 97 cycles > > kmalloc_bench.c: > #include > #include > #include > #include > #include > #include > #include > > MODULE_LICENSE("GPL"); > MODULE_AUTHOR("Gemini AI"); > MODULE_DESCRIPTION("A simple kmalloc performance benchmark"); > > static int size = 64; // Default allocation size in bytes > module_param(size, int, 0644); > > static int iterations = 9000000; // Default number of iterations > module_param(iterations, int, 0644); > > static int __init kmalloc_bench_init(void) { > void **ptrs; > cycles_t start, end; > uint64_t total_cycles; > int i; > pr_info("kmalloc_bench: Starting test (size=%d, iterations=%d)\n", size, iterations); > > // Allocate an array to store pointers to avoid immediate kfree-reuse optimization > ptrs = vmalloc(sizeof(void *) * iterations); > if (!ptrs) { > pr_err("kmalloc_bench: Failed to allocate pointer array\n"); > return -ENOMEM; > } > > preempt_disable(); > start = get_cycles(); > > for (i = 0; i < iterations; i++) { > ptrs[i] = kmalloc(size, GFP_ATOMIC); > } > > end = get_cycles(); > > total_cycles = end - start; > preempt_enable(); > > pr_info("kmalloc_bench: Total cycles for %d allocs: %llu\n", iterations, total_cycles); > pr_info("kmalloc_bench: Avg cycles per kmalloc: %llu\n", total_cycles / iterations); > > // Cleanup > for (i = 0; i < iterations; i++) { > kfree(ptrs[i]); > } > vfree(ptrs); > > return 0; > } > > static void __exit kmalloc_bench_exit(void) { > pr_info("kmalloc_bench: Module unloaded\n"); > } > > module_init(kmalloc_bench_init); > module_exit(kmalloc_bench_exit); > > The following testcase triggers lru_add_drain_all on an isolated CPU > (that does sys_write to a file before entering its realtime > loop). > > /* > * Simulates a low latency loop program that is interrupted > * due to lru_add_drain_all. To trigger lru_add_drain_all, run: > * > * blockdev --flushbufs /dev/sdX > * > */ > #define _GNU_SOURCE > #include > #include > #include > #include > #include > #include > #include > #include > #include > #include > #include > #include > > int cpu; > > static void *run(void *arg) > { > pthread_t current_thread; > cpu_set_t cpuset; > int ret, nrloops; > struct sched_param sched_p; > pid_t pid; > int fd; > char buf[] = "xxxxxxxxxxx"; > > CPU_ZERO(&cpuset); > CPU_SET(cpu, &cpuset); > > current_thread = pthread_self(); > ret = pthread_setaffinity_np(current_thread, sizeof(cpu_set_t), &cpuset); > if (ret) { > perror("pthread_setaffinity_np failed\n"); > exit(0); > } > > memset(&sched_p, 0, sizeof(struct sched_param)); > sched_p.sched_priority = 1; > pid = gettid(); > ret = sched_setscheduler(pid, SCHED_FIFO, &sched_p); > if (ret) { > perror("sched_setscheduler"); > exit(0); > } > > fd = open("/tmp/tmpfile", O_RDWR|O_CREAT|O_TRUNC); > if (fd == -1) { > perror("open"); > exit(0); > } > > ret = write(fd, buf, sizeof(buf)); > if (ret == -1) { > perror("write"); > exit(0); > } > > do { > nrloops = nrloops+2; > nrloops--; > } while (1); > } > > int main(int argc, char *argv[]) > { > int fd, ret; > pthread_t thread; > long val; > char *endptr, *str; > struct sched_param sched_p; > pid_t pid; > > if (argc != 2) { > printf("usage: %s cpu-nr\n", argv[0]); > printf("where CPU number is the CPU to pin thread to\n"); > exit(0); > } > str = argv[1]; > cpu = strtol(str, &endptr, 10); > if (cpu < 0) { > printf("strtol returns %d\n", cpu); > exit(0); > } > printf("cpunr=%d\n", cpu); > > memset(&sched_p, 0, sizeof(struct sched_param)); > sched_p.sched_priority = 1; > pid = getpid(); > ret = sched_setscheduler(pid, SCHED_FIFO, &sched_p); > if (ret) { > perror("sched_setscheduler"); > exit(0); > } > > pthread_create(&thread, NULL, run, NULL); > > sleep(5000); > > pthread_join(thread, NULL); > } > > > > >