linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v3 0/2] Btrfs: compression fixes
@ 2017-05-20 18:40 Timofey Titovets
  2017-05-20 18:40 ` [PATCH v3 1/2] Btrfs: lzo.c pr_debug() deflate->lzo Timofey Titovets
  2017-05-20 18:40 ` [PATCH v3 2/2] Btrfs: compression must free at least PAGE_SIZE Timofey Titovets
  0 siblings, 2 replies; 5+ messages in thread
From: Timofey Titovets @ 2017-05-20 18:40 UTC (permalink / raw)
  To: linux-btrfs; +Cc: Timofey Titovets

First patch: fix copy paste typo in debug message in lzo.c, lzo is not deflate

Second patch: force btrfs to not store data as compressed, if compression will not
free at least one PAGE_SIZE, because it's useless in term of storage and reading data from disk, as a result
productivity suffers

Changes since v1:
- Merge patches for zlib and lzo in one
- Sync check logic for zlib and lzo
- Check profit after all data are compressed (not while compressing)

Changes since v2:
- Fix comparassion logic, it's enough if:
  compressed size + PAGE_SIZE not bigger then input data size

Timofey Titovets (2):
  Btrfs: lzo.c pr_debug() deflate->lzo
  Btrfs: compression must free at least PAGE_SIZE

 fs/btrfs/lzo.c  | 7 +++++--
 fs/btrfs/zlib.c | 3 ++-
 2 files changed, 7 insertions(+), 3 deletions(-)

--
2.13.0

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH v3 1/2] Btrfs: lzo.c pr_debug() deflate->lzo
  2017-05-20 18:40 [PATCH v3 0/2] Btrfs: compression fixes Timofey Titovets
@ 2017-05-20 18:40 ` Timofey Titovets
  2017-05-20 18:40 ` [PATCH v3 2/2] Btrfs: compression must free at least PAGE_SIZE Timofey Titovets
  1 sibling, 0 replies; 5+ messages in thread
From: Timofey Titovets @ 2017-05-20 18:40 UTC (permalink / raw)
  To: linux-btrfs; +Cc: Timofey Titovets

Signed-off-by: Timofey Titovets <nefelim4ag@gmail.com>
---
 fs/btrfs/lzo.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/btrfs/lzo.c b/fs/btrfs/lzo.c
