From: Michael Vrable Date: Sun, 19 Sep 2010 22:22:02 +0000 (-0700) Subject: Work on reducing memory pinned by the inode map. X-Git-Url: https://git.vrable.net/?a=commitdiff_plain;h=0a5db8fb9777ff872240053593fd86af71360ee8;p=bluesky.git Work on reducing memory pinned by the inode map. --- diff --git a/bluesky/bluesky-private.h b/bluesky/bluesky-private.h index 7ebd728..61238eb 100644 --- a/bluesky/bluesky-private.h +++ b/bluesky/bluesky-private.h @@ -385,14 +385,9 @@ typedef struct { typedef struct { uint64_t inum; - /* The ID of the most recent version of the inode. */ - BlueSkyCloudID id; - - /* The location where that version is written in the cloud. */ - BlueSkyCloudPointer location; - - /* If the cloud log entry exists in memory, then a pointer to it, otherwise - * NULL. */ + /* A pointer to the cloud log entry for this inode. This may or may not + * actually have data loaded (it might just contain pointers to the data + * location, and in fact this will likely often be the case). */ BlueSkyCloudLog *item; } InodeMapEntry; @@ -414,6 +409,7 @@ typedef struct { InodeMapEntry *bluesky_inode_map_lookup(GSequence *inode_map, uint64_t inum, int action); BlueSkyCloudLog *bluesky_inode_map_serialize(BlueSkyFS *fs); +void bluesky_inode_map_minimize(BlueSkyFS *fs); gboolean bluesky_checkpoint_load(BlueSkyFS *fs); diff --git a/bluesky/cache.c b/bluesky/cache.c index 3afceca..d1c5c84 100644 --- a/bluesky/cache.c +++ b/bluesky/cache.c @@ -195,6 +195,8 @@ static void flushd_cloud(BlueSkyFS *fs) journal_seq_start); fs->log->journal_watermark = journal_seq_start; + + bluesky_inode_map_minimize(fs); } /* Drop cached data for a given inode, if it is clean. inode must be locked. */ diff --git a/bluesky/cloudlog.c b/bluesky/cloudlog.c index e50c269..9243948 100644 --- a/bluesky/cloudlog.c +++ b/bluesky/cloudlog.c @@ -383,8 +383,6 @@ BlueSkyCloudPointer bluesky_cloudlog_serialize(BlueSkyCloudLog *log, g_mutex_lock(fs->lock); InodeMapEntry *entry = bluesky_inode_map_lookup(fs->inode_map, log->inum, 1); - entry->id = log->id; - entry->location = log->location; entry->item = log; bluesky_cloudlog_ref(entry->item); g_mutex_unlock(fs->lock); diff --git a/bluesky/debug.c b/bluesky/debug.c index ee6e0c5..7de5095 100644 --- a/bluesky/debug.c +++ b/bluesky/debug.c @@ -81,9 +81,14 @@ void inode_map_dump(GSequence *inode_map) !g_sequence_iter_is_end(j); j = g_sequence_iter_next(j)) { InodeMapEntry *entry = (InodeMapEntry *)g_sequence_get(j); - char *id = bluesky_cloudlog_id_to_string(entry->id); - g_print(" Entry %"PRIu64" id=%s\n", entry->inum, id); - g_free(id); + BlueSkyCloudLog *item = entry->item; + if (item != NULL) { + char *id = bluesky_cloudlog_id_to_string(item->id); + g_print(" Entry %"PRIu64" id=%s\n", entry->inum, id); + g_free(id); + } else { + g_print(" Entry %"PRIu64" not available\n", entry->inum); + } } } } diff --git a/bluesky/imap.c b/bluesky/imap.c index c496f99..6318256 100644 --- a/bluesky/imap.c +++ b/bluesky/imap.c @@ -145,6 +145,7 @@ static void bluesky_inode_map_serialize_section(BlueSkyFS *fs, InodeMapEntry *entry = (InodeMapEntry *)g_sequence_get(i); uint64_t inum = GUINT64_TO_LE(entry->inum); g_string_append_len(buf, (const char *)&inum, sizeof(inum)); + bluesky_cloudlog_ref(entry->item); g_array_append_val(log->links, entry->item); i = g_sequence_iter_next(i); } @@ -189,6 +190,23 @@ BlueSkyCloudLog *bluesky_inode_map_serialize(BlueSkyFS *fs) } } +/* Minimize resources consumed the inode map. This should only be called once + * an updated inode map has been serialized to the cloud, and will replace + * cloud log objects with skeletal versions that just reference the data + * location in the cloud (rather than pinning all object data in memory). */ +void bluesky_inode_map_minimize(BlueSkyFS *fs) +{ + GSequenceIter *i = g_sequence_get_begin_iter(fs->inode_map); + while (!g_sequence_iter_is_end(i)) { + InodeMapRange *range = (InodeMapRange *)g_sequence_get(i); + + if (range->serialized != NULL) + bluesky_cloudlog_erase(range->serialized); + + i = g_sequence_iter_next(i); + } +} + /* Reconstruct the inode map from data stored in the cloud. */ static void bluesky_inode_map_deserialize(BlueSkyFS *fs, BlueSkyCloudLog *imap) { @@ -214,8 +232,6 @@ static void bluesky_inode_map_deserialize(BlueSkyFS *fs, BlueSkyCloudLog *imap) entry->item = g_array_index(section->links, BlueSkyCloudLog *, j); bluesky_cloudlog_ref(entry->item); - entry->id = entry->item->id; - entry->location = entry->item->location; fs->next_inum = MAX(fs->next_inum, entry->inum + 1); inum++; }