From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx1.redhat.com ([209.132.183.28]:52986 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751583AbdJMVK6 (ORCPT ); Fri, 13 Oct 2017 17:10:58 -0400 Subject: Re: [PATCH v7 1/6] lib/dlock-list: Distributed and lock-protected lists To: Boqun Feng Cc: Alexander Viro , Jan Kara , Jeff Layton , "J. Bruce Fields" , Tejun Heo , Christoph Lameter , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Ingo Molnar , Peter Zijlstra , Andi Kleen , Dave Chinner , Davidlohr Bueso References: <1507229008-20569-1-git-send-email-longman@redhat.com> <1507229008-20569-2-git-send-email-longman@redhat.com> <20171010053504.m37pzhammhgucqyy@tardis> From: Waiman Long Message-ID: <6c30c0ed-66d2-bf78-d827-06c677b44666@redhat.com> Date: Fri, 13 Oct 2017 17:10:55 -0400 MIME-Version: 1.0 In-Reply-To: <20171010053504.m37pzhammhgucqyy@tardis> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 8BIT Content-Language: en-US Sender: linux-fsdevel-owner@vger.kernel.org List-ID: On 10/10/2017 01:35 AM, Boqun Feng wrote: > On Thu, Oct 05, 2017 at 06:43:23PM +0000, Waiman Long wrote: > [...] >> +/* >> + * As all the locks in the dlock list are dynamically allocated, they need >> + * to belong to their own special lock class to avoid warning and stack >> + * trace in kernel log when lockdep is enabled. Statically allocated locks >> + * don't have this problem. >> + */ >> +static struct lock_class_key dlock_list_key; >> + > So in this way, you make all dlock_lists share the same lock_class_key, > which means if there are two structures: > > struct some_a { > ... > struct dlock_list_heads dlists; > }; > > struct some_b { > ... > struct dlock_list_heads dlists; > }; > > some_a::dlists and some_b::dlists are going to have the same lockdep > key, is this what you want? If not, you may want to do something like > init_srcu_struct() does. I think it will be a problem only if a task acquire a lock in a dlock-list and then acquire another lock from another dlock-list. The way the dlock-list is used, no more than one lock will be acquired at any time, so there won't be nested locking within the same dlock-list. It is not a problem with the current use cases that I and Davidlohr have, but it may be a problem if dlock-list becomes more widely used. I will take a look at how init_srcu_struct() does, and maybe update the patch accordingly. Thanks for the suggestion. > >> + * dlock_lists_del - Delete a node from a dlock list >> + * @node : The node to be deleted >> + * >> + * We need to check the lock pointer again after taking the lock to guard >> + * against concurrent deletion of the same node. If the lock pointer changes >> + * (becomes NULL or to a different one), we assume that the deletion was done >> + * elsewhere. A warning will be printed if this happens as it is likely to be >> + * a bug. >> + */ >> +void dlock_lists_del(struct dlock_list_node *node) >> +{ >> + struct dlock_list_head *head; >> + bool retry; >> + >> + do { >> + head = READ_ONCE(node->head); > Since we read node->head locklessly here, I think we should use > WRITE_ONCE() for all the stores of node->head, to avoid store tearings? Yes, you are right. I will use WRITE_ONCE() in my next version. Cheers, Longman