From: Michael Vrable Date: Mon, 20 Sep 2010 03:07:27 +0000 (-0700) Subject: More fixes for memory management. X-Git-Url: https://git.vrable.net/?a=commitdiff_plain;h=67c472ce34adf484d93c06b29cd1b822566c3b57;p=bluesky.git More fixes for memory management. This should allow memory and cache space to be reclaimed by not keeping items pinned in memory, finally. Still needs a bit more testing. --- diff --git a/bluesky/cloudlog.c b/bluesky/cloudlog.c index 9243948..ec168e8 100644 --- a/bluesky/cloudlog.c +++ b/bluesky/cloudlog.c @@ -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); } diff --git a/bluesky/imap.c b/bluesky/imap.c index 6318256..24144b4 100644 --- a/bluesky/imap.c +++ b/bluesky/imap.c @@ -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; } diff --git a/bluesky/serialize.c b/bluesky/serialize.c index b99a35e..00ff218 100644 --- a/bluesky/serialize.c +++ b/bluesky/serialize.c @@ -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);