From patchwork Mon Jul 24 11:37:07 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Timofey Titovets X-Patchwork-Id: 9859287 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 C7AAC60349 for ; Mon, 24 Jul 2017 11:37:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BA261284F4 for ; Mon, 24 Jul 2017 11:37:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AF49928565; Mon, 24 Jul 2017 11:37:30 +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 B4AB828516 for ; Mon, 24 Jul 2017 11:37:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754403AbdGXLh0 (ORCPT ); Mon, 24 Jul 2017 07:37:26 -0400 Received: from mail-lf0-f68.google.com ([209.85.215.68]:36777 "EHLO mail-lf0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753226AbdGXLhU (ORCPT ); Mon, 24 Jul 2017 07:37:20 -0400 Received: by mail-lf0-f68.google.com with SMTP id t128so2721305lff.3 for ; Mon, 24 Jul 2017 04:37:20 -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=/llC8ekUZTStEdrvXCqd0soUBSvuKiCByC/mt+1NKDE=; b=FwlI8M1ot1DzWDrV3J4WGEFTUqg8ywWzYsDkU3WyUrC4cjNM8nnmvlTCK3fQgYF3Bk K2hkJQqOM3kFGX/yQjONQhFU12jaqMd2WcFLai1gqqFk3XrpMjk7i3VsBz4ebBsDPzme XHKBoOFVr9UTcfa5CarEKHvkFHWrPx6YOOrCl7CsqxFnDekyHdGHnr4zxrVz8f8uPHQ9 ZvRM0qtU01FJy6IiC+gMZxFeHVamfcEEMTPSG9CmNs63UevHFDPIZkMUPn1Ngbre1G9n GdG9owJxrffZUq0UU4IbpZUQB7+ueiS0wJ5uvsKSzREj+QlVly2lSasq2ayEFiguzvlE 6fNw== 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=/llC8ekUZTStEdrvXCqd0soUBSvuKiCByC/mt+1NKDE=; b=a9ldnc2DsqI56YOuEVmVZqe/duirhPZeZQoAw5JqcCspVZBBpFd0vdSnKzPAOUvLhO HzuyabMzQ4zwwiBZt5ckChSJa26/GCs5wFux4TXMsAwobhptq6AKCoBPYmZNx8KAjcGM yJld7TcaSRn9/Jpx1J/BxbkaPFpfCUr3PW16HRg4KyD3fjea8PdkcEtQWd2HH28/jsDK leoubXcnC2MCwFD+W7UriiJ39RS7H1S0BaI8zPeQpMmaZQ8JIyZ1EkmAIb+ExPZKxBF6 pBmBXmFyYXCJAYINaN1szdK2z5o/ferdYveWJDb2dTS0Squ6jCiW0QH5cICslLIK1bRz 7q7g== X-Gm-Message-State: AIVw1113nAxCuyuTKgy/zjSwF/632sKigmbYP4ytxW0XWRulluvtqbc5 YDeNSCWjbaa9eHj0 X-Received: by 10.46.22.13 with SMTP id w13mr5024216ljd.76.1500896239321; Mon, 24 Jul 2017 04:37:19 -0700 (PDT) Received: from titovetst-beplan.itransition.corp ([93.171.6.183]) by smtp.gmail.com with ESMTPSA id f98sm1462385lfi.35.2017.07.24.04.37.18 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 24 Jul 2017 04:37:18 -0700 (PDT) From: Timofey Titovets To: linux-btrfs@vger.kernel.org Cc: Timofey Titovets Subject: [PATCH 2/3] Btrfs: heuristic add byte set calculation Date: Mon, 24 Jul 2017 14:37:07 +0300 Message-Id: <20170724113708.18088-3-nefelim4ag@gmail.com> X-Mailer: git-send-email 2.13.3 In-Reply-To: <20170724113708.18088-1-nefelim4ag@gmail.com> References: <20170724113708.18088-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 if byte set low, data are easily compressible Signed-off-by: Timofey Titovets --- fs/btrfs/compression.c | 27 +++++++++++++++++++++++++++ fs/btrfs/compression.h | 1 + 2 files changed, 28 insertions(+) diff --git a/fs/btrfs/compression.c b/fs/btrfs/compression.c index 1501d4fe90cc..fee7808e3f15 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 984943e5e1ae..6e5b2ce36b52 100644 --- a/fs/btrfs/compression.h +++ b/fs/btrfs/compression.h @@ -139,6 +139,7 @@ struct heuristic_bucket_item { #define BTRFS_HEURISTIC_READS_PER_PAGE 8*PAGE_SIZE/4096 #define BTRFS_HEURISTIC_ITERATOR_OFFSET PAGE_SIZE/BTRFS_HEURISTIC_READS_PER_PAGE #define BTRFS_HEURISTIC_BUCKET_SIZE 256 +#define BTRFS_HEURISTIC_BYTE_SET_THRESHOLD (256/4) int btrfs_compress_heuristic(struct inode *inode, u64 start, u64 end);