From patchwork Sat Jun 22 03:58:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leonardo Bras X-Patchwork-Id: 13708199 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 CDFCAC27C53 for ; Sat, 22 Jun 2024 03:59:08 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 603CC8E0001; Fri, 21 Jun 2024 23:59:08 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 5B3248D01AF; Fri, 21 Jun 2024 23:59:08 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 406348E0001; Fri, 21 Jun 2024 23:59:08 -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 1EC848D01AF for ; Fri, 21 Jun 2024 23:59:08 -0400 (EDT) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id C72A1C132D for ; Sat, 22 Jun 2024 03:59:07 +0000 (UTC) X-FDA: 82257169134.08.AEE2C77 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf23.hostedemail.com (Postfix) with ESMTP id B483114000C for ; Sat, 22 Jun 2024 03:59:05 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=ZqB8sRot; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf23.hostedemail.com: domain of leobras@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=leobras@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1719028733; 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=gr/4mKEcg1BO/1nqaoL0eifI3AwTZgGcUhIFK99x5ho=; b=ufNxrF33YNneG9wJqM9Wg9hpI6S388bhm9h45WhF0ds2EHOKqCTnsbnE+TOTZOrP/kzj54 BKq2oswNn9qJC70JAUKAEYzIkF/uE2k2qwXU4Kq8umu5TgtypH2qZWpUOGVLcoebBho/Dh gPVxi1PNHe1kw8xm0iS4jlDTxeg3QM4= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1719028733; a=rsa-sha256; cv=none; b=ByMQ/PlaMiNVA9qRAggPiQ43AqT1XkOJ8wXtPEEV3paPmCQm39RzDNc5CM/C2d41T4O+Xr dqUYInulOHoNM7X53hrYYGgFpoervVjHQCN8tANCja+T+HVv6uB52a66ziNB3lVHcOcQz4 IRByhnVNPu4COFERASDACfmTakq1CqY= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=ZqB8sRot; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf23.hostedemail.com: domain of leobras@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=leobras@redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1719028745; 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=gr/4mKEcg1BO/1nqaoL0eifI3AwTZgGcUhIFK99x5ho=; b=ZqB8sRotdJfAI1qLOxA+hvDct0foVVmDBnBXsrKbFloTTQ5e4O4Ebg2o1MT5uHtarPU0Tc nxKvvRJvMZmbbYq9aQrIk4tlAAKeWmUhQbpaDkv710cguXpCas/IwOxKVaJKftu/rcWON+ Hi1aRlvnrVIeMGRHXimpiDiCFHeRXGU= Received: from mail-pj1-f69.google.com (mail-pj1-f69.google.com [209.85.216.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-530-aQPd91bAP5WeiR42VgUZuw-1; Fri, 21 Jun 2024 23:59:03 -0400 X-MC-Unique: aQPd91bAP5WeiR42VgUZuw-1 Received: by mail-pj1-f69.google.com with SMTP id 98e67ed59e1d1-2c7a6c639bfso2854904a91.3 for ; Fri, 21 Jun 2024 20:59:03 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719028742; x=1719633542; 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=gr/4mKEcg1BO/1nqaoL0eifI3AwTZgGcUhIFK99x5ho=; b=Xbkr6ZR4oSd8CX95uA8Dxc2kCm4hLCtjhZYPoTJN9yX5BCeWsrCsXmkyzytobdUOWa 1yxhoQT1Fwf3AU0g5H08HVRy2KtZYmGe7xWYyz/0WdxYJOVj7NDg40AbVg2FDXtT7GWp GO5UIs7gKnuAlMA60nYTtSPdb94RwssscVDcdj7teUrtxaUhFlpsnsZwzQhwhgsFGRxs uMznJniIwnRzVDuj4kKLROZ20yuaL0felEiq7vKpqJc60npvngbpKU9M4mnw8MsMombF wewgBT/pfZ61wPvoxCUHS9AlDkk9JxBt5Pa4GbaZPl1m8QJdVMjVq6WnjfjbQrf0m67n KNIg== X-Forwarded-Encrypted: i=1; AJvYcCUY8IF/x0m9sBHKhs8nJMQznDDtQfcp3ez1qHMjQllKQTLRm9Ew9K+bijBETpTLaDUeI/XMlNJhBgmdBxjqL5CIZZs= X-Gm-Message-State: AOJu0YzEx3tLj1m+zOBjiB7W2l1nlOP3PJFZmoYGvvGeI8s7xhzvXAJF ReaJFQ8dqx1/3VAerc+7b0fD8utwKgECDU7bcgcUAcHENRQLJdUf3DQMFsf1DCoTdDmwBmGqQJf Cic2I+M82rUj09HjuC7zNhZwPGBD2hx9iHFy1pllStcXimI+S X-Received: by 2002:a17:90a:6006:b0:2c3:cc6:636e with SMTP id 98e67ed59e1d1-2c7b59fa68cmr10387330a91.2.1719028742279; Fri, 21 Jun 2024 20:59:02 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHbqsAmN/2usMDnEbfUaqXha6LBh1OFap3JUlsvia0ZFkQTobQ3J2rvz24LicWySb2pIwxdrA== X-Received: by 2002:a17:90a:6006:b0:2c3:cc6:636e with SMTP id 98e67ed59e1d1-2c7b59fa68cmr10387308a91.2.1719028741834; Fri, 21 Jun 2024 20:59:01 -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.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Jun 2024 20:59:01 -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 4/4] slub: apply new queue_percpu_work_on() interface Date: Sat, 22 Jun 2024 00:58:12 -0300 Message-ID: <20240622035815.569665-5-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-Rspamd-Server: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nyM 5mhslcuw hzSAyKFau6pqImjg79Dr1mNK1kywiqLAgg4b3XcMgQHKZYAkz+ZgEbBH7RD0ziVJnTMZm3qJH/yxD82AMgt4q9VvNDnzMa30k5tdTRckNyTNOyFpEJztV93E18xNji1nbffoSVLcVtx0f7V2UDDaWC8oOGkvktRxUtxo1B9KPToGJXJm5lvNzFYQnQg2N35TsVz7OZekeVX2y//kL8C/6twl9L+3kImQiFMsA5IuwRO9z06RTOiLzSH+Ubf+XHD3Yy1/TE4xi5RVWvIk+Ucb5RckkwP39kXHubkupEOdIg4zlqNWnGZIL5e//uxzKeSB382hXCGj4BfWioa1ZgMcFGdaZ6oBEkN2CIlpKaoUEVyzKixnkJvSDz//EwiWdeLn53aISbheg/FKydJ+nlioPD1j9kJQrrrpQJRoL5UBovcR504Ab9TU32+a2Soxb5KH56Wf7bSjH5jDqiK0PwArgyWg2og== 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(). This 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/slub.c | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/mm/slub.c b/mm/slub.c index 1373ac365a46..5cd91541906e 100644 --- a/mm/slub.c +++ b/mm/slub.c @@ -35,20 +35,21 @@ #include #include #include #include #include #include #include #include #include #include +#include #include #include #include "internal.h" /* * Lock order: * 1. slab_mutex (Global Mutex) * 2. node->list_lock (Spinlock) @@ -3073,36 +3074,37 @@ static void put_cpu_partial(struct kmem_cache *s, struct slab *slab, int drain) } #else /* CONFIG_SLUB_CPU_PARTIAL */ static inline void put_partials(struct kmem_cache *s) { } static inline void put_partials_cpu(struct kmem_cache *s, struct kmem_cache_cpu *c) { } #endif /* CONFIG_SLUB_CPU_PARTIAL */ -static inline void flush_slab(struct kmem_cache *s, struct kmem_cache_cpu *c) +static inline void flush_slab(struct kmem_cache *s, struct kmem_cache_cpu *c, + int cpu) { unsigned long flags; struct slab *slab; void *freelist; - local_lock_irqsave(&s->cpu_slab->lock, flags); + qpw_lock_irqsave(&s->cpu_slab->lock, flags, cpu); slab = c->slab; freelist = c->freelist; c->slab = NULL; c->freelist = NULL; c->tid = next_tid(c->tid); - local_unlock_irqrestore(&s->cpu_slab->lock, flags); + qpw_unlock_irqrestore(&s->cpu_slab->lock, flags, cpu); if (slab) { deactivate_slab(s, slab, freelist); stat(s, CPUSLAB_FLUSH); } } static inline void __flush_cpu_slab(struct kmem_cache *s, int cpu) { struct kmem_cache_cpu *c = per_cpu_ptr(s->cpu_slab, cpu); @@ -3115,82 +3117,84 @@ static inline void __flush_cpu_slab(struct kmem_cache *s, int cpu) if (slab) { deactivate_slab(s, slab, freelist); stat(s, CPUSLAB_FLUSH); } put_partials_cpu(s, c); } struct slub_flush_work { - struct work_struct work; + struct qpw_struct qpw; struct kmem_cache *s; bool skip; }; +static DEFINE_PER_CPU(struct slub_flush_work, slub_flush); + /* * Flush cpu slab. * * Called from CPU work handler with migration disabled. */ static void flush_cpu_slab(struct work_struct *w) { struct kmem_cache *s; struct kmem_cache_cpu *c; struct slub_flush_work *sfw; + int cpu = qpw_get_cpu(w); - sfw = container_of(w, struct slub_flush_work, work); + sfw = &per_cpu(slub_flush, cpu); s = sfw->s; - c = this_cpu_ptr(s->cpu_slab); + c = per_cpu_ptr(s->cpu_slab, cpu); if (c->slab) - flush_slab(s, c); + flush_slab(s, c, cpu); put_partials(s); } static bool has_cpu_slab(int cpu, struct kmem_cache *s) { struct kmem_cache_cpu *c = per_cpu_ptr(s->cpu_slab, cpu); return c->slab || slub_percpu_partial(c); } static DEFINE_MUTEX(flush_lock); -static DEFINE_PER_CPU(struct slub_flush_work, slub_flush); static void flush_all_cpus_locked(struct kmem_cache *s) { struct slub_flush_work *sfw; unsigned int cpu; lockdep_assert_cpus_held(); mutex_lock(&flush_lock); for_each_online_cpu(cpu) { sfw = &per_cpu(slub_flush, cpu); if (!has_cpu_slab(cpu, s)) { sfw->skip = true; continue; } - INIT_WORK(&sfw->work, flush_cpu_slab); + INIT_QPW(&sfw->qpw, flush_cpu_slab, cpu); sfw->skip = false; sfw->s = s; - queue_work_on(cpu, flushwq, &sfw->work); + queue_percpu_work_on(cpu, flushwq, &sfw->qpw); } for_each_online_cpu(cpu) { sfw = &per_cpu(slub_flush, cpu); if (sfw->skip) continue; - flush_work(&sfw->work); + flush_percpu_work(&sfw->qpw); } mutex_unlock(&flush_lock); } static void flush_all(struct kmem_cache *s) { cpus_read_lock(); flush_all_cpus_locked(s); cpus_read_unlock();