Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp3766262rwi; Wed, 12 Oct 2022 06:33:48 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5Fqf7C/G6D2ho3+arSiXwmBQFdLTj1Ez3/Cb0FqYmp9DXIa5Lr0t4wOhvePmq8EmRbyS0N X-Received: by 2002:a63:698a:0:b0:41c:8dfb:29cb with SMTP id e132-20020a63698a000000b0041c8dfb29cbmr25368508pgc.170.1665581628648; Wed, 12 Oct 2022 06:33:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665581628; cv=none; d=google.com; s=arc-20160816; b=HgP3iVCzoUZuxtI14BbFdRwO5Eag5DjOFSWPGa1ey51Zht4jUGpf4HA+mPlTSDHFs7 ldPfvS7hQccUg2hc1kFwKLFwOX1aaChRP+qHYmdR4jkNNlZK+SCaFvB3N+DFcm5NNoCM 7dLs0esl7DR4CMJT68WFsIpxArI+lRFMr85IXDltFzE0w4pMt1javl2Dojjpezzd8FB1 8YSI77N/LDJeKxSt+d7jTQHqdIYBNJOI63dKMpuvtyawqL+FqRGRW+Yd5JnU8FUozMqH UL+6ge16q1kJ2/Phrpuwa8eJksPfWOlcPgU0OGFTlXQDyhBtzGSRdKRBwwGYAd150Vk+ S/Bw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=GcZ45yRu2GyW+Co6nWRGGRC1Ai53wvLIU4B5zOXWM2E=; b=q1AlW0zVBFoF+PzpxcQQHGalQLZ9awgLkjtGYQQNzGRt5pVhB4h5sEjU9qeKT/K7yR NEJQSEFomQlVnr7WiGs21adf+yNw6JTq4fnSdq6y8+SZToP+E23yRcJXJf3DU5p3DfAP isdjgj2rThAqeH1YnCkyqOa0mGSUIOFIzZJx3aVPY06tiDrqifICPf/eBmP7SN3puFuR T/D4dgNzMHBck+r00eZ8Dd/e+0yjcjS+m1f0pxC/tqz6zzCbrD8xKgBOEtzTeih1NSQg /t1KJycRXPe5U9kkxWPmBBsJ4VGUpQBM70/GE4wNDdrLsFO5M7mcufC5/NXyuV3hmQ+5 BIJg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="h3qV9/Tm"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id p10-20020a635b0a000000b00439ce36e9d3si18874706pgb.570.2022.10.12.06.33.37; Wed, 12 Oct 2022 06:33:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="h3qV9/Tm"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229997AbiJLNU2 (ORCPT + 99 others); Wed, 12 Oct 2022 09:20:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39900 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229994AbiJLNUJ (ORCPT ); Wed, 12 Oct 2022 09:20:09 -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 6E89F474DB for ; Wed, 12 Oct 2022 06:19:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1665580797; 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=GcZ45yRu2GyW+Co6nWRGGRC1Ai53wvLIU4B5zOXWM2E=; b=h3qV9/TmyHZO6Vw18huYnprzTw8FrX5iunOtGqIk9EFOLIzZ4ENY+ClsPNmiPZtyOPoh9f kpiF7jwiBrpUnSAuzYlUuGbpH1DL17LLOQZEYTdIlHT7xV322r6B1gHqvb2S3pGJgrxOiK HzTItL4rx2fx7dkSCUj8Cj4OF2TMEwE= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-218-sbiD5b3-M0mfKTYos3RZwA-1; Wed, 12 Oct 2022 09:19:54 -0400 X-MC-Unique: sbiD5b3-M0mfKTYos3RZwA-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id CE48A1C05AF3; Wed, 12 Oct 2022 13:19:53 +0000 (UTC) Received: from [10.22.33.120] (unknown [10.22.33.120]) by smtp.corp.redhat.com (Postfix) with ESMTP id 788EE492CA2; Wed, 12 Oct 2022 13:19:53 +0000 (UTC) Message-ID: Date: Wed, 12 Oct 2022 09:19:53 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.12.0 Subject: Re: [PATCH] locking/rwsem: Prevent non-first waiter from spinning in down_write() slowpath Content-Language: en-US To: Hillf Danton , Mukesh Ojha Cc: linux-kernel@vger.kernel.org, john.p.donnelly@oracle.com, linux-mm@kvack.org, Peter Zijlstra , Will Deacon , Boqun Feng , Ingo Molnar References: <20221012040410.403-1-hdanton@sina.com> From: Waiman Long In-Reply-To: <20221012040410.403-1-hdanton@sina.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 3.1 on 10.11.54.9 X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 10/12/22 00:04, Hillf Danton wrote: >> you mean, you want to check and change waiter->handoff_set on every run >> rwsem_try_write_lock(). >> > Yes, with RWSEM_FLAG_HANDOFF set, it is too late for non first waiters to > spin, and with both RWSEM_LOCK_MASK and RWSEM_FLAG_HANDOFF set, the rivals > in the RWSEM_LOCK_MASK have an uphand over the first waiter wrt acquiring > the lock, and it is not a bad option for the first waiter to take a step > back off. > > if (count & RWSEM_LOCK_MASK) { > if (has_handoff || (!rt_task(waiter->task) && > !time_after(jiffies, waiter->timeout))) > return false; > > new |= RWSEM_FLAG_HANDOFF; > } else { > >> But does it break optimistic spinning ? @waiman ? > Waiters spin for acquiring lock instead of lockup and your report shows > spinning too much makes trouble. The key is stop spinning neither too > late nor too early. My proposal is a simple one with as few heuristics > added as possible. Yes, too much spinning is bad if we have RT tasks in the mix, otherwise it should be fine. Cheers, Longman