Skip to contentSkip to conversation

ceph: fix write_begin optimization when write is beyond EOF

RFC PATCH In review Jeff Layton 1 participant 2 messages Jun 11, 2021 Ceph client

lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/1 ceph: fix write_begin optimization when write is beyond EOF

It's not sufficient to skip reading when the pos is beyond the EOF. There may be data at the head of the page that we need to fill in before the write. Only elide the read if the pos is beyond the last page in the file.

---
 fs/ceph/addr.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

I've not tested this at all yet, but I think this is probably what we'll want for stable series v5.10.z - v5.12.z.

fs/ceph/addr.c +2 -2
index 35c83f65475b..9f60f541b423 100644
@@ -1353,11 +1353,11 @@ static int ceph_write_begin(struct file *file, struct address_space *mapping,
 		/*
 		 * In some cases we don't need to read at all:
 		 * - full page write
-		 * - write that lies completely beyond EOF
+		 * - write that lies in a page that is completely beyond EOF
 		 * - write that covers the the page from start to EOF or beyond it
 		 */
 		if ((pos_in_page == 0 && len == PAGE_SIZE) ||
-		    (pos >= i_size_read(inode)) ||
+		    (index >= (i_size_read(inode) << PAGE_SHIFT)) ||
 		    (pos_in_page == 0 && (pos + len) >= i_size_read(inode))) {
 			zero_user_segments(page, 0, pos_in_page,
 					   pos_in_page + len, PAGE_SIZE);
Signature · 1 line
2.31.1
#1 lore raw
Quoted 19 lines · Jeff Layton

It's not sufficient to skip reading when the pos is beyond the EOF. There may be data at the head of the page that we need to fill in before the write. Only elide the read if the pos is beyond the last page in the file.

---
 fs/ceph/addr.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

I've not tested this at all yet, but I think this is probably what we'll want for stable series v5.10.z - v5.12.z.

fs/ceph/addr.c +0 -0
index 35c83f65475b..9f60f541b423 100644

fs/ceph/addr.c static int ceph_write_begin(struct file *file, struct address_space *mapping, · line 1360

Quoted 10 lines
fs/ceph/addr.c +2 -2
@@ -1353,11 +1353,11 @@ static int ceph_write_begin(struct file *file, struct address_space *mapping,
 		/*
 		 * In some cases we don't need to read at all:
 		 * - full page write
-		 * - write that lies completely beyond EOF
+		 * - write that lies in a page that is completely beyond EOF
 		 * - write that covers the the page from start to EOF or beyond it
 		 */
 		if ((pos_in_page == 0 && len == PAGE_SIZE) ||
-		    (pos >= i_size_read(inode)) ||
+		    (index >= (i_size_read(inode) << PAGE_SHIFT)) ||

...and this should be:

		(index > (i_size_read(inode) << PAGE_SHIFT)) ||

We only get to skip the read if the write pos is _beyond_ the last page.

Quoted 3 lines
fs/ceph/addr.c +0 -0
 		    (pos_in_page == 0 && (pos + len) >= i_size_read(inode))) {
 			zero_user_segments(page, 0, pos_in_page,
 					   pos_in_page + len, PAGE_SIZE);
Signature · 1 line
Jeff Layton <[email protected]>