From patchwork Wed Aug 23 00:26:49 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Timofey Titovets X-Patchwork-Id: 9916411 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 5CC04603F9 for ; Wed, 23 Aug 2017 00:27:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4FBB3287E3 for ; Wed, 23 Aug 2017 00:27:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 44D702892E; Wed, 23 Aug 2017 00:27:17 +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.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, 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 E7BDA287E3 for ; Wed, 23 Aug 2017 00:27:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752891AbdHWA1O (ORCPT ); Tue, 22 Aug 2017 20:27:14 -0400 Received: from mail-wm0-f65.google.com ([74.125.82.65]:38002 "EHLO mail-wm0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752789AbdHWA1N (ORCPT ); Tue, 22 Aug 2017 20:27:13 -0400 Received: by mail-wm0-f65.google.com with SMTP id y206so678324wmd.5 for ; Tue, 22 Aug 2017 17:27:12 -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=3NGQJx0y1SfgQm7sZf8AdVFwcByfvF4HARs3kBvEo6Y=; b=GHRg1UYcF8/QUzr4X3hiI5ESBl4SK2yA2gt5lAix0r9Pt3YBbc7vDfW2GtLXfQYroY K2RBGeQCEa5vEqxt5ZiVQC4KZIkrAAoG6s5ssuQTptKF9kl50FC9qPTepWmUa+MYDQEb /sNAyhgd7brP8Ph4lvrk1Z3n44hzHg2gdQFOZ0qTu082ks26M/tn6WM5G4yVFF18KzN4 H6LcrF9GP6fSrZuETxaACMjdJ9saDreQmE8l9CXt7+6IB++u3Qu+wlCahdFFH6CGwmeo Vz5ToK+uLdAcFuSJN0DX8cKCpMuxAf8GCf263p2LOqzRg/EukxSBFDwhVm4UazbEIvik ZC1Q== 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=3NGQJx0y1SfgQm7sZf8AdVFwcByfvF4HARs3kBvEo6Y=; b=d3t8WJnymUyAo8sJfa6dmFjZEkAs4Pt8eE5DOweK++xu+Qgz+1btVAIkrryzWIGEPN SdUtHm3T6FM7ZuK9LYiRtOwghHb0mmSdICdZ6Ki9BYmHEIROOrd/IhLoYlC73dx+pgM1 nX2O2i6dWHWqJIMlxH7dyC8VVmZrRUVzI4wV6sxlZgD8C5P65cDAfXSvp5UnBr7Islak D0fj7r8xhCN9LeV2fLRyL5uXz6biK0JujxfMKlX6jz36L/Mg0vxMH3UJWfNZ23dV5UNI 3vMIe6FbI5iHf9aHTEi5pfp1TZroGUvYlLtFwrqV+2KOx8S8Aw/GlLropRQhf1omkIKO RvyA== X-Gm-Message-State: AHYfb5gTYiU9V3AtDWVkavxEjuLRV1AR2+ZAoyQLfADWycl5ynGaEkO7 ZNYpN/kf9yC+hH8d X-Received: by 10.28.186.139 with SMTP id k133mr832407wmf.159.1503448031831; Tue, 22 Aug 2017 17:27:11 -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 k45sm136926wre.1.2017.08.22.17.27.10 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 22 Aug 2017 17:27:11 -0700 (PDT) From: Timofey Titovets To: linux-btrfs@vger.kernel.org Cc: Timofey Titovets Subject: [PATCH v5 5/6] Btrfs: heuristic add byte set calculation Date: Wed, 23 Aug 2017 03:26:49 +0300 Message-Id: <20170823002650.3133-6-nefelim4ag@gmail.com> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20170823002650.3133-1-nefelim4ag@gmail.com> References: <20170823002650.3133-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 4557ea1db373..953428fde305 100644 --- a/fs/btrfs/heuristic.c +++ b/fs/btrfs/heuristic.c @@ -31,6 +31,7 @@ */ #define MAX_INPUT_PAGES ((BTRFS_MAX_UNCOMPRESSED >> PAGE_SHIFT)+1) #define MAX_SAMPLE_SIZE (MAX_INPUT_PAGES*PAGE_SIZE*READ_SIZE/ITER_SHIFT) +#define BYTE_SET_THRESHOLD 64 struct bucket_item { u32 count; @@ -73,6 +74,27 @@ static struct list_head *heuristic_alloc_workspace(void) return ERR_PTR(-ENOMEM); } +static int byte_set_size(const struct workspace *workspace) +{ + int a = 0; + int byte_set_size = 0; + + for (; a < BYTE_SET_THRESHOLD; a++) { + if (workspace->bucket[a].count > 0) + byte_set_size++; + } + + for (; a < BUCKET_SIZE; a++) { + if (workspace->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_zeroed(struct workspace *workspace) { u32 i; @@ -135,6 +157,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; }