Skip to content

Commit 1de14a5

Browse files
committed
client: use vectors for context lists
To avoid an allocation for each Context and improved cache locality. Signed-off-by: Patrick Donnelly <[email protected]>
1 parent 616fbc1 commit 1de14a5

File tree

5 files changed

+16
-33
lines changed

5 files changed

+16
-33
lines changed

src/client/Client.cc

Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4265,7 +4265,7 @@ void Client::signal_cond_list(list<ceph::condition_variable*>& ls)
42654265
}
42664266
}
42674267

4268-
void Client::wait_on_context_list(list<Context*>& ls)
4268+
void Client::wait_on_context_list(std::vector<Context*>& ls)
42694269
{
42704270
ceph::condition_variable cond;
42714271
bool done = false;
@@ -4276,30 +4276,14 @@ void Client::wait_on_context_list(list<Context*>& ls)
42764276
l.release();
42774277
}
42784278

4279-
void Client::signal_context_list(list<Context*>& ls)
4280-
{
4281-
while (!ls.empty()) {
4282-
ls.front()->complete(0);
4283-
ls.pop_front();
4284-
}
4285-
}
4286-
42874279
void Client::signal_caps_inode(Inode *in)
42884280
{
42894281
// Process the waitfor_caps list
4290-
while (!in->waitfor_caps.empty()) {
4291-
in->waitfor_caps.front()->complete(0);
4292-
in->waitfor_caps.pop_front();
4293-
}
4282+
signal_context_list(in->waitfor_caps);
42944283

42954284
// New items may have been added to the pending list, move them onto the
42964285
// waitfor_caps list
4297-
while (!in->waitfor_caps_pending.empty()) {
4298-
Context *ctx = in->waitfor_caps_pending.front();
4299-
4300-
in->waitfor_caps_pending.pop_front();
4301-
in->waitfor_caps.push_back(ctx);
4302-
}
4286+
std::swap(in->waitfor_caps, in->waitfor_caps_pending);
43034287
}
43044288

43054289
void Client::wake_up_session_caps(MetaSession *s, bool reconnect)
@@ -11904,7 +11888,7 @@ void Client::C_nonblocking_fsync_state::advance()
1190411888
ldout(clnt->cct, 15) << "waiting on unsafe requests, last tid " << req->get_tid() << dendl;
1190511889

1190611890
req->get();
11907-
clnt->add_nonblocking_onfinish_to_context_list(req->waitfor_safe, advancer);
11891+
req->waitfor_safe.push_back(advancer);
1190811892
// ------------ here is a state machine break point
1190911893
return;
1191011894
}
@@ -11930,7 +11914,7 @@ void Client::C_nonblocking_fsync_state::advance()
1193011914
ldout(clnt->cct, 10) << "ino " << in->ino << " has " << in->cap_refs[CEPH_CAP_FILE_BUFFER]
1193111915
<< " uncommitted, waiting" << dendl;
1193211916
advancer = new C_nonblocking_fsync_state_advancer(clnt, this);
11933-
clnt->add_nonblocking_onfinish_to_context_list(in->waitfor_commit, advancer);
11917+
in->waitfor_commit.push_back(advancer);
1193411918
// ------------ here is a state machine break point but we have to
1193511919
// return to this case because this might loop.
1193611920
progress = 1;
@@ -11988,9 +11972,9 @@ void Client::C_nonblocking_fsync_state::advance()
1198811972
<< " for C_nonblocking_fsync_state " << this
1198911973
<< dendl;
1199011974
if (progress == 3)
11991-
clnt->add_nonblocking_onfinish_to_context_list(in->waitfor_caps, advancer);
11975+
in->waitfor_caps.push_back(advancer);
1199211976
else
11993-
clnt->add_nonblocking_onfinish_to_context_list(in->waitfor_caps_pending, advancer);
11977+
in->waitfor_caps_pending.push_back(advancer);
1199411978
// ------------ here is a state machine break point
1199511979
// the advancer completion will resume with case 3
1199611980
progress = 4;
@@ -16796,7 +16780,7 @@ void Client::ms_handle_remote_reset(Connection *con)
1679616780
case MetaSession::STATE_OPENING:
1679716781
{
1679816782
ldout(cct, 1) << "reset from mds we were opening; retrying" << dendl;
16799-
list<Context*> waiters;
16783+
std::vector<Context*> waiters;
1680016784
waiters.swap(s->waiting_for_open);
1680116785
_closed_mds_session(s.get());
1680216786
auto news = _get_or_open_mds_session(mds);

src/client/Client.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1057,11 +1057,10 @@ class Client : public Dispatcher, public md_config_obs_t {
10571057
// helpers
10581058
void wake_up_session_caps(MetaSession *s, bool reconnect);
10591059

1060-
void add_nonblocking_onfinish_to_context_list(std::list<Context*>& ls, Context *onfinish) {
1061-
ls.push_back(onfinish);
1060+
void wait_on_context_list(std::vector<Context*>& ls);
1061+
void signal_context_list(std::vector<Context*>& ls) {
1062+
finish_contexts(cct, ls, 0);
10621063
}
1063-
void wait_on_context_list(std::list<Context*>& ls);
1064-
void signal_context_list(std::list<Context*>& ls);
10651064
void signal_caps_inode(Inode *in);
10661065

10671066
// -- metadata cache stuff

src/client/Inode.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -238,9 +238,9 @@ struct Inode : RefCountedObject {
238238
std::map<frag_t,int> fragmap; // known frag -> mds mappings
239239
std::map<frag_t, std::vector<mds_rank_t>> frag_repmap; // non-auth mds mappings
240240

241-
std::list<Context*> waitfor_caps;
242-
std::list<Context*> waitfor_caps_pending;
243-
std::list<Context*> waitfor_commit;
241+
std::vector<Context*> waitfor_caps;
242+
std::vector<Context*> waitfor_caps_pending;
243+
std::vector<Context*> waitfor_commit;
244244
std::list<ceph::condition_variable*> waitfor_deleg;
245245

246246
Dentry *get_first_parent() {

src/client/MetaRequest.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ struct MetaRequest {
7070

7171
ceph::condition_variable *caller_cond = NULL; // who to take up
7272
ceph::condition_variable *dispatch_cond = NULL; // who to kick back
73-
std::list<Context*> waitfor_safe;
73+
std::vector<Context*> waitfor_safe;
7474

7575
InodeRef target;
7676
UserPerm perms;

src/client/MetaSession.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ struct MetaSession {
4747
int mds_state = MDSMap::STATE_NULL;
4848
bool readonly = false;
4949

50-
std::list<Context*> waiting_for_open;
50+
std::vector<Context*> waiting_for_open;
5151

5252
xlist<Cap*> caps;
5353
// dirty_list keeps all the dirty inodes before flushing in current session.

0 commit comments

Comments
 (0)