From daac6b0e72d0d3eb8b54f5c7ba527bde3ff0e775 Mon Sep 17 00:00:00 2001 From: sage Date: Tue, 14 Jun 2005 17:23:21 +0000 Subject: [PATCH] memory leaks git-svn-id: https://ceph.svn.sf.net/svnroot/ceph@312 29311d96-e01e-0410-9327-a35deaab8ce9 --- ceph/client/Client.cc | 46 ++++++++++++++++++++++++++++++++-- ceph/client/Client.h | 12 +++------ ceph/client/SyntheticClient.cc | 3 ++- ceph/common/Timer.cc | 1 + ceph/common/Timer.h | 31 ++++++++++++++++++++--- ceph/fakesyn.cc | 4 ++- ceph/mds/MDCache.cc | 7 +++--- ceph/mds/MDCache.h | 2 +- ceph/mds/MDS.cc | 3 +-- ceph/mds/MDStore.cc | 28 ++++++--------------- ceph/msg/CheesySerializer.cc | 3 ++- ceph/msg/FakeMessenger.cc | 12 ++++++--- ceph/msg/HostMonitor.cc | 3 +++ ceph/msg/HostMonitor.h | 2 ++ ceph/msg/MPIMessenger.cc | 2 ++ ceph/osd/FakeStore.cc | 4 +-- ceph/osd/OSD.cc | 1 + 17 files changed, 114 insertions(+), 50 deletions(-) diff --git a/ceph/client/Client.cc b/ceph/client/Client.cc index c67d7b8f2a0c7..6d9f076d1e814 100644 --- a/ceph/client/Client.cc +++ b/ceph/client/Client.cc @@ -54,6 +54,35 @@ Client::~Client() if (messenger) { delete messenger; messenger = 0; } if (filer) { delete filer; filer = 0; } if (osdcluster) { delete osdcluster; osdcluster = 0; } + + tear_down_cache(); +} + +void Client::tear_down_cache() +{ + // fh's + for (map::iterator it = fh_map.begin(); + it != fh_map.end(); + it++) { + Fh *fh = it->second; + put_inode(fh->inode); + delete fh; + } + fh_map.clear(); + + // empty lru + lru.lru_set_max(0); + trim_cache(); + + // close root ino + assert(inode_map.size() <= 1); + if (root && inode_map.size() == 1) { + delete root; + root = 0; + inode_map.clear(); + } + + assert(inode_map.empty()); } @@ -72,6 +101,16 @@ void Client::shutdown() { // =================== // metadata cache stuff +void Client::trim_cache() +{ + while (lru.lru_get_size() > lru.lru_get_max()) { + Dentry *dn = (Dentry*)lru.lru_expire(); + if (!dn) break; // done + + //dout(10) << "unlinking dn " << dn->name << " in dir " << dn->dir->inode->inode.ino << endl; + unlink(dn); + } +} // insert inode info into metadata cache @@ -886,14 +925,16 @@ int Client::open(const char *path, int mode) // success? if (result > 0) { // yay + fileh_t fh = reply->get_result(); // FIXME? Fh *f = new Fh; memset(f, 0, sizeof(*f)); f->mds = reply->get_source(); f->inode = inode_map[trace[trace.size()-1]->inode.ino]; f->caps = reply->get_file_caps(); - fh_map[reply->get_result()] = f; + assert(fh_map.count(fh) == 0); + fh_map[fh] = f; - dout(3) << "open success, fh is " << reply->get_result() << " caps " << f->caps << " fh size " << f->size << endl; + dout(3) << "open success, fh is " << fh << " caps " << f->caps << " fh size " << f->size << endl; } delete reply; @@ -927,6 +968,7 @@ int Client::close(fileh_t fh) /* mds may ack our close() after reissuing same fh to another open; remove from fh_map _before_ sending request. */ fh_map.erase(fh); + delete f; release_inode_buffers(in); diff --git a/ceph/client/Client.h b/ceph/client/Client.h index c1358c5336678..a609fc12c3e76 100644 --- a/ceph/client/Client.h +++ b/ceph/client/Client.h @@ -210,7 +210,7 @@ class Client : public Dispatcher { // unlink from inode dn->inode = 0; in->dn = 0; - in->put(); + put_inode(in); // unlink from dir dn->dir->dentries.erase(dn->name); @@ -227,14 +227,7 @@ class Client : public Dispatcher { void touch_dn(Dentry *dn) { lru.lru_touch(dn); } // trim cache. - void trim_cache() { - while (lru.lru_get_size() > lru.lru_get_max()) { - Dentry *dn = (Dentry*)lru.lru_expire(); - if (!dn) break; // done - - unlink(dn); - } - } + void trim_cache(); // find dentry based on filepath Dentry *lookup(filepath& path); @@ -253,6 +246,7 @@ class Client : public Dispatcher { public: Client(MDCluster *mdc, int id, Messenger *m); ~Client(); + void tear_down_cache(); int get_nodeid() { return whoami; } diff --git a/ceph/client/SyntheticClient.cc b/ceph/client/SyntheticClient.cc index 8e9ad17486679..d514f0248460e 100644 --- a/ceph/client/SyntheticClient.cc +++ b/ceph/client/SyntheticClient.cc @@ -165,10 +165,11 @@ int SyntheticClient::make_dirs(const char *basedir, int dirs, int files, int dep -int SyntheticClient::write_file(string& fn, int size, int wrsize) // size is in MB +int SyntheticClient::write_file(string& fn, int size, int wrsize) // size is in MB, wrsize in bytes { //__uint64_t wrsize = 1024*256; char *buf = new char[wrsize]; // 1 MB + memset(buf, 1, wrsize); __uint64_t chunks = (__uint64_t)size * (__uint64_t)(1024*1024) / (__uint64_t)wrsize; int fd = client->open(fn.c_str(), O_WRONLY|O_CREAT); diff --git a/ceph/common/Timer.cc b/ceph/common/Timer.cc index a50d7f9a5cacd..c250de9cff15d 100644 --- a/ceph/common/Timer.cc +++ b/ceph/common/Timer.cc @@ -173,6 +173,7 @@ bool Timer::cancel_event(Context *callback) if (!event_times.count(callback)) { dout(DBL) << "cancel_event " << callback << " wasn't scheduled?" << endl; lock.Unlock(); + assert(0); return false; // wasn't scheduled. } diff --git a/ceph/common/Timer.h b/ceph/common/Timer.h index 32ca93dac9f47..f0a6b316efe8d 100644 --- a/ceph/common/Timer.h +++ b/ceph/common/Timer.h @@ -66,11 +66,34 @@ class Timer { thread_stop = false; } ~Timer() { - // cancel any wakeup/thread crap + // scheduled + for (map< timepair_t, set >::iterator it = scheduled.begin(); + it != scheduled.end(); + it++) { + for (set::iterator sit = it->second.begin(); + sit != it->second.end(); + sit++) + delete *sit; + } + scheduled.clear(); + + // pending + for (map< timepair_t, set >::iterator it = pending.begin(); + it != pending.end(); + it++) { + for (set::iterator sit = it->second.begin(); + sit != it->second.end(); + sit++) + delete *sit; + } + pending.clear(); + } + + void init() { + register_timer(); + } + void shutdown() { cancel_timer(); - - // clean up pending events - // ** FIXME ** } void set_messenger(Messenger *m); diff --git a/ceph/fakesyn.cc b/ceph/fakesyn.cc index 1683192854c80..82bad147db80d 100644 --- a/ceph/fakesyn.cc +++ b/ceph/fakesyn.cc @@ -182,7 +182,9 @@ int main(int oargc, char **oargv) { delete client[i]; } delete mdc; - + + free(argv); + delete[] nargv; return 0; } diff --git a/ceph/mds/MDCache.cc b/ceph/mds/MDCache.cc index 3cef53b907407..29e87d7795e62 100644 --- a/ceph/mds/MDCache.cc +++ b/ceph/mds/MDCache.cc @@ -3176,7 +3176,7 @@ void MDCache::handle_rename_notify(MRenameNotify *m) int MDCache::issue_file_caps(CInode *in, int mode, - Context *onwait) + MClientRequest *req) { dout(7) << "issue_file_caps for mode " << mode << " on " << *in << endl; @@ -3222,14 +3222,15 @@ int MDCache::issue_file_caps(CInode *in, } } - in->add_waiter(CINODE_WAIT_CAPS, onwait); + in->add_waiter(CINODE_WAIT_CAPS, new C_MDS_RetryRequest(mds, req, in)); return 0; } // we're okay! int caps = my_want & allowed; dout(7) << " issuing caps " << caps << " (i want " << my_want << ", allowed " << allowed << ")" << endl; - assert(caps); + assert(caps > 0); + return caps; } diff --git a/ceph/mds/MDCache.h b/ceph/mds/MDCache.h index 6ec7d1040c807..367e5e64d29fb 100644 --- a/ceph/mds/MDCache.h +++ b/ceph/mds/MDCache.h @@ -258,7 +258,7 @@ class MDCache { // -- file i/o -- - int issue_file_caps(CInode *in, int mode, Context *onwait); + int issue_file_caps(CInode *in, int mode, MClientRequest *req); void eval_file_caps(CInode *in); void handle_client_file_caps(class MClientFileCaps *m); diff --git a/ceph/mds/MDS.cc b/ceph/mds/MDS.cc index 7d663ebe32571..9b3b8bb2f467f 100644 --- a/ceph/mds/MDS.cc +++ b/ceph/mds/MDS.cc @@ -2238,8 +2238,7 @@ void MDS::handle_client_open(MClientRequest *req, // can we issue the caps they want? - int caps = mdcache->issue_file_caps(cur, mode, - new C_MDS_RetryRequest(this, req, cur)); + int caps = mdcache->issue_file_caps(cur, mode, req); if (!caps) return; // can't issue (yet), so wait! // create fh diff --git a/ceph/mds/MDStore.cc b/ceph/mds/MDStore.cc index c725cd27bb13f..48e7cdccbbf07 100644 --- a/ceph/mds/MDStore.cc +++ b/ceph/mds/MDStore.cc @@ -302,8 +302,6 @@ class MDDoCommitDirContext : public Context { __uint64_t version; public: - bufferlist bl; - MDDoCommitDirContext(MDStore *ms, CDir *dir, Context *c, int w) : Context() { this->ms = ms; this->dir = dir; @@ -393,32 +391,20 @@ void MDStore::do_commit_dir( CDir *dir, dout(14) << "num " << num << endl; // put count in buffer + bufferlist bl; size_t size = sizeof(num) + dirdata.length(); - fin->bl.append((char*)&size, sizeof(size)); - fin->bl.append((char*)&num, sizeof(num)); - fin->bl.append(dirdata.c_str(), dirdata.length()); - assert(fin->bl.length() == size + sizeof(size)); + bl.append((char*)&size, sizeof(size)); + bl.append((char*)&num, sizeof(num)); + bl.append(dirdata.c_str(), dirdata.length()); + assert(bl.length() == size + sizeof(size)); // pin inode dir->auth_pin(); // submit to osd - int osd; - object_t oid; - if (hashcode >= 0) { - // hashed - osd = mds->mdcluster->get_hashdir_meta_osd(dir->ino(), hashcode); - oid = mds->mdcluster->get_hashdir_meta_oid(dir->ino(), hashcode); - } else { - // normal - osd = mds->mdcluster->get_meta_osd(dir->ino()); - oid = mds->mdcluster->get_meta_oid(dir->ino()); - } - - mds->filer->write( dir->ino(), - fin->bl.length(), 0, - fin->bl, + bl.length(), 0, + bl, 0, //OSD_OP_FLAGS_TRUNCATE, // truncate file/object after end of this write fin ); } diff --git a/ceph/msg/CheesySerializer.cc b/ceph/msg/CheesySerializer.cc index aa9fbc3b98fad..a73db49fdcadd 100644 --- a/ceph/msg/CheesySerializer.cc +++ b/ceph/msg/CheesySerializer.cc @@ -121,6 +121,7 @@ int CheesySerializer::shutdown() } lock.Unlock(); - // shutdown underlying messenger. + // shutdown and delete underlying messenger. messenger->shutdown(); + delete messenger; } diff --git a/ceph/msg/FakeMessenger.cc b/ceph/msg/FakeMessenger.cc index 8a7826d67e026..754dbf28f7bcd 100644 --- a/ceph/msg/FakeMessenger.cc +++ b/ceph/msg/FakeMessenger.cc @@ -95,6 +95,8 @@ int fakemessenger_do_loop() lock.Lock(); fakemessenger_do_loop_2(); lock.Unlock(); + + g_timer.shutdown(); } @@ -176,6 +178,7 @@ FakeMessenger::FakeMessenger(long me) : Messenger(me) cout << "fakemessenger " << whoami << " messenger is " << this << endl; + /* string name; name = "m."; name += MSG_ADDR_TYPE(whoami); @@ -185,15 +188,18 @@ FakeMessenger::FakeMessenger(long me) : Messenger(me) if (w >= 10) name += ('0' + ((w/10)%10)); name += ('0' + ((w/1)%10)); - logger = new Logger(name, (LogType*)&fakemsg_logtype); - loggers[ whoami ] = logger; + loggers[ whoami ] = new Logger(name, (LogType*)&fakemsg_logtype); + */ } FakeMessenger::~FakeMessenger() { shutdown(); - delete logger; + if (loggers[whoami]) { + delete loggers[whoami]; + loggers.erase(whoami); + } } diff --git a/ceph/msg/HostMonitor.cc b/ceph/msg/HostMonitor.cc index a6ab29921c6af..7d35712a9717a 100644 --- a/ceph/msg/HostMonitor.cc +++ b/ceph/msg/HostMonitor.cc @@ -30,6 +30,7 @@ public: } void finish(int r) { //cout << "HEARTBEAT" << endl; + hm->pending_events.erase(this); hm->initiate_heartbeat(); } }; @@ -42,6 +43,7 @@ public: } void finish(int r) { //cout << "CHECK" << endl; + hm->pending_events.erase(this); hm->check_heartbeat(); } }; @@ -72,6 +74,7 @@ void HostMonitor::shutdown() it != pending_events.end(); it++) { g_timer.cancel_event(*it); + delete *it; } pending_events.clear(); } diff --git a/ceph/msg/HostMonitor.h b/ceph/msg/HostMonitor.h index b3627e9852c04..b3e61eecf3bbf 100644 --- a/ceph/msg/HostMonitor.h +++ b/ceph/msg/HostMonitor.h @@ -42,8 +42,10 @@ class HostMonitor { int max_heartbeat_misses; // how many misses before i tell float notify_retry_interval; // how often to retry failure notification + public: set pending_events; + private: void schedule_heartbeat(); public: diff --git a/ceph/msg/MPIMessenger.cc b/ceph/msg/MPIMessenger.cc index 3d1f2b92f1ce3..e755c56f6aa46 100644 --- a/ceph/msg/MPIMessenger.cc +++ b/ceph/msg/MPIMessenger.cc @@ -407,6 +407,8 @@ void* mpimessenger_loop(void*) dout(5) << "finishing async sends" << endl; mpi_finish_sends(); + g_timer.shutdown(); + dout(5) << "mpimessenger_loop exiting loop" << endl; } diff --git a/ceph/osd/FakeStore.cc b/ceph/osd/FakeStore.cc index c4f67f0c22c73..921673bb0cf9c 100644 --- a/ceph/osd/FakeStore.cc +++ b/ceph/osd/FakeStore.cc @@ -91,7 +91,7 @@ void FakeStore::wipe_dir(string mydir) { DIR *dir = opendir(mydir.c_str()); if (dir) { - dout(1) << "wiping " << mydir << endl; + dout(10) << "wiping " << mydir << endl; struct dirent *ent = 0; while (ent = readdir(dir)) { @@ -123,7 +123,7 @@ int FakeStore::mkfs() // make sure my dir exists r = ::stat(mydir.c_str(), &st); if (r != 0) { - dout(1) << "creating " << mydir << endl; + dout(10) << "creating " << mydir << endl; mkdir(mydir.c_str(), 0755); r = ::stat(mydir.c_str(), &st); if (r != 0) { diff --git a/ceph/osd/OSD.cc b/ceph/osd/OSD.cc index 2baa90253b46a..82b9fcc7d3ca0 100644 --- a/ceph/osd/OSD.cc +++ b/ceph/osd/OSD.cc @@ -82,6 +82,7 @@ OSD::OSD(int id, Messenger *m) OSD::~OSD() { if (osdcluster) { delete osdcluster; osdcluster = 0; } + if (monitor) { delete monitor; monitor = 0; } if (messenger) { delete messenger; messenger = 0; } if (logger) { delete logger; logger = 0; } if (store) { delete store; store = 0; } -- 2.39.5