Commit 05ebad85 authored by Joern Engel's avatar Joern Engel

logfs: commit reservations under space pressure

Ensures we only return -ENOSPC when there really is no space.
Signed-off-by: default avatarJoern Engel <joern@logfs.org>
parent 20503664
...@@ -161,6 +161,16 @@ static int logfs_writepage(struct page *page, struct writeback_control *wbc) ...@@ -161,6 +161,16 @@ static int logfs_writepage(struct page *page, struct writeback_control *wbc)
static void logfs_invalidatepage(struct page *page, unsigned long offset) static void logfs_invalidatepage(struct page *page, unsigned long offset)
{ {
struct logfs_block *block = logfs_block(page);
if (block->reserved_bytes) {
struct super_block *sb = page->mapping->host->i_sb;
struct logfs_super *super = logfs_super(sb);
super->s_dirty_pages -= block->reserved_bytes;
block->ops->free_block(sb, block);
BUG_ON(bitmap_weight(block->alias_map, LOGFS_BLOCK_FACTOR));
} else
move_page_to_btree(page); move_page_to_btree(page);
BUG_ON(PagePrivate(page) || page->private); BUG_ON(PagePrivate(page) || page->private);
} }
......
...@@ -394,6 +394,7 @@ struct logfs_super { ...@@ -394,6 +394,7 @@ struct logfs_super {
int s_lock_count; int s_lock_count;
mempool_t *s_block_pool; /* struct logfs_block pool */ mempool_t *s_block_pool; /* struct logfs_block pool */
mempool_t *s_shadow_pool; /* struct logfs_shadow pool */ mempool_t *s_shadow_pool; /* struct logfs_shadow pool */
struct list_head s_writeback_list; /* writeback pages */
/* /*
* Space accounting: * Space accounting:
* - s_used_bytes specifies space used to store valid data objects. * - s_used_bytes specifies space used to store valid data objects.
......
...@@ -1095,17 +1095,25 @@ static int logfs_reserve_bytes(struct inode *inode, int bytes) ...@@ -1095,17 +1095,25 @@ static int logfs_reserve_bytes(struct inode *inode, int bytes)
int get_page_reserve(struct inode *inode, struct page *page) int get_page_reserve(struct inode *inode, struct page *page)
{ {
struct logfs_super *super = logfs_super(inode->i_sb); struct logfs_super *super = logfs_super(inode->i_sb);
struct logfs_block *block = logfs_block(page);
int ret; int ret;
if (logfs_block(page) && logfs_block(page)->reserved_bytes) if (block && block->reserved_bytes)
return 0; return 0;
logfs_get_wblocks(inode->i_sb, page, WF_LOCK); logfs_get_wblocks(inode->i_sb, page, WF_LOCK);
ret = logfs_reserve_bytes(inode, 6 * LOGFS_MAX_OBJECTSIZE); while ((ret = logfs_reserve_bytes(inode, 6 * LOGFS_MAX_OBJECTSIZE)) &&
!list_empty(&super->s_writeback_list)) {
block = list_entry(super->s_writeback_list.next,
struct logfs_block, alias_list);
block->ops->write_block(block);
}
if (!ret) { if (!ret) {
alloc_data_block(inode, page); alloc_data_block(inode, page);
logfs_block(page)->reserved_bytes += 6 * LOGFS_MAX_OBJECTSIZE; block = logfs_block(page);
block->reserved_bytes += 6 * LOGFS_MAX_OBJECTSIZE;
super->s_dirty_pages += 6 * LOGFS_MAX_OBJECTSIZE; super->s_dirty_pages += 6 * LOGFS_MAX_OBJECTSIZE;
list_move_tail(&block->alias_list, &super->s_writeback_list);
} }
logfs_put_wblocks(inode->i_sb, page, WF_LOCK); logfs_put_wblocks(inode->i_sb, page, WF_LOCK);
return ret; return ret;
...@@ -2251,6 +2259,7 @@ int logfs_init_rw(struct super_block *sb) ...@@ -2251,6 +2259,7 @@ int logfs_init_rw(struct super_block *sb)
int min_fill = 3 * super->s_no_blocks; int min_fill = 3 * super->s_no_blocks;
INIT_LIST_HEAD(&super->s_object_alias); INIT_LIST_HEAD(&super->s_object_alias);
INIT_LIST_HEAD(&super->s_writeback_list);
mutex_init(&super->s_write_mutex); mutex_init(&super->s_write_mutex);
super->s_block_pool = mempool_create_kmalloc_pool(min_fill, super->s_block_pool = mempool_create_kmalloc_pool(min_fill,
sizeof(struct logfs_block)); sizeof(struct logfs_block));
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment