From 493f5aff9d66a83deb7cf3b3527d0d836fbd12ec Mon Sep 17 00:00:00 2001 From: Raghavendra G Date: Fri, 25 May 2018 08:50:19 +0530 Subject: performance/read-ahead: throwaway read-ahead cache of all fds on writes on any fd This is to make sure applications that read and write on different fds of the same file work. This patch also fixes two other issues: 1. while iterating over the list of open fds on an inode, initialize tmp_file to 0 for each iteration before fd_ctx_get to make sure we don't carry over the history from previous iterations. 2. remove flushing of cache in flush and fsync as by themselves, they don't modify the data Change-Id: Ib9959eb73702a3ebbf90badccaa16b2608050eff Signed-off-by: Raghavendra G Updates: bz#1512691 --- xlators/performance/read-ahead/src/read-ahead.c | 60 +++++++++++++------------ 1 file changed, 32 insertions(+), 28 deletions(-) diff --git a/xlators/performance/read-ahead/src/read-ahead.c b/xlators/performance/read-ahead/src/read-ahead.c index d001784797a..1185c6e4183 100644 --- a/xlators/performance/read-ahead/src/read-ahead.c +++ b/xlators/performance/read-ahead/src/read-ahead.c @@ -583,21 +583,12 @@ ra_fsync_cbk (call_frame_t *frame, void *cookie, xlator_t *this, int32_t op_ret, int ra_flush (call_frame_t *frame, xlator_t *this, fd_t *fd, dict_t *xdata) { - ra_file_t *file = NULL; - uint64_t tmp_file = 0; int32_t op_errno = EINVAL; GF_ASSERT (frame); GF_VALIDATE_OR_GOTO (frame->this->name, this, unwind); GF_VALIDATE_OR_GOTO (frame->this->name, fd, unwind); - fd_ctx_get (fd, this, &tmp_file); - - file = (ra_file_t *)(long)tmp_file; - if (file) { - flush_region (frame, file, 0, file->pages.prev->offset+1, 0); - } - STACK_WIND (frame, ra_flush_cbk, FIRST_CHILD (this), FIRST_CHILD (this)->fops->flush, fd, xdata); return 0; @@ -612,21 +603,12 @@ int ra_fsync (call_frame_t *frame, xlator_t *this, fd_t *fd, int32_t datasync, dict_t *xdata) { - ra_file_t *file = NULL; - uint64_t tmp_file = 0; int32_t op_errno = EINVAL; GF_ASSERT (frame); GF_VALIDATE_OR_GOTO (frame->this->name, this, unwind); GF_VALIDATE_OR_GOTO (frame->this->name, fd, unwind); - fd_ctx_get (fd, this, &tmp_file); - - file = (ra_file_t *)(long)tmp_file; - if (file) { - flush_region (frame, file, 0, file->pages.prev->offset+1, 0); - } - STACK_WIND (frame, ra_fsync_cbk, FIRST_CHILD (this), FIRST_CHILD (this)->fops->fsync, fd, datasync, xdata); return 0; @@ -664,22 +646,39 @@ ra_writev (call_frame_t *frame, xlator_t *this, fd_t *fd, struct iovec *vector, int32_t count, off_t offset, uint32_t flags, struct iobref *iobref, dict_t *xdata) { - ra_file_t *file = NULL; - uint64_t tmp_file = 0; - int32_t op_errno = EINVAL; + ra_file_t *file = NULL; + uint64_t tmp_file = 0; + int32_t op_errno = EINVAL; + inode_t *inode = NULL; + fd_t *iter_fd = NULL; GF_ASSERT (frame); GF_VALIDATE_OR_GOTO (frame->this->name, this, unwind); GF_VALIDATE_OR_GOTO (frame->this->name, fd, unwind); - fd_ctx_get (fd, this, &tmp_file); - file = (ra_file_t *)(long)tmp_file; - if (file) { - flush_region (frame, file, 0, file->pages.prev->offset+1, 1); - frame->local = file; - /* reset the read-ahead counters too */ - file->expected = file->page_count = 0; + inode = fd->inode; + + LOCK (&inode->lock); + { + list_for_each_entry (iter_fd, &inode->fd_list, inode_list) { + tmp_file = 0; + fd_ctx_get (iter_fd, this, &tmp_file); + file = (ra_file_t *)(long)tmp_file; + + if (!file) + continue; + + if (iter_fd == fd) + frame->local = file; + + flush_region (frame, file, 0, + file->pages.prev->offset + 1, 1); + + /* reset the read-ahead counters too */ + file->expected = file->page_count = 0; + } } + UNLOCK (&inode->lock); STACK_WIND (frame, ra_writev_cbk, FIRST_CHILD(this), @@ -737,6 +736,7 @@ ra_truncate (call_frame_t *frame, xlator_t *this, loc_t *loc, off_t offset, LOCK (&inode->lock); { list_for_each_entry (iter_fd, &inode->fd_list, inode_list) { + tmp_file = 0; fd_ctx_get (iter_fd, this, &tmp_file); file = (ra_file_t *)(long)tmp_file; @@ -877,6 +877,7 @@ ra_fstat (call_frame_t *frame, xlator_t *this, fd_t *fd, dict_t *xdata) LOCK (&inode->lock); { list_for_each_entry (iter_fd, &inode->fd_list, inode_list) { + tmp_file = 0; fd_ctx_get (iter_fd, this, &tmp_file); file = (ra_file_t *)(long)tmp_file; @@ -917,6 +918,7 @@ ra_ftruncate (call_frame_t *frame, xlator_t *this, fd_t *fd, off_t offset, LOCK (&inode->lock); { list_for_each_entry (iter_fd, &inode->fd_list, inode_list) { + tmp_file = 0; fd_ctx_get (iter_fd, this, &tmp_file); file = (ra_file_t *)(long)tmp_file; if (!file) @@ -975,6 +977,7 @@ ra_discard(call_frame_t *frame, xlator_t *this, fd_t *fd, off_t offset, LOCK (&inode->lock); { list_for_each_entry (iter_fd, &inode->fd_list, inode_list) { + tmp_file = 0; fd_ctx_get (iter_fd, this, &tmp_file); file = (ra_file_t *)(long)tmp_file; if (!file) @@ -1025,6 +1028,7 @@ ra_zerofill(call_frame_t *frame, xlator_t *this, fd_t *fd, off_t offset, LOCK (&inode->lock); { list_for_each_entry (iter_fd, &inode->fd_list, inode_list) { + tmp_file = 0; fd_ctx_get (iter_fd, this, &tmp_file); file = (ra_file_t *)(long)tmp_file; if (!file) -- cgit