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 99DD3CD4F22 for ; Thu, 5 Sep 2024 00:08:25 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 017936B0393; Wed, 4 Sep 2024 20:08:25 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id F09446B0397; Wed, 4 Sep 2024 20:08:24 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DAB686B0398; Wed, 4 Sep 2024 20:08:24 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id B842A6B0393 for ; Wed, 4 Sep 2024 20:08:24 -0400 (EDT) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 4FE4BC153C for ; Thu, 5 Sep 2024 00:08:24 +0000 (UTC) X-FDA: 82528747728.06.95DB6D8 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf14.hostedemail.com (Postfix) with ESMTP id 63D72100010 for ; Thu, 5 Sep 2024 00:08:22 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=TYNrBkhZ; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf14.hostedemail.com: domain of longman@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=longman@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1725494824; a=rsa-sha256; cv=none; b=g0KG0gqGBV6u6oPbL6KF7aqEIb7IzlsEJ09E+xpHgDwR8QshEy5JRGEMDw438kIugdllJh 1RlAiA258neygbyKKV14ziCJ0hbNGO0Falie0lVaN+k3w57aEwbePv/xwK6867EvJ+VcGp +PNcTt6Rc1DUVR8o0xyOFok3XtN6iro= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=TYNrBkhZ; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf14.hostedemail.com: domain of longman@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=longman@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1725494824; 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=UHS4zP9jA0mTvK7JF/ePZcYsAK2+oZaSxTHPolbumnA=; b=VbANWpNeol/MWRfPaVhatiMpXtYRhr9CDnqGqKcp7WUj+S1TR+fFD0v8Be/YhhmXgvnQ4v 5cdEILikmHtCsbCYdM5IYw+GraEb1xqb7n91z47JTm1DDb7s7gLqynBZCBiqYnnLuvjhu6 0iO9QhEdrI/2gU/K5XuLZdL/zEofh24= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1725494901; 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=UHS4zP9jA0mTvK7JF/ePZcYsAK2+oZaSxTHPolbumnA=; b=TYNrBkhZ181cosz4sXYLjOpZWqK47cbwO8/tyTrRjOY87cq71FWicC86YysMk7htbgtSbP MfleqwqlGN773qwmPFnjsILQSOKHIDB9ev8wWFpLDjBjInHceNvuL8ObA7yYqGy3nu3wwf 5A5AfSaP9J03KnF4b8EfjGv0YLN2mYs= Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-390-SmZMspabPjaLULqbFRBxhQ-1; Wed, 04 Sep 2024 20:08:20 -0400 X-MC-Unique: SmZMspabPjaLULqbFRBxhQ-1 Received: from mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.15]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id D2AD31955D45; Thu, 5 Sep 2024 00:08:17 +0000 (UTC) Received: from [10.2.16.172] (unknown [10.2.16.172]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 902B21956086; Thu, 5 Sep 2024 00:08:13 +0000 (UTC) Message-ID: Date: Wed, 4 Sep 2024 20:08:12 -0400 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [RFC PATCH v1 1/4] Introducing qpw_lock() and per-cpu queue & flush work From: Waiman Long To: Leonardo Bras , 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>, Thomas Gleixner , Marcelo Tosatti Cc: linux-kernel@vger.kernel.org, cgroups@vger.kernel.org, linux-mm@kvack.org References: <20240622035815.569665-1-leobras@redhat.com> <20240622035815.569665-2-leobras@redhat.com> Content-Language: en-US In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.0 on 10.30.177.15 X-Rspamd-Server: rspam12 X-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Wi7w D8Gj+Mc8 WqV+BrygC0IcseYPyzDF/QhuCSPJuZf2yLmXilKoe/TxVYAYAXqgILJW/MwFeLqzkkTwjx9RUL/KbIK4cx3grP9JBZ3SqiNkmNL48D6NEcM/M4KSo5+hGYBIG02CoEv3sZmiDBw4PxPDign0x/DcqyPIPSpNyKwVj4zg9vplNB8j2NQQXwQ1PqnBcVvtA9LLgk0J43iUzgj7G5r8QKJuWA0ZoUapzDCilcIqRXJrydDJrphNHacxGEeUMzTdtBbMndBelnER5BQoLyUxq9Xsh7SBBSPLzLOK9bKSrjMDAn8lQr7toixO10PDd2woYL+3ZGbMyBmnmtpKcq/aWVMg0QTBB4jRotsOwFaGPh82Vks5KCgvMApCjRDDrUE3WtOrSxdFIMSO8cKTtxjiBx1PQdP8b8p/WgG07/Cnwap43s44v8bsN5UnPKOKN9YsajOseL/9Hqaarv0+EH2pxpVZMye2cXGaJGCuDX3gRCbdGlslYvUI= 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 9/4/24 17:39, Waiman Long wrote: > On 6/21/24 23:58, Leonardo Bras wrote: >> 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 some unrelated task is >> sure to introduce unexpected deadline misses. >> >> It's interesting, though, that local_lock()s in RT kernels become >> spinlock(). We can make use of those to avoid scheduling work on a >> remote >> cpu by directly updating another cpu's per_cpu structure, while holding >> it's spinlock(). >> >> In order to do that, it's necessary to introduce a new set of >> functions to >> make it possible to get another cpu's per-cpu "local" lock >> (qpw_{un,}lock*) >> and also the corresponding queue_percpu_work_on() and >> flush_percpu_work() >> helpers to run the remote work. >> >> On non-RT kernels, no changes are expected, as every one of the >> introduced >> helpers work the exactly same as the current implementation: >> qpw_{un,}lock*()        ->  local_{un,}lock*() (ignores cpu parameter) >> queue_percpu_work_on()  ->  queue_work_on() >> flush_percpu_work()     ->  flush_work() >> >> For RT kernels, though, qpw_{un,}lock*() will use the extra cpu >> parameter >> to select the correct per-cpu structure to work on, and acquire the >> spinlock for that cpu. >> >> queue_percpu_work_on() will just call the requested function in the >> current >> cpu, which will operate in another cpu's per-cpu object. Since the >> local_locks() become spinlock()s in PREEMPT_RT, we are safe doing that. >> >> flush_percpu_work() then becomes a no-op since no work is actually >> scheduled on a remote cpu. >> >> Some minimal code rework is needed in order to make this mechanism work: >> The calls for local_{un,}lock*() on the functions that are currently >> scheduled on remote cpus need to be replaced by qpw_{un,}lock_n*(), >> so in >> RT kernels they can reference a different cpu. It's also necessary to >> use a >> qpw_struct instead of a work_struct, but it just contains a work struct >> and, in PREEMPT_RT, the target cpu. >> >> This should have almost no impact on non-RT kernels: few this_cpu_ptr() >> will become per_cpu_ptr(,smp_processor_id()). >> >> On RT kernels, this should improve performance and reduce latency by >> removing scheduling noise. >> >> Signed-off-by: Leonardo Bras >> --- >>   include/linux/qpw.h | 88 +++++++++++++++++++++++++++++++++++++++++++++ >>   1 file changed, 88 insertions(+) >>   create mode 100644 include/linux/qpw.h >> >> diff --git a/include/linux/qpw.h b/include/linux/qpw.h >> new file mode 100644 >> index 000000000000..ea2686a01e5e >> --- /dev/null >> +++ b/include/linux/qpw.h >> @@ -0,0 +1,88 @@ >> +/* SPDX-License-Identifier: GPL-2.0 */ >> +#ifndef _LINUX_QPW_H >> +#define _LINUX_QPW_H I would suggest adding a comment with a brief description of what qpw_lock/unlock() are for and their use cases. The "qpw" prefix itself isn't intuitive enough for a casual reader to understand what they are for. Cheers, Longman