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 X-Spam-Level: X-Spam-Status: No, score=-7.3 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 034F3C56201 for ; Fri, 20 Nov 2020 17:04:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 974572245B for ; Fri, 20 Nov 2020 17:04:51 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="eTlaPESw" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730265AbgKTREc (ORCPT ); Fri, 20 Nov 2020 12:04:32 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:26399 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728771AbgKTREb (ORCPT ); Fri, 20 Nov 2020 12:04:31 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1605891870; 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=+fDQVmfFKeAGKLRGbsrcZpScq4bc7Sw4oihjxYlBdLs=; b=eTlaPESwXU6G90UsLc4CyS5sb9sNrPPQYqTED7puhmDlvcKpUKis9j2eV9p72LI4zzBYBy chVDMhTEWMeSqBbY1rLEG5/hmS4vYqtab43YgqirrcA1VvZcuF+GgZDjU+IQ6rkqmTw/gw Ig+vpL2pPwOCOzMFIVuT5nRaNXRH0jM= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-428-q6tZPtKfNw-l-ZXQ9ou6cA-1; Fri, 20 Nov 2020 12:04:28 -0500 X-MC-Unique: q6tZPtKfNw-l-ZXQ9ou6cA-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 43985CE647; Fri, 20 Nov 2020 17:04:26 +0000 (UTC) Received: from llong.remote.csb (ovpn-118-157.rdu2.redhat.com [10.10.118.157]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6E4201F0; Fri, 20 Nov 2020 17:04:24 +0000 (UTC) Subject: Re: [RFC PATCH 5/5] locking/rwsem: Remove reader optimistic spinning To: David Laight , Davidlohr Bueso Cc: Peter Zijlstra , Ingo Molnar , Will Deacon , "linux-kernel@vger.kernel.org" , Phil Auld References: <20201118030429.23017-1-longman@redhat.com> <20201118030429.23017-6-longman@redhat.com> <20201118053556.3fmmtat7upv6dtvd@linux-p48b.lan> <5fe76531782f4a8492b341d5f381147b@AcuMS.aculab.com> From: Waiman Long Organization: Red Hat Message-ID: <68d07068-ff31-26b5-f90d-7ea8b4ee2389@redhat.com> Date: Fri, 20 Nov 2020 12:04:24 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.12.0 MIME-Version: 1.0 In-Reply-To: <5fe76531782f4a8492b341d5f381147b@AcuMS.aculab.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-Language: en-US X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 11/20/20 8:11 AM, David Laight wrote: > From: Waiman Long >> Sent: 19 November 2020 18:40 > ... >> My own testing also show not too much performance difference when >> removing reader spinning except in the lightly loaded cases. > I'm confused. > > I got massive performance improvements from changing a driver > we have to use mutex instead of the old semaphores (the driver > was written a long time ago). > > While these weren't 'rw' the same issue will apply. > > The problem was that the semaphore/mutex was typically only held over > a few instructions (eg to add an item to a list). > But with semaphore if you got contention the process always slept. > OTOH mutex spin 'for a while' before sleeping so the code rarely slept. > > So I really expect that readers need to spin (for a while) if > a rwsem (etc) is locked for writing. > > Clearly you really need a CBU (Crystal Ball Unit) to work out > whether to spin or not. That is the hard part. For short critical section and not many readers around, making the readers spin will likely improve performance. On the other hand, if the critical section is long with many readers, make readers sleep and then wake them all up at once can have better performance. There is no one-size-fit-all solution here. Cheers, Longman