index f48c8c14..bd0b0938 100644
--- a/fs/btrfs/lzo.c
+++ b/fs/btrfs/lzo.c
@@ -141,7 +141,7 @@ static int lzo_compress_pages(struct list_head *ws,
 		ret = lzo1x_1_compress(data_in, in_len, workspace->cbuf,
 				       &out_len, workspace->mem);
 		if (ret != LZO_E_OK) {
-			pr_debug("BTRFS: deflate in loop returned %d\n",
+			pr_debug("BTRFS: lzo in loop returned %d\n",
 			       ret);
 			ret = -EIO;
 			goto out;
--
2.13.0

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH v3 2/2] Btrfs: compression must free at least PAGE_SIZE
  2017-05-20 18:40 [PATCH v3 0/2] Btrfs: compression fixes Timofey Titovets
  2017-05-20 18:40 ` [PATCH v3 1/2] Btrfs: lzo.c pr_debug() deflate->lzo Timofey Titovets
@ 2017-05-20 18:40 ` Timofey Titovets
  2017-05-25 12:51   ` Chandan Rajendra
  1 sibling, 1 reply; 5+ messages in thread
From: Timofey Titovets @ 2017-05-20 18:40 UTC (permalink / raw)
  To: linux-btrfs; +Cc: Timofey Titovets

Btrfs already skip store of data where compression didn't free at least one byte.
So make logic better and make check that compression free at least one PAGE_SIZE,
because in another case it useless to store this data compressed

Signed-off-by: Timofey Titovets <nefelim4ag@gmail.com>
---
 fs/btrfs/lzo.c  | 5 ++++-
 fs/btrfs/zlib.c | 3 ++-
 2 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/fs/btrfs/lzo.c b/fs/btrfs/lzo.c
index bd0b0938..39678499 100644
--- a/fs/btrfs/lzo.c
+++ b/fs/btrfs/lzo.c
@@ -229,8 +229,11 @@ static int lzo_compress_pages(struct list_head *ws,
 		in_len = min(bytes_left, PAGE_SIZE);
 	}

-	if (tot_out > tot_in)
+	/* Compression must save at least one PAGE_SIZE */
+	if (tot_out + PAGE_SIZE > tot_in) {
+		ret = -E2BIG;
 		goto out;
+	}

 	/* store the size of all chunks of compressed data */
 	cpage_out = kmap(pages[0]);
diff --git a/fs/btrfs/zlib.c b/fs/btrfs/zlib.c
index 135b1082..11e117b5 100644
--- a/fs/btrfs/zlib.c
+++ b/fs/btrfs/zlib.c
@@ -191,7 +191,8 @@ static int zlib_compress_pages(struct list_head *ws,
 		goto out;
 	}

-	if (workspace->strm.total_out >= workspace->strm.total_in) {
+	/* Compression must save at least one PAGE_SIZE */
+	if (workspace->strm.total_out + PAGE_SIZE > workspace->strm.total_in) {
 		ret = -E2BIG;
 		goto out;
 	}
--
2.13.0

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH v3 2/2] Btrfs: compression must free at least PAGE_SIZE
  2017-05-20 18:40 ` [PATCH v3 2/2] Btrfs: compression must free at least PAGE_SIZE Timofey Titovets
@ 2017-05-25 12:51   ` Chandan Rajendra
  2017-05-25 17:55     ` Timofey Titovets
  0 siblings, 1 reply; 5+ messages in thread
From: Chandan Rajendra @ 2017-05-25 12:51 UTC (permalink / raw)
  To: Timofey Titovets; +Cc: linux-btrfs, Roman Mamedov, Duncan

On Sunday, May 21, 2017 12:10:39 AM IST Timofey Titovets wrote:
> Btrfs already skip store of data where compression didn't free at least one byte.
> So make logic better and make check that compression free at least one PAGE_SIZE,
> because in another case it useless to store this data compressed
> 
> Signed-off-by: Timofey Titovets <nefelim4ag@gmail.com>
> ---
>  fs/btrfs/lzo.c  | 5 ++++-
>  fs/btrfs/zlib.c | 3 ++-
>  2 files changed, 6 insertions(+), 2 deletions(-)
> 
> diff --git a/fs/btrfs/lzo.c b/fs/btrfs/lzo.c
> index bd0b0938..39678499 100644
> --- a/fs/btrfs/lzo.c
> +++ b/fs/btrfs/lzo.c
> @@ -229,8 +229,11 @@ static int lzo_compress_pages(struct list_head *ws,
>  		in_len = min(bytes_left, PAGE_SIZE);
>  	}
> 
> -	if (tot_out > tot_in)
> +	/* Compression must save at least one PAGE_SIZE */
> +	if (tot_out + PAGE_SIZE > tot_in) {
> +		ret = -E2BIG;
>  		goto out;
> +	}

Apologies for the delayed response.

I am not really sure if compression code must save atleast one sectorsize
worth of space. But if other developers agree to it, then the above
'if' condition can be replaced with,

u32 sectorsize = btrfs_inode_sectorsize(mapping->host);
...
...

if (tot_out + sectorsize > tot_in) {

> 
>  	/* store the size of all chunks of compressed data */
>  	cpage_out = kmap(pages[0]);
> diff --git a/fs/btrfs/zlib.c b/fs/btrfs/zlib.c
> index 135b1082..11e117b5 100644
> --- a/fs/btrfs/zlib.c
> +++ b/fs/btrfs/zlib.c
> @@ -191,7 +191,8 @@ static int zlib_compress_pages(struct list_head *ws,
>  		goto out;
>  	}
> 
> -	if (workspace->strm.total_out >= workspace->strm.total_in) {
> +	/* Compression must save at least one PAGE_SIZE */
> +	if (workspace->strm.total_out + PAGE_SIZE > workspace->strm.total_in) {
>  		ret = -E2BIG;
>  		goto out;
>  	}
> --
> 2.13.0
> --
> To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> 
> 


-- 
chandan


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v3 2/2] Btrfs: compression must free at least PAGE_SIZE
  2017-05-25 12:51   ` Chandan Rajendra
@ 2017-05-25 17:55     ` Timofey Titovets
  0 siblings, 0 replies; 5+ messages in thread
From: Timofey Titovets @ 2017-05-25 17:55 UTC (permalink / raw)
  To: Chandan Rajendra; +Cc: linux-btrfs, Roman Mamedov, Duncan

2017-05-25 15:51 GMT+03:00 Chandan Rajendra <chandan@linux.vnet.ibm.com>:
...
> Apologies for the delayed response.
>
> I am not really sure if compression code must save atleast one sectorsize
> worth of space. But if other developers agree to it, then the above
> 'if' condition can be replaced with,
>
> u32 sectorsize = btrfs_inode_sectorsize(mapping->host);
> ...
> ...
>
> if (tot_out + sectorsize > tot_in) {
> --
> chandan
>

Thanks a lot!
This approach much simplier then i imagined, i will update patch set and resend.

Thank you!
-- 
Have a nice day,
Timofey.

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2017-05-25 17:55 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-05-20 18:40 [PATCH v3 0/2] Btrfs: compression fixes Timofey Titovets
2017-05-20 18:40 ` [PATCH v3 1/2] Btrfs: lzo.c pr_debug() deflate->lzo Timofey Titovets
2017-05-20 18:40 ` [PATCH v3 2/2] Btrfs: compression must free at least PAGE_SIZE Timofey Titovets
2017-05-25 12:51   ` Chandan Rajendra
2017-05-25 17:55     ` Timofey Titovets

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).