Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp2582453imm; Fri, 20 Jul 2018 00:55:38 -0700 (PDT) X-Google-Smtp-Source: AAOMgpcLQRHflNfdf0buo+Ly+cLD2f0FlI3JTt2BXFL6sb1ihB2zxWOyT1BQthpOekvbWh63Tj9j X-Received: by 2002:a62:571b:: with SMTP id l27-v6mr1129101pfb.29.1532073338500; Fri, 20 Jul 2018 00:55:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532073338; cv=none; d=google.com; s=arc-20160816; b=agK5JYz98KD9LqrxKmP9S5Xd+mzwBnPwdno5r/r7JWY+AVL00Er4G2gYuIo4DABi+N LYeQiq9U1PB8dgI9uE+pnCtNI/TU8WuimcRxGauL56LMKbE6+RLGwMHUtwWpobqdUoil bWeOwmfjbSJRIhU5t8qbjpTSvaN4+1TZyXNlrNkIa/Hvh7PA+mjkrqc5tfQjs2ele5L0 Xxz4B4IMJ3FJ8fsH6iU6VOhi6l0q8OTSdVMgYWSf9YZtNRKCDC7l1wBy4jG/Uqutmmd9 DetaDmXFVGygUSIZ26Jlr6wRMW3ItM50c6naS6A1acVrELshTW6RTx2mUSM3AXsoQFeZ gGlA== 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:arc-authentication-results; bh=DmQwDTc0uN0dqI5lV0ptw7ieTRHMMbcOfEcLNbMSweg=; b=Lj3McxBYF5aXKVqG65j+6Wd4Dg1TdhXYaeda4S7dIFMczrIFRtm6TYd3DKuGYWRYhw jWk8A/1fCg3CIrobb6d8JRMe/mkU32uNuz3eghMqjxzyr1K80yJ+GwEJM1n9vLQWfzwk dEoYwerMPd1hmxm+Zs/M+SiJ/x09vz3NwK2fbgKpsiPX4Y/h2zPJXPYeejs46db8F9X0 835teB7tREoNV1u/lbn02VptZls8q1KG8oI6sEcUiTf7df4If13YCNQ7LZQoahOPloIH SGknf4jdgorifGASD64ZIeAmjdISJHsbIwNRv7PeXOr2V4DKtsnhpRoKUb/3tpRjgsDa L41g== 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 l81-v6si1407267pfa.368.2018.07.20.00.55.24; Fri, 20 Jul 2018 00:55:38 -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 S1727825AbeGTIl2 (ORCPT + 99 others); Fri, 20 Jul 2018 04:41:28 -0400 Received: from orcrist.hmeau.com ([104.223.48.154]:39030 "EHLO deadmen.hmeau.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726779AbeGTIl2 (ORCPT ); Fri, 20 Jul 2018 04:41:28 -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 1fgQEw-0007aI-3L; Fri, 20 Jul 2018 15:54:14 +0800 Received: from herbert by gondobar with local (Exim 4.89) (envelope-from ) id 1fgQEr-0007lo-B0; Fri, 20 Jul 2018 15:54:09 +0800 Date: Fri, 20 Jul 2018 15:54:09 +0800 From: Herbert Xu To: NeilBrown , "Paul E. McKenney" Cc: Thomas Graf , netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 2/5] rhashtable: don't hold lock on first table throughout insertion. Message-ID: <20180720075409.kfckhodsnvktift7@gondor.apana.org.au> References: <153086169828.24852.10332573315056854948.stgit@noble> <153086175009.24852.7782466383056542839.stgit@noble> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <153086175009.24852.7782466383056542839.stgit@noble> 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, Jul 06, 2018 at 05:22:30PM +1000, NeilBrown wrote: > rhashtable_try_insert() currently hold 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 match 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 > ->rcu.func in rhashtable_walk_stop(). If it is not NULL, then > the bucket table is empty and dead. > > Signed-off-by: NeilBrown ... > @@ -339,13 +338,16 @@ static int rhashtable_rehash_table(struct rhashtable *ht) > spin_lock(&ht->lock); > list_for_each_entry(walker, &old_tbl->walkers, list) > walker->tbl = NULL; > - spin_unlock(&ht->lock); > > /* Wait for readers. All new readers will see the new > * table, and thus no references to the old table will > * remain. > + * We do this inside the locked region so that > + * rhashtable_walk_stop() can check ->rcu.func and know > + * not to re-link the table. > */ > call_rcu(&old_tbl->rcu, bucket_table_free_rcu); > + spin_unlock(&ht->lock); > > return rht_dereference(new_tbl->future_tbl, ht) ? -EAGAIN : 0; > } ... > @@ -964,7 +942,7 @@ void rhashtable_walk_stop(struct rhashtable_iter *iter) > ht = iter->ht; > > spin_lock(&ht->lock); > - if (tbl->rehash < tbl->size) > + if (tbl->rcu.func == NULL) > list_add(&iter->walker.list, &tbl->walkers); > else > iter->walker.tbl = NULL; This appears to be relying on implementation details within RCU. Paul, are you OK with rhashtable doing this trick? Thanks, -- Email: Herbert Xu Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt