mirror of
https://gitlab.com/sortix/sortix.git
synced 2023-02-13 20:55:38 -05:00
Optimize extfs syncing blocks.
This commit is contained in:
parent
8f0db0f541
commit
dc213256c0
4 changed files with 23 additions and 3 deletions
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <assert.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.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->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();
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Add table
Reference in a new issue