Skip to content

Commit 20bec8a

Browse files
committed
Merge branch 'ext3-latency-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/tytso/ext4
* 'ext3-latency-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/tytso/ext4: ext3: Add replace-on-rename hueristics for data=writeback mode ext3: Add replace-on-truncate hueristics for data=writeback mode ext3: Use WRITE_SYNC for commits which are caused by fsync() block_write_full_page: Use synchronous writes for WBC_SYNC_ALL writebacks
2 parents 18b34b9 + e7c8f50 commit 20bec8a

8 files changed

Lines changed: 38 additions & 11 deletions

File tree

‎fs/buffer.c‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1595,6 +1595,7 @@ static int __block_write_full_page(struct inode *inode, struct page *page,
15951595
struct buffer_head *bh, *head;
15961596
const unsigned blocksize = 1 << inode->i_blkbits;
15971597
int nr_underway = 0;
1598+
int write_op = (wbc->sync_mode == WB_SYNC_ALL ? WRITE_SYNC : WRITE);
15981599

15991600
BUG_ON(!PageLocked(page));
16001601

@@ -1686,7 +1687,7 @@ static int __block_write_full_page(struct inode *inode, struct page *page,
16861687
do {
16871688
struct buffer_head *next = bh->b_this_page;
16881689
if (buffer_async_write(bh)) {
1689-
submit_bh(WRITE, bh);
1690+
submit_bh(write_op, bh);
16901691
nr_underway++;
16911692
}
16921693
bh = next;
@@ -1740,7 +1741,7 @@ static int __block_write_full_page(struct inode *inode, struct page *page,
17401741
struct buffer_head *next = bh->b_this_page;
17411742
if (buffer_async_write(bh)) {
17421743
clear_buffer_dirty(bh);
1743-
submit_bh(WRITE, bh);
1744+
submit_bh(write_op, bh);
17441745
nr_underway++;
17451746
}
17461747
bh = next;

‎fs/ext3/file.c‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@
3333
*/
3434
static int ext3_release_file (struct inode * inode, struct file * filp)
3535
{
36+
if (EXT3_I(inode)->i_state & EXT3_STATE_FLUSH_ON_CLOSE) {
37+
filemap_flush(inode->i_mapping);
38+
EXT3_I(inode)->i_state &= ~EXT3_STATE_FLUSH_ON_CLOSE;
39+
}
3640
/* if we are the last writer on the inode, drop the block reservation */
3741
if ((filp->f_mode & FMODE_WRITE) &&
3842
(atomic_read(&inode->i_writecount) == 1))

‎fs/ext3/inode.c‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2363,6 +2363,9 @@ void ext3_truncate(struct inode *inode)
23632363
if (!ext3_can_truncate(inode))
23642364
return;
23652365

2366+
if (inode->i_size == 0 && ext3_should_writeback_data(inode))
2367+
ei->i_state |= EXT3_STATE_FLUSH_ON_CLOSE;
2368+
23662369
/*
23672370
* We have to lock the EOF page here, because lock_page() nests
23682371
* outside journal_start().

‎fs/ext3/namei.c‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2274,7 +2274,7 @@ static int ext3_rename (struct inode * old_dir, struct dentry *old_dentry,
22742274
struct inode * old_inode, * new_inode;
22752275
struct buffer_head * old_bh, * new_bh, * dir_bh;
22762276
struct ext3_dir_entry_2 * old_de, * new_de;
2277-
int retval;
2277+
int retval, flush_file = 0;
22782278

22792279
old_bh = new_bh = dir_bh = NULL;
22802280

@@ -2410,6 +2410,8 @@ static int ext3_rename (struct inode * old_dir, struct dentry *old_dentry,
24102410
ext3_mark_inode_dirty(handle, new_inode);
24112411
if (!new_inode->i_nlink)
24122412
ext3_orphan_add(handle, new_inode);
2413+
if (ext3_should_writeback_data(new_inode))
2414+
flush_file = 1;
24132415
}
24142416
retval = 0;
24152417

@@ -2418,6 +2420,8 @@ static int ext3_rename (struct inode * old_dir, struct dentry *old_dentry,
24182420
brelse (old_bh);
24192421
brelse (new_bh);
24202422
ext3_journal_stop(handle);
2423+
if (retval == 0 && flush_file)
2424+
filemap_flush(old_inode->i_mapping);
24212425
return retval;
24222426
}
24232427

‎fs/jbd/commit.c‎

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include <linux/slab.h>
2121
#include <linux/mm.h>
2222
#include <linux/pagemap.h>
23+
#include <linux/bio.h>
2324

2425
/*
2526
* Default IO end handler for temporary BJ_IO buffer_heads.
@@ -171,22 +172,24 @@ static int journal_write_commit_record(journal_t *journal,
171172
return (ret == -EIO);
172173
}
173174

174-
static void journal_do_submit_data(struct buffer_head **wbuf, int bufs)
175+
static void journal_do_submit_data(struct buffer_head **wbuf, int bufs,
176+
int write_op)
175177
{
176178
int i;
177179

178180
for (i = 0; i < bufs; i++) {
179181
wbuf[i]->b_end_io = end_buffer_write_sync;
180182
/* We use-up our safety reference in submit_bh() */
181-
submit_bh(WRITE, wbuf[i]);
183+
submit_bh(write_op, wbuf[i]);
182184
}
183185
}
184186

185187
/*
186188
* Submit all the data buffers to disk
187189
*/
188190
static int journal_submit_data_buffers(journal_t *journal,
189-
transaction_t *commit_transaction)
191+
transaction_t *commit_transaction,
192+
int write_op)
190193
{
191194
struct journal_head *jh;
192195
struct buffer_head *bh;
@@ -225,7 +228,7 @@ static int journal_submit_data_buffers(journal_t *journal,
225228
BUFFER_TRACE(bh, "needs blocking lock");
226229
spin_unlock(&journal->j_list_lock);
227230
/* Write out all data to prevent deadlocks */
228-
journal_do_submit_data(wbuf, bufs);
231+
journal_do_submit_data(wbuf, bufs, write_op);
229232
bufs = 0;
230233
lock_buffer(bh);
231234
spin_lock(&journal->j_list_lock);
@@ -256,7 +259,7 @@ static int journal_submit_data_buffers(journal_t *journal,
256259
jbd_unlock_bh_state(bh);
257260
if (bufs == journal->j_wbufsize) {
258261
spin_unlock(&journal->j_list_lock);
259-
journal_do_submit_data(wbuf, bufs);
262+
journal_do_submit_data(wbuf, bufs, write_op);
260263
bufs = 0;
261264
goto write_out_data;
262265
}
@@ -286,7 +289,7 @@ static int journal_submit_data_buffers(journal_t *journal,
286289
}
287290
}
288291
spin_unlock(&journal->j_list_lock);
289-
journal_do_submit_data(wbuf, bufs);
292+
journal_do_submit_data(wbuf, bufs, write_op);
290293

291294
return err;
292295
}
@@ -315,6 +318,7 @@ void journal_commit_transaction(journal_t *journal)
315318
int first_tag = 0;
316319
int tag_flag;
317320
int i;
321+
int write_op = WRITE;
318322

319323
/*
320324
* First job: lock down the current transaction and wait for
@@ -347,6 +351,8 @@ void journal_commit_transaction(journal_t *journal)
347351
spin_lock(&journal->j_state_lock);
348352
commit_transaction->t_state = T_LOCKED;
349353

354+
if (commit_transaction->t_synchronous_commit)
355+
write_op = WRITE_SYNC;
350356
spin_lock(&commit_transaction->t_handle_lock);
351357
while (commit_transaction->t_updates) {
352358
DEFINE_WAIT(wait);
@@ -431,7 +437,8 @@ void journal_commit_transaction(journal_t *journal)
431437
* Now start flushing things to disk, in the order they appear
432438
* on the transaction lists. Data blocks go first.
433439
*/
434-
err = journal_submit_data_buffers(journal, commit_transaction);
440+
err = journal_submit_data_buffers(journal, commit_transaction,
441+
write_op);
435442

436443
/*
437444
* Wait for all previously submitted IO to complete.
@@ -660,7 +667,7 @@ void journal_commit_transaction(journal_t *journal)
660667
clear_buffer_dirty(bh);
661668
set_buffer_uptodate(bh);
662669
bh->b_end_io = journal_end_buffer_io_sync;
663-
submit_bh(WRITE, bh);
670+
submit_bh(write_op, bh);
664671
}
665672
cond_resched();
666673

‎fs/jbd/transaction.c‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1440,6 +1440,8 @@ int journal_stop(handle_t *handle)
14401440
}
14411441
}
14421442

1443+
if (handle->h_sync)
1444+
transaction->t_synchronous_commit = 1;
14431445
current->journal_info = NULL;
14441446
spin_lock(&journal->j_state_lock);
14451447
spin_lock(&transaction->t_handle_lock);

‎include/linux/ext3_fs.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@ static inline __u32 ext3_mask_flags(umode_t mode, __u32 flags)
208208
#define EXT3_STATE_JDATA 0x00000001 /* journaled data exists */
209209
#define EXT3_STATE_NEW 0x00000002 /* inode is newly created */
210210
#define EXT3_STATE_XATTR 0x00000004 /* has in-inode xattrs */
211+
#define EXT3_STATE_FLUSH_ON_CLOSE 0x00000008
211212

212213
/* Used to pass group descriptor data when online resize is done */
213214
struct ext3_new_group_input {

‎include/linux/jbd.h‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -552,6 +552,11 @@ struct transaction_s
552552
*/
553553
int t_handle_count;
554554

555+
/*
556+
* This transaction is being forced and some process is
557+
* waiting for it to finish.
558+
*/
559+
int t_synchronous_commit:1;
555560
};
556561

557562
/**

0 commit comments

Comments
 (0)