Skip to content

Commit 6f83ab2

Browse files
committed
io_uring: io_kiocb_update_pos() should not touch file for non -1 offset
-1 tells use to use the current position, but we check if the file is a stream regardless of that. Fix up io_kiocb_update_pos() to only dip into file if we need to. This is both more efficient and also drops 12 bytes of text on aarch64 and 64 bytes on x86-64. Fixes: b4aec40 ("io_uring: do not recalculate ppos unnecessarily") Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent c4212f3 commit 6f83ab2

1 file changed

Lines changed: 10 additions & 11 deletions

File tree

fs/io_uring.c

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3183,19 +3183,18 @@ static inline void io_rw_done(struct kiocb *kiocb, ssize_t ret)
31833183
static inline loff_t *io_kiocb_update_pos(struct io_kiocb *req)
31843184
{
31853185
struct kiocb *kiocb = &req->rw.kiocb;
3186-
bool is_stream = req->file->f_mode & FMODE_STREAM;
31873186

3188-
if (kiocb->ki_pos == -1) {
3189-
if (!is_stream) {
3190-
req->flags |= REQ_F_CUR_POS;
3191-
kiocb->ki_pos = req->file->f_pos;
3192-
return &kiocb->ki_pos;
3193-
} else {
3194-
kiocb->ki_pos = 0;
3195-
return NULL;
3196-
}
3187+
if (kiocb->ki_pos != -1)
3188+
return &kiocb->ki_pos;
3189+
3190+
if (!(req->file->f_mode & FMODE_STREAM)) {
3191+
req->flags |= REQ_F_CUR_POS;
3192+
kiocb->ki_pos = req->file->f_pos;
3193+
return &kiocb->ki_pos;
31973194
}
3198-
return is_stream ? NULL : &kiocb->ki_pos;
3195+
3196+
kiocb->ki_pos = 0;
3197+
return NULL;
31993198
}
32003199

32013200
static void kiocb_done(struct io_kiocb *req, ssize_t ret,

0 commit comments

Comments
 (0)