From patchwork Fri Aug 25 09:18:44 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Timofey Titovets X-Patchwork-Id: 9921507 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 01F21600C5 for ; Fri, 25 Aug 2017 09:19:32 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EEE8326D05 for ; Fri, 25 Aug 2017 09:19:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E3F7E27D4D; Fri, 25 Aug 2017 09:19:31 +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 8772126D05 for ; Fri, 25 Aug 2017 09:19:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755238AbdHYJTZ (ORCPT ); Fri, 25 Aug 2017 05:19:25 -0400 Received: from mail-wm0-f68.google.com ([74.125.82.68]:33798 "EHLO mail-wm0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754565AbdHYJTP (ORCPT ); Fri, 25 Aug 2017 05:19:15 -0400 Received: by mail-wm0-f68.google.com with SMTP id i76so1965046wme.1 for ; Fri, 25 Aug 2017 02:19:14 -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=FZVwJOp0slZUn6Pc0TqhgXj03vD+jIyDeJ6eIVqIrfo=; b=OckJq3F0ceg2zK+nJVDbupxAGw/wzXlR5m4+mtNkZiePX/6lPef/FpB2MYwcMh74Z6 +dRZug3GqvXFfdkfR2XbfQrFZFUBKAls5OXP2RHOIYEPcK30ajb1iJc7YZdYI95sm2WK VBdbDrVuC4WM4QzE0b+zTTuWKoXrTV4jZkI4CyHWNtkRG3gV/+sNnC4UE6e0EYgMNn4B 5sEKu6NLgrzSI8uaVoMe2Ssj8qcGDriDAir+iWj7gWwcJurEMPApTWgUBUASlCY0aH5e 6PWa7D3/cd8HD9DB/kiipRl8AeNfk7CRaRz3yG3Hnty9vl3MLIWDK21ENhkyMvncqU56 OsKw== 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=FZVwJOp0slZUn6Pc0TqhgXj03vD+jIyDeJ6eIVqIrfo=; b=QxpgrCbkSfxSxK6eq6egJljplOPY7dg7Mtr9Fgruf4Uh5AR6DscHJluukyaNeheiMa jhtbaZSXw0GHERGY/pCjr0L9AMyqf/udBF5sna2Jrkhb6PbZQBSDOPeDBsQTqFkweTA4 5VCXGL7udhGBNY90z0YBx5184z1ufAaYUjU19ejXWD5XLD0ZWqZSMBLyufCrSbU+I3pS FEXwXIK8qgT7kjZYc0IV/rKrWxAIMMJi/7Pdax0/JvgUG/i1kEty3fL8yF6bVunyR3Cx 7MRA9+zVbpFSyCum/ouJcnOig4t5vQMCKdE3etbi/BhC//Ru2gICGieAMCgjMMawNYin 3QsA== X-Gm-Message-State: AHYfb5hyskNylYlEzf/RZJckgWsNLJxLd1VmzL56MeK5Oh3iEwwGNEB7 HjznB+twEuKbcz6w X-Received: by 10.28.104.86 with SMTP id d83mr862369wmc.34.1503652753713; Fri, 25 Aug 2017 02:19:13 -0700 (PDT) Received: from titovetst-l.itransition.corp ([93.170.143.179]) by smtp.gmail.com with ESMTPSA id o7sm6208243wra.39.2017.08.25.02.19.12 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 25 Aug 2017 02:19:13 -0700 (PDT) From: Timofey Titovets To: linux-btrfs@vger.kernel.org Cc: Timofey Titovets Subject: [PATCH v7 5/6] Btrfs: heuristic add byte set calculation Date: Fri, 25 Aug 2017 12:18:44 +0300 Message-Id: <20170825091845.4120-6-nefelim4ag@gmail.com> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20170825091845.4120-1-nefelim4ag@gmail.com> References: <20170825091845.4120-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/heuristic.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 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/heuristic.c b/fs/btrfs/heuristic.c index f1fa6e4f1c11..ef723e991576 100644 --- a/fs/btrfs/heuristic.c +++ b/fs/btrfs/heuristic.c @@ -24,6 +24,7 @@ #define ITER_SHIFT 256 #define BUCKET_SIZE 256 #define MAX_SAMPLE_SIZE (BTRFS_MAX_UNCOMPRESSED*READ_SIZE/ITER_SHIFT) +#define BYTE_SET_THRESHOLD 64 struct bucket_item { u32 count; @@ -66,6 +67,27 @@ static struct list_head *heuristic_alloc_workspace(void) return ERR_PTR(-ENOMEM); } +static u32 byte_set_size(const struct workspace *ws) +{ + u32 a = 0; + u32 byte_set_size = 0; + + for (; a < BYTE_SET_THRESHOLD; a++) { + if (ws->bucket[a].count > 0) + byte_set_size++; + } + + for (; a < BUCKET_SIZE; a++) { + if (ws->bucket[a].count > 0) { + byte_set_size++; + if (byte_set_size > BYTE_SET_THRESHOLD) + return byte_set_size; + } + } + + return byte_set_size; +} + static bool sample_repeated_patterns(struct workspace *ws) { u32 i = 0; @@ -138,6 +160,10 @@ static int heuristic(struct list_head *ws, struct inode *inode, workspace->bucket[byte].count++; } + a = byte_set_size(workspace); + if (a > BYTE_SET_THRESHOLD) + return 2; + return 1; }