More fixes for memory management.
authorMichael Vrable <mvrable@cs.ucsd.edu>
Mon, 20 Sep 2010 03:07:27 +0000 (20:07 -0700)
committerMichael Vrable <mvrable@cs.ucsd.edu>
Mon, 20 Sep 2010 03:07:27 +0000 (20:07 -0700)
This should allow memory and cache space to be reclaimed by not keeping
items pinned in memory, finally.  Still needs a bit more testing.

bluesky/cloudlog.c
bluesky/imap.c
bluesky/serialize.c

index 9243948..ec168e8 100644 (file)
@@ -147,7 +147,10 @@ void bluesky_cloudlog_unref(BlueSkyCloudLog *log)
             return;
         }
 
-        g_hash_table_remove(fs->locations, &log->id);
+        if (!g_hash_table_remove(fs->locations, &log->id)) {
+            if (bluesky_verbose)
+                g_warning("Could not find and remove cloud log item from hash table!");
+        }
         g_mutex_unlock(fs->lock);
 
         bluesky_cloudlog_stats_update(log, -1);
@@ -202,6 +205,9 @@ void bluesky_cloudlog_erase(BlueSkyCloudLog *log)
 {
     g_assert(log->data_lock_count == 0);
 
+    if (log->type == LOGTYPE_UNKNOWN)
+        return;
+
     log->type = LOGTYPE_UNKNOWN;
     log->data_size = 0;
     bluesky_string_unref(log->data);
@@ -253,7 +259,7 @@ BlueSkyCloudLog *bluesky_cloudlog_get(BlueSkyFS *fs, BlueSkyCloudID id)
     item = g_hash_table_lookup(fs->locations, &id);
     if (item == NULL) {
         item = bluesky_cloudlog_new(fs, &id);
-        g_hash_table_insert(fs->locations, &id, item);
+        bluesky_cloudlog_insert_locked(item);
     } else {
         bluesky_cloudlog_ref(item);
     }
index 6318256..24144b4 100644 (file)
@@ -203,6 +203,24 @@ void bluesky_inode_map_minimize(BlueSkyFS *fs)
         if (range->serialized != NULL)
             bluesky_cloudlog_erase(range->serialized);
 
+        GSequenceIter *j;
+        for (j = g_sequence_get_begin_iter(range->map_entries);
+             !g_sequence_iter_is_end(j); j = g_sequence_iter_next(j))
+        {
+            InodeMapEntry *entry = (InodeMapEntry *)g_sequence_get(j);
+            BlueSkyCloudLog *item = entry->item;
+            if (item != NULL) {
+                g_mutex_lock(item->lock);
+                if (g_atomic_int_get(&item->refcount) == 1) {
+                    bluesky_cloudlog_erase(item);
+                }
+                g_mutex_unlock(item->lock);
+            } else {
+                g_warning("Null item for inode map entry %"PRIu64"!",
+                          entry->inum);
+            }
+        }
+
         i = g_sequence_iter_next(i);
     }
 }
@@ -307,7 +325,7 @@ gboolean bluesky_checkpoint_load(BlueSkyFS *fs)
     g_mutex_unlock(commit->lock);
 
     bluesky_inode_map_deserialize(fs, commit);
-    //bluesky_cloudlog_unref(commit);
+    bluesky_cloudlog_unref(commit);
 
     return TRUE;
 }
index b99a35e..00ff218 100644 (file)
@@ -318,6 +318,10 @@ void bluesky_deserialize_cloudlog(BlueSkyCloudLog *item,
         return;
     }
 
+    if (memcmp(&id, &item->id, sizeof(BlueSkyCloudID)) != 0) {
+        g_warning("ID does not match expected value!\n");
+    }
+
     BlueSkyFS *fs = item->fs;
 
     bluesky_string_unref(item->data);