Skip to content

Commit b31dc66

Browse files
Jens AxboeJens Axboe
authored andcommitted
[PATCH] Kill PF_SYNCWRITE flag
A process flag to indicate whether we are doing sync io is incredibly ugly. It also causes performance problems when one does a lot of async io and then proceeds to sync it. Part of the io will go out as async, and the other part as sync. This causes a disconnect between the previously submitted io and the synced io. For io schedulers such as CFQ, this will cause us lost merges and suboptimal behaviour in scheduling. Remove PF_SYNCWRITE completely from the fsync/msync paths, and let the O_DIRECT path just directly indicate that the writes are sync by using WRITE_SYNC instead. Signed-off-by: Jens Axboe <axboe@suse.de>
1 parent 271f18f commit b31dc66

10 files changed

Lines changed: 20 additions & 29 deletions

File tree

‎block/as-iosched.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1339,7 +1339,7 @@ static void as_add_request(request_queue_t *q, struct request *rq)
13391339
arq->state = AS_RQ_NEW;
13401340

13411341
if (rq_data_dir(arq->request) == READ
1342-
|| current->flags&PF_SYNCWRITE)
1342+
|| (arq->request->flags & REQ_RW_SYNC))
13431343
arq->is_sync = 1;
13441344
else
13451345
arq->is_sync = 0;

