Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp226243img; Tue, 19 Mar 2019 22:42:56 -0700 (PDT) X-Google-Smtp-Source: APXvYqw2IjKrdE6EW3/FN3n2sx9kjNZKPX9F0zH5GUYaoQqNEh4QXZkoFMdz+lEDFUICBEcJIDqk X-Received: by 2002:a63:e845:: with SMTP id a5mr4800214pgk.246.1553060576232; Tue, 19 Mar 2019 22:42:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553060576; cv=none; d=google.com; s=arc-20160816; b=ehUsh46gjldbHuhk+OTfX0VV8wW8h4tetcQRNHOGAObxBHr9VCbx1CUgF2uGLkA0d7 wGPvfKRRd1IvnjhnIpS6YGJtOKAqyeEN+9rYUL+BLl3NvMhS6BvCGqpF01DWCFzIWGXW 6kMQIYoS2Td2Oz10E4pyUOfS5wSkruBoBpzwicUFthptKuV4Sr769TBnZ/RLzrN+VIVg 51EAA7u+2jAWCRPtrOoPeLIS2n3bwj+484GsuWKqbwn8ZqhIpLerCSOSdUkq7eOKMRq5 yA1IlTTjCg4XL9pIiwqxDPYDhiTLLwlhso+JW9fmddpUxkZ3IoDcdp+/yOjHUTHuPS0S KWow== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=qHKOY7WW1bIxY20WxzdC4l4qVSkCwNpA/lSg/B4wPWI=; b=DYjBi5RhhwjcXe0ryAr0hIhRfdIHHCx5RrTNk4eGj3Du+e9BzJfo7yLyDXitQmFfdj vcp243s93J0DKg2CvxU9PLfA6i/hgI09/7YfzdIq1WrmfpaKT7ZdNQR1MUWm5OumYRq1 Y1lWAvDGFyxdGBSxmEfqExr+DE8vw1eP/S7GxOmXaHlBSX8QGky7QO57fMQwu4rtLtQX I4cnDI1z2q7v1bA9Avs4a2eJRh2EPWKjHMARwyXDQb4Na6H2LIpQOFX1JtNtkQjpC26p Vm3WMEVU4k+C8NWN0pc9sQCe8RK8WrF0rmMCrlbbjVE0ZzQyWsAcH3x4X4jTqZPXMpmt /h7Q== 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 5si1030085plx.421.2019.03.19.22.42.41; Tue, 19 Mar 2019 22:42:56 -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 S1727374AbfCTFkm (ORCPT + 99 others); Wed, 20 Mar 2019 01:40:42 -0400 Received: from orcrist.hmeau.com ([104.223.48.154]:47144 "EHLO deadmen.hmeau.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725900AbfCTFkm (ORCPT ); Wed, 20 Mar 2019 01:40:42 -0400 Received: from gondobar.mordor.me.apana.org.au ([192.168.128.4] helo=gondobar) by deadmen.hmeau.com with esmtps (Exim 4.89 #2 (Debian)) id 1h6Txg-00057H-Jv; Wed, 20 Mar 2019 13:40:24 +0800 Received: from herbert by gondobar with local (Exim 4.89) (envelope-from ) id 1h6Txd-00078Y-7v; Wed, 20 Mar 2019 13:40:21 +0800 Date: Wed, 20 Mar 2019 13:40:21 +0800 From: Herbert Xu To: NeilBrown Cc: Thomas Graf , netdev@vger.kernel.org, "Paul E. McKenney" , linux-kernel@vger.kernel.org Subject: Re: [PATCH 2/3] rhashtable: don't hold lock on first table throughout insertion. Message-ID: <20190320054021.sjxkye3bi5cvyip2@gondor.apana.org.au> References: <155253979234.5022.1840929790507376038.stgit@noble.brown> <155253992829.5022.17977838545670077984.stgit@noble.brown> <20190315054709.mlcctcv3qy57wini@gondor.apana.org.au> <87o96cocs2.fsf@notabene.neil.brown.name> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <87o96cocs2.fsf@notabene.neil.brown.name> User-Agent: NeoMutt/20170113 (1.7.2) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Mar 15, 2019 at 05:46:37PM +1100, NeilBrown wrote: > > From: NeilBrown > Date: Mon, 25 Jun 2018 08:09:19 +1000 > Subject: [PATCH] rhashtable: don't hold lock on first table throughout > insertion. > > rhashtable_try_insert() currently holds a lock on the bucket in > the first table, while also locking buckets in subsequent tables. > This is unnecessary and looks like a hold-over from some earlier > version of the implementation. > > As insert and remove always lock a bucket in each table in turn, and > as insert only inserts in the final table, there cannot be any races > that are not covered by simply locking a bucket in each table in turn. > > When an insert call reaches that last table it can be sure that there > is no matchinf entry in any other table as it has searched them all, and > insertion never happens anywhere but in the last table. The fact that > code tests for the existence of future_tbl while holding a lock on > the relevant bucket ensures that two threads inserting the same key > will make compatible decisions about which is the "last" table. > > This simplifies the code and allows the ->rehash field to be > discarded. > > We still need a way to ensure that a dead bucket_table is never > re-linked by rhashtable_walk_stop(). This can be achieved by calling > call_rcu() inside the locked region, and checking with > rcu_head_after_call_rcu() in rhashtable_walk_stop() to see if the > bucket table is empty and dead. > > Signed-off-by: NeilBrown > --- > include/linux/rhashtable.h | 13 ------------ > lib/rhashtable.c | 52 ++++++++++++++-------------------------------- > 2 files changed, 16 insertions(+), 49 deletions(-) Acked-by: Herbert Xu -- Email: Herbert Xu Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt