Skip to contentSkip to conversation

Improve FL_KEEP_SIZE handling

PATCH New Davide Italiano 3 participants 9 messages Apr 7, 2015 – Mar 17, 2016 Btrfs file system

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Improve FL_KEEP_SIZE handling

This matches the logic of ext4. I think it's more correct passing (offset + len) to inode_newsize_ok() rather than rounding up to block size.
The call can be skipped in some cases too. It works for me but I'm new to this code so I might miss something. Let me know what you think.

Davide Italiano (1):
Btrfs: Improve FL_KEEP_SIZE handling in fallocate.

 fs/btrfs/file.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)
Signature · 1 line
2.3.4
#1 lore raw

PATCH 1/1 Btrfs: Improve FL_KEEP_SIZE handling in fallocate.

- We call inode_size_ok() only if FL_KEEP_SIZE isn't specified.
- As an optimisation we can skip the call if (off + len) isn't greater than the current size of the file. This operation is called under the lock so the less work we do, the better.
- If we call inode_size_ok() pass to it the correct value rather than a more conservative estimation.

---
 fs/btrfs/file.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)
fs/btrfs/file.c +7 -3
index 30982bb..f649bfc 100644
@@ -2586,9 +2586,13 @@ static long btrfs_fallocate(struct file *file, int mode,
 	}
 
 	mutex_lock(&inode->i_mutex);
