From patchwork Wed Aug 23 22:45: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: 9918587 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 84442600C5 for ; Wed, 23 Aug 2017 22:46:05 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 77C2128A7E for ; Wed, 23 Aug 2017 22:46:05 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6C6BD28AA0; Wed, 23 Aug 2017 22:46:05 +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 14E7528A7E for ; Wed, 23 Aug 2017 22:46:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751116AbdHWWqB (ORCPT ); Wed, 23 Aug 2017 18:46:01 -0400 Received: from mail-wr0-f195.google.com ([209.85.128.195]:37167 "EHLO mail-wr0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750715AbdHWWp7 (ORCPT ); Wed, 23 Aug 2017 18:45:59 -0400 Received: by mail-wr0-f195.google.com with SMTP id 72so520420wrc.4 for ; Wed, 23 Aug 2017 15:45:58 -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=P+slE3Bz5Uk+4TdEsvD66zYa3jLFFI7vrJRo0yrehUw=; b=iDMqWqT0UZRrDghbCNVDGyNLKBAikqhnFfnZYgXwjkiJaRlnmIit0w3pOhtFJ2aykG a2zLq+l2lCUvGUnSKhMScnejT/s2q87SW4bWOXje/hUJc+1nFaUwRH7EavItZ8rEWwn6 ayn8tS/Kft3bys5FVNwkUqpfb9Um5Be93gaieLXydfFwpoOaBjK1hnnxn+Avs5nSl9aj 98n7wgJ+ndcM3iNMEyvqtXbGdA+jez0ZZmM8spz2zjXGKVHJaQkMExio+vMe7bSSO+cl LO53Rk5G9OBRuQD4DEN0lBFLl6TfzR8ZaLNSxRQ4vsagazNYO0op5X5bAcWQI0ueomuZ M74g== 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=P+slE3Bz5Uk+4TdEsvD66zYa3jLFFI7vrJRo0yrehUw=; b=PR2F8iblYCa1U4sIfwUHdOPQFvSGL6zKur4a5rp1MeAmjN5M42uY8/QDmyuGJoTlH6 Ays9UNQTc0Whvlqpd2YJpA1Rx42UYSkQ28MixtdkMbw9GIho0DTh1pr3opdUwTdCT36I ReCIi8M5Ak9gJtc5U0i7C3cvIF3h04XRzcZuPmZ/SMU+72V1c79XytmAqZr2dq0I2GFD OIu6hY06weeVQU4H2UlDDqpncDecFqspCSrX/EobTXjaE09dq4BHAo1CX5jLCwqNcbOJ d2qlYtKoHscjBrNHGvdcq1eS4WZ+WjzJfITajSBgXHbJj/aZKf8c+QL9nNZE0uSSdF9/ jSgQ== X-Gm-Message-State: AHYfb5jOM8+6nTwBSMc+Uhxsnp8Lwsrx9JsWkfEVuh08f0M5MsJcNL0i zcP0oYdA+JJfPQaa X-Received: by 10.223.163.147 with SMTP id l19mr2466315wrb.272.1503528357995; Wed, 23 Aug 2017 15:45:57 -0700 (PDT) Received: from localhost.localdomain (nat3-minsk-pool-46-53-180-190.telecom.by. [46.53.180.190]) by smtp.gmail.com with ESMTPSA id m27sm5896166wrf.69.2017.08.23.15.45.57 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 23 Aug 2017 15:45:57 -0700 (PDT) From: Timofey Titovets To: linux-btrfs@vger.kernel.org Cc: Timofey Titovets Subject: [PATCH v6 2/6] Btrfs: heuristic workspace add bucket and sample items Date: Thu, 24 Aug 2017 01:45:41 +0300 Message-Id: <20170823224545.16375-3-nefelim4ag@gmail.com> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20170823224545.16375-1-nefelim4ag@gmail.com> References: <20170823224545.16375-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 d0e9f9112b7e..9a212674f527 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,