ocfs2: lighten up allocate transaction
PATCH 5/22 ocfs2: lighten up allocate transaction
From: Younger Liu <[email protected]>
Subject: ocfs2: lighten up allocate transaction
The issue scenario is as following:
When fallocating a very large disk space for a small file, __ocfs2_extend_allocation attempts to get a very large transaction. For some journal sizes, there may be not enough room for this transaction, and the fallocate will fail.
The patch below extends & restarts the transaction as necessary while allocating space, and should work with even the smallest journal. This patch refers ext4 resize.
Test:
# mkfs.ocfs2 -b 4K -C 32K -T datafiles /dev/sdc ...(jounral size is 32M) # mount.ocfs2 /dev/sdc /mnt/ocfs2/ # touch /mnt/ocfs2/1.log # fallocate -o 0 -l 400G /mnt/ocfs2/1.log fallocate: /mnt/ocfs2/1.log: fallocate failed: Cannot allocate memory # tail -f /var/log/messages [ 7372.278591] JBD: fallocate wants too many credits (2051 > 2048) [ 7372.278597] (fallocate,6438,0):__ocfs2_extend_allocation:709 ERROR: status = -12 [ 7372.278603] (fallocate,6438,0):ocfs2_allocate_unwritten_extents:1504 ERROR: status = -12 [ 7372.278607] (fallocate,6438,0):__ocfs2_change_file_space:1955 ERROR: status = -12 ^C With this patch, the test works well.
---
fs/ocfs2/file.c | 6 +----- fs/ocfs2/journal.c | 35 +++++++++++++++++++++++++++++++++++ fs/ocfs2/journal.h | 11 +++++++++++ fs/ocfs2/ocfs2_trace.h | 2 ++ 4 files changed, 49 insertions(+), 5 deletions(-)
fs/ocfs2/file.c renamed from fs/ocfs2/file.c~ocfs2-lighten-up-allocate-transaction +1 -5
@@ -666,11 +666,7 @@ restarted_transaction: }else {BUG_ON (why !=RESTART_TRANS ); -/* TODO: This can be more intelligent. */ - credits =ocfs2_calc_extend_credits (osb->sb, - &fe->id2.i_list, - clusters_to_add); - status =ocfs2_extend_trans (handle, credits); + status =ocfs2_allocate_extend_trans (handle,1 );if (status <0 ) {/* handle still has to be committed at * this point. */
fs/ocfs2/journal.c renamed from fs/ocfs2/journal.c~ocfs2-lighten-up-allocate-transaction +35 -0
@@ -455,6 +455,41 @@ bail:return status; } +/* +* If we have fewer than thresh credits, extend by OCFS2_MAX_TRANS_DATA. +* If that fails, restart the transaction & regain write access for the +* buffer head which is used for metadata modifications. +* Taken from Ext4: extend_or_restart_transaction() +*/ +int ocfs2_allocate_extend_trans (handle_t *handle,int thresh) +{ +int status, old_nblks; + +BUG_ON (!handle); + + old_nblks = handle->h_buffer_credits; +trace_ocfs2_allocate_extend_trans (old_nblks, thresh); + +if (old_nblks < thresh) +return 0 ; + + status =jbd2_journal_extend (handle,OCFS2_MAX_TRANS_DATA ); +if (status <0 ) { +mlog_errno (status); + goto bail; + } + +if (status >0 ) { + status =jbd2_journal_restart (handle,OCFS2_MAX_TRANS_DATA ); +if (status <0 ) +mlog_errno (status); + } + +bail: +return status; +} + +struct ocfs2_triggers {struct jbd2_buffer_trigger_type ot_triggers;int ot_offset;
fs/ocfs2/journal.h renamed from fs/ocfs2/journal.h~ocfs2-lighten-up-allocate-transaction +11 -0
@@ -258,6 +258,17 @@ handle_t *ocfs2_start_trans(structint ocfs2_commit_trans (struct ocfs2_super *osb,handle_t *handle);int ocfs2_extend_trans (handle_t *handle,int nblocks); +int ocfs2_allocate_extend_trans (handle_t *handle, +int thresh); + +/* +* Define an arbitrary limit for the amount of data we will anticipate +* writing to any given transaction. For unbounded transactions such as +* fallocate(2) we can write more than this, but we always +* start off@the maximum transaction size and grow the transaction +* optimistically as we go. +*/ +#define OCFS2_MAX_TRANS_DATA 64U/* * Create access is for when we get a newly created buffer and we're
fs/ocfs2/ocfs2_trace.h renamed from fs/ocfs2/ocfs2_trace.h~ocfs2-lighten-up-allocate-transaction +2 -0
@@ -2579,6 +2579,8 @@ DEFINE_OCFS2_INT_INT_EVENT(ocfs2_extend_DEFINE_OCFS2_INT_EVENT (ocfs2_extend_trans_restart); +DEFINE_OCFS2_INT_INT_EVENT (ocfs2_allocate_extend_trans); +DEFINE_OCFS2_ULL_ULL_UINT_UINT_EVENT (ocfs2_journal_access);DEFINE_OCFS2_ULL_EVENT (ocfs2_journal_dirty);
_
PATCH 5/22 ocfs2: lighten up allocate transaction
Quoted 15 lines · akpm at linux-foundation.org
From: Younger Liu <[email protected]>
Subject: ocfs2: lighten up allocate transactionThe issue scenario is as following:
When fallocating a very large disk space for a small file,
__ocfs2_extend_allocationattempts to get a very large transaction. For some journal sizes, there may be not enough room for this transaction, and the fallocate will fail.The patch below extends & restarts the transaction as necessary while allocating space, and should work with even the smallest journal. This patch refers ext4 resize.
Test:
Quoted 14 lines
# mkfs.ocfs2 -b 4K -C 32K -T datafiles /dev/sdc ...(jounral size is 32M) # mount.ocfs2 /dev/sdc /mnt/ocfs2/ # touch /mnt/ocfs2/1.log # fallocate -o 0 -l 400G /mnt/ocfs2/1.log fallocate: /mnt/ocfs2/1.log: fallocate failed: Cannot allocate memory # tail -f /var/log/messages [ 7372.278591] JBD: fallocate wants too many credits (2051 > 2048) [ 7372.278597] (fallocate,6438,0):__ocfs2_extend_allocation:709 ERROR: status = -12 [ 7372.278603] (fallocate,6438,0):ocfs2_allocate_unwritten_extents:1504 ERROR: status = -12 [ 7372.278607] (fallocate,6438,0):__ocfs2_change_file_space:1955 ERROR: status = -12 ^C With this patch, the test works well.
Hi Andrew Morton,
This patch is not the newest one, I have sent patch V3.
In patch V3, some coding style errors are modified. I will resent the patch V3 in a moment, and please drop this patch.
Thanks.
--Younger
Quoted 111 lines
Signed-off-by Younger Liu <[email protected]>Cc Jie Liu <[email protected]>Cc Joel Becker <[email protected]>Cc Mark Fasheh <[email protected]>Signed-off-by Andrew Morton <[email protected]>---
fs/ocfs2/file.c | 6 +----- fs/ocfs2/journal.c | 35 +++++++++++++++++++++++++++++++++++ fs/ocfs2/journal.h | 11 +++++++++++ fs/ocfs2/ocfs2_trace.h | 2 ++ 4 files changed, 49 insertions(+), 5 deletions(-)diff -puN
fs/ocfs2/file.c~ocfs2-lighten-up-allocate-transactionfs/ocfs2/file.cfs/ocfs2/file.c renamed from fs/ocfs2/file.c~ocfs2-lighten-up-allocate-transaction +1
-5@@ -666,11 +666,7 @@ restarted_transaction: }else {BUG_ON (why !=RESTART_TRANS ); -/* TODO: This can be more intelligent. */ - credits =ocfs2_calc_extend_credits (osb->sb, - &fe->id2.i_list, - clusters_to_add); - status =ocfs2_extend_trans (handle, credits); + status =ocfs2_allocate_extend_trans (handle,1 );if (status <0 ) {/* handle still has to be committed at * this point. */ diff -puN
fs/ocfs2/journal.c~ocfs2-lighten-up-allocate-transactionfs/ocfs2/journal.cfs/ocfs2/journal.c renamed from fs/ocfs2/journal.c~ocfs2-lighten-up-allocate-transaction +35
-0@@ -455,6 +455,41 @@ bail:return status; } +/* +* If we have fewer than thresh credits, extend by OCFS2_MAX_TRANS_DATA. +* If that fails, restart the transaction & regain write access for the +* buffer head which is used for metadata modifications. +* Taken from Ext4: extend_or_restart_transaction() +*/ +int ocfs2_allocate_extend_trans (handle_t *handle,int thresh) +{ +int status, old_nblks; + +BUG_ON (!handle); + + old_nblks = handle->h_buffer_credits; +trace_ocfs2_allocate_extend_trans (old_nblks, thresh); + +if (old_nblks < thresh) +return 0 ; + + status =jbd2_journal_extend (handle,OCFS2_MAX_TRANS_DATA ); +if (status <0 ) { +mlog_errno (status); + goto bail; + } + +if (status >0 ) { + status =jbd2_journal_restart (handle,OCFS2_MAX_TRANS_DATA ); +if (status <0 ) +mlog_errno (status); + } + +bail: +return status; +} + +struct ocfs2_triggers {struct jbd2_buffer_trigger_type ot_triggers;int ot_offset;diff -puN
fs/ocfs2/journal.h~ocfs2-lighten-up-allocate-transactionfs/ocfs2/journal.hfs/ocfs2/journal.h renamed from fs/ocfs2/journal.h~ocfs2-lighten-up-allocate-transaction +11
-0@@ -258,6 +258,17 @@ handle_t *ocfs2_start_trans(structint ocfs2_commit_trans (struct ocfs2_super *osb,handle_t *handle);int ocfs2_extend_trans (handle_t *handle,int nblocks); +int ocfs2_allocate_extend_trans (handle_t *handle, +int thresh); + +/* +* Define an arbitrary limit for the amount of data we will anticipate +* writing to any given transaction. For unbounded transactions such as +* fallocate(2) we can write more than this, but we always +* start off at the maximum transaction size and grow the transaction +* optimistically as we go. +*/ +#define OCFS2_MAX_TRANS_DATA 64U/* * Create access is for when we get a newly created buffer and we're diff -puN
fs/ocfs2/ocfs2_trace.h~ocfs2-lighten-up-allocate-transactionfs/ocfs2/ocfs2_trace.hfs/ocfs2/ocfs2_trace.h renamed from fs/ocfs2/ocfs2_trace.h~ocfs2-lighten-up-allocate-transaction +2
-0@@ -2579,6 +2579,8 @@ DEFINE_OCFS2_INT_INT_EVENT(ocfs2_extend_DEFINE_OCFS2_INT_EVENT (ocfs2_extend_trans_restart); +DEFINE_OCFS2_INT_INT_EVENT (ocfs2_allocate_extend_trans); +DEFINE_OCFS2_ULL_ULL_UINT_UINT_EVENT (ocfs2_journal_access);DEFINE_OCFS2_ULL_EVENT (ocfs2_journal_dirty);_
.