From patchwork Wed Jul 26 12:49:56 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Timofey Titovets X-Patchwork-Id: 9864739 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 60B3160382 for ; Wed, 26 Jul 2017 12:50:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 61C5528748 for ; Wed, 26 Jul 2017 12:50:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 56D3128757; Wed, 26 Jul 2017 12:50: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.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 044FB28748 for ; Wed, 26 Jul 2017 12:50:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751802AbdGZMuN (ORCPT ); Wed, 26 Jul 2017 08:50:13 -0400 Received: from mail-lf0-f67.google.com ([209.85.215.67]:38317 "EHLO mail-lf0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751668AbdGZMuK (ORCPT ); Wed, 26 Jul 2017 08:50:10 -0400 Received: by mail-lf0-f67.google.com with SMTP id y15so6931317lfd.5 for ; Wed, 26 Jul 2017 05:50:09 -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=A1T2Gu1jZz2yKyoozRAgxHWUVK3MEpFXbRJ/kGF7+Jc=; b=ofFzMcmU1pcnRlmXaeYMtrh76iLqkK0z3bbRcjrfvAmO+XwAkV1R/iVdSZIqnAaRNK yuFz21LwnI2vh4zvvtlmQS3J461mf+2Q1P1S7CwGfXMtmqe55IY50EWZtBBEz84/yzku eR/t8PULKNCY0sDrXQzkXElXWimgUzGsIKQ4vx9lm6Zw9KsZvRILxHZ9gaLjl4NcZ6JC Tki7Q6GA45hz8JEyYv6YdT8vxTFye2JWXiO18qVHILJt6BPDyK5d1ebDJbMWHktRmFAY /sc17WiRWrFsBksA8bdMZNeM5kx5oDSr/WPFne+LTSNL+wPFJ6lo/S40nhMXgQcPBzUJ CpCg== 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=A1T2Gu1jZz2yKyoozRAgxHWUVK3MEpFXbRJ/kGF7+Jc=; b=Hp2Ndl+65/f8aL0OYZTHde0OdGoprLw/+lhh3XoOSgOEldoOawJZvL7jgeeg5ZEzLo 8E2l0M+344HGKBJVM36lRmRy3GpRX+//6Hh+Tqnu1Lb9J/ryHmCe5GBSzMbMDi5umcaC 5dXMqpEbnqKvd6fvi0zp8ymxkRy39uNHM477otD66CkUr9Yz6BUCUAfUOg9t1fFt6y/w 7bK01ZrGGkeP+CwSIc09UWwQg44yrP+l780tKne9Gx9nBfCevxeDpfqPw/PhyuRCQMcO iav2sNzhKkilnQsXtAc84OAhWCmiVI4dRr3AmrMffpRzVT6cMqXgwIyweAFj7S0s9bG7 oLlQ== X-Gm-Message-State: AIVw11204reYxX1g3aPirGUCbuSLxJMkp+UvGisjCHBisAAG/HtHuUoN MezpTgs05PcmY2eL X-Received: by 10.46.21.8 with SMTP id s8mr346659ljd.147.1501073408849; Wed, 26 Jul 2017 05:50:08 -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.07 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 26 Jul 2017 05:50:08 -0700 (PDT) From: Timofey Titovets To: linux-btrfs@vger.kernel.org Cc: Timofey Titovets Subject: [PATCH v2 1/3] Btrfs: heuristic add simple sampling logic Date: Wed, 26 Jul 2017 15:49:56 +0300 Message-Id: <20170726124958.18837-2-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 Get small sample from input data and calculate byte type count for that sample into bucket. Bucket will store info about which bytes and how many has been detected in sample Signed-off-by: Timofey Titovets --- fs/btrfs/compression.c | 24 ++++++++++++++++++++++-- fs/btrfs/compression.h | 10 ++++++++++ 2 files changed, 32 insertions(+), 2 deletions(-) -- 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 63f54bd2d5bb..ca7cfaad6e2f 100644 --- a/fs/btrfs/compression.c +++ b/fs/btrfs/compression.c @@ -1068,15 +1068,35 @@ int btrfs_compress_heuristic(struct inode *inode, u64 start, u64 end) u64 index = start >> PAGE_SHIFT; u64 end_index = end >> PAGE_SHIFT; struct page *page; - int ret = 1; + struct heuristic_bucket_item *bucket; + int a, b, ret; + u8 symbol, *input_data; + + ret = 1; + + bucket = kcalloc(BTRFS_HEURISTIC_BUCKET_SIZE, + sizeof(struct heuristic_bucket_item), GFP_NOFS); + + if (!bucket) + goto out; while (index <= end_index) { page = find_get_page(inode->i_mapping, index); - kmap(page); + input_data = kmap(page); + a = 0; + while (a < PAGE_SIZE) { + for (b = 0; b < BTRFS_HEURISTIC_READ_SIZE; b++) { + symbol = input_data[a+b]; + bucket[symbol].count++; + } + a += BTRFS_HEURISTIC_ITER_OFFSET; + } kunmap(page); put_page(page); index++; } +out: + kfree(bucket); return ret; } diff --git a/fs/btrfs/compression.h b/fs/btrfs/compression.h index d1f4eee2d0af..e30a9df1937e 100644 --- a/fs/btrfs/compression.h +++ b/fs/btrfs/compression.h @@ -129,6 +129,16 @@ struct btrfs_compress_op { extern const struct btrfs_compress_op btrfs_zlib_compress; extern const struct btrfs_compress_op btrfs_lzo_compress; +struct heuristic_bucket_item { + u8 padding; + u8 symbol; + u16 count; +}; + +#define BTRFS_HEURISTIC_READ_SIZE 16 +#define BTRFS_HEURISTIC_ITER_OFFSET 256 +#define BTRFS_HEURISTIC_BUCKET_SIZE 256 + int btrfs_compress_heuristic(struct inode *inode, u64 start, u64 end); #endif