Optimize extfs syncing blocks.
This commit is contained in:
parent
8f0db0f541
commit
dc213256c0
|
@ -35,6 +35,8 @@ Block::Block(Device* device, uint32_t block_id)
|
||||||
this->next_block = NULL;
|
this->next_block = NULL;
|
||||||
this->prev_hashed = NULL;
|
this->prev_hashed = NULL;
|
||||||
this->next_hashed = NULL;
|
this->next_hashed = NULL;
|
||||||
|
this->prev_dirty = NULL;
|
||||||
|
this->next_dirty = NULL;
|
||||||
this->device = device;
|
this->device = device;
|
||||||
this->reference_count = 1;
|
this->reference_count = 1;
|
||||||
this->block_id = block_id;
|
this->block_id = block_id;
|
||||||
|
@ -69,6 +71,11 @@ void Block::Sync()
|
||||||
if ( !dirty )
|
if ( !dirty )
|
||||||
return;
|
return;
|
||||||
dirty = false;
|
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 )
|
if ( !device->write )
|
||||||
return;
|
return;
|
||||||
off_t file_offset = (off_t) device->block_size * (off_t) block_id;
|
off_t file_offset = (off_t) device->block_size * (off_t) block_id;
|
||||||
|
@ -77,7 +84,15 @@ void Block::Sync()
|
||||||
|
|
||||||
void Block::Dirty()
|
void Block::Dirty()
|
||||||
{
|
{
|
||||||
|
if ( !dirty )
|
||||||
|
{
|
||||||
dirty = true;
|
dirty = true;
|
||||||
|
prev_dirty = NULL;
|
||||||
|
next_dirty = device->dirty_block;
|
||||||
|
if ( next_dirty )
|
||||||
|
next_dirty->prev_dirty = this;
|
||||||
|
device->dirty_block = this;
|
||||||
|
}
|
||||||
Use();
|
Use();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -36,6 +36,8 @@ public:
|
||||||
Block* next_block;
|
Block* next_block;
|
||||||
Block* prev_hashed;
|
Block* prev_hashed;
|
||||||
Block* next_hashed;
|
Block* next_hashed;
|
||||||
|
Block* prev_dirty;
|
||||||
|
Block* next_dirty;
|
||||||
Device* device;
|
Device* device;
|
||||||
size_t reference_count;
|
size_t reference_count;
|
||||||
uint32_t block_id;
|
uint32_t block_id;
|
||||||
|
|
|
@ -23,6 +23,7 @@
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
|
#include <assert.h>
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
@ -41,6 +42,7 @@ Device::Device(int fd, uint32_t block_size, bool write)
|
||||||
this->device_size = st.st_size;
|
this->device_size = st.st_size;
|
||||||
this->mru_block = NULL;
|
this->mru_block = NULL;
|
||||||
this->lru_block = NULL;
|
this->lru_block = NULL;
|
||||||
|
this->dirty_block = NULL;
|
||||||
for ( size_t i = 0; i < DEVICE_HASH_LENGTH; i++ )
|
for ( size_t i = 0; i < DEVICE_HASH_LENGTH; i++ )
|
||||||
hash_blocks[i] = NULL;
|
hash_blocks[i] = NULL;
|
||||||
}
|
}
|
||||||
|
@ -91,6 +93,6 @@ Block* Device::GetCachedBlock(uint32_t block_id)
|
||||||
|
|
||||||
void Device::Sync()
|
void Device::Sync()
|
||||||
{
|
{
|
||||||
for ( Block* iter = mru_block; iter; iter = iter->next_block )
|
while ( dirty_block )
|
||||||
iter->Sync();
|
dirty_block->Sync();
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,6 +36,7 @@ public:
|
||||||
public:
|
public:
|
||||||
Block* mru_block;
|
Block* mru_block;
|
||||||
Block* lru_block;
|
Block* lru_block;
|
||||||
|
Block* dirty_block;
|
||||||
Block* hash_blocks[DEVICE_HASH_LENGTH];
|
Block* hash_blocks[DEVICE_HASH_LENGTH];
|
||||||
off_t device_size;
|
off_t device_size;
|
||||||
uint32_t block_size;
|
uint32_t block_size;
|
||||||
|
|
Loading…
Reference in New Issue