From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 86E1DC3064D for ; Tue, 25 Jun 2024 02:58:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D268B6B0337; Mon, 24 Jun 2024 22:58:17 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id CD5516B0338; Mon, 24 Jun 2024 22:58:17 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B76676B0339; Mon, 24 Jun 2024 22:58:17 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 993516B0337 for ; Mon, 24 Jun 2024 22:58:17 -0400 (EDT) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 2205816158B for ; Tue, 25 Jun 2024 02:58:17 +0000 (UTC) X-FDA: 82267902234.07.7646852 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf05.hostedemail.com (Postfix) with ESMTP id E021C10000E for ; Tue, 25 Jun 2024 02:58:14 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=gcvCZzol; spf=pass (imf05.hostedemail.com: domain of leobras@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=leobras@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1719284288; h=from:from:sender:reply-to:subject:subject: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:dkim-signature; bh=syJjt5ixA/f0tjdi5WdyuW2MiVMWIPWhYOIIe9HkUzQ=; b=vtZQcWLm46Cjnw9+oIo4sTKqJbpkP/JAz34Z44bsedLRUz3gCYo873kZ7TKsH+8Z+6hCTT 5cc27hxU4WVJ2oDuPH/3k1z5xq2GQaOWko3C0UQb5e356GcNB2a9MLK3rHpYZdSZZFf6V6 PNZaWiLQnuz4eV21ihFJ9hkBNGRAlMs= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=gcvCZzol; spf=pass (imf05.hostedemail.com: domain of leobras@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=leobras@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1719284288; a=rsa-sha256; cv=none; b=H85tKq8OV8OzaoWKMsUf5skho5re6E2/2IysKs6SbInPB3nbTiorqaceBsONtHzkvJw3BO qGlswLxGdjZYnHwH28FcC/PG+opttQc4576wEzW4UgCS5M5RfGJDhSGIAeMCLjCIW/wGm/ REeVVYOvU1jIN3GljkmfVeXgzk6mjlU= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1719284294; h=from:from:reply-to:subject:subject: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; bh=syJjt5ixA/f0tjdi5WdyuW2MiVMWIPWhYOIIe9HkUzQ=; b=gcvCZzoln7H+CTIwO4JxZhuFMF4rxdaaRsvChX4WbJms9Ka5ZL3B1P3SMgZ85idwBgdBow EuoVizvSxkLT5x7CNl3IeOO2VDAGbu1/41d8EuRFPNVebpGpd0DtMq6WxoT+7Sfney2smn 9488DD/ZeRuxCevjLEoftqf6kO/T4lc= Received: from mail-pl1-f197.google.com (mail-pl1-f197.google.com [209.85.214.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-605-R7HFv6l9PTiQhDdTntPVVw-1; Mon, 24 Jun 2024 22:58:11 -0400 X-MC-Unique: R7HFv6l9PTiQhDdTntPVVw-1 Received: by mail-pl1-f197.google.com with SMTP id d9443c01a7336-1f998f5e5fdso55248255ad.1 for ; Mon, 24 Jun 2024 19:58:11 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719284290; x=1719889090; h=content-transfer-encoding:content-disposition:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=syJjt5ixA/f0tjdi5WdyuW2MiVMWIPWhYOIIe9HkUzQ=; b=WCRejf10Ti3E7H17pEESUiCRL9BuXCPDVYqjxB6jYAkZ4E2fuUYscNegHTT23iF3t6 o43dKKKcAHeNdTYQfYN6RqmM3gFEFLBZUSAMGSX1jeOFtp5YrLi/szlMOB/Yo3JAxU+y UZX6qggIPYsL++iAD678n6QwfuSHgjeKFabNB3XWgKPJhymZkcHP8S0Fh6TjEKUZd4Mb aTmnfXwHynqj0OCLwvIfYKZaWAUzLqUjnKzf5OgONsxiePmSQGY4IrBLIap/M0CO0xLL FNYndgriUWpY9rFk/tRibucKm5bgeWFbkm0M2rQQCSS+1/rxTTsX6dlWfQl3Yy9IGAz/ hN0Q== X-Forwarded-Encrypted: i=1; AJvYcCUV7YTJbCwrd52qTxgEWvy0zqsycmAQhN4x5piyeKSseABDY0B6gSrmoOYXjVDPhuNxGAHh/ccRPDEHE5wT1UiCQkU= X-Gm-Message-State: AOJu0Yx0C8PNIVxpTktqtdNqlXmJRaR7CBKwA9Ww+jLOsRGXT2BFWlXp /qs0OA3XXr+EWWTb5QPhWtiI04rubXo1ddrJlHPWHPODoVBZIrrYcwgJei8zxsNkP9lKUCsIWPq JSxmjuWkgl+gI8uP68J0zI3aDdpURkGTpazwTzYdoLr9iagjP X-Received: by 2002:a17:902:e851:b0:1fa:cbf:c8b9 with SMTP id d9443c01a7336-1fa158f79b2mr91419495ad.38.1719284290575; Mon, 24 Jun 2024 19:58:10 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF4BRlOcWHTc7rAkYWYrFoBO7157nBjNcPk/UZJfP6+36id69+6Snc9jGenlIdVCvXxJPkqSQ== X-Received: by 2002:a17:902:e851:b0:1fa:cbf:c8b9 with SMTP id d9443c01a7336-1fa158f79b2mr91419225ad.38.1719284290153; Mon, 24 Jun 2024 19:58:10 -0700 (PDT) Received: from LeoBras.redhat.com ([2804:1b3:a801:fda9:d11e:3755:61da:97fd]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1f9eb32973asm69694765ad.113.2024.06.24.19.58.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Jun 2024 19:58:09 -0700 (PDT) From: Leonardo Bras To: Boqun Feng Cc: Leonardo Bras , Vlastimil Babka , 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 , linux-kernel@vger.kernel.org, cgroups@vger.kernel.org, linux-mm@kvack.org Subject: Re: [RFC PATCH v1 0/4] Introduce QPW for per-cpu operations Date: Mon, 24 Jun 2024 23:57:57 -0300 Message-ID: X-Mailer: git-send-email 2.45.2 In-Reply-To: References: <20240622035815.569665-1-leobras@redhat.com> <261612b9-e975-4c02-a493-7b83fa17c607@suse.cz> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: 8bit X-Rspam-User: X-Rspamd-Server: rspam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T+AgM/ HzBSp6kuRHvHmI7huaanm/40pLCD3OXqCd8k4Xrx1PbCFytzlagMx85HqBgLp+V3zduoF2SBmG1p+G5WZxJzNFmdguTCEoHA5cCr3mjRktLTTIGepC1+j8lbxVlJiWXKD9w6Hf6jtJTHOsLx2gCbMqPKU8l6uUV56FSOnOHBswWigGI9jbSbdaxg0DSK7t+LrqpbeC8muES9A1VjoLbqDcARf2KKhr9x4fGQn+a2PVNQqQ4PXq475Wv2wltG0OE507JshfMOKb6bvk1SkkZRN5X2Feo4x9MlHnifbWbreMVgzs+0N3cAlZKP1rl8i+qe2+I9wp4DMIgti7KZpU33GUZd1auGoaxunLz0YBFnyhJC1NC6nfn1OFV0SPNCAI8JS3xrs9vf9cFDl++NAszBJ1+mvJtP4YPGWu/FBl+L1lRQEoDDRACGGPqma2cmX+4UBYCBUsVgyPISdWGvCXmd3ZEGiEtecC6N+cMBN9Ckgpgd6ovTox4CYp995zmH5um19ZIQ08torc2X19yMMEQnexCwq28JQGDEZSFW00x8OnzM0T08D3V9TLmA3ddacK53c2s3t3AWpQaI1/yTe+OUk06jKrdcUB6M5pEyI X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: On Mon, Jun 24, 2024 at 03:54:14PM -0700, Boqun Feng wrote: > On Mon, Jun 24, 2024 at 09:31:51AM +0200, Vlastimil Babka wrote: > > 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. > > Thanks! > > > Link to full series: > > https://lore.kernel.org/all/20240622035815.569665-1-leobras@redhat.com/ > > > > And apologies to Leonardo... I think this is a follow-up of: > > https://lpc.events/event/17/contributions/1484/ > > and I did remember we had a quick chat after that which I suggested it's > better to change to a different name, sorry that I never found time to > write a proper rely to your previous seriese [1] as promised. > > [1]: https://lore.kernel.org/lkml/20230729083737.38699-2-leobras@redhat.com/ That's correct, I commented about this in the end of above presentation. Don't worry, and thanks for suggesting the per-cpu naming, it was very helpful on designing this solution. > > > 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... > > > > I think it's a good idea, especially the new name is less confusing ;-) > So I wonder Thomas' thoughts as well. Thanks! > > And I think a few (micro-)benchmark numbers will help. Last year I got some numbers on how replacing local_locks with spinlocks would impact memcontrol.c cache operations: https://lore.kernel.org/all/20230125073502.743446-1-leobras@redhat.com/ tl;dr: It increased clocks spent in the most common this_cpu operations, while reducing clocks spent in remote operations (drain_all_stock). In RT case, since local locks are already spinlocks, this cost is already paid, so we can get results like these: drain_all_stock cpus Upstream Patched Diff (cycles) Diff(%) 1 44331.10831 38978.03581 -5353.072507 -12.07520567 8 43992.96512 39026.76654 -4966.198572 -11.2886198 128 156274.6634 58053.87421 -98220.78915 -62.85138425 Upstream: Clocks to schedule work on remote CPU (performing not accounted) Patched: Clocks to grab remote cpu's spinlock and perform the needed work locally. Do you have other suggestions to use as (micro-) benchmarking? Thanks! Leo > > Regards, > Boqun > > > > 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 > > >