‎block/cfq-iosched.c‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -277,8 +277,6 @@ static struct cfq_queue *cfq_find_cfq_hash(struct cfq_data *, unsigned int, unsi
277277
static void cfq_dispatch_insert(request_queue_t *, struct cfq_rq *);
278278
static struct cfq_queue *cfq_get_queue(struct cfq_data *cfqd, unsigned int key, struct task_struct *tsk, gfp_t gfp_mask);
279279

280-
#define process_sync(tsk) ((tsk)->flags & PF_SYNCWRITE)
281-
282280
/*
283281
* lots of deadline iosched dupes, can be abstracted later...
284282
*/
@@ -334,7 +332,7 @@ static int cfq_queue_empty(request_queue_t *q)
334332

335333
static inline pid_t cfq_queue_pid(struct task_struct *task, int rw)
336334
{
337-
if (rw == READ || process_sync(task))
335+
if (rw == READ || rw == WRITE_SYNC)
338336
return task->pid;
339337

340338
return CFQ_KEY_ASYNC;

‎block/ll_rw_blk.c‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2827,6 +2827,9 @@ static void init_request_from_bio(struct request *req, struct bio *bio)
28272827
if (unlikely(bio_barrier(bio)))
28282828
req->flags |= (REQ_HARDBARRIER | REQ_NOMERGE);
28292829

2830+
if (bio_sync(bio))
2831+
req->flags |= REQ_RW_SYNC;
2832+
28302833
req->errors = 0;
28312834
req->hard_sector = req->sector = bio->bi_sector;
28322835
req->hard_nr_sectors = req->nr_sectors = bio_sectors(bio);

‎drivers/usb/gadget/file_storage.c‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1906,15 +1906,13 @@ static int fsync_sub(struct lun *curlun)
19061906

19071907
inode = filp->f_dentry->d_inode;
19081908
mutex_lock(&inode->i_mutex);
1909-
current->flags |= PF_SYNCWRITE;
19101909
rc = filemap_fdatawrite(inode->i_mapping);
19111910
err = filp->f_op->fsync(filp, filp->f_dentry, 1);
19121911
if (!rc)
19131912
rc = err;
19141913
err = filemap_fdatawait(inode->i_mapping);
19151914
if (!rc)
19161915
rc = err;
1917-
current->flags &= ~PF_SYNCWRITE;
19181916
mutex_unlock(&inode->i_mutex);
19191917
VLDBG(curlun, "fdatasync -> %d\n", rc);
19201918
return rc;

‎fs/buffer.c‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,6 @@ long do_fsync(struct file *file, int datasync)
331331
goto out;
332332
}
333333

334-
current->flags |= PF_SYNCWRITE;
335334
ret = filemap_fdatawrite(mapping);
336335

337336
/*
@@ -346,7 +345,6 @@ long do_fsync(struct file *file, int datasync)
346345
err = filemap_fdatawait(mapping);
347346
if (!ret)
348347
ret = err;
349-
current->flags &= ~PF_SYNCWRITE;
350348
out:
351349
return ret;
352350
}

‎fs/direct-io.c‎

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ static int dio_refill_pages(struct dio *dio)
162162
NULL); /* vmas */
163163
up_read(&current->mm->mmap_sem);
164164

165-
if (ret < 0 && dio->blocks_available && (dio->rw == WRITE)) {
165+
if (ret < 0 && dio->blocks_available && (dio->rw & WRITE)) {
166166
struct page *page = ZERO_PAGE(dio->curr_user_address);
167167
/*
168168
* A memory fault, but the filesystem has some outstanding
@@ -535,7 +535,7 @@ static int get_more_blocks(struct dio *dio)
535535
map_bh->b_state = 0;
536536
map_bh->b_size = fs_count << dio->inode->i_blkbits;
537537

538-
create = dio->rw == WRITE;
538+
create = dio->rw & WRITE;
539539
if (dio->lock_type == DIO_LOCKING) {
540540
if (dio->block_in_file < (i_size_read(dio->inode) >>
541541
dio->blkbits))
@@ -867,7 +867,7 @@ static int do_direct_IO(struct dio *dio)
867867
loff_t i_size_aligned;
868868

869869
/* AKPM: eargh, -ENOTBLK is a hack */
870-
if (dio->rw == WRITE) {
870+
if (dio->rw & WRITE) {
871871
page_cache_release(page);
872872
return -ENOTBLK;
873873
}
@@ -1045,7 +1045,7 @@ direct_io_worker(int rw, struct kiocb *iocb, struct inode *inode,
10451045
}
10461046
} /* end iovec loop */
10471047

1048-
if (ret == -ENOTBLK && rw == WRITE) {
1048+
if (ret == -ENOTBLK && (rw & WRITE)) {
10491049
/*
10501050
* The remaining part of the request will be
10511051
* be handled by buffered I/O when we return
@@ -1089,7 +1089,7 @@ direct_io_worker(int rw, struct kiocb *iocb, struct inode *inode,
10891089
if (dio->is_async) {
10901090
int should_wait = 0;
10911091

1092-
if (dio->result < dio->size && rw == WRITE) {
1092+
if (dio->result < dio->size && (rw & WRITE)) {
10931093
dio->waiter = current;
10941094
should_wait = 1;
10951095
}
@@ -1142,7 +1142,7 @@ direct_io_worker(int rw, struct kiocb *iocb, struct inode *inode,
11421142
ret = transferred;
11431143

11441144
/* We could have also come here on an AIO file extend */
1145-
if (!is_sync_kiocb(iocb) && rw == WRITE &&
1145+
if (!is_sync_kiocb(iocb) && (rw & WRITE) &&
11461146
ret >= 0 && dio->result == dio->size)
11471147
/*
11481148
* For AIO writes where we have completed the
@@ -1194,7 +1194,7 @@ __blockdev_direct_IO(int rw, struct kiocb *iocb, struct inode *inode,
11941194
int acquire_i_mutex = 0;
11951195

11961196
if (rw & WRITE)
1197-
current->flags |= PF_SYNCWRITE;
1197+
rw = WRITE_SYNC;
11981198

11991199
if (bdev)
12001200
bdev_blkbits = blksize_bits(bdev_hardsect_size(bdev));
@@ -1270,7 +1270,7 @@ __blockdev_direct_IO(int rw, struct kiocb *iocb, struct inode *inode,
12701270
* even for AIO, we need to wait for i/o to complete before
12711271
* returning in this case.
12721272
*/
1273-
dio->is_async = !is_sync_kiocb(iocb) && !((rw == WRITE) &&
1273+
dio->is_async = !is_sync_kiocb(iocb) && !((rw & WRITE) &&
12741274
(end > i_size_read(inode)));
12751275

12761276
retval = direct_io_worker(rw, iocb, inode, iov, offset,
@@ -1284,8 +1284,6 @@ __blockdev_direct_IO(int rw, struct kiocb *iocb, struct inode *inode,
12841284
mutex_unlock(&inode->i_mutex);
12851285
else if (acquire_i_mutex)
12861286
mutex_lock(&inode->i_mutex);
1287-
if (rw & WRITE)
1288-
current->flags &= ~PF_SYNCWRITE;
12891287
return retval;
12901288
}
12911289
EXPORT_SYMBOL(__blockdev_direct_IO);

‎fs/fs-writeback.c‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -623,7 +623,6 @@ int generic_osync_inode(struct inode *inode, struct address_space *mapping, int
623623
int need_write_inode_now = 0;
624624
int err2;
625625

626-
current->flags |= PF_SYNCWRITE;
627626
if (what & OSYNC_DATA)
628627
err = filemap_fdatawrite(mapping);
629628
if (what & (OSYNC_METADATA|OSYNC_DATA)) {
@@ -636,7 +635,6 @@ int generic_osync_inode(struct inode *inode, struct address_space *mapping, int
636635
if (!err)
637636
err = err2;
638637
}
639-
current->flags &= ~PF_SYNCWRITE;
640638

641639
spin_lock(&inode_lock);
642640
if ((inode->i_state & I_DIRTY) &&

‎include/linux/blkdev.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,7 @@ enum rq_flag_bits {
241241
__REQ_PM_RESUME, /* resume request */
242242
__REQ_PM_SHUTDOWN, /* shutdown request */
243243
__REQ_ORDERED_COLOR, /* is before or after barrier */
244+
__REQ_RW_SYNC, /* request is sync (O_DIRECT) */
244245
__REQ_NR_BITS, /* stops here */
245246
};
246247

@@ -270,6 +271,7 @@ enum rq_flag_bits {
270271
#define REQ_PM_RESUME (1 << __REQ_PM_RESUME)
271272
#define REQ_PM_SHUTDOWN (1 << __REQ_PM_SHUTDOWN)
272273
#define REQ_ORDERED_COLOR (1 << __REQ_ORDERED_COLOR)
274+
#define REQ_RW_SYNC (1 << __REQ_RW_SYNC)
273275

274276
/*
275277
* State information carried for REQ_PM_SUSPEND and REQ_PM_RESUME

‎include/linux/sched.h‎

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -941,12 +941,11 @@ static inline void put_task_struct(struct task_struct *t)
941941
#define PF_KSWAPD 0x00040000 /* I am kswapd */
942942
#define PF_SWAPOFF 0x00080000 /* I am in swapoff */
943943
#define PF_LESS_THROTTLE 0x00100000 /* Throttle me less: I clean memory */
944-
#define PF_SYNCWRITE 0x00200000 /* I am doing a sync write */
945-
#define PF_BORROWED_MM 0x00400000 /* I am a kthread doing use_mm */
946-
#define PF_RANDOMIZE 0x00800000 /* randomize virtual address space */
947-
#define PF_SWAPWRITE 0x01000000 /* Allowed to write to swap */
948-
#define PF_SPREAD_PAGE 0x04000000 /* Spread page cache over cpuset */
949-
#define PF_SPREAD_SLAB 0x08000000 /* Spread some slab caches over cpuset */
944+
#define PF_BORROWED_MM 0x00200000 /* I am a kthread doing use_mm */
945+
#define PF_RANDOMIZE 0x00400000 /* randomize virtual address space */
946+
#define PF_SWAPWRITE 0x00800000 /* Allowed to write to swap */
947+
#define PF_SPREAD_PAGE 0x01000000 /* Spread page cache over cpuset */
948+
#define PF_SPREAD_SLAB 0x02000000 /* Spread some slab caches over cpuset */
950949
#define PF_MEMPOLICY 0x10000000 /* Non-default NUMA mempolicy */
951950

952951
/*

‎mm/msync.c‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,6 @@ asmlinkage long sys_msync(unsigned long start, size_t len, int flags)
170170
* just ignore them, but return -ENOMEM at the end.
171171
*/
172172
down_read(&current->mm->mmap_sem);
173-
if (flags & MS_SYNC)
174-
current->flags |= PF_SYNCWRITE;
175173
vma = find_vma(current->mm, start);
176174
if (!vma) {
177175
error = -ENOMEM;
@@ -228,7 +226,6 @@ asmlinkage long sys_msync(unsigned long start, size_t len, int flags)
228226
}
229227
} while (vma && !done);
230228
out_unlock:
231-
current->flags &= ~PF_SYNCWRITE;
232229
up_read(&current->mm->mmap_sem);
233230
out:
234231
return error;

0 commit comments

Comments
 (0)