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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6187DC6FD1D for ; Mon, 20 Mar 2023 17:49:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229671AbjCTRt3 (ORCPT ); Mon, 20 Mar 2023 13:49:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34044 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229890AbjCTRsx (ORCPT ); Mon, 20 Mar 2023 13:48:53 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9EBF459ED for ; Mon, 20 Mar 2023 10:43:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1679334171; 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=8rKq3lr86YAGdsTZ7QDkIJZmue64t7FvGz7XkMV/DXA=; b=RIq/+Y6qE8RRnx2JDy8/Wfkmh/DX81E/QGtS9OTgk1tBUeiKEJo7QGznjHOSnmn7HLPj0y 1imk4qDDWEoYt7fSmz0VbcD5s9AgGvzlub1J92qRNmekHrg/ecS/iqW3lkTykHt7o8lwy5 IbZjTjDlrzB16xu5/SuzIhIPxNuor7U= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-589-9Trh2GVXOq2ykUrhEtYtYA-1; Mon, 20 Mar 2023 13:36:48 -0400 X-MC-Unique: 9Trh2GVXOq2ykUrhEtYtYA-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 240AC101A550; Mon, 20 Mar 2023 17:36:48 +0000 (UTC) Received: from [10.18.17.153] (dhcp-17-153.bos.redhat.com [10.18.17.153]) by smtp.corp.redhat.com (Postfix) with ESMTP id F17FE1121318; Mon, 20 Mar 2023 17:36:47 +0000 (UTC) Message-ID: <59ecce70-08de-260c-b5b9-60e0b2e58dbd@redhat.com> Date: Mon, 20 Mar 2023 13:36:46 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.7.1 Subject: Re: [PATCH 3/6] locking/rwsem: Rework writer wakeup Content-Language: en-US To: Peter Zijlstra Cc: mingo@redhat.com, will@kernel.org, linux-kernel@vger.kernel.org, boqun.feng@gmail.com References: <20230223122642.491637862@infradead.org> <20230223123319.487908155@infradead.org> <943686ee-975d-a463-46d1-04b200ac19b1@redhat.com> <20230320081238.GC2194297@hirez.programming.kicks-ass.net> From: Waiman Long In-Reply-To: <20230320081238.GC2194297@hirez.programming.kicks-ass.net> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 3/20/23 04:12, Peter Zijlstra wrote: > On Mon, Feb 27, 2023 at 03:16:25PM -0500, Waiman Long wrote: >> On 2/27/23 05:31, Peter Zijlstra wrote: >>>> I do have some concern that early lock transfer to a lock owner that has not >>>> been woken up yet may suppress writer lock stealing from optimistic spinning >>>> causing some performance regression in some cases. Let's see if the test >>>> robot report anything. >>> Ah yes, I suppose that is indeed a possibility. Given this is all under >>> wait_lock and the spinner is not, I was hoping it would still have >>> sufficient time to win. But yes, robots will tell us. >>> >> I run my rwsem locking microbenchmark on a 2-socket 96-thread x86-64 >> system with lock event turned on for 15 secs. >> >> Before this patchset: >> >> Running locktest with rwsem [runtime = 15s, r% = 50%, load = 100] >> Threads = 96, Min/Mean/Max = 74,506/91,260/112,409 >> Threads = 96, Total Rate = 584,091 op/s; Percpu Rate = 6,084 op/s >> >> rwsem_opt_fail=127305 >> rwsem_opt_lock=4252147 >> rwsem_opt_nospin=28920 >> rwsem_rlock=2713129 >> rwsem_rlock_fail=0 >> rwsem_rlock_fast=5 >> rwsem_rlock_handoff=280 >> rwsem_rlock_steal=1486617 >> rwsem_sleep_reader=2713085 >> rwsem_sleep_writer=4313369 >> rwsem_wake_reader=29876 >> rwsem_wake_writer=5829160 >> rwsem_wlock=127305 >> rwsem_wlock_fail=0 >> rwsem_wlock_handoff=2515 >> >> After this patchset: >> >> Running locktest with rwsem [runtime = 15s, r% = 50%, load = 100] >> Threads = 96, Min/Mean/Max = 26,573/26,749/26,833 >> Threads = 96, Total Rate = 171,184 op/s; Percpu Rate = 1,783 op/s >> >> rwsem_opt_fail=1265481 >> rwsem_opt_lock=17939 >> rwsem_rlock=1266157 >> rwsem_rlock_fail=0 >> rwsem_rlock_fast=0 >> rwsem_rlock_handoff=0 >> rwsem_rlock_steal=551 >> rwsem_sleep_reader=1266157 >> rwsem_sleep_writer=1265481 >> rwsem_wake_reader=26612 >> rwsem_wake_writer=0 >> rwsem_wlock=1265481 >> rwsem_wlock_ehandoff=94 >> rwsem_wlock_fail=0 >> rwsem_wlock_handoff=94 >> >> So the locking rate is reduced to just 29.3% of the original. Looking at >> the number of successful writer lock stealings from optimistic spinning >> (rwsem_opt_lock), it is reduced from 4252147 to 17939. It is just about >> 0.4% of the original. >> >> So for workloads that have a lot of writer contention, there will be >> performance regressions. Do you mind if we try to keep the original >> logic of my patchset to allow write lock acquisition in writer slow >> path, but transfer the lock ownership in the wakeup path when handoff >> is required. We can do this with some minor code changes on top of your >> current patchset. > Urgh, sorry, I seem to have lost sight of this... those results,.. > sadness :/ > > Yeah, I suppose there's nothing for it but to have live with that mess, > be very sure to add comments eludicating any future poor sod reading it > as to why the code is the way it is. OK, I will add additional patches to your series to remediate the performance degradation. Hopefully, I am planning to get it done either by the end of the week or early next week. Thanks, Longman