linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Waiman Long <Waiman.Long@hpe.com>
To: Alexander Viro <viro@zeniv.linux.org.uk>,
	Jan Kara <jack@suse.com>, Jeff Layton <jlayton@poochiereds.net>,
	"J. Bruce Fields" <bfields@fieldses.org>,
	Tejun Heo <tj@kernel.org>,
	Christoph Lameter <cl@linux-foundation.org>
Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org,
	Ingo Molnar <mingo@redhat.com>,
	Peter Zijlstra <peterz@infradead.org>,
	Andi Kleen <andi@firstfloor.org>,
	Dave Chinner <dchinner@redhat.com>,
	Boqun Feng <boqun.feng@gmail.com>,
	Scott J Norton <scott.norton@hpe.com>,
	Douglas Hatch <doug.hatch@hpe.com>,
	Waiman Long <Waiman.Long@hpe.com>
Subject: [PATCH v4 5/5] lib/dlock-list: Allow cacheline alignment of percpu head
Date: Fri, 22 Jul 2016 16:35:56 -0400	[thread overview]
Message-ID: <1469219756-26353-6-git-send-email-Waiman.Long@hpe.com> (raw)
In-Reply-To: <1469219756-26353-1-git-send-email-Waiman.Long@hpe.com>

Christoph Lameter had raised the concern that the spinlock in the
dlock_list_head_percpu structure may cause undesirable cacheline
contention in the percpu area that normally shouldn't have contention
of this kind.

This patch addresses this issue by allowing an option to force the
dlock_list_head_percpu structure to be cacheline aligned so that any
contention on the spinlock will not affect any nearby data items. It
then forces cacheline alignment when alloc_dlock_list_head() is called
by alloc_super() in fs/super.c.

Reported-by: Christoph Lameter <cl@linux.com>
Signed-off-by: Waiman Long <Waiman.Long@hpe.com>
---
 fs/super.c                 |    2 +-
 include/linux/dlock-list.h |    2 +-
 lib/dlock-list.c           |   20 ++++++++++++++++++--
 3 files changed, 20 insertions(+), 4 deletions(-)

diff --git a/fs/super.c b/fs/super.c
index 4c33204..39f2214 100644
--- a/fs/super.c
+++ b/fs/super.c
@@ -206,7 +206,7 @@ static struct super_block *alloc_super(struct file_system_type *type, int flags)
 	INIT_HLIST_BL_HEAD(&s->s_anon);
 	mutex_init(&s->s_sync_lock);
 
-	if (alloc_dlock_list_head(&s->s_inodes))
+	if (alloc_dlock_list_head(&s->s_inodes, 1))
 		goto fail;
 	if (list_lru_init_memcg(&s->s_dentry_lru))
 		goto fail;
diff --git a/include/linux/dlock-list.h b/include/linux/dlock-list.h
index ceb4228..f0a0b2a 100644
--- a/include/linux/dlock-list.h
+++ b/include/linux/dlock-list.h
@@ -127,7 +127,7 @@ static inline void dlock_list_relock(struct dlock_list_iter *iter)
 /*
  * Allocation and freeing of dlock list
  */
-extern int  alloc_dlock_list_head(struct dlock_list_head *dlist);
+extern int alloc_dlock_list_head(struct dlock_list_head *dlist, int align);
 extern void free_dlock_list_head(struct dlock_list_head *dlist);
 
 /*
diff --git a/lib/dlock-list.c b/lib/dlock-list.c
index 54006dc..f117d11 100644
--- a/lib/dlock-list.c
+++ b/lib/dlock-list.c
@@ -26,22 +26,38 @@
  */
 static struct lock_class_key dlock_list_key;
 
+struct dlock_list_head_percpu_caligned {
+	struct dlock_list_head_percpu head;
+} ____cacheline_aligned_in_smp;
+
 /**
  * alloc_dlock_list_head - Initialize and allocate the per-cpu list head
  * @dlist: Pointer to the dlock_list_head structure to be initialized
+ * @align: A boolean flag for cacheline alignment
  * Return: 0 if successful, -ENOMEM if memory allocation error
  *
  * This function does not allocate the dlock_list_head structure itself. The
  * callers will have to do their own memory allocation, if necessary. However,
  * this allows embedding the dlock_list_head structure directly into other
  * structures.
+ *
+ * As the percpu spinlocks can be accessed remotely from other CPUs, it may
+ * have a performance impact on other percpu data items resided in the same
+ * cacheline as the spinlock. This performance impact can be avoided by
+ * setting the align flag forcing cacheline alignment for the percpu head
+ * structure at the expense of some wasted memory space.
  */
-int alloc_dlock_list_head(struct dlock_list_head *dlist)
+int alloc_dlock_list_head(struct dlock_list_head *dlist, int align)
 {
 	struct dlock_list_head dlist_tmp;
 	int cpu;
 
-	dlist_tmp.head = alloc_percpu(struct dlock_list_head_percpu);
+	if (align)
+		dlist_tmp.head = (struct dlock_list_head_percpu __percpu *)
+			alloc_percpu(struct dlock_list_head_percpu_caligned);
+	else
+		dlist_tmp.head = alloc_percpu(struct dlock_list_head_percpu);
+
 	if (!dlist_tmp.head)
 		return -ENOMEM;
 
-- 
1.7.1

  parent reply	other threads:[~2016-07-22 20:36 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-07-22 20:35 [PATCH v4 0/5] vfs: Use dlock list for SB's s_inodes list Waiman Long
2016-07-22 20:35 ` [PATCH v4 1/5] lib/dlock-list: Distributed and lock-protected lists Waiman Long
2016-07-22 20:35 ` [PATCH v4 2/5] fsnotify: Simplify inode iteration on umount Waiman Long
2016-07-22 20:35 ` [PATCH v4 3/5] vfs: Remove unnecessary list_for_each_entry_safe() variants Waiman Long
2016-07-22 20:35 ` [PATCH v4 4/5] vfs: Use dlock list for superblock's inode list Waiman Long
2016-07-22 20:35 ` Waiman Long [this message]
2016-07-25 13:48 ` [PATCH v4 0/5] vfs: Use dlock list for SB's s_inodes list Christoph Lameter
2016-07-25 17:41   ` Tejun Heo
2016-07-27 15:12     ` Christoph Lameter
2016-08-09  3:26       ` Waiman Long

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1469219756-26353-6-git-send-email-Waiman.Long@hpe.com \
    --to=waiman.long@hpe.com \
    --cc=andi@firstfloor.org \
    --cc=bfields@fieldses.org \
    --cc=boqun.feng@gmail.com \
    --cc=cl@linux-foundation.org \
    --cc=dchinner@redhat.com \
    --cc=doug.hatch@hpe.com \
    --cc=jack@suse.com \
    --cc=jlayton@poochiereds.net \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    --cc=scott.norton@hpe.com \
    --cc=tj@kernel.org \
    --cc=viro@zeniv.linux.org.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).