Return-Path: Received: from mx2.suse.de ([195.135.220.15]:47587 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750951AbdCPH6F (ORCPT ); Thu, 16 Mar 2017 03:58:05 -0400 Date: Thu, 16 Mar 2017 08:58:02 +0100 From: Jan Kara To: Amir Goldstein Cc: Jan Kara , linux-fsdevel , Miklos Szeredi , Paul Moore Subject: Re: [PATCH 09/33] fsnotify: Remove indirection from mark list addition Message-ID: <20170316075802.GL12989@quack2.suse.cz> References: <20170315104632.7037-1-jack@suse.cz> <20170315104632.7037-10-jack@suse.cz> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Sender: linux-fsdevel-owner@vger.kernel.org List-ID: On Wed 15-03-17 21:19:13, Amir Goldstein wrote: > On Wed, Mar 15, 2017 at 12:46 PM, Jan Kara wrote: > > +static int fsnotify_add_mark_list(struct fsnotify_mark *mark, > > + struct inode *inode, struct vfsmount *mnt, > > + int allow_dups) > > { > > struct fsnotify_mark *lmark, *last = NULL; > > struct fsnotify_mark_connector *conn; > > + struct fsnotify_mark_connector **connp; > > + spinlock_t *lock; > > int cmp; > > + int err = 0; > > + > > + if (WARN_ON(!inode && !mnt)) > > + return -EINVAL; > > + if (inode) { > > + connp = &inode->i_fsnotify_marks; > > + lock = &inode->i_lock; > > + } else { > > + connp = &real_mount(mnt)->mnt_fsnotify_marks; > > + lock = &mnt->mnt_root->d_lock; > > + } > > > > if (!*connp) { > > conn = kmem_cache_alloc(fsnotify_mark_connector_cachep, > > - GFP_ATOMIC); > > + GFP_KERNEL); > > if (!conn) > > return -ENOMEM; > > INIT_HLIST_HEAD(&conn->list); > > @@ -350,8 +363,17 @@ int fsnotify_add_mark_list(struct fsnotify_mark_connector **connp, > > * lockless_dereference() in fsnotify(). > > */ > > smp_wmb(); > > - *connp = conn; > > + spin_lock(&mark->lock); > > + spin_lock(lock); > > + if (!*connp) { > > + *connp = conn; > > + } else { > > + kmem_cache_free(fsnotify_mark_connector_cachep, conn); > > + conn = *connp; > > + } > > } else { > > + spin_lock(&mark->lock); > > + spin_lock(lock); > > conn = *connp; > > } > > > > This chunk has become overly convoluted IMO. > How about something like this: > > conn = fsnotify_connector_get(connp, lock); > > spin_lock(&mark->lock); > spin_lock(lock); > > Where fsnotify_connector_get() acquires and releases only the object lock > and only for the case of allocating a new connector. Agreed and changed. Honza -- Jan Kara SUSE Labs, CR