]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
lockdep: Reduce "follows" matrix size by 8
authorPiotr Dałek <ceph@predictor.org.pl>
Fri, 22 Apr 2016 18:34:05 +0000 (20:34 +0200)
committerPiotr Dałek <git@predictor.org.pl>
Sun, 22 May 2016 14:05:12 +0000 (16:05 +0200)
Convert "follows" matrix to 2-dimensional array of bits, reducing its
storage size from 16 MB (assuming MAX_LOCKS = 4096) to 2MB.

Signed-off-by: Piotr Dałek <git@predictor.org.pl>
src/common/lockdep.cc

index b542b3b840437bfb52de6c7a649e8a126acb09dd..0b2046b6bc922f60e0d2f3ffaa98db47b1e0c0c6 100644 (file)
@@ -54,7 +54,7 @@ static map<int, std::string> lock_names;
 static map<int, int> lock_refs;
 static list<int> free_ids;
 static ceph::unordered_map<pthread_t, map<int,BackTrace*> > held;
-static bool follows[MAX_LOCKS][MAX_LOCKS]; // follows[a][b] means b taken after a
+static char follows[MAX_LOCKS][MAX_LOCKS/8]; // follows[a][b] means b taken after a
 static BackTrace *follows_bt[MAX_LOCKS][MAX_LOCKS];
 unsigned current_maxid;
 
@@ -106,7 +106,7 @@ void lockdep_unregister_ceph_context(CephContext *cct)
     lock_ids.clear();
     lock_refs.clear();
     free_ids.clear();
-    memset((void*)&follows[0][0], 0, sizeof(bool) * current_maxid * MAX_LOCKS);
+    memset((void*)&follows[0][0], 0, current_maxid * MAX_LOCKS/8);
     memset((void*)&follows_bt[0][0], 0, sizeof(BackTrace*) * current_maxid * MAX_LOCKS);
     current_maxid = 0;
   }
@@ -135,7 +135,6 @@ int lockdep_dump_locks()
   return 0;
 }
 
-
 int lockdep_register(const char *name)
 {
   int id;
@@ -184,14 +183,14 @@ void lockdep_unregister(int id)
   int &refs = lock_refs[id];
   if (--refs == 0) {
     // reset dependency ordering
-    memset((void*)&follows[id][0], 0, current_maxid);
+    memset((void*)&follows[id][0], 0, MAX_LOCKS/8);
     for (unsigned i=0; i<current_maxid; ++i) {
       delete follows_bt[id][i];
       follows_bt[id][i] = NULL;
 
       delete follows_bt[i][id];
       follows_bt[i][id] = NULL;
-      follows[i][id] = false;
+      follows[i][id / 8] &= 255 - (1 << (id % 8));
     }
 
     lockdep_dout(10) << "unregistered '" << p->second << "' from " << id
@@ -211,7 +210,7 @@ void lockdep_unregister(int id)
 // does b follow a?
 static bool does_follow(int a, int b)
 {
-  if (follows[a][b]) {
+  if (follows[a][b/8] & (1 << (b % 8))) {
     lockdep_dout(0) << "\n";
     *_dout << "------------------------------------" << "\n";
     *_dout << "existing dependency " << lock_names[a] << " (" << a << ") -> "
@@ -224,7 +223,7 @@ static bool does_follow(int a, int b)
   }
 
   for (unsigned i=0; i<current_maxid; i++) {
-    if (follows[a][i] &&
+    if ((follows[a][i/8] & (1 << (i % 8))) &&
        does_follow(i, b)) {
       lockdep_dout(0) << "existing intermediate dependency " << lock_names[a]
           << " (" << a << ") -> " << lock_names[i] << " (" << i << ") at:\n";
@@ -265,7 +264,7 @@ int lockdep_will_lock(const char *name, int id, bool force_backtrace)
       *_dout << dendl;
       assert(0);
     }
-    else if (!follows[p->first][id]) {
+    else if (!(follows[p->first][id/8] & (1 << (id % 8)))) {
       // new dependency
 
       // did we just create a cycle?
@@ -300,7 +299,7 @@ int lockdep_will_lock(const char *name, int id, bool force_backtrace)
         if (force_backtrace || lockdep_force_backtrace()) {
           bt = new BackTrace(BACKTRACE_SKIP);
         }
-        follows[p->first][id] = true;
+        follows[p->first][id/8] |= 1 << (id % 8);
         follows_bt[p->first][id] = bt;
        lockdep_dout(10) << lock_names[p->first] << " -> " << name << " at" << dendl;
        //bt->print(*_dout);