linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Lionel Bouton <lionel-subscription@bouton.name>
To: Timofey Titovets <nefelim4ag@gmail.com>, linux-btrfs@vger.kernel.org
Subject: Re: [PATCH 2/3] Btrfs: lzo compression must free at least PAGE_SIZE
Date: Fri, 19 May 2017 16:17:38 +0200	[thread overview]
Message-ID: <6a1f17d5-3cc8-f5c0-36af-39b41eebc426@bouton.name> (raw)
In-Reply-To: <20170519133835.27843-3-nefelim4ag@gmail.com>

Hi,

Le 19/05/2017 à 15:38, Timofey Titovets a écrit :
> If data compression didn't free at least one PAGE_SIZE, it useless to store that compressed extent
>
> 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 bd0b0938..637ef1b0 100644
> --- a/fs/btrfs/lzo.c
> +++ b/fs/btrfs/lzo.c
> @@ -207,7 +207,7 @@ static int lzo_compress_pages(struct list_head *ws,
>  		}
>  
>  		/* we're making it bigger, give up */
> -		if (tot_in > 8192 && tot_in < tot_out) {
> +		if (tot_in > 8192 && tot_in < tot_out + PAGE_SIZE) {
>  			ret = -E2BIG;
>  			goto out;
>  		}
I'm not familiar with this code but I was surprised by the test : you
would expect compression having a benefit when you are freeing an actual
page not reducing data by a page size. So unless I don't understand the
context shouldn't it be something like :

if (tot_in > 8192 && ((tot_in % PAGE_SIZE) <= (tot_out % PAGE_SIZE))

but looking at the code I see that this is in a while loop and there's
another test just after the loop in the existing code :

        if (tot_out > tot_in)
                goto out;

There's a couple of things I don't understand but isn't this designed to
stream data in small chunks through compression before writing it in the
end ? So isn't this later test the proper location to detect if
compression was beneficial ?

You might not save a page early on in the while loop working on a subset
of the data to compress but after enough data being processed you could
save a page. It seems odd that your modification could abort compression
early on although the same condition would become true after enough loops.

Isn't what you want something like :

        if (tot_out % PAGE_SIZE >= tot_in % PAGE_SIZE)
                goto out;

after the loop ?
The >= instead of > would avoid decompression in the case where the
compressed data is smaller but uses the same space on disk.

Best regards,

Lionel

  reply	other threads:[~2017-05-19 14:17 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-05-19 13:38 [PATCH 0/3] Btrfs: compression fixes Timofey Titovets
2017-05-19 13:38 ` [PATCH 1/3] Btrfs: lzo.c pr_debug() deflate->lzo Timofey Titovets
2017-05-19 13:38 ` [PATCH 2/3] Btrfs: lzo compression must free at least PAGE_SIZE Timofey Titovets
2017-05-19 14:17   ` Lionel Bouton [this message]
2017-05-19 20:19     ` Lionel Bouton
2017-05-19 21:15       ` Timofey Titovets
2017-05-20 15:47         ` Lionel Bouton
2017-05-20 16:23           ` Timofey Titovets
2017-05-19 13:38 ` [PATCH 3/3] Btrfs: zlib " Timofey Titovets

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=6a1f17d5-3cc8-f5c0-36af-39b41eebc426@bouton.name \
    --to=lionel-subscription@bouton.name \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=nefelim4ag@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).