From patchwork Sun Aug 20 18:11:14 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Timofey Titovets X-Patchwork-Id: 9911283 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 C502B603FA for ; Sun, 20 Aug 2017 18:11:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BC56F286F6 for ; Sun, 20 Aug 2017 18:11:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B122228770; Sun, 20 Aug 2017 18:11:45 +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 53BB8286F6 for ; Sun, 20 Aug 2017 18:11:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753338AbdHTSLa (ORCPT ); Sun, 20 Aug 2017 14:11:30 -0400 Received: from mail-wr0-f196.google.com ([209.85.128.196]:35672 "EHLO mail-wr0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753328AbdHTSL1 (ORCPT ); Sun, 20 Aug 2017 14:11:27 -0400 Received: by mail-wr0-f196.google.com with SMTP id p8so11484040wrf.2 for ; Sun, 20 Aug 2017 11:11:27 -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=eAjfDtSj23utf5A0fB/8pJI/gGPgOIrWRd4b6rCPIJs=; b=Co4XvNqtFeTB795DaXA/B7Nf2P51YWlqneQVDzCsKWZExmlOzZGIXyKjPa6C0YhUbs gO5s12OymyN8hvNTWozX4p0taYube4iOf/8QKFCtb/rrgtlulxZ+fDuLIEABgm8Noyt/ ogxpD6nsUgJkAb9/WY6jw8/hNa8ElnPzjI4o98kU3BX5taOUIFiEjpe+rHqOUojQfwDu CNtkMuIToCeh+II7Kdc49ATe8TcR979slkC51EJulaiEvnS4kk/KaIyzoVOCABSlRiFI QKrn9y+vzZg8nKKp49gK2TKk+XYVY5a+pi7/QZTIUaH1y752dzDrTcParV1OKmlE5INk d/9w== 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=eAjfDtSj23utf5A0fB/8pJI/gGPgOIrWRd4b6rCPIJs=; b=iGm6715YJf1hNwhKQh5vnYn7xVZRT074oRIDs/ZnIqWOBFdEDv6aFT2a81SXjLyIyV KxI16zLLXhDCN9rP+FYBVlIvu84fsdfFQG9zMNkw8kRkUB9fd1fC3vAZml+bDnou893H sydVOqqd7LXddmTKZzWtpiq09If7zvuNURbdwXpRhl/ileSrY6qf4ItQadFOz0CeJZuO ZQEycDbcaEpt6dyGZ3WDb7B5rdWBo5LqsqyjlSiyk3Orme1o+pWz3ZT8CjGyIfWtp/PZ DCmBygIDx9JK5OQn3gKdR1Qpv1WF0vZqOciJWS28FS5Ur/56758e1kaw8mQKBDEVko0V +JDg== X-Gm-Message-State: AHYfb5jWKH4rjSwQYHSu6nbdZBo/2ne4bsxI5XVOMRj76Gz7G3tSHFxn h5Zftlx8ASdBYwTd X-Received: by 10.28.57.197 with SMTP id g188mr5201299wma.33.1503252686338; Sun, 20 Aug 2017 11:11:26 -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 a1sm14406344wra.17.2017.08.20.11.11.25 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 20 Aug 2017 11:11:25 -0700 (PDT) From: Timofey Titovets To: linux-btrfs@vger.kernel.org Cc: Timofey Titovets Subject: [PATCH v4 1/3] Btrfs: heuristic add simple sampling logic Date: Sun, 20 Aug 2017 21:11:14 +0300 Message-Id: <20170820181116.5131-2-nefelim4ag@gmail.com> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20170820181116.5131-1-nefelim4ag@gmail.com> References: <20170820181116.5131-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 | 8 ++++++++ 2 files changed, 30 insertions(+), 2 deletions(-) -- 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/compression.c b/fs/btrfs/compression.c index 883ecc58fd0d..c078c8d8c034 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 3b1b0ac15fdc..e0421705b80b 100644 --- a/fs/btrfs/compression.h +++ b/fs/btrfs/compression.h @@ -128,6 +128,14 @@ 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 { + u32 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