Commit 324d116c authored by Andreas Gruenbacher's avatar Andreas Gruenbacher

gfs2: Align read and write chunks to the page cache

Align the chunks that reads and writes are carried out in to the page
cache rather than the user buffers.  This will be more efficient in
general, especially for allocating writes.  Optimizing the case that the
user buffer is gfs2 backed isn't very useful; we only need to make sure
we won't deadlock.
Signed-off-by: default avatarAndreas Gruenbacher <agruenba@redhat.com>
parent 72382264
...@@ -771,6 +771,7 @@ static int gfs2_fsync(struct file *file, loff_t start, loff_t end, ...@@ -771,6 +771,7 @@ static int gfs2_fsync(struct file *file, loff_t start, loff_t end,
} }
static inline bool should_fault_in_pages(struct iov_iter *i, static inline bool should_fault_in_pages(struct iov_iter *i,
struct kiocb *iocb,
size_t *prev_count, size_t *prev_count,
size_t *window_size) size_t *window_size)
{ {
...@@ -783,15 +784,13 @@ static inline bool should_fault_in_pages(struct iov_iter *i, ...@@ -783,15 +784,13 @@ static inline bool should_fault_in_pages(struct iov_iter *i,
return false; return false;
size = PAGE_SIZE; size = PAGE_SIZE;
offs = offset_in_page(i->iov[0].iov_base + i->iov_offset); offs = offset_in_page(iocb->ki_pos);
if (*prev_count != count || !*window_size) { if (*prev_count != count || !*window_size) {
size_t nr_dirtied; size_t nr_dirtied;
size = ALIGN(offs + count, PAGE_SIZE);
size = min_t(size_t, size, SZ_1M);
nr_dirtied = max(current->nr_dirtied_pause - nr_dirtied = max(current->nr_dirtied_pause -
current->nr_dirtied, 8); current->nr_dirtied, 8);
size = min(size, nr_dirtied << PAGE_SHIFT); size = min_t(size_t, SZ_1M, nr_dirtied << PAGE_SHIFT);
} }
*prev_count = count; *prev_count = count;
...@@ -845,7 +844,7 @@ static ssize_t gfs2_file_direct_read(struct kiocb *iocb, struct iov_iter *to, ...@@ -845,7 +844,7 @@ static ssize_t gfs2_file_direct_read(struct kiocb *iocb, struct iov_iter *to,
if (ret > 0) if (ret > 0)
read = ret; read = ret;
if (should_fault_in_pages(to, &prev_count, &window_size)) { if (should_fault_in_pages(to, iocb, &prev_count, &window_size)) {
gfs2_holder_allow_demote(gh); gfs2_holder_allow_demote(gh);
window_size -= fault_in_iov_iter_writeable(to, window_size); window_size -= fault_in_iov_iter_writeable(to, window_size);
gfs2_holder_disallow_demote(gh); gfs2_holder_disallow_demote(gh);
...@@ -916,7 +915,7 @@ static ssize_t gfs2_file_direct_write(struct kiocb *iocb, struct iov_iter *from, ...@@ -916,7 +915,7 @@ static ssize_t gfs2_file_direct_write(struct kiocb *iocb, struct iov_iter *from,
if (ret > 0) if (ret > 0)
written = ret; written = ret;
if (should_fault_in_pages(from, &prev_count, &window_size)) { if (should_fault_in_pages(from, iocb, &prev_count, &window_size)) {
gfs2_holder_allow_demote(gh); gfs2_holder_allow_demote(gh);
window_size -= fault_in_iov_iter_readable(from, window_size); window_size -= fault_in_iov_iter_readable(from, window_size);
gfs2_holder_disallow_demote(gh); gfs2_holder_disallow_demote(gh);
...@@ -984,7 +983,7 @@ static ssize_t gfs2_file_read_iter(struct kiocb *iocb, struct iov_iter *to) ...@@ -984,7 +983,7 @@ static ssize_t gfs2_file_read_iter(struct kiocb *iocb, struct iov_iter *to)
if (ret > 0) if (ret > 0)
read += ret; read += ret;
if (should_fault_in_pages(to, &prev_count, &window_size)) { if (should_fault_in_pages(to, iocb, &prev_count, &window_size)) {
gfs2_holder_allow_demote(&gh); gfs2_holder_allow_demote(&gh);
window_size -= fault_in_iov_iter_writeable(to, window_size); window_size -= fault_in_iov_iter_writeable(to, window_size);
gfs2_holder_disallow_demote(&gh); gfs2_holder_disallow_demote(&gh);
...@@ -1061,7 +1060,7 @@ static ssize_t gfs2_file_buffered_write(struct kiocb *iocb, ...@@ -1061,7 +1060,7 @@ static ssize_t gfs2_file_buffered_write(struct kiocb *iocb,
goto out_unlock; goto out_unlock;
from->count = orig_count - written; from->count = orig_count - written;
if (should_fault_in_pages(from, &prev_count, &window_size)) { if (should_fault_in_pages(from, iocb, &prev_count, &window_size)) {
gfs2_holder_allow_demote(gh); gfs2_holder_allow_demote(gh);
window_size -= fault_in_iov_iter_readable(from, window_size); window_size -= fault_in_iov_iter_readable(from, window_size);
gfs2_holder_disallow_demote(gh); gfs2_holder_disallow_demote(gh);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment