Skip to content

Commit

Permalink
gfs2: Align read and write chunks to the page cache
Browse files Browse the repository at this point in the history
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: Andreas Gruenbacher <agruenba@redhat.com>
  • Loading branch information
Andreas Gruenbacher committed May 13, 2022
1 parent 7238226 commit 324d116
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions fs/gfs2/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
struct kiocb *iocb,
size_t *prev_count,
size_t *window_size)
{
Expand All @@ -783,15 +784,13 @@ static inline bool should_fault_in_pages(struct iov_iter *i,
return false;

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) {
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 -
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;
Expand Down Expand Up @@ -845,7 +844,7 @@ static ssize_t gfs2_file_direct_read(struct kiocb *iocb, struct iov_iter *to,
if (ret > 0)
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);
window_size -= fault_in_iov_iter_writeable(to, window_size);
gfs2_holder_disallow_demote(gh);
Expand Down Expand Up @@ -916,7 +915,7 @@ static ssize_t gfs2_file_direct_write(struct kiocb *iocb, struct iov_iter *from,
if (ret > 0)
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);
window_size -= fault_in_iov_iter_readable(from, window_size);
gfs2_holder_disallow_demote(gh);
Expand Down Expand Up @@ -984,7 +983,7 @@ static ssize_t gfs2_file_read_iter(struct kiocb *iocb, struct iov_iter *to)
if (ret > 0)
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);
window_size -= fault_in_iov_iter_writeable(to, window_size);
gfs2_holder_disallow_demote(&gh);
Expand Down Expand Up @@ -1061,7 +1060,7 @@ static ssize_t gfs2_file_buffered_write(struct kiocb *iocb,
goto out_unlock;

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);
window_size -= fault_in_iov_iter_readable(from, window_size);
gfs2_holder_disallow_demote(gh);
Expand Down

0 comments on commit 324d116

Please sign in to comment.