From dc213256c0b01cc2de188fffb86a50984db8c624 Mon Sep 17 00:00:00 2001 From: Jonas 'Sortie' Termansen Date: Wed, 1 Oct 2014 22:27:19 +0200 Subject: [PATCH] Optimize extfs syncing blocks. --- ext/block.cpp | 17 ++++++++++++++++- ext/block.h | 2 ++ ext/device.cpp | 6 ++++-- ext/device.h | 1 + 4 files changed, 23 insertions(+), 3 deletions(-) diff --git a/ext/block.cpp b/ext/block.cpp index 10f6abce..8299e232 100644 --- a/ext/block.cpp +++ b/ext/block.cpp @@ -35,6 +35,8 @@ Block::Block(Device* device, uint32_t block_id) this->next_block = NULL; this->prev_hashed = NULL; this->next_hashed = NULL; + this->prev_dirty = NULL; + this->next_dirty = NULL; this->device = device; this->reference_count = 1; this->block_id = block_id; @@ -69,6 +71,11 @@ void Block::Sync() if ( !dirty ) return; dirty = false; + (prev_dirty ? prev_dirty->next_dirty : device->dirty_block) = next_dirty; + if ( next_dirty ) + next_dirty->prev_dirty = prev_dirty; + prev_dirty = NULL; + next_dirty = NULL; if ( !device->write ) return; off_t file_offset = (off_t) device->block_size * (off_t) block_id; @@ -77,7 +84,15 @@ void Block::Sync() void Block::Dirty() { - dirty = true; + if ( !dirty ) + { + dirty = true; + prev_dirty = NULL; + next_dirty = device->dirty_block; + if ( next_dirty ) + next_dirty->prev_dirty = this; + device->dirty_block = this; + } Use(); } diff --git a/ext/block.h b/ext/block.h index 94cec14f..6a3f68f4 100644 --- a/ext/block.h +++ b/ext/block.h @@ -36,6 +36,8 @@ public: Block* next_block; Block* prev_hashed; Block* next_hashed; + Block* prev_dirty; + Block* next_dirty; Device* device; size_t reference_count; uint32_t block_id; diff --git a/ext/device.cpp b/ext/device.cpp index 13d742fe..4c7a38ab 100644 --- a/ext/device.cpp +++ b/ext/device.cpp @@ -23,6 +23,7 @@ #include #include +#include #include #include #include @@ -41,6 +42,7 @@ Device::Device(int fd, uint32_t block_size, bool write) this->device_size = st.st_size; this->mru_block = NULL; this->lru_block = NULL; + this->dirty_block = NULL; for ( size_t i = 0; i < DEVICE_HASH_LENGTH; i++ ) hash_blocks[i] = NULL; } @@ -91,6 +93,6 @@ Block* Device::GetCachedBlock(uint32_t block_id) void Device::Sync() { - for ( Block* iter = mru_block; iter; iter = iter->next_block ) - iter->Sync(); + while ( dirty_block ) + dirty_block->Sync(); } diff --git a/ext/device.h b/ext/device.h index 9a33e5eb..b736f408 100644 --- a/ext/device.h +++ b/ext/device.h @@ -36,6 +36,7 @@ public: public: Block* mru_block; Block* lru_block; + Block* dirty_block; Block* hash_blocks[DEVICE_HASH_LENGTH]; off_t device_size; uint32_t block_size;