From patchwork Sun Aug 20 18:11:15 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Timofey Titovets X-Patchwork-Id: 9911281 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 9A906603F9 for ; Sun, 20 Aug 2017 18:11:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 94E692874A for ; Sun, 20 Aug 2017 18:11:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 895E128778; Sun, 20 Aug 2017 18:11:45 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.3 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 338FB2874A for ; Sun, 20 Aug 2017 18:11:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753340AbdHTSLa (ORCPT ); Sun, 20 Aug 2017 14:11:30 -0400 Received: from mail-wr0-f193.google.com ([209.85.128.193]:36280 "EHLO mail-wr0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753323AbdHTSL2 (ORCPT ); Sun, 20 Aug 2017 14:11:28 -0400 Received: by mail-wr0-f193.google.com with SMTP id f8so9040499wrf.3 for ; Sun, 20 Aug 2017 11:11:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=Fv8CL0+y6+xjU1wEfqHxjWxgv7Vb61SEhEJQIMMyl9A=; b=SNTzx1tqutBX1wOWsw2YnUUh3+rR3VajTj23rHCMWdp0yXJthlmXCdXe2zzRiruAFs 9/4d9wGt8QihvA6A8pFfyXjcxOBT2M6L+gb1hbrwjGmEM8z7HTKRsxXbuS6VJfS55Wxl LpZdsmE6XCEWsFRCR2ZRXVrjnQ+NMem3ZOSn8/pvdgmqOJe8xA/vidimnRnDP+GaiNe5 cvYp+psx+EZ+cNLNr5FS8wH8nj0vbNsyv5yHV5Io6robXh66dXQrxKokvZp3UmfdBroe u8jbGATrKsgfQxVf4nrXFuxbY3iDtnD0WSFDWZGwtEKrodnvQ8V/7ktkn4RzrlpXBxxO HDlw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=Fv8CL0+y6+xjU1wEfqHxjWxgv7Vb61SEhEJQIMMyl9A=; b=EHhlORI9vuNT2sl2v35e+VmVyS4ltxj5eCKa64rcw3MmHS6TsN7yItNK0Te1gncbwb u+ODO022y2fY7fw/ymhogha8suX5q9CIgISkp+dr0dbi4BHpaapVP5r2ObLK2TaUrbYy VUtBu431iwtcJcEvQcLjkhjWCUAggDf6D0tWdM9rGBy1eJUd5UlUZzd6w0PyPcNu+F/z HWYpIy7SkmL1HjTj3KTX04T8iCp+ATv7K3qqZ8XsdXNSDUr3Wb1GpMlfjTKSeOZntQ3d MVxDmCSG0/0G65o5S8m7aw6eIwI+1FWktF+yWjWWKdagwFuewF19a2HStHTjI+RJUebW qZEw== X-Gm-Message-State: AHYfb5hxCD2SQlI9z49gqA7WagnwjWNFjw1P+Bii9C8JglrZbwyjyk0Q QH/4922Mz8BEQpQ+ X-Received: by 10.28.175.65 with SMTP id y62mr5586727wme.77.1503252687143; Sun, 20 Aug 2017 11:11:27 -0700 (PDT) Received: from titovetst-l.itransition.corp (nat3-minsk-pool-46-53-180-190.telecom.by. [46.53.180.190]) by smtp.gmail.com with ESMTPSA id a1sm14406344wra.17.2017.08.20.11.11.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 20 Aug 2017 11:11:26 -0700 (PDT) From: Timofey Titovets To: linux-btrfs@vger.kernel.org Cc: Timofey Titovets Subject: [PATCH v4 2/3] Btrfs: heuristic add byte set calculation Date: Sun, 20 Aug 2017 21:11:15 +0300 Message-Id: <20170820181116.5131-3-nefelim4ag@gmail.com> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20170820181116.5131-1-nefelim4ag@gmail.com> References: <20170820181116.5131-1-nefelim4ag@gmail.com> Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Calculate byte set size for data sample: Calculate how many unique bytes has been in sample By count all bytes in bucket with count > 0 If byte set low (~25%), data are easily compressible Signed-off-by: Timofey Titovets --- fs/btrfs/compression.c | 27 +++++++++++++++++++++++++++ fs/btrfs/compression.h | 1 + 2 files changed, 28 insertions(+) -- 2.14.1 -- 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 diff --git a/fs/btrfs/compression.c b/fs/btrfs/compression.c index c078c8d8c034..fe26a44bcc9b 100644 --- a/fs/btrfs/compression.c +++ b/fs/btrfs/compression.c @@ -1048,6 +1048,27 @@ int btrfs_decompress_buf2page(const char *buf, unsigned long buf_start, return 1; } +static inline int byte_set_size(const struct heuristic_bucket_item *bucket) +{ + int a = 0; + int byte_set_size = 0; + + for (; a < BTRFS_HEURISTIC_BYTE_SET_THRESHOLD; a++) { + if (bucket[a].count > 0) + byte_set_size++; + } + + for (; a < BTRFS_HEURISTIC_BUCKET_SIZE; a++) { + if (bucket[a].count > 0) { + byte_set_size++; + if (byte_set_size > BTRFS_HEURISTIC_BYTE_SET_THRESHOLD) + return byte_set_size; + } + } + + return byte_set_size; +} + /* * Compression heuristic. * @@ -1096,6 +1117,12 @@ int btrfs_compress_heuristic(struct inode *inode, u64 start, u64 end) index++; } + a = byte_set_size(bucket); + if (a > BTRFS_HEURISTIC_BYTE_SET_THRESHOLD) { + ret = 1; + goto out; + } + out: kfree(bucket); return ret; diff --git a/fs/btrfs/compression.h b/fs/btrfs/compression.h index e0421705b80b..07e3d0652e62 100644 --- a/fs/btrfs/compression.h +++ b/fs/btrfs/compression.h @@ -135,6 +135,7 @@ struct heuristic_bucket_item { #define BTRFS_HEURISTIC_READ_SIZE 16 #define BTRFS_HEURISTIC_ITER_OFFSET 256 #define BTRFS_HEURISTIC_BUCKET_SIZE 256 +#define BTRFS_HEURISTIC_BYTE_SET_THRESHOLD 64 int btrfs_compress_heuristic(struct inode *inode, u64 start, u64 end);