From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) (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 45A6F44C9B; Mon, 24 Jun 2024 07:31:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.135.223.131 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719214316; cv=none; b=A++CHCQscvI7KCYYbNQ2uiur6OHoFROKjWEZioQacU820nL8HfBVWHfvjmZ6u2hkdtc62yHk9IFr5iq87GGXCbSVk0a/0rMI7ZJZcOhdNtMMFxnu9Xm/RG7KS99gAmXaPI0g2Z9fG3TmdlUM+NTbvCDAaU3d+jhR8vRXZKsXJTA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719214316; c=relaxed/simple; bh=WheDYIvSXPFHlJ+vjpFSdiYww6phbPNBqdRM6HpTPnc=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=QDWOk8Zo2EU5wI/xC3B1LCi3Wq/tpnXWVA7eBWIlMg0M881640Mjx344LhwL6DjPKP6NIcWKvjo9z/+Mj9+TjlDwNPEuzBB+IL42Ii5QvZzJul6Uim062mieTRs8apHuQg+HONq8K0xNgut26ZfGa0Xk6gKnErc2FFov7KHx7yc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=suse.cz; spf=pass smtp.mailfrom=suse.cz; dkim=pass (1024-bit key) header.d=suse.cz header.i=@suse.cz header.b=cGaALcot; dkim=permerror (0-bit key) header.d=suse.cz header.i=@suse.cz header.b=F/nVGCQp; dkim=pass (1024-bit key) header.d=suse.cz header.i=@suse.cz header.b=cGaALcot; dkim=permerror (0-bit key) header.d=suse.cz header.i=@suse.cz header.b=F/nVGCQp; arc=none smtp.client-ip=195.135.223.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=suse.cz Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.cz Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=suse.cz header.i=@suse.cz header.b="cGaALcot"; dkim=permerror (0-bit key) header.d=suse.cz header.i=@suse.cz header.b="F/nVGCQp"; dkim=pass (1024-bit key) header.d=suse.cz header.i=@suse.cz header.b="cGaALcot"; dkim=permerror (0-bit key) header.d=suse.cz header.i=@suse.cz header.b="F/nVGCQp" Received: from imap1.dmz-prg2.suse.org (unknown [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 7A8681F7B8; Mon, 24 Jun 2024 07:31:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1719214312; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:autocrypt:autocrypt; bh=wf4xdzLYLuHWo1JVz5hvLlR9WFrEMxWJf5gClzD7V9A=; b=cGaALcotC+G2tl/AjrCaBRoTmir/FK0RFgGktls9x5Me9l91K/ctHwrGIV2EKNxFDWCHri 4f7zEAk3SKB4yMqTiP+RrfjvnfOBkOHdt4OQGoPBweh9xBo/19Fv36Yb5F4ROCXONAd6F1 8g+1ni7Aj96iSMF+MGn/91RjQ2JSwg0= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1719214312; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:autocrypt:autocrypt; bh=wf4xdzLYLuHWo1JVz5hvLlR9WFrEMxWJf5gClzD7V9A=; b=F/nVGCQpLodoZ4nJO2LBlx9BDHhJwj7fo70TOZiGtdSlL70ejuGjvTKBN8b2jWAhuqvjMq w19lxh7MUkHLRzBQ== Authentication-Results: smtp-out2.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1719214312; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:autocrypt:autocrypt; bh=wf4xdzLYLuHWo1JVz5hvLlR9WFrEMxWJf5gClzD7V9A=; b=cGaALcotC+G2tl/AjrCaBRoTmir/FK0RFgGktls9x5Me9l91K/ctHwrGIV2EKNxFDWCHri 4f7zEAk3SKB4yMqTiP+RrfjvnfOBkOHdt4OQGoPBweh9xBo/19Fv36Yb5F4ROCXONAd6F1 8g+1ni7Aj96iSMF+MGn/91RjQ2JSwg0= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1719214312; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:autocrypt:autocrypt; bh=wf4xdzLYLuHWo1JVz5hvLlR9WFrEMxWJf5gClzD7V9A=; b=F/nVGCQpLodoZ4nJO2LBlx9BDHhJwj7fo70TOZiGtdSlL70ejuGjvTKBN8b2jWAhuqvjMq w19lxh7MUkHLRzBQ== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 4869B13ACD; Mon, 24 Jun 2024 07:31:52 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id wgcwEeggeWYtfgAAD6G6ig (envelope-from ); Mon, 24 Jun 2024 07:31:52 +0000 Message-ID: <261612b9-e975-4c02-a493-7b83fa17c607@suse.cz> Date: Mon, 24 Jun 2024 09:31:51 +0200 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [RFC PATCH v1 0/4] Introduce QPW for per-cpu operations To: Leonardo Bras , Johannes Weiner , Michal Hocko , Roman Gushchin , Shakeel Butt , Muchun Song , Andrew Morton , Christoph Lameter , Pekka Enberg , David Rientjes , Joonsoo Kim , Hyeonggon Yoo <42.hyeyoo@gmail.com>, Thomas Gleixner , Marcelo Tosatti , Peter Zijlstra , Ingo Molnar , Will Deacon , Waiman Long , Boqun Feng Cc: linux-kernel@vger.kernel.org, cgroups@vger.kernel.org, linux-mm@kvack.org References: <20240622035815.569665-1-leobras@redhat.com> Content-Language: en-US From: Vlastimil Babka Autocrypt: addr=vbabka@suse.cz; keydata= xsFNBFZdmxYBEADsw/SiUSjB0dM+vSh95UkgcHjzEVBlby/Fg+g42O7LAEkCYXi/vvq31JTB KxRWDHX0R2tgpFDXHnzZcQywawu8eSq0LxzxFNYMvtB7sV1pxYwej2qx9B75qW2plBs+7+YB 87tMFA+u+L4Z5xAzIimfLD5EKC56kJ1CsXlM8S/LHcmdD9Ctkn3trYDNnat0eoAcfPIP2OZ+ 9oe9IF/R28zmh0ifLXyJQQz5ofdj4bPf8ecEW0rhcqHfTD8k4yK0xxt3xW+6Exqp9n9bydiy tcSAw/TahjW6yrA+6JhSBv1v2tIm+itQc073zjSX8OFL51qQVzRFr7H2UQG33lw2QrvHRXqD Ot7ViKam7v0Ho9wEWiQOOZlHItOOXFphWb2yq3nzrKe45oWoSgkxKb97MVsQ+q2SYjJRBBH4 8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 1C2o4i/yZPLXIVy387EjA6GZMqvQUFuSTs/GeBcv0NjIQi8867H3uLjz+mQy63fAitsDwLmR EP+ylKVEKb0Q2A== In-Reply-To: <20240622035815.569665-1-leobras@redhat.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Score: -2.79 X-Spam-Level: X-Spam-Flag: NO X-Spamd-Result: default: False [-2.79 / 50.00]; BAYES_HAM(-3.00)[100.00%]; SUSPICIOUS_RECIPS(1.50)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain]; XM_UA_NO_VERSION(0.01)[]; MIME_TRACE(0.00)[0:+]; FUZZY_BLOCKED(0.00)[rspamd.com]; DKIM_SIGNED(0.00)[suse.cz:s=susede2_rsa,suse.cz:s=susede2_ed25519]; TO_MATCH_ENVRCPT_ALL(0.00)[]; RCPT_COUNT_TWELVE(0.00)[22]; ARC_NA(0.00)[]; FREEMAIL_TO(0.00)[redhat.com,cmpxchg.org,kernel.org,linux.dev,linux-foundation.org,linux.com,google.com,lge.com,gmail.com,linutronix.de,infradead.org]; FREEMAIL_ENVRCPT(0.00)[gmail.com]; RCVD_TLS_ALL(0.00)[]; FROM_EQ_ENVFROM(0.00)[]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; RCVD_COUNT_TWO(0.00)[2]; TAGGED_RCPT(0.00)[]; MID_RHS_MATCH_FROM(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[imap1.dmz-prg2.suse.org:helo] Hi, you've included tglx, which is great, but there's also LOCKING PRIMITIVES section in MAINTAINERS so I've added folks from there in my reply. Link to full series: https://lore.kernel.org/all/20240622035815.569665-1-leobras@redhat.com/ On 6/22/24 5:58 AM, Leonardo Bras 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. Tha major cost, which is un/locking in every local function, > already happens in PREEMPT_RT. I've also noticed this a while ago (likely in the context of rewriting SLUB to use local_lock) and asked about it on IRC, and IIRC tglx wasn't fond of the idea. But I forgot the details about why, so I'll let the the locking experts reply... > 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. > > For patches 2, 3 & 4, I noticed just grabing the lock and executing > the function locally is much faster than just scheduling it on a > remote cpu. > > 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 > local_locks + WorkQueue behavior, so no expected change in runtime. > > If PREEMPT_RT=y, 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. > > Patch 1 implements QPW interface, and patches 2, 3 & 4 replaces the > current local_lock + WorkQueue interface by the QPW interface in > swap, memcontrol & slub interface. > > Please let me know what you think on that, and please suggest > improvements. > > Thanks a lot! > Leo > > Leonardo Bras (4): > Introducing qpw_lock() and per-cpu queue & flush work > swap: apply new queue_percpu_work_on() interface > memcontrol: apply new queue_percpu_work_on() interface > slub: apply new queue_percpu_work_on() interface > > include/linux/qpw.h | 88 +++++++++++++++++++++++++++++++++++++++++++++ > mm/memcontrol.c | 20 ++++++----- > mm/slub.c | 26 ++++++++------ > mm/swap.c | 26 +++++++------- > 4 files changed, 127 insertions(+), 33 deletions(-) > create mode 100644 include/linux/qpw.h > > > base-commit: 50736169ecc8387247fe6a00932852ce7b057083