From patchwork Fri Aug 25 09:18:41 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Timofey Titovets X-Patchwork-Id: 9921503 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 CBD43600C5 for ; Fri, 25 Aug 2017 09:19:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C3B6C26D05 for ; Fri, 25 Aug 2017 09:19:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B85C627E5A; Fri, 25 Aug 2017 09:19:23 +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 597DB26D05 for ; Fri, 25 Aug 2017 09:19:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755232AbdHYJTQ (ORCPT ); Fri, 25 Aug 2017 05:19:16 -0400 Received: from mail-wm0-f65.google.com ([74.125.82.65]:33316 "EHLO mail-wm0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754836AbdHYJTM (ORCPT ); Fri, 25 Aug 2017 05:19:12 -0400 Received: by mail-wm0-f65.google.com with SMTP id e67so1976258wmd.0 for ; Fri, 25 Aug 2017 02:19:11 -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=bD9/7G4EROOLau6txoRtBxTem8lB2qXRXccYQ/PWxxQ=; b=IEfXyVW7E2s8qwETT3D/VoERTmNVW93NfYLuoZtETWpv9PyMcr5v3qQP1WseBrtzkz DcVHVmAYSVJNyhsW7tHb2bepVRbva6NaUB4z4VEtlih9WmetD9JXRSMKiSPwZeQajpjk LF72yAGKELGOUHvbUwuE4gINtwG/FwoTPMAJioxRZiSRsT2ehG6LQBHWm2q7WqtBx6Pf P8CndF3RuujYjHDGLc8RLJCMwQVLaYbcsemDRitPv0xZ1lMPm/S4iBGgl/Y+qNL4vjkg /rUfJx6bOjShHTmksLmWzOuowCaGKWCc9Yny6VzT/enZsytHvfIwZB9ZpV2/0IvOz3H9 bVDQ== 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=bD9/7G4EROOLau6txoRtBxTem8lB2qXRXccYQ/PWxxQ=; b=kgYXnNak9yzFkSfI5w6snoXZod20HcyETzytu7sZNdxwkbKyH3Fo6cPyqepam5n1tA hk7O+zrMiHQXtt7KjLsA4Z3Gvc6ht2KKEs0oT3Ru3oLOdb1H3EqlG8PE1F1jRqczDDgq 7Jqzq0mj0RznCsbPifwjB18gtKxn/HDrOEfFnZwGo5SazUak5ycmIT5orF5ns4fnYZmo eo77QONkYfd9Dbro/bxt+Jus4o++N1TuFj8WwRpk41BrT+Mdy+2ox74b7WnZ3Tzt3DcV H4m/frFe0lX4cfFyj17Wz6BITUMJt5SQ405X7AXy9gFVP7RX1q7lL58/qOfhcGtad8hl B9HA== X-Gm-Message-State: AHYfb5g7dK5tqI3n/0b+lUJMKao81et7nOGspgHKgRkc7YdS5M51ZPJD YUQ5eX5j4XqEkggS X-Received: by 10.28.88.199 with SMTP id m190mr808242wmb.183.1503652750724; Fri, 25 Aug 2017 02:19:10 -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.09 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 25 Aug 2017 02:19:10 -0700 (PDT) From: Timofey Titovets To: linux-btrfs@vger.kernel.org Cc: Timofey Titovets Subject: [PATCH v7 2/6] Btrfs: heuristic workspace add bucket and sample items Date: Fri, 25 Aug 2017 12:18:41 +0300 Message-Id: <20170825091845.4120-3-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 Heuristic workspace: - Add bucket for storing byte type counters - Add sample array for storing partial copy of input data range - Add counter for store current sample size to workspace Signed-off-by: Timofey Titovets --- fs/btrfs/heuristic.c | 23 +++++++++++++++++++++++ 1 file changed, 23 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 92f9335bafd4..e3924c87af08 100644 --- a/fs/btrfs/heuristic.c +++ b/fs/btrfs/heuristic.c @@ -20,13 +20,29 @@ #include #include "compression.h" +#define READ_SIZE 16 +#define ITER_SHIFT 256 +#define BUCKET_SIZE 256 +#define MAX_SAMPLE_SIZE (BTRFS_MAX_UNCOMPRESSED*READ_SIZE/ITER_SHIFT) + +struct bucket_item { + u32 count; +}; + struct workspace { + u8 *sample; + /* Partial copy of input data */ + u32 sample_size; + /* Bucket store counter for each byte type */ + struct bucket_item bucket[BUCKET_SIZE]; struct list_head list; }; static void heuristic_free_workspace(struct list_head *ws) { struct workspace *workspace = list_entry(ws, struct workspace, list); + + kvfree(workspace->sample); kfree(workspace); } @@ -38,9 +54,16 @@ static struct list_head *heuristic_alloc_workspace(void) if (!workspace) return ERR_PTR(-ENOMEM); + workspace->sample = kvmalloc(MAX_SAMPLE_SIZE, GFP_KERNEL); + if (!workspace->sample) + goto fail; + INIT_LIST_HEAD(&workspace->list); return &workspace->list; +fail: + heuristic_free_workspace(&workspace->list); + return ERR_PTR(-ENOMEM); } static int heuristic(struct list_head *ws, struct inode *inode,