From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wr1-f41.google.com (mail-wr1-f41.google.com [209.85.221.41]) (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 4587E3148AE for ; Fri, 6 Feb 2026 23:56:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.41 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770422186; cv=none; b=a/9tNSNIRFMrx1vaAJ8FlJLjxbOMZXERtxdIjQPuZLl8gDeCIa1k/O1DkivQgGI2zYmRpD7cApP+3XTXdqQj/7BuhOfuyoPdUueHh5bOMK3foLxrMGVfyfygaC6GnxswogvNcB7xDQvnSkWNFtY8zTa+GEWdVUFbDctubq14PDg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770422186; c=relaxed/simple; bh=OkJt9zpckdw22ZpKHkb7JRzpfCA6dn//rhBE2I0MbLo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type:Content-Disposition; b=YmPa/MZemQR7c9RP+Ks6rAT9D6Dbbu3Cq2do+sJeLU0Wfu1dz3EHe9KMJXxNItUUkBek2tHXS94tPpzOdFbm52uSLFLx3bYigfvJNII1WXbcV3As5dD2dXBrCWryM8y64uwOC4Fi3jW9FytdKKysrdojhdXLHIeVOxwuVBJbHp0= 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=gvtmtm60; arc=none smtp.client-ip=209.85.221.41 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="gvtmtm60" Received: by mail-wr1-f41.google.com with SMTP id ffacd0b85a97d-4362c63531bso840014f8f.0 for ; Fri, 06 Feb 2026 15:56:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1770422184; x=1771026984; 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=yMvWXl+16besIoFxtupa8KqKhPGPXd3D6bW5GUBT3Eo=; b=gvtmtm6051gjSwpWkUc64ozoNQiIt4kWtnrwTcz87UpduA/wFYE8SJt5XlZ5LAFH+3 rFwhE1g0jORg6UV9d7ihmSKPkAWJWfvrjyesfASOWQtDBb6bm0Sj64ZELLh/Crzye6Di 8uP1FnZyd/SaZyGfnGd1VRM7N22Y41ImtlfamW5cmZpIUqZOEoGRy9iKTPtNZBoKEr2A hEArJLze8Z6A01mmiC7ExA6aQHwY4XDvqx5CGXmhXZAmIHPGSuPfElMkY5Sx53SZ+9am xpJWyNdtEoXcAaBDMlaR5tryHOlq8tSUY7RbmRQvZ/RAg4hISyCGYMmn9xQwxsg4dXHK AFiA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1770422184; x=1771026984; 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=yMvWXl+16besIoFxtupa8KqKhPGPXd3D6bW5GUBT3Eo=; b=wwMhgoIby9tSFfhtLPj5YlwfoWX1CIMgGjXdemlLjZG/rIfn9W1EFLEx3+bEK/ZIac t/OvLYu/HD3l5/M13lhx7XhmygxbsvodBMpLMp4s3DelfOIp5r4TAZI8UIXgyDJr2gT8 GBSD0PQVxm+1k1h7yWeHatF7BEWqajRzEo4qLHBEeuddfaNLoJdBjD9y/MZq/QFJiEzz IruAdQZccH5DsZIJTYOk3ei52tESHtlkbZW69g0+zKRTH5gzqsXA/cEs7R9p1kG4YlxS u3A8saVXGjzVgv8Rtn+8KyCZYxjQbxYBZGDAkFR6Y08JjwF/eeql/a7tpHfmRhuyX1kn A1Zg== X-Forwarded-Encrypted: i=1; AJvYcCVTcM4vZ6/06GAGL5iqv7NIWNz8ft41jk/FVsca4atX3IYXy2WeNqJ9qX9J4hCxNsTTiZmD7TlzUgmvJk0=@vger.kernel.org X-Gm-Message-State: AOJu0YwSlmnCcd+Jw6B9Mvns+NvwOiSbi6K87PUnxJFCgdRUFSOB6Sz+ ah/RE8/S1mRzJ6AQ5i9sL4pjtQjAeseuDAymSfZzGZgl9Y2BDXKrYmMj X-Gm-Gg: AZuq6aKf0zi8yStxMIvgtIzLVBXfPz/7dQtWA6iNJyfDSwMTU30/moxcwtv2qFfgv9X RlCdXCwcCWPplF1AuTed+esuzmX2oFErQv60qSwYqzDobNI+hLiwU1hqvJ2PsY7TDB25wCxSJrW YIAr2FlwmTp12m40/4FXvi7etiAbNb3CUl0XE/ojTo0ZEF2bvsUQHXZff1JuV6OoRHDkfHXlJyT vqmMy2C5kq2uyi2XhBn9mwPHUN7f22DGt71vM5Nep8b6KenIZx8ykceCZ3HF+cBSLMY13q+f/n4 uwR0v+zro6U9+aj1/+HSENtsGnxBIXHMK3a98ItvPb+jk8C+m+iYbEMyL80D5ClbQELuhFfytYc LPrTbzN00I59T4gTHzVIV9Dv6XO7YlwI3j7vIvo1oaefPIhzEyvi3Z0bRKevG+QECT6FpzAiFFL KK1Jw6nJ5lMo5gPhQGYEpq4JDmay8j8fIq1A== X-Received: by 2002:a05:6000:2304:b0:436:cea:6165 with SMTP id ffacd0b85a97d-4362904b70dmr5665598f8f.6.1770422184414; Fri, 06 Feb 2026 15:56:24 -0800 (PST) Received: from WindFlash.powerhub ([2a0a:ef40:1b2a:fa01:9944:6a8c:dc37:eba5]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-43629754c62sm8306435f8f.38.2026.02.06.15.56.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Feb 2026 15:56:23 -0800 (PST) From: Leonardo Bras To: Marcelo Tosatti Cc: Leonardo Bras , linux-kernel@vger.kernel.org, cgroups@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 Feng Subject: Re: [PATCH 0/4] Introduce QPW for per-cpu operations Date: Fri, 6 Feb 2026 20:56:21 -0300 Message-ID: X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260206143430.021026873@redhat.com> References: <20260206143430.021026873@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=us-ascii Content-Disposition: inline Content-Transfer-Encoding: 8bit On Fri, Feb 06, 2026 at 11:34:30AM -0300, Marcelo Tosatti wrote: > 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. > Marcelo, thanks for finishing this series! > Proposed solution: > A new interface called Queue PerCPU Work (QPW), which should replace > Work Queue in the above mentioned use case. > > If PREEMPT_RT=n this interfaces just wraps the current Are we enabling it by default in PREEMPT_RT=y? If not, If CONFIG_QPW=n or qpw=0 this interfaces just wraps the current > local_locks + WorkQueue behavior, so no expected change in runtime. > > If PREEMPT_RT=y, or CONFIG_QPW=y, queue_percpu_work_on(cpu,...) will Same here If CONFIG_QPW=y and qpw=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. > > 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). A document was a nice touch :) > > > 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); > } > > Also, having the reproducer in the cover letter was a great idea! Thanks! Leo