-	ret = inode_newsize_ok(inode, alloc_end);
-	if (ret)
-		goto out;
+
+	if (!(mode & FALLOC_FL_KEEP_SIZE) &&
+	    offset + len > inode->i_size) {
+		ret = inode_newsize_ok(inode, offset + len);
+		if (ret)
+			goto out;
+	}
 
 	if (alloc_start > inode->i_size) {
 		ret = btrfs_cont_expand(inode, i_size_read(inode),
Signature · 1 line
2.3.4
#2 lore raw

Re: [PATCH] Btrfs: Improve FL_KEEP_SIZE handling in fallocate.

Quoted 34 lines · Davide Italiano

- We call inode_size_ok() only if FL_KEEP_SIZE isn't specified.
- As an optimisation we can skip the call if (off + len) isn't greater than the current size of the file. This operation is called under the lock so the less work we do, the better.
- If we call inode_size_ok() pass to it the correct value rather than a more conservative estimation.

---
 fs/btrfs/file.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)
fs/btrfs/file.c +7 -4
index 30982bb..f649bfc 100644
@@ -2586,9 +2586,13 @@ static long btrfs_fallocate(struct file *file, int mode,
        }
 
        mutex_lock(&inode->i_mutex);
-       ret = inode_newsize_ok(inode, alloc_end);
-       if (ret)
-               goto out;
+
+       if (!(mode & FALLOC_FL_KEEP_SIZE) &&
+           offset + len > inode->i_size) {
+               ret = inode_newsize_ok(inode, offset + len);
+               if (ret)
+                       goto out;
+       }
 
        if (alloc_start > inode->i_size) {
                ret = btrfs_cont_expand(inode, i_size_read(inode),
--
Quoted 2 lines

2.3.4

Any comment on this?

#3 lore raw

Re: [PATCH] Btrfs: Improve FL_KEEP_SIZE handling in fallocate.

Quoted 32 lines · Davide Italiano
Quoted 31 lines · Davide Italiano

- We call inode_size_ok() only if FL_KEEP_SIZE isn't specified.
- As an optimisation we can skip the call if (off + len) isn't greater than the current size of the file. This operation is called under the lock so the less work we do, the better.
- If we call inode_size_ok() pass to it the correct value rather than a more conservative estimation.

---
 fs/btrfs/file.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)
fs/btrfs/file.c +7 -3
index 30982bb..f649bfc 100644
@@ -2586,9 +2586,13 @@ static long btrfs_fallocate(struct file *file, int mode,
        }
 
        mutex_lock(&inode->i_mutex);
-       ret = inode_newsize_ok(inode, alloc_end);
-       if (ret)
-               goto out;
+
+       if (!(mode & FALLOC_FL_KEEP_SIZE) &&
+           offset + len > inode->i_size) {
+               ret = inode_newsize_ok(inode, offset + len);
+               if (ret)
+                       goto out;
+       }
 
Quoted 7 lines
Quoted 5 lines
fs/btrfs/file.c +0 -1
        if (alloc_start > inode->i_size) {
                ret = btrfs_cont_expand(inode, i_size_read(inode),
--

2.3.4

Any comment on this?

Very gentle ping after couple of months.

Reviewed-by on v1 1/1
#4 lore raw

Re: [PATCH] Btrfs: Improve FL_KEEP_SIZE handling in fallocate.

In reply to Davide Italiano
Quoted 6 lines · Davide Italiano

- We call inode_size_ok() only if FL_KEEP_SIZE isn't specified.
- As an optimisation we can skip the call if (off + len) isn't greater than the current size of the file. This operation is called under the lock so the less work we do, the better.
- If we call inode_size_ok() pass to it the correct value rather than a more conservative estimation.

Looks good.

Quoted 34 lines
---
 fs/btrfs/file.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)
fs/btrfs/file.c +7 -3
index 30982bb..f649bfc 100644
@@ -2586,9 +2586,13 @@ static long btrfs_fallocate(struct file *file, int mode,
 	}
 
 	mutex_lock(&inode->i_mutex);
-	ret = inode_newsize_ok(inode, alloc_end);
-	if (ret)
-		goto out;
+
+	if (!(mode & FALLOC_FL_KEEP_SIZE) &&
+	    offset + len > inode->i_size) {
+		ret = inode_newsize_ok(inode, offset + len);
+		if (ret)
+			goto out;
+	}
 
 	if (alloc_start > inode->i_size) {
 		ret = btrfs_cont_expand(inode, i_size_read(inode),
Signature · 6 lines
2.3.4

--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Reviewed-by on v1 1/1
#5 lore raw

Re: [PATCH] Btrfs: Improve FL_KEEP_SIZE handling in fallocate.

In reply to Davide Italiano
Quoted 8 lines · Davide Italiano

- We call inode_size_ok() only if FL_KEEP_SIZE isn't specified.
- As an optimisation we can skip the call if (off + len) isn't greater than the current size of the file. This operation is called under the lock so the less work we do, the better.
- If we call inode_size_ok() pass to it the correct value rather than a more conservative estimation.

#6 lore raw

Re: [PATCH] Btrfs: Improve FL_KEEP_SIZE handling in fallocate.

Quoted 11 lines · David Sterba
Quoted 8 lines · Davide Italiano

- We call inode_size_ok() only if FL_KEEP_SIZE isn't specified.
- As an optimisation we can skip the call if (off + len) isn't greater than the current size of the file. This operation is called under the lock so the less work we do, the better.
- If we call inode_size_ok() pass to it the correct value rather than a more conservative estimation.

Hi Chris, this has been around for a while and it's been reviewed by multiple people. Any chances you can pull in your branch?

Thanks,

--
Davide

#7 lore raw

Re: [PATCH] Btrfs: Improve FL_KEEP_SIZE handling in fallocate.

Quoted 13 lines · Davide Italiano
Quoted 11 lines · David Sterba
Quoted 8 lines · Davide Italiano

- We call inode_size_ok() only if FL_KEEP_SIZE isn't specified.
- As an optimisation we can skip the call if (off + len) isn't greater than the current size of the file. This operation is called under the lock so the less work we do, the better.
- If we call inode_size_ok() pass to it the correct value rather than a more conservative estimation.

Quoted 7 lines

Hi Chris, this has been around for a while and it's been reviewed by multiple people. Any chances you can pull in your branch?

Thanks,

--
Davide

Any chance to get this in?

#8 lore raw

Re: [PATCH] Btrfs: Improve FL_KEEP_SIZE handling in fallocate.

Quoted 10 lines · Davide Italiano
Quoted 9 lines · Davide Italiano
Quoted 8 lines · David Sterba
Quoted 7 lines · Davide Italiano

- We call inode_size_ok() only if FL_KEEP_SIZE isn't specified.
- As an optimisation we can skip the call if (off + len) isn't greater than the current size of the file. This operation is called under the lock so the less work we do, the better.
- If we call inode_size_ok() pass to it the correct value rather than a more conservative estimation.

Quoted 6 lines
Quoted 6 lines
Quoted 3 lines
Quoted 1 line

Hi Chris, this has been around for a while and it's been reviewed by multiple people. Any chances you can pull in your branch?

I'm adding this patch to my for-next, sorry for late response.