From patchwork Mon Jul 24 11:37:06 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Timofey Titovets X-Patchwork-Id: 9859283 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 4038060349 for ; Mon, 24 Jul 2017 11:37:26 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 32C90284F4 for ; Mon, 24 Jul 2017 11:37:26 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 27C422857E; Mon, 24 Jul 2017 11:37:26 +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 41111284F4 for ; Mon, 24 Jul 2017 11:37:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754345AbdGXLhX (ORCPT ); Mon, 24 Jul 2017 07:37:23 -0400 Received: from mail-lf0-f67.google.com ([209.85.215.67]:36776 "EHLO mail-lf0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751839AbdGXLhT (ORCPT ); Mon, 24 Jul 2017 07:37:19 -0400 Received: by mail-lf0-f67.google.com with SMTP id t128so2721299lff.3 for ; Mon, 24 Jul 2017 04:37:19 -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=h81W8/i3QOX7wWcQbND4i40N5Tw9er5z0a6AvQZx+us=; b=kqYaAHM31uSw/Rszoas0AwP/Orovv01IiK6uQcQd+uZleCiW8C7LHRQbTVKDWjeaBS IVqJmkECjdVozYEfqzGkh4FG9tyU5RwefELxIcxro6Pt5gH17xJ1p+UZnQc9Jlj1VmeX Riwoknxax+fc8kEDQX+1BxbKVRqsU/X3KXb4f+1tOQ5Aa+Sdb02SxsJIPcv6WxTg8Zlu sNpUo+ngAQqLOAvASEPwdTSON25Bb4q9fa3zaKoLLDLu7NOxSgv6po9C5qEejJd3Sm9K o61jau2ff059lTfFowRk6tvjRFW4Sum2NXVaIWWGC3DyA4SEps4fHqijij+zPnA5v4uj /Dzw== 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=h81W8/i3QOX7wWcQbND4i40N5Tw9er5z0a6AvQZx+us=; b=ZkcnBezuHsUs6HrbeLvyTzk1gKOOoi9Yny37y60iedeTmt1t3rmv5r1VDL/IQOmGLy T7qp1eXMKrv4Tpre2m1m6VVsxDQ7Lg611TZzp3PDpHPwKC1czHpV4IIRbcor6tRvS1H4 Wb4jbaQJ6WeXpqk9KEFtSJFECtalhKW0ldxbxfVii8+hp+CSDT5Fk52QN3KZshBQOuTl GMBfNd5I3yCPKGuxuW2o9j+8AkkSNV2sjL6YxaYiL+lvuyrjKYrlazOErRIm7QUxPOET ykD2Cqw38TEXPFPtEZt+i81J74bVANYNPRxggJNfcaa2xtItQIq7jKO6Ztc9C5yqSmX1 vm5A== X-Gm-Message-State: AIVw1111m98WCsp0ZaJxUFXtKnIshegYSTk04CUTXCGLbEeg/BhtGvW5 M98KOLrePxcrCz4w X-Received: by 10.46.9.202 with SMTP id 193mr588286ljj.137.1500896238348; Mon, 24 Jul 2017 04:37:18 -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.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 24 Jul 2017 04:37:17 -0700 (PDT) From: Timofey Titovets To: linux-btrfs@vger.kernel.org Cc: Timofey Titovets Subject: [PATCH 1/3] Btrfs: heuristic add simple sampling logic Date: Mon, 24 Jul 2017 14:37:06 +0300 Message-Id: <20170724113708.18088-2-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 Get small sample from input data and calculate byte type count for that sample Signed-off-by: Timofey Titovets --- fs/btrfs/compression.c | 24 ++++++++++++++++++++++-- fs/btrfs/compression.h | 11 +++++++++++ 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/fs/btrfs/compression.c b/fs/btrfs/compression.c index 63f54bd2d5bb..1501d4fe90cc 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_ITERATOR_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..984943e5e1ae 100644 --- a/fs/btrfs/compression.h +++ b/fs/btrfs/compression.h @@ -129,6 +129,17 @@ 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_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 + int btrfs_compress_heuristic(struct inode *inode, u64 start, u64 end); #endif