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 88306C0032E for ; Wed, 25 Oct 2023 18:49:36 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1DE488D000F; Wed, 25 Oct 2023 14:49:36 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 18E3E8D0001; Wed, 25 Oct 2023 14:49:36 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 056D38D000F; Wed, 25 Oct 2023 14:49:36 -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 EBB1A8D0001 for ; Wed, 25 Oct 2023 14:49:35 -0400 (EDT) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id C82C540818 for ; Wed, 25 Oct 2023 18:49:35 +0000 (UTC) X-FDA: 81384872310.14.6D968D3 Received: from smtpout.efficios.com (smtpout.efficios.com [167.114.26.122]) by imf23.hostedemail.com (Postfix) with ESMTP id 8279014002F for ; Wed, 25 Oct 2023 18:49:32 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=efficios.com header.s=smtpout1 header.b=meVTLcDJ; spf=pass (imf23.hostedemail.com: domain of mathieu.desnoyers@efficios.com designates 167.114.26.122 as permitted sender) smtp.mailfrom=mathieu.desnoyers@efficios.com; dmarc=pass (policy=none) header.from=efficios.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1698259773; 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=sZgwWltvV8RSIifJ/GqPDar5Ey/e9ia2p4TFngd8CcE=; b=L7q4wnBwjWiXIfTV3F1yUHn/7AnUMgF2lFoP5w5oScsv2YmRgWIGhbh61ZnCqfa9rlNTwp BxmTC5SXbb1Qxji/5ryvSLdryciZcU99zVDtuKrVwnmL2Kun9znF1HYtt1vXDNnWDSBhxp 7GFDRgWReRo+hBfIIFWkAK6s8mgL3lQ= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=efficios.com header.s=smtpout1 header.b=meVTLcDJ; spf=pass (imf23.hostedemail.com: domain of mathieu.desnoyers@efficios.com designates 167.114.26.122 as permitted sender) smtp.mailfrom=mathieu.desnoyers@efficios.com; dmarc=pass (policy=none) header.from=efficios.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1698259773; a=rsa-sha256; cv=none; b=M69ZKHrwirkPBGZDAwTC3CJG7sxKKhutLjHjZPkqqcaF9GO7lfMUQjcYXAj9/a85nAqBMc PnICa136kAUi+/NAPKCI6H5OxwMvC6folgVzRBI61hmeF70/kgRTR9liF3jxIxwxyMWXAP MVUJ6L4SpMkSQU8H2OuRyOWqTBP8+lg= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=efficios.com; s=smtpout1; t=1698259771; bh=ZVx1Dd7UUSNMJt/FMbzBDNVrdpJzMCrzVrAzp4eNAq0=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=meVTLcDJsVk464UwUqmGKOXvf8firSVrqfWIhyKrLm0s2ZwzTr3kHBoi+mfcJX7tq T30GnP0KhYnCS/HK8q9JAT7ffhHzHJGKNuCNr26F+K9QTv5rBprMSbjO3WMp9TM7z7 0pZZY6NvluaWH5RejWgGMjSTAeUAkk4/ZMfqSnBrFmLqnCHeaoO/uyCS9F5HyTm8Kr rsOP47d+mnifU36SG4Y/ZIMYTtLT3Hix/u1PXi01NnY9P6C846rqwWCcqQoEBLW3QQ 0S1OpTzv9uYFFPq1AsI+8SJ9d/ZUAB2BEvCFPDJWBReaFm1wqUGoJA9SAhSjvEPBcP 0btgXqEPy6uGA== Received: from [172.16.0.134] (192-222-143-198.qc.cable.ebox.net [192.222.143.198]) by smtpout.efficios.com (Postfix) with ESMTPSA id 4SFydj4Fzmz1ZQw; Wed, 25 Oct 2023 14:49:29 -0400 (EDT) Message-ID: <0d95385f-1be1-4dcf-93cb-8c5df3bc9d0c@efficios.com> Date: Wed, 25 Oct 2023 14:49:44 -0400 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [POC][RFC][PATCH] sched: Extended Scheduler Time Slice Content-Language: en-US To: Steven Rostedt , Mateusz Guzik Cc: Peter Zijlstra , LKML , Thomas Gleixner , Ankur Arora , Linus Torvalds , linux-mm@kvack.org, x86@kernel.org, akpm@linux-foundation.org, luto@kernel.org, bp@alien8.de, dave.hansen@linux.intel.com, hpa@zytor.com, mingo@redhat.com, juri.lelli@redhat.com, vincent.guittot@linaro.org, willy@infradead.org, mgorman@suse.de, jon.grimm@amd.com, bharata@amd.com, raghavendra.kt@amd.com, boris.ostrovsky@oracle.com, konrad.wilk@oracle.com, jgross@suse.com, andrew.cooper3@citrix.com, Joel Fernandes , Youssef Esmat , Vineeth Pillai , Suleiman Souhlal , Ingo Molnar , Daniel Bristot de Oliveira References: <20231025054219.1acaa3dd@gandalf.local.home> <20231025102952.GG37471@noisy.programming.kicks-ass.net> <20231025085434.35d5f9e0@gandalf.local.home> <20231025135545.GG31201@noisy.programming.kicks-ass.net> <20231025103105.5ec64b89@gandalf.local.home> <884e4603-4d29-41ae-8715-a070c43482c4@efficios.com> <20231025162435.ibhdktcshhzltr3r@f> <20231025131731.48461873@gandalf.local.home> From: Mathieu Desnoyers In-Reply-To: <20231025131731.48461873@gandalf.local.home> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Rspamd-Queue-Id: 8279014002F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BewKo0Hx31RaG2vOzJvsRIacWj6DyYSDLq5fX6FCIsd2dK4fOGTFW8T/muBMy3R2CLy9zZDSPf4iaTq3EsvuW0IpeRJuc5Mmqd6nbUHT6BbTQ+Q507X4xeG4083W0MDpAP/OxLF8GxUNPXXF0Sx7mBvQnK6fjtKb5/mKd4nbbhWuuY4RR+mWNPv3YzIqgHN2Qke2KeoyDU7AZTxtx2JtXQJ/vS1KJANM475Rjwg38Q05HUmfodCewhaVm44vYFm9Bwh9M/lffS50wfBpPVEyWMeHFMTx68CxViLsZ7u9HFaY0enTN8vqqQRZMBC7KSNaSNyjPlp1jky2KillZwZ00I4yfhEpt/1G9vB/GOcHH2g8fk5f3IUWD76V9jZFJoUA0qgFJm8sJ7UstQ1T0LfW7vcNX7fKUEqKFiarYBqSp8duBn4oGL3fRvaiWgPhn 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 2023-10-25 13:17, Steven Rostedt wrote: > On Wed, 25 Oct 2023 18:24:35 +0200 > Mateusz Guzik wrote: > >> On Wed, Oct 25, 2023 at 11:42:34AM -0400, Mathieu Desnoyers wrote: >>> On 2023-10-25 10:31, Steven Rostedt wrote: >>>> On Wed, 25 Oct 2023 15:55:45 +0200 >>>> Peter Zijlstra wrote: >>> [...] > > No, I wouldn't say it's the same as priority inheritance, which is to help > with determinism and not performance. PI adds overhead but removes > unbounded latency. On average, a non PI mutex is faster than PI mutex, but > can suffer from unbounded priority inversion. AFAIU, this is because PI mutex as implemented by sys futex only boosts the priority of the lock owner. In my proposal here the owner would be able to borrow scheduler slices from the waiters as well. [...] >>> >>> Hopefully I'm not oversimplifying if I state that we have mainly two >>> actors to consider: >>> >>> [A] the lock owner thread >>> >>> [B] threads that block trying to acquire the lock >>> >>> The fast-path here is [A]. [B] can go through a system call, I don't >>> think it matters at all. > > No, B going into a system call can be just as devastating. Adaptive > spinning helps with that. The thing here is that if A gets preempted, there > will be a lot more B's getting stuck. I would indeed combine this with an adaptive spinning scheme to allow waiters to stay in userspace if contention is short. As you know, rseq can also help there: https://lore.kernel.org/lkml/20230529191416.53955-1-mathieu.desnoyers@efficios.com/ Therefore, it's only the blocking case that would call into the kernel, which should not be so devastating. > > I implemented the test with futexes (where you go to sleep on contention) > and the performance dropped considerably, where the benefits of not having > A get preempted made no difference at all. Sure, adaptive spinning helps in > that case, but adaptive spinning would only make it as good as my spinning > in user space logic is without any changes. I'm not sure what you are arguing here. My overall idea would be to combine: 1) Adaptive spinning in userspace, 2) Priority inheritance, 3) Scheduler slices inheritance. > >>> >>> Those lock addresses could then be used as keys for private locks, >>> or transformed into inode/offset keys for shared-memory locks. Threads >>> [B] blocking trying to acquire the lock can call a system call which >>> would boost the lock owner's slice and/or priority for a given lock key. > > Do you mean that this would be done in user space? Going into the kernel to > do any of this would make it already lost. Going to the kernel only happens when threads need to block, which means that the typical contended half-happy path should be busy-spinning in userspace (adaptive spinning). I see why blocking in a scenario where busy-spinning would be better is inefficient, but I don't see how going to the kernel for the _blocking_ case is bad. > >>> >>> When the scheduler preempts [A], it would check whether the rseq >>> per-thread area has a "held locks" field set and use this information >>> to find the slice/priority boost which are currently active for each >>> lock, and use this information to boost the task slice/priority >>> accordingly. > > Why do we care about locks here? Note, I'm looking at using this same > feature for VMs on interrupt handlers. The only thing user space needs to > tell the kernel is "It's not a good time to preempt me, but it will be > shortly". > Quoting https://lore.kernel.org/lkml/20231024103426.4074d319@gandalf.local.home/ "The goal is to prevent a thread / vCPU being preempted while holding a lock or resource that other threads / vCPUs will want. That is, prevent contention, as that's usually the biggest issue with performance in user space and VMs." We care about locks here because this is in fact your own problem statement. If you want to consider the different problem of making VM interrupt handlers go fast, then you should state it up front. Those two distinct problems may or may not require entirely different solutions. >>> >>> A scheme like this should allow lock priority inheritance without >>> requiring system calls on the userspace lock/unlock fast path. > > Priority inheritance doesn't make sense when everything is running. I should have also said that this scheme should allow the lock owner to borrow scheduler time slices from waiters (in addition to PI). [...] Thanks, Mathieu -- Mathieu Desnoyers EfficiOS Inc. https://www.efficios.com