From patchwork Sat Jun 22 03:58:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leonardo Bras X-Patchwork-Id: 13708197 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 50868C27C53 for ; Sat, 22 Jun 2024 03:58:57 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D3BD68D01B5; Fri, 21 Jun 2024 23:58:56 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id CE0E48D01AF; Fri, 21 Jun 2024 23:58:56 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B31B68D01B5; Fri, 21 Jun 2024 23:58:56 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 92F7E8D01AF for ; Fri, 21 Jun 2024 23:58:56 -0400 (EDT) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 4053E1A13C0 for ; Sat, 22 Jun 2024 03:58:56 +0000 (UTC) X-FDA: 82257168672.17.C9E76D5 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf09.hostedemail.com (Postfix) with ESMTP id 32CF414001A for ; Sat, 22 Jun 2024 03:58:54 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=TrmswcNM; spf=pass (imf09.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=1719028728; a=rsa-sha256; cv=none; b=DREaxbeo1KLcM5S4UhbZz8uyqCyg55uRpk4/1dCLPGCf4eOmuRneRLDY2VUo6hd1a+y/fk iKgwaiS2Agbv5H7VwbERFMajGzcLSX90+XaOKZmNLu3Zp1XDDg6zYWu0QjypeEAoc1wrgR AbwlEWmWwSD334HMCV/PlWqUbuQXTc8= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=TrmswcNM; spf=pass (imf09.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=1719028728; 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=YZ33pz4CG9kAvALadE1yZYVBLwtylkbWD53nilFvhZA=; b=nlWYV+gFNJY9FGJAnUQWhITpiiDYV0g1DST6pHSHlqzvdxXaQZCb5YE1X2DebUPyr9ett6 GcGcNLRqo1s5mSqpCe0AO79nGZxFcFCyAN8zR0K1jet7gzPbRpvpV1/6STbq/4xpqeQo4U d2fgb2VOLuDW/OmNLD5UAi/y6Aq71Ko= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1719028733; 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=YZ33pz4CG9kAvALadE1yZYVBLwtylkbWD53nilFvhZA=; b=TrmswcNMiK457t4jXxGFe966qyRJLFxtsNDjh5mNNXNo2IlLalKUeBoBgT6uFOZaJJQJ/5 mU5NuXYF3CNDyRHA9sjmU8WFCWyQpQrsFFn/cIxyv2FQqDzQnksQ4xxw9rv6KaqE0BFR7N DgZfnfUYjAtucyG5L8xPBnO00DSnywg= Received: from mail-pl1-f199.google.com (mail-pl1-f199.google.com [209.85.214.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-223-BhsJnZJ_N6aqFwdNVHgRZQ-1; Fri, 21 Jun 2024 23:58:51 -0400 X-MC-Unique: BhsJnZJ_N6aqFwdNVHgRZQ-1 Received: by mail-pl1-f199.google.com with SMTP id d9443c01a7336-1f9a6356a02so23069095ad.3 for ; Fri, 21 Jun 2024 20:58:51 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719028731; x=1719633531; h=content-transfer-encoding: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=YZ33pz4CG9kAvALadE1yZYVBLwtylkbWD53nilFvhZA=; b=EM8bJdZzUVmpnca5yCojzNFGsjLEp2DOTnuNI2CGQTXyzBBrhURYDwrNarl2PVIph2 qW2tH7/VUFOjtFmzWgWd/VcqIDNG78T5KHIWkhYzMliTEVvaoNn23VSEBDFqJ+0GInL/ nHCKoXC+vz6HYOpb/z271j2LDEW4rBQiVWFYo9mbgl2/+E8yB9tepWi3i2Z2EY0i04on Tj0VVzu8j4hwWG6YTMf+t+4PfbqTgX9tebU/0KabCyhVekMbGUeLIr0yF+dojomav9lJ pQGxDH4rrgFAB1W6Dt1AercTn9o6Y6Y0Ee6qeAYYEenFtxK1ozH6SxG/rKS6Jz3wGgXQ 3ZTw== X-Forwarded-Encrypted: i=1; AJvYcCUMtRMpSOU0qksoMRuerA9w1NjMLsJ5xspt3TGoO4Mu/QZLQxGf72sQXkZRPu8a17Wui3g91TuTkv7T4wQZ9acoKks= X-Gm-Message-State: AOJu0YwxYKb8SXfDATS75Z213DRJgWJf0ocz7O/+0bprTyFLcixGCjGL 7j/jP7rSTYopTcvP99cBHwb0d8SF56XWZRZNr/CPfwz3BI5pCe7SgAnTA3TzSIaN9S5PTullppd IgFzzv40g7CsUJ+bxrn+O+dZJajazraT+YvQyAhqLa3EpSWFz X-Received: by 2002:a17:903:1cf:b0:1f9:9d40:c9bf with SMTP id d9443c01a7336-1f9aa4121cdmr114843275ad.18.1719028730781; Fri, 21 Jun 2024 20:58:50 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHt4UWWF8YWLxNNykxeuK6L5NtoG3cPihSQQtBcVaMFhxxpNx9bPrFdzerXafMwk+8wW98i8A== X-Received: by 2002:a17:903:1cf:b0:1f9:9d40:c9bf with SMTP id d9443c01a7336-1f9aa4121cdmr114843195ad.18.1719028730370; Fri, 21 Jun 2024 20:58:50 -0700 (PDT) Received: from LeoBras.redhat.com ([2804:1b3:a801:c138:e21d:3579:5747:ad1]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1f9eb32b9edsm21832365ad.118.2024.06.21.20.58.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Jun 2024 20:58:49 -0700 (PDT) From: Leonardo Bras To: 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 , Marcelo Tosatti Cc: linux-kernel@vger.kernel.org, cgroups@vger.kernel.org, linux-mm@kvack.org Subject: [RFC PATCH v1 2/4] swap: apply new queue_percpu_work_on() interface Date: Sat, 22 Jun 2024 00:58:10 -0300 Message-ID: <20240622035815.569665-3-leobras@redhat.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240622035815.569665-1-leobras@redhat.com> References: <20240622035815.569665-1-leobras@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Stat-Signature: dk1y1cphgc3jget7ryzqphqpfh3ku5ug X-Rspamd-Queue-Id: 32CF414001A X-Rspam-User: X-Rspamd-Server: rspam10 X-HE-Tag: 1719028734-194649 X-HE-Meta: U2FsdGVkX18TjkiCUkXABss9R8R4fqU+YgBOO4K1lrZRgNtpMcUMwHLDBxu1GJEY110x8GREVbJTBXrjviGsvlbzNnMRF+pYxPMV3KwV9EyTCotzKVC6JbXZX5DotZavx0r/hMp9+2fGSY2f6kSFiDwG5pXwhEs1J9z1zVDtcbDd/NgDLrfmksRU/Q+bOMMgsRafuRi6ksuHdf15famKpLwqijeULpnKFzcFfrAdCEIri55ZDJzL3cFZcwph+/I98eCDGwFFAX8kP75F77/fz/8nR7oF5tqfFUwsRjJ97gojVHvY42SQKm1iLQ/ewWlWfhS5SLpaI5kWwDq5z8JXBcEgYSroG87a2FL1/BDwNcOLiEXJLZtmBJ0dsEUdUfOHPizLbex3GiceQzE3UGkVmUJacj2YRLHszZvk2woWXNFTQBMKpkbrIkktUBjoco3O8aJF+ArG0ccDOOF75xY7N9VJfJtzo3EDpAKrPS3niGD/MGMIMCV0nOflkcgOIeFNDRzY/VqNEIO0W2yZmOnqaQAk7L6mYop0zWEDvd2In5e0q4ST/zUaJ158Ss1WXyi/l4lUycqsRG82l5H/lzF5d8cpf6Y7ZNEk4GWuwDLGCZAbk9QAVNELadYCGc56rWCqCXkCjcdTl6hdRfsDA11we+qWtbunrJ5ddfV7dsARTmJlgzEyW/rHYNsjxeShFIGpCj7RUn73i9b0Qd2rR9BZBqWVElZfczBdbWYiSyID/yunB9JeqfGZS3JR9O0PWmSfTkTsxUlDXpH/RMfKrXBzz2eca0KSY+7ne/heZrXVijsVRAYNCwXYMmVudU9oaQPFhrBNJzb/4kjBBDLYyJ84d4CmbjNDrHti/gxVgXh7kRMHkRpWwYWT+H8aSVx9RzxHR/GAFZogIhvofbz0GMqLOmWs4swRwDFpQF/GQELpMcEFRsNmA2dNl19h+FkKBjxeyGAd8ggxRbmC99c+TpC nEW1VYbf HNuimg1yesg1/GIKiD7n8QEOIIRKqCTJf7gkyP6s1QKNMkq63jp12+MGTLREBafw+QTYLFMUhFGwDofL0Q3LdUO/fmbLGmBPfyV8Nf/FsT0FHdlPgoDS4mINLDhe3tGbIrvJQ5bCJAaVnGiv9HqQSei3/SH0XdeykhDzMSN3YOI08uARZppCdBP69XFsKso1YYI2223Rj7P4Vb5gC7vEx96/Jqfn6cmHUt3915tsTJfP8S+BmO3qnWsPldlHBeQseYJwk4KhjNtsJAaBDNdYIWvcWz20cRdy3zJDqj4BzbFE132b+pku7iO/cAWdhSywsD9Z/WkM5wiThd8q0dIsMV9vVvgLhbEZ6Tl82K9u5aDcImugr1moj8cfSvOJ4x2/ZarpdinH/dRyqawHs+MLBcL9+13+b9E65/GqpZTqaKrzEElQ= 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: Make use of the new qpw_{un,}lock*() and queue_percpu_work_on() interface to improve performance & latency on PREEMTP_RT kernels. For functions that may be scheduled in a different cpu, replace local_{un,}lock*() by qpw_{un,}lock*(), and replace schedule_work_on() by queue_percpu_work_on(). The same happens for flush_work() and flush_percpu_work(). The change requires allocation of qpw_structs instead of a work_structs, and changing parameters of a few functions to include the cpu parameter. This should bring no relevant performance impact on non-RT kernels: For functions that may be scheduled in a different cpu, the local_*lock's this_cpu_ptr() becomes a per_cpu_ptr(smp_processor_id()). Signed-off-by: Leonardo Bras --- mm/swap.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/mm/swap.c b/mm/swap.c index 67786cb77130..c1a61b7cd71a 100644 --- a/mm/swap.c +++ b/mm/swap.c @@ -28,21 +28,21 @@ #include #include #include #include #include #include #include #include #include #include -#include +#include #include #include "internal.h" #define CREATE_TRACE_POINTS #include /* How many pages do we try to swap or page in/out together? As a power of 2 */ int page_cluster; const int page_cluster_max = 31; @@ -758,45 +758,45 @@ void lru_add_drain(void) local_unlock(&cpu_fbatches.lock); mlock_drain_local(); } /* * It's called from per-cpu workqueue context in SMP case so * lru_add_drain_cpu and invalidate_bh_lrus_cpu should run on * the same cpu. It shouldn't be a problem in !SMP case since * the core is only one and the locks will disable preemption. */ -static void lru_add_and_bh_lrus_drain(void) +static void lru_add_and_bh_lrus_drain(int cpu) { - local_lock(&cpu_fbatches.lock); - lru_add_drain_cpu(smp_processor_id()); - local_unlock(&cpu_fbatches.lock); + qpw_lock(&cpu_fbatches.lock, cpu); + lru_add_drain_cpu(cpu); + qpw_unlock(&cpu_fbatches.lock, cpu); invalidate_bh_lrus_cpu(); mlock_drain_local(); } void lru_add_drain_cpu_zone(struct zone *zone) { local_lock(&cpu_fbatches.lock); lru_add_drain_cpu(smp_processor_id()); drain_local_pages(zone); local_unlock(&cpu_fbatches.lock); mlock_drain_local(); } #ifdef CONFIG_SMP -static DEFINE_PER_CPU(struct work_struct, lru_add_drain_work); +static DEFINE_PER_CPU(struct qpw_struct, lru_add_drain_qpw); -static void lru_add_drain_per_cpu(struct work_struct *dummy) +static void lru_add_drain_per_cpu(struct work_struct *w) { - lru_add_and_bh_lrus_drain(); + lru_add_and_bh_lrus_drain(qpw_get_cpu(w)); } static bool cpu_needs_drain(unsigned int cpu) { struct cpu_fbatches *fbatches = &per_cpu(cpu_fbatches, cpu); /* Check these in order of likelihood that they're not zero */ return folio_batch_count(&fbatches->lru_add) || data_race(folio_batch_count(&per_cpu(lru_rotate.fbatch, cpu))) || folio_batch_count(&fbatches->lru_deactivate_file) || @@ -882,31 +882,31 @@ static inline void __lru_add_drain_all(bool force_all_cpus) * * If the paired barrier is done at any later step, e.g. after the * loop, CPU #x will just exit at (C) and miss flushing out all of its * added pages. */ WRITE_ONCE(lru_drain_gen, lru_drain_gen + 1); smp_mb(); cpumask_clear(&has_work); for_each_online_cpu(cpu) { - struct work_struct *work = &per_cpu(lru_add_drain_work, cpu); + struct qpw_struct *qpw = &per_cpu(lru_add_drain_qpw, cpu); if (cpu_needs_drain(cpu)) { - INIT_WORK(work, lru_add_drain_per_cpu); - queue_work_on(cpu, mm_percpu_wq, work); + INIT_QPW(qpw, lru_add_drain_per_cpu, cpu); + queue_percpu_work_on(cpu, mm_percpu_wq, qpw); __cpumask_set_cpu(cpu, &has_work); } } for_each_cpu(cpu, &has_work) - flush_work(&per_cpu(lru_add_drain_work, cpu)); + flush_percpu_work(&per_cpu(lru_add_drain_qpw, cpu)); done: mutex_unlock(&lock); } void lru_add_drain_all(void) { __lru_add_drain_all(false); } #else @@ -939,21 +939,21 @@ void lru_cache_disable(void) * * Since v5.1 kernel, synchronize_rcu() is guaranteed to wait on * preempt_disable() regions of code. So any CPU which sees * lru_disable_count = 0 will have exited the critical * section when synchronize_rcu() returns. */ synchronize_rcu_expedited(); #ifdef CONFIG_SMP __lru_add_drain_all(true); #else - lru_add_and_bh_lrus_drain(); + lru_add_and_bh_lrus_drain(smp_processor_id()); #endif } /** * folios_put_refs - Reduce the reference count on a batch of folios. * @folios: The folios. * @refs: The number of refs to subtract from each folio. * * Like folio_put(), but for a batch of folios. This is more efficient * than writing the loop yourself as it will optimise the locks which need