From: Waiman Long <longman@redhat.com>
To: Thomas Gleixner <tglx@linutronix.de>,
Ingo Molnar <mingo@kernel.org>,
Peter Zijlstra <peterz@infradead.org>,
Jonathan Corbet <corbet@lwn.net>
Cc: linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org,
Arnaldo Carvalho de Melo <acme@kernel.org>,
Davidlohr Bueso <dave@stgolabs.net>,
Mike Galbraith <umgwanakikbuti@gmail.com>,
Scott J Norton <scott.norton@hpe.com>,
Waiman Long <longman@redhat.com>
Subject: [PATCH-tip v6 08/22] futex: Allow direct attachment of futex_state objects to hash bucket
Date: Wed, 22 Mar 2017 13:38:44 -0400 [thread overview]
Message-ID: <1490204338-1856-9-git-send-email-longman@redhat.com> (raw)
In-Reply-To: <1490204338-1856-1-git-send-email-longman@redhat.com>
Currently, the futex state objects can only be located indirectly as
hash bucket => futex_q => futex state
Actually it can be beneficial in some cases to locate the futex state
object directly from the hash bucket without the futex_q middleman.
Therefore, a new list head to link the futex state objects as well
as a new spinlock to manage them are added to the hash bucket.
To limit size increase for UP systems, these new fields are only for
SMP machines where the cacheline alignment of the hash bucket leaves
it with enough empty space for the new fields.
Signed-off-by: Waiman Long <longman@redhat.com>
---
kernel/futex.c | 24 ++++++++++++++++++++++++
1 file changed, 24 insertions(+)
diff --git a/kernel/futex.c b/kernel/futex.c
index fd365b2..eb15095 100644
--- a/kernel/futex.c
+++ b/kernel/futex.c
@@ -209,6 +209,11 @@ struct futex_state {
struct list_head list;
/*
+ * Can link to fs_head in the owning hash bucket.
+ */
+ struct list_head fs_list;
+
+ /*
* The PI object:
*/
struct rt_mutex pi_mutex;
@@ -264,11 +269,24 @@ struct futex_q {
* Hash buckets are shared by all the futex_keys that hash to the same
* location. Each key may have multiple futex_q structures, one for each task
* waiting on a futex.
+ *
+ * Alternatively (in SMP), a key can be associated with a unique futex_state
+ * object where multiple waiters waiting for that futex can queue up in that
+ * futex_state object without using the futex_q structure. A separate
+ * futex_state lock (fs_lock) is used for processing those futex_state objects.
*/
struct futex_hash_bucket {
atomic_t waiters;
spinlock_t lock;
struct plist_head chain;
+
+#ifdef CONFIG_SMP
+ /*
+ * Fields for managing futex_state object list
+ */
+ spinlock_t fs_lock;
+ struct list_head fs_head;
+#endif
} ____cacheline_aligned_in_smp;
/*
@@ -875,6 +893,8 @@ static int refill_futex_state_cache(void)
return -ENOMEM;
INIT_LIST_HEAD(&state->list);
+ INIT_LIST_HEAD(&state->fs_list);
+
/* pi_mutex gets initialized later */
state->owner = NULL;
atomic_set(&state->refcount, 1);
@@ -3377,6 +3397,10 @@ static int __init futex_init(void)
atomic_set(&futex_queues[i].waiters, 0);
plist_head_init(&futex_queues[i].chain);
spin_lock_init(&futex_queues[i].lock);
+#ifdef CONFIG_SMP
+ INIT_LIST_HEAD(&futex_queues[i].fs_head);
+ spin_lock_init(&futex_queues[i].fs_lock);
+#endif
}
return 0;
--
1.8.3.1
next prev parent reply other threads:[~2017-03-22 17:45 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-03-22 17:38 [PATCH-tip v6 00/22] futex: Introducing throughput-optimized (TP) futexes Waiman Long
2017-03-22 17:38 ` [PATCH-tip v6 01/22] perf bench: New microbenchmark for userspace mutex performance Waiman Long
2017-03-22 17:38 ` [PATCH-tip v6 02/22] perf bench: New microbenchmark for userspace rwlock performance Waiman Long
2017-03-22 17:38 ` [PATCH-tip v6 03/22] futex: Consolidate duplicated timer setup code Waiman Long
2017-03-22 17:38 ` [PATCH-tip v6 04/22] futex: Rename futex_pi_state to futex_state Waiman Long
2017-03-22 17:38 ` [PATCH-tip v6 05/22] futex: Add helpers to get & cmpxchg futex value without lock Waiman Long
2017-03-22 17:38 ` [PATCH-tip v6 06/22] futex: Consolidate pure pi_state_list add & delete codes to helpers Waiman Long
2017-03-22 17:38 ` [PATCH-tip v6 07/22] futex: Add a new futex type field into futex_state Waiman Long
2017-03-22 17:38 ` Waiman Long [this message]
2017-03-22 17:38 ` [PATCH-tip v6 09/22] futex: Introduce throughput-optimized (TP) futexes Waiman Long
2017-03-22 17:38 ` [PATCH-tip v6 10/22] TP-futex: Enable robust handling Waiman Long
2017-03-22 17:38 ` [PATCH-tip v6 11/22] TP-futex: Implement lock handoff to prevent lock starvation Waiman Long
2017-03-22 17:38 ` [PATCH-tip v6 12/22] TP-futex: Return status code on FUTEX_LOCK calls Waiman Long
2017-03-22 17:38 ` [PATCH-tip v6 13/22] TP-futex: Add timeout support Waiman Long
2017-03-22 17:38 ` [PATCH-tip v6 14/22] TP-futex: Optionally return EAGAIN for userspace locking Waiman Long
2017-03-22 17:38 ` [PATCH-tip v6 15/22] TP-futex, doc: Add TP futexes documentation Waiman Long
2017-03-22 17:38 ` [PATCH-tip v6 16/22] TP-futex: Support userspace reader/writer locks Waiman Long
2017-03-22 17:38 ` [PATCH-tip v6 17/22] TP-futex: Enable kernel reader lock stealing Waiman Long
2017-03-22 17:38 ` [PATCH-tip v6 18/22] TP-futex: Group readers together in wait queue Waiman Long
2017-03-24 8:19 ` kbuild test robot
2017-03-24 8:28 ` kbuild test robot
2017-03-22 17:38 ` [PATCH-tip v6 19/22] TP-futex, doc: Update TP futexes document on shared locking Waiman Long
2017-03-22 17:38 ` [PATCH-tip v6 20/22] perf bench: Extend mutex/rwlock futex suite to test TP futexes Waiman Long
2017-03-22 17:38 ` [PATCH-tip v6 21/22] sched, TP-futex: Make wake_up_q() return wakeup count Waiman Long
2017-03-22 17:38 ` [PATCH-tip v6 22/22] futex: Dump internal futex state via debugfs 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=1490204338-1856-9-git-send-email-longman@redhat.com \
--to=longman@redhat.com \
--cc=acme@kernel.org \
--cc=corbet@lwn.net \
--cc=dave@stgolabs.net \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=peterz@infradead.org \
--cc=scott.norton@hpe.com \
--cc=tglx@linutronix.de \
--cc=umgwanakikbuti@gmail.com \
/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
all inboxes | Powered by JetHome®