From patchwork Wed Jul 26 12:49:57 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Timofey Titovets X-Patchwork-Id: 9864743 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 CEDEE60382 for ; Wed, 26 Jul 2017 12:50:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CFE2728748 for ; Wed, 26 Jul 2017 12:50:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C4D0B28757; Wed, 26 Jul 2017 12:50:23 +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 5848828748 for ; Wed, 26 Jul 2017 12:50:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751821AbdGZMuU (ORCPT ); Wed, 26 Jul 2017 08:50:20 -0400 Received: from mail-lf0-f68.google.com ([209.85.215.68]:34925 "EHLO mail-lf0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751735AbdGZMuM (ORCPT ); Wed, 26 Jul 2017 08:50:12 -0400 Received: by mail-lf0-f68.google.com with SMTP id w199so4336239lff.2 for ; Wed, 26 Jul 2017 05:50:11 -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=P6aZrOccPeWL+YhOSIrEQ7VgN8YR+8xiTkIyiTyav8I=; b=YFS4ffETKrFkFJgUmH1PHhCIbUgaCl3oNZReSPbDufFgW01oUXg2PDfbdL69NKNBRi cmY/DDvycBRi9FkPIuB9KABjVRIdV7SCyADeVklQ+7MQo50G7OjhSeRDaP9H+RCt0ZhE Qn1U2vscWZ59df1q6ad1R/CgPfw/DfBI4/Z7xuSIMRc2FGVUkeVE9EagQV8V/hkIv92q YSi+kMMuWhV5qZ3ABBuv1Bajrz3yPkZKCdAofFbUiQaSOwefMOi8Z5gctGcu2xq4YkHI CE4PvwnOF8XZWZC2gsxi3ISXcdDotd/cb83MZSDpDECt1HQ/bv6WJKC9UdvkDZM5zq5A 80uQ== 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=P6aZrOccPeWL+YhOSIrEQ7VgN8YR+8xiTkIyiTyav8I=; b=IhuXqQl0tLz6rTFiXUdUHVKBZJl6vOsZSqcZH802j/P0uXnd5nb6KdlHckONIlYVKJ 73t0sLgfMh+rGDSXrh8HF8bZ0gblJNn1tzFYNvqMOfTGVz01OFJLuadTCEh9UzlVy3Rk flqObBBqZCO7UUVLYrFN3/KNpo6o4krh2jLJTluyETYY247RQXD4Fvscc+SDexBX2yhF U9lVb/crBc9MCXR9wQbXvlvDgX3dNQdtusu5H+DSzYzwPbQ9T01v0e5/wByvHmBZvV5I yQssZ7evTMqnE9xH/XSKBCqdzyKfNtJSvK5zbz14pNvfV5JxAWEeN0qo4L3Wm/iqtGKO rpog== X-Gm-Message-State: AIVw111s8KekM7zeIP8m6U+JWuMSkzkgG66QBIdx0Fk3e9mSyL2OtVwL 7aImxWbPBEkSILdv X-Received: by 10.25.43.80 with SMTP id r77mr289673lfr.3.1501073410323; Wed, 26 Jul 2017 05:50:10 -0700 (PDT) Received: from titovetst-l.itransition.corp ([93.171.6.183]) by smtp.gmail.com with ESMTPSA id e14sm3405444lji.53.2017.07.26.05.50.08 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 26 Jul 2017 05:50:09 -0700 (PDT) From: Timofey Titovets To: linux-btrfs@vger.kernel.org Cc: Timofey Titovets Subject: [PATCH v2 2/3] Btrfs: heuristic add byte set calculation Date: Wed, 26 Jul 2017 15:49:57 +0300 Message-Id: <20170726124958.18837-3-nefelim4ag@gmail.com> X-Mailer: git-send-email 2.13.3 In-Reply-To: <20170726124958.18837-1-nefelim4ag@gmail.com> References: <20170726124958.18837-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.13.3 -- 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 ca7cfaad6e2f..1429b11f2c5f 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 e30a9df1937e..03857967815a 100644 --- a/fs/btrfs/compression.h +++ b/fs/btrfs/compression.h @@ -138,6 +138,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);