Skip to content

Commit f363e45

Browse files
htejunliewegas
authored andcommitted
net/ceph: make ceph_msgr_wq non-reentrant
ceph messenger code does a rather complex dancing around multithread workqueue to make sure the same work item isn't executed concurrently on different CPUs. This restriction can be provided by workqueue with WQ_NON_REENTRANT. Make ceph_msgr_wq non-reentrant workqueue with the default concurrency level and remove the QUEUED/BUSY logic. * This removes backoff handling in con_work() but it couldn't reliably block execution of con_work() to begin with - queue_con() can be called after the work started but before BUSY is set. It seems that it was an optimization for a rather cold path and can be safely removed. * The number of concurrent work items is bound by the number of connections and connetions are independent from each other. With the default concurrency level, different connections will be executed independently. Signed-off-by: Tejun Heo <tj@kernel.org> Cc: Sage Weil <sage@newdream.net> Cc: ceph-devel@vger.kernel.org Signed-off-by: Sage Weil <sage@newdream.net>
1 parent 01e6acc commit f363e45

2 files changed

Lines changed: 2 additions & 49 deletions

File tree

‎include/linux/ceph/messenger.h‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -110,17 +110,12 @@ struct ceph_msg_pos {
110110

111111
/*
112112
* ceph_connection state bit flags
113-
*
114-
* QUEUED and BUSY are used together to ensure that only a single
115-
* thread is currently opening, reading or writing data to the socket.
116113
*/
117114
#define LOSSYTX 0 /* we can close channel or drop messages on errors */
118115
#define CONNECTING 1
119116
#define NEGOTIATING 2
120117
#define KEEPALIVE_PENDING 3
121118
#define WRITE_PENDING 4 /* we have data ready to send */
122-
#define QUEUED 5 /* there is work queued on this connection */
123-
#define BUSY 6 /* work is being done */
124119
#define STANDBY 8 /* no outgoing messages, socket closed. we keep
125120
* the ceph_connection around to maintain shared
126121
* state with the peer. */

‎net/ceph/messenger.c‎

Lines changed: 2 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ struct workqueue_struct *ceph_msgr_wq;
9696

9797
int ceph_msgr_init(void)
9898
{
99-
ceph_msgr_wq = create_workqueue("ceph-msgr");
99+
ceph_msgr_wq = alloc_workqueue("ceph-msgr", WQ_NON_REENTRANT, 0);
100100
if (!ceph_msgr_wq) {
101101
pr_err("msgr_init failed to create workqueue\n");
102102
return -ENOMEM;
@@ -1920,20 +1920,6 @@ static int try_read(struct ceph_connection *con)
19201920
/*
19211921
* Atomically queue work on a connection. Bump @con reference to
19221922
* avoid races with connection teardown.
1923-
*
1924-
* There is some trickery going on with QUEUED and BUSY because we
1925-
* only want a _single_ thread operating on each connection at any
1926-
* point in time, but we want to use all available CPUs.
1927-
*
1928-
* The worker thread only proceeds if it can atomically set BUSY. It
1929-
* clears QUEUED and does it's thing. When it thinks it's done, it
1930-
* clears BUSY, then rechecks QUEUED.. if it's set again, it loops
1931-
* (tries again to set BUSY).
1932-
*
1933-
* To queue work, we first set QUEUED, _then_ if BUSY isn't set, we
1934-
* try to queue work. If that fails (work is already queued, or BUSY)
1935-
* we give up (work also already being done or is queued) but leave QUEUED
1936-
* set so that the worker thread will loop if necessary.
19371923
*/
19381924
static void queue_con(struct ceph_connection *con)
19391925
{
@@ -1948,11 +1934,7 @@ static void queue_con(struct ceph_connection *con)
19481934
return;
19491935
}
19501936

1951-
set_bit(QUEUED, &con->state);
1952-
if (test_bit(BUSY, &con->state)) {
1953-
dout("queue_con %p - already BUSY\n", con);
1954-
con->ops->put(con);
1955-
} else if (!queue_work(ceph_msgr_wq, &con->work.work)) {
1937+
if (!queue_delayed_work(ceph_msgr_wq, &con->work, 0)) {
19561938
dout("queue_con %p - already queued\n", con);
19571939
con->ops->put(con);
19581940
} else {
@@ -1967,15 +1949,6 @@ static void con_work(struct work_struct *work)
19671949
{
19681950
struct ceph_connection *con = container_of(work, struct ceph_connection,
19691951
work.work);
1970-
int backoff = 0;
1971-
1972-
more:
1973-
if (test_and_set_bit(BUSY, &con->state) != 0) {
1974-
dout("con_work %p BUSY already set\n", con);
1975-
goto out;
1976-
}
1977-
dout("con_work %p start, clearing QUEUED\n", con);
1978-
clear_bit(QUEUED, &con->state);
19791952

19801953
mutex_lock(&con->mutex);
19811954

@@ -1994,28 +1967,13 @@ static void con_work(struct work_struct *work)
19941967
try_read(con) < 0 ||
19951968
try_write(con) < 0) {
19961969
mutex_unlock(&con->mutex);
1997-
backoff = 1;
19981970
ceph_fault(con); /* error/fault path */
19991971
goto done_unlocked;
20001972
}
20011973

20021974
done:
20031975
mutex_unlock(&con->mutex);
2004-
20051976
done_unlocked:
2006-
clear_bit(BUSY, &con->state);
2007-
dout("con->state=%lu\n", con->state);
2008-
if (test_bit(QUEUED, &con->state)) {
2009-
if (!backoff || test_bit(OPENING, &con->state)) {
2010-
dout("con_work %p QUEUED reset, looping\n", con);
2011-
goto more;
2012-
}
2013-
dout("con_work %p QUEUED reset, but just faulted\n", con);
2014-
clear_bit(QUEUED, &con->state);
2015-
}
2016-
dout("con_work %p done\n", con);
2017-
2018-
out:
20191977
con->ops->put(con);
20201978
}
20211979

0 commit comments

Comments
 (0)