Received: by 10.223.176.46 with SMTP id f43csp4749942wra; Tue, 23 Jan 2018 14:10:39 -0800 (PST) X-Google-Smtp-Source: AH8x226ylfceyKp08GZ+RhdW/uXX9YYQu4bwnUZkgHSkpXYMpQW7ZhyqGVZCQxrWCyXBGhRX6JyP X-Received: by 10.107.150.199 with SMTP id y190mr5910507iod.121.1516745438988; Tue, 23 Jan 2018 14:10:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516745438; cv=none; d=google.com; s=arc-20160816; b=q/FKKfCou0gk86PMqDRL5IL0uSmWLLiX/1yNWk8D7VytUZW6312FMZ5Fu/ZXNCDU94 9IzosmPxaR8miikByWt82mlYLMc/S3isVVFpCZohVgD22kOFvcXJ3zZWR90tEdpzrm/G x5TS5QPWbBn5eltX5WdPQGcdOnR3Hwt0lbRtCG8lJTgoyGdWlno/1A7V/41TkXpQ9+cv G4ANIjQLImv3ElVuMmeCG3LP+vKQD96ffTO2+1ejCCiEbTZxQ3qnQQtDUuxqmdbUIB8/ PwgbfmxV1aTMz0Zynn91wnvlv30g6SEUsDbpSPh+NzYFEummq9pUvOaZPnMnQKg/lE+7 7ITg== 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=G6SCV8b2UIa+pxk0F3+PZMCGnp9yDHZ72y+ss7esCHU=; b=e1Oz7/FIiHls6mlAvJ51ib5UBqbzmYZUKU+fwdXJ/GQw5I01WVk4VuRPKII8NPfb7e xlYtLmn4FUPTIH16OAO0EG22myrT4afYPsA6FXsKCyUgZHq681dS+0OJ7uMZbEsnuB/6 3qCJVyRp2teWhIktgqkm1YkSIYhe9mwMfj0qFkwtqPyPSgBq3zUUvyDW1hh/SuiXFv/j RA4fbIElziPSr/4gsiOGsN4bnAv6oYAwRDmQjCQrDisl5nGtqmE3FFvsSknylRoqSneP 08ovPs4vKL//q4bJOH1Nj9At6HePz3nQsVqyHdYvLhTZ8TH3T/7uj+e1zhpxjLFVbC6S 3R7g== 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 j16si9505980ita.72.2018.01.23.14.10.24; Tue, 23 Jan 2018 14:10:38 -0800 (PST) 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 S932248AbeAWWJw (ORCPT + 99 others); Tue, 23 Jan 2018 17:09:52 -0500 Received: from fieldses.org ([173.255.197.46]:49544 "EHLO fieldses.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932150AbeAWWJu (ORCPT ); Tue, 23 Jan 2018 17:09:50 -0500 Received: by fieldses.org (Postfix, from userid 2815) id 4D3BC89A; Tue, 23 Jan 2018 17:09:50 -0500 (EST) Date: Tue, 23 Jan 2018 17:09:50 -0500 From: "J. Bruce Fields" To: "Reshetova, Elena" Cc: "linux-nfs@vger.kernel.org" , "linux-kernel@vger.kernel.org" , "jlayton@kernel.org" , "trond.myklebust@primarydata.com" , "anna.schumaker@netapp.com" , "peterz@infradead.org" , "keescook@chromium.org" Subject: Re: [PATCH 1/4] lockd: convert nlm_host.h_count from atomic_t to refcount_t Message-ID: <20180123220950.GA5632@fieldses.org> References: <1511954146-11793-1-git-send-email-elena.reshetova@intel.com> <1511954146-11793-2-git-send-email-elena.reshetova@intel.com> <20171221202350.GE31467@fieldses.org> <2236FBA76BA1254E88B949DDB74E612B802CFB57@IRSMSX102.ger.corp.intel.com> <20171222142553.GA9630@fieldses.org> <20171222154250.GB9630@fieldses.org> <2236FBA76BA1254E88B949DDB74E612B802D08DA@IRSMSX102.ger.corp.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <2236FBA76BA1254E88B949DDB74E612B802D08DA@IRSMSX102.ger.corp.intel.com> User-Agent: Mutt/1.5.21 (2010-09-15) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Dec 27, 2017 at 12:10:15PM +0000, Reshetova, Elena wrote: > > On Fri, Dec 22, 2017 at 09:25:53AM -0500, J. Bruce Fields wrote: > > > On Fri, Dec 22, 2017 at 09:29:15AM +0000, Reshetova, Elena wrote: > > > > > > > > On Wed, Nov 29, 2017 at 01:15:43PM +0200, Elena Reshetova wrote: > > > > > atomic_t variables are currently used to implement reference > > > > > counters with the following properties: > > > > > - counter is initialized to 1 using atomic_set() > > > > > - a resource is freed upon counter reaching zero > > > > > - once counter reaches zero, its further > > > > > increments aren't allowed > > > > > - counter schema uses basic atomic operations > > > > > (set, inc, inc_not_zero, dec_and_test, etc.) > > > > > > > > >Whoops, I forgot that this doesn't apply to h_count. > > > > > > > > >Well, it's confusing, because h_count is actually used in two different > > > > >ways: depending on whether a nlm_host represents a client or server, it > > > > >may have the above properties or not. > > > > > > > > > > > > So, what happens when it is not having the above properties? Is the object > > > > being reused or? > > > > > > The object isn't destroyed when the counter hits zero--zero is just > > > taken as a hint to some garbage collection algorithm that it would be OK > > > to destroy it. So decrementing to or incrementing from zero is OK. > > > > In more detail: the nlm_host objects that are used on the NFS server to > > represent NFS clients are put by nlmsvc_release_host, and then may > > eventually be freed by nlm_gc_hosts. > > > > The nlm_host objects that are used on the NFS client to represent NFS > > servers are put (and freed when h_count goes to zero) by > > nlmclnt_release_host. > > > > In both cases reference are taken by nlm_get_host. It would be possible > > to replace nlm_get_host by two different functions if that would help. > > Most callers are obviously only client-side or server-side. The only > > exception is next_host_state. It could be passed a pointer to the "get" > > function it should use. > > > > After that we might actually just want to define separate client and > > server structs like: > > > > struct nlm_clnt_host { > > struct nlm_host ch_host; > > refcount_t ch_count; > > ... > > } > > > > struct nlm_srv_host { > > struct nlm_host sh_host; > > refcount_t sh_count; > > ... > > } > > > > rather than have a single h_count which is used in two confusingly > > different ways. There are also some other nlm_host fields that really > > only make sense for client or server. > > This sounds reasonable for me, but obviously it is a bigger change and I might not > have enough knowledge on NFS to make it correctly. > > In any case, even for the current server case, when freeing might not happen and object gets > re-used later on, is it possible to simply re-initialize the object (and its reference counter) properly before reusing? The object still has useful information in it so we can't just reinitalize it completely. I guess we could make nlm_get_host do if (refcount_read(&host->h_count)) refcount_inc(&host->h_count); else refcount_set(&host->h_count, 1); Or we could just change the code so the refcount is always 1 higher in the NFS server case, so "1" instead of "0" is used to mean "nobody's using this, you can garbage collect this", and then it won't go to 0 until the garbage collector actually destroys it. This isn't an unusual pattern, what have other subsystems been doing? --b. > I think this is the only thing that is needed from the correct refcounting POV in this case, so > instead of using refcount_inc() on reused object, you would explicitly do refcount_set(counter, 1) when reuse happens.