Received: by 10.192.165.148 with SMTP id m20csp1000027imm; Sat, 5 May 2018 02:41:50 -0700 (PDT) X-Google-Smtp-Source: AB8JxZpyO3l2p7m976fWnNAw9wsD0tsGfVDfCvLINaNw3OLo8BpX2JULVkcZ/B2OE+di2cPVUOT2 X-Received: by 2002:a63:7702:: with SMTP id s2-v6mr24292384pgc.399.1525513310667; Sat, 05 May 2018 02:41:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525513310; cv=none; d=google.com; s=arc-20160816; b=ZS71AZVuWwCRf3aIsRGkzpIs61LoLa/szQiyZXttopnSq6u6a0xKFKKOCdQ4RoUNzq Ob4DMBKpDYM66l/mrlH9jmLjUI+q9ROhaIFCH8Esg8oCT5AXjuh4a4ei7yzoM5m4nyrV mvNV+oN8oX4VFHrKhbG4BHOva7fOKQKSqpBHwOB1st/kh/Y41+d6YjUEfIEB5ZecwWnZ oFTIfOsADfHrf1klUPCyICfUaCzs4+6f0TLePgp1RSRdHaOgOtWCSpOmZfpQuep+i89d 1XHyHTdz/I4e95fTrymSPcU5G6UfBuq0qUvswSuZtRzRWG3642YPAiJvDCPIIpZR1b/v pLWA== 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=YiE5fBK795rKIC7VFqAEkHjmNWu9n+LAVSL7i8/4j8g=; b=WCinWrHuarKEV5I8bLs93rAe63HCZs574OqFaaj8L0S8z4eG3tbLQ7+rfyxww7ZUH1 uBLCEBlwKi23Kx+IE7IjEks8u0PrPaF8Bdd5DUDaXjXMc/V3jKI5CWKUkFo/FNEUFlJU sxc9C3Fc1A4mi50LXFy/dYf9Ylo/bh31PVEowPkjGkL1lTgGCmOHCHo12uViKvGsc+TJ hRV0rp0u5mfrJY0b7IhipVciZEfMGpASo9+aNEux9cgA4SngFa4bZphlq4+Y51RLC9oa lPAKdCDvvybwuAil6EjU1ZCi/yM8SdPEX1CRpU1cy5U3vyxPuEN/Nh1FifqoVV4pseVG /Ssw== 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 f7-v6si14370127pgq.207.2018.05.05.02.41.35; Sat, 05 May 2018 02:41:50 -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 S1751203AbeEEJlZ (ORCPT + 99 others); Sat, 5 May 2018 05:41:25 -0400 Received: from orcrist.hmeau.com ([104.223.48.154]:35438 "EHLO deadmen.hmeau.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750821AbeEEJlY (ORCPT ); Sat, 5 May 2018 05:41:24 -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 1fEtgt-00021q-VU; Sat, 05 May 2018 17:41:20 +0800 Received: from herbert by gondobar with local (Exim 4.89) (envelope-from ) id 1fEtgr-0005zd-Fr; Sat, 05 May 2018 17:41:17 +0800 Date: Sat, 5 May 2018 17:41:17 +0800 From: Herbert Xu To: NeilBrown Cc: Thomas Graf , netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 8/8] rhashtable: don't hold lock on first table throughout insertion. Message-ID: <20180505094117.pl7b6bbk6mtyri6d@gondor.apana.org.au> References: <152540595840.18473.11298241115621799037.stgit@noble> <152540605444.18473.9591316658457316578.stgit@noble> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <152540605444.18473.9591316658457316578.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, May 04, 2018 at 01:54:14PM +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 > setting the ->size to 1. This still allows lookup code to work (and > correctly not find anything) but can never happen on an active bucket > table (as the minimum size is 4). > > Signed-off-by: NeilBrown I'm not convinced this is safe. There can be multiple tables in existence. Unless you hold the lock on the first table, what is to stop two parallel inserters each from inserting into their "last" tables which may not be the same table? Cheers, -- Email: Herbert Xu Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt