Received: by 10.192.165.148 with SMTP id m20csp131684imm; Thu, 3 May 2018 16:27:20 -0700 (PDT) X-Google-Smtp-Source: AB8JxZrrF/Z+XeeLdyE9AmlwwYjKip5BRTgIW/nOKmVAx3GFuZXuvX574OC6EEmms52Nq4CszrKF X-Received: by 2002:a65:4842:: with SMTP id i2-v6mr6459162pgs.252.1525390040500; Thu, 03 May 2018 16:27:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525390040; cv=none; d=google.com; s=arc-20160816; b=P2xPB3Xg8DWtbKp7FcADo86I169aXOaZM289fA9KXa7S3XU5tTxfbEjMG4SQLkxv83 9ySh4t4kMJ1FHaF0n5wBlZGBoui6bIKRpikYmSAzOBhfPcfEnS9noQHPUqo7Yt/eH42q KaV+HcjN3bNs+UDUZ+agFNDMgqH8PROaxTD+SBKP57lunNSv0n4CCtBBLR4b+WEOngqe xeKSMEXZ91CLZKfq9IHMqrS/NxJ9gBbRX78yioXC4aSvFAI2USGwKT36Yicer93T/WAi 0krc1HBMwbkHKWkUpwdXPhzQ4DCxSV/AzlBqDDywkIZQzcnN1hIF1zZPvW3w5d9zFrh6 1x/A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:references :in-reply-to:subject:cc:date:to:from:arc-authentication-results; bh=8dTrA0nYBiFyOWYZH1l/nkcZK36dSAHhQuUEHKz1ucw=; b=Dau3apoMGy/n7fc4HmZ686i1RyARfxDghdtKvhZfSDdKsYRZItolc0O2AJ2C7WbDAD gMAoq0pboFO0OMHeh88QNyCktBi6alFElPQ8UYVCSbQCgT2/93OR4Ym2NNjqBNEQz0/r h6JwHZ6YuEgRvrt8Fv9Usv+mdsV8SjpXJcf4p5VTeIvbgLpMPW9AZDDZuQZ1xXYSqLIn DgRQRli3uJukEpMFrmGXXfL5lMh20uSNpKOSL2TukQDlWqdcQ2o1+Qo46BoQ6i7fFLg9 e0Sd+ygwOJRA+1hcsD5CnwQgubUER+6PiC6W7IrjLDGHSpRpeC5/dt/qT6K4BIuhX8Ee cmQw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z20si14329264pfh.251.2018.05.03.16.27.06; Thu, 03 May 2018 16:27:20 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751195AbeECX0w (ORCPT + 99 others); Thu, 3 May 2018 19:26:52 -0400 Received: from mx2.suse.de ([195.135.220.15]:59176 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751036AbeECX0v (ORCPT ); Thu, 3 May 2018 19:26:51 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 1D289AF5E; Thu, 3 May 2018 23:26:50 +0000 (UTC) From: NeilBrown To: David Laight , 'James Simmons' , Greg Kroah-Hartman , "devel\@driverdev.osuosl.org" , Andreas Dilger , Oleg Drokin , Lai Siyao , Jinshan Xiong Date: Fri, 04 May 2018 09:26:36 +1000 Cc: Linux Kernel Mailing List , "Lustre Development List" , Li Xi , "Gu Zheng" Subject: RE: [PATCH 1/4] staging: lustre: obdclass: change spinlock of key to rwlock In-Reply-To: References: <1525285308-15347-1-git-send-email-jsimmons@infradead.org> <1525285308-15347-2-git-send-email-jsimmons@infradead.org> Message-ID: <87po2cfhhv.fsf@notabene.neil.brown.name> MIME-Version: 1.0 Content-Type: multipart/signed; boundary="=-=-="; micalg=pgp-sha256; protocol="application/pgp-signature" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --=-=-= Content-Type: text/plain Content-Transfer-Encoding: quoted-printable On Thu, May 03 2018, David Laight wrote: > From: James Simmons >> Sent: 02 May 2018 19:22 >> From: Li Xi >>=20 >> Most of the time, keys are never changed. So rwlock might be >> better for the concurrency of key read. > > OTOH unless there is contention on the spin lock during reads the > additional cost of a rwlock (probably double that of a spinlock) > will hurt performance. That's roughly what I was going to say - rwlocks are rarely a win. I think the second patch which caused the lock to be taken less often would have a bigger impact that the switch to rwlocks. However I suspect a better approach would be to investigate some sort of lockless solution. I think the use of the spinlock in lu_context_key_register() could be replaced with a careful cmp_xchg(). I'm less sure about lu_context_key_degister(), but it might be possible. > > ... >> - spin_lock(&lu_keys_guard); >> + read_lock(&lu_keys_guard); >> atomic_inc(&lu_key_initing_cnt); >> - spin_unlock(&lu_keys_guard); >> + read_unlock(&lu_keys_guard); > > WTF, seems unlikely that you need to hold any kind of lock > over an atomic_inc(). > > If this is just ensuring that no code holds the lock then > it would need to request the write_lock(). > (and would need a comment) There is a comment - that patch showed the last 2 lines of it. This is for synchronization with lu_context_key_quiesce(). That spins(!! calling schedule, but still... not good) until the lu_key_initing_cnt is zero while it holds the write lock. Then it is sure that the code protected by this counter isn't running. I'm sure this can be improved! I would need to study it carefully to see how. Note that I don't object to these patches going in - if they provide a measurable improvement which seems likely, then in they go. But I hope the code won't stay like this long term. Thanks, NeilBrown --=-=-= Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEG8Yp69OQ2HB7X0l6Oeye3VZigbkFAlrrmqwACgkQOeye3VZi gbmdGxAAgBcMxEEM49WNOVfIDnNije4MPuD0Qo2e32hwQFXE2EvBDFWro1zoDKCE QdsUFeOurwjS9frS7wjy9QiJEVP22S5ePskSiOEf0bjJ3pq0mLn+J0PT+vi/vtlP Z+LmwS80/uQqnxf9bfHd4dExoQiSQMbU52U93Pm3ByKt86XVaktM9ACFtTbfqeVb LpxMexL7X/moYXHjB3aeohVKsfLLxPQ5eVh0O8LTogugN8zbOPbYDxUKJ21Dsk/O 8ja1vwuvfntMePMZX0tW2LOcUVu/GX5lZmSKn7FmHnVtNKlL2BeUx/XHGsWXZe24 +jPUZZxFlYEiZJjwW9ucIQVQzWCHlB/9iHE85y6fLyrB12QjY9qboJCnUv+MSGik r5l9HLQ+3WUaR9F1YMK2sY7I/YwHop5ayXQuqba5Hbw8NSB1nr7vW0ccBNQTB3pY RBfqHovEeCRqIKs5uFJadLq5E/8hEo43EqD0TGmY6N4WwBXvO50T1eEw2bKqAq62 zdW7Rlr+Cad533tASCWvsc5DDGC7ZzISnZtxUUXdyM6fOMpcOGtX9McaqgUP8mZG HIYrt0Ms6qOmCq/O4wzX6Zjf1G4GzcjrGWvYYeTB3lCMdoeEHChSsi7giAcrVD3G c7xoUOq8RwSViCc4SBW18T9yjQ+TjlpRRyiWWPOBrFhS8ZC3rDo= =9e77 -----END PGP SIGNATURE----- --=-=-=--