From patchwork Fri Aug 25 09:18:45 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Timofey Titovets X-Patchwork-Id: 9921501 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 20457600C5 for ; Fri, 25 Aug 2017 09:19:22 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1975925EA6 for ; Fri, 25 Aug 2017 09:19:22 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0E57027D4D; Fri, 25 Aug 2017 09:19:22 +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 AE5E825EA6 for ; Fri, 25 Aug 2017 09:19:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755236AbdHYJTT (ORCPT ); Fri, 25 Aug 2017 05:19:19 -0400 Received: from mail-wr0-f194.google.com ([209.85.128.194]:32833 "EHLO mail-wr0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755231AbdHYJTQ (ORCPT ); Fri, 25 Aug 2017 05:19:16 -0400 Received: by mail-wr0-f194.google.com with SMTP id z91so1124856wrc.0 for ; Fri, 25 Aug 2017 02:19:15 -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=5RQgrpDSoGSb2WOsSIsPf1fDpKH2oZG+Chtl0ytrw30=; b=iJut1DCmNmZbSRFtibA9cWnRUnCUEVv/iRZUD+pLuqD88nP1aP2vmhoBg+75tZPUZ3 ZUir421Q6/kSEfaWMvZWYqzYINY/R/sL5yXLyWIxQ7rABfAmsxBsVUqlnaR7fMWi4ywa dcq4xJbaTxmKqhnrSE5YIC6QMOUi9m3rH+dzvUDO/0AcUK13kOT7iLaGUVB1k1eblej6 9ss92IzGmT50fip2iM2Y+u9syOuZrWf/jIWEo75+45ImeOz5eOq+0tr3zZhllNZDFrbg J5+ImL7mnlhiPlxQBrw1sTRtOHcAcPD4/yVDwaHcrGB9lK0ZG722ZXWLcraVt1IKQzWA G3Aw== 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=5RQgrpDSoGSb2WOsSIsPf1fDpKH2oZG+Chtl0ytrw30=; b=ULzRVnmHcUMqI/SvZr/4Wp5DhUJ0ZAy2o7Y+plOWGu+fA17HIxyDayrt3U02//AxyH 7849WpldAA+icc8iq1KOYqzEjnlG8i/K4WvJPgg+Gcf2fgX7qk13GSYrT/ERSVidtXnD YN5D4E0aXUnDZ3F8xCKw1etsXY21nBHxuXyVTWes3NfACzyVwwaC9YLhTp2E7TYK/S8I pGIXFyRG+8tB4CSBpi9OTp9AdZi2T3jB1iq+TywnPRMCb5MioyOAhWKws5xelyF0FrXx nV37ECdR5cV+DJMlqIyiSbCnDF9jF1ecQXKlcVAxWDwbYybEufSLkmCQPvlphNQND+Md d4kA== X-Gm-Message-State: AHYfb5jm5hs8w5tUfC+OjusDjEvy7lrDuMpBP945MdMKNy2UZvExePfV dfcvNfQxpfK+HEW7 X-Received: by 10.223.142.42 with SMTP id n39mr6174394wrb.51.1503652754913; Fri, 25 Aug 2017 02:19:14 -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.13 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 25 Aug 2017 02:19:14 -0700 (PDT) From: Timofey Titovets To: linux-btrfs@vger.kernel.org Cc: Timofey Titovets Subject: [PATCH v7 6/6] Btrfs: heuristic add byte core set calculation Date: Fri, 25 Aug 2017 12:18:45 +0300 Message-Id: <20170825091845.4120-7-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 Calculate byte core set for data sample: Sort bucket's numbers in decreasing order Count how many numbers use 90% of sample If core set are low (<=25%), data are easily compressible If core set high (>=80%), data are not compressible Signed-off-by: Timofey Titovets --- fs/btrfs/heuristic.c | 51 ++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 50 insertions(+), 1 deletion(-) -- 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 ef723e991576..df0cefa42857 100644 --- a/fs/btrfs/heuristic.c +++ b/fs/btrfs/heuristic.c @@ -18,6 +18,7 @@ #include #include #include +#include #include "compression.h" #define READ_SIZE 16 @@ -25,6 +26,8 @@ #define BUCKET_SIZE 256 #define MAX_SAMPLE_SIZE (BTRFS_MAX_UNCOMPRESSED*READ_SIZE/ITER_SHIFT) #define BYTE_SET_THRESHOLD 64 +#define BYTE_CORE_SET_LOW BYTE_SET_THRESHOLD +#define BYTE_CORE_SET_HIGH 200 // ~80% struct bucket_item { u32 count; @@ -67,6 +70,45 @@ static struct list_head *heuristic_alloc_workspace(void) return ERR_PTR(-ENOMEM); } +/* For bucket sorting */ +static inline int bucket_compare(const void *lv, const void *rv) +{ + struct bucket_item *l = (struct bucket_item *)(lv); + struct bucket_item *r = (struct bucket_item *)(rv); + + return r->count - l->count; +} + +/* + * Byte Core set size + * How many bytes use 90% of sample + */ +static int byte_core_set_size(struct workspace *ws) +{ + u32 a = 0; + u32 coreset_sum = 0; + u32 core_set_threshold = ws->sample_size*90/100; + struct bucket_item *bucket = ws->bucket; + + /* Sort in reverse order */ + sort(bucket, BUCKET_SIZE, sizeof(*bucket), + &bucket_compare, NULL); + + for (; a < BYTE_CORE_SET_LOW; a++) + coreset_sum += bucket[a].count; + + if (coreset_sum > core_set_threshold) + return a; + + for (; a < BYTE_CORE_SET_HIGH && bucket[a].count > 0; a++) { + coreset_sum += bucket[a].count; + if (coreset_sum > core_set_threshold) + break; + } + + return a; +} + static u32 byte_set_size(const struct workspace *ws) { u32 a = 0; @@ -164,7 +206,14 @@ static int heuristic(struct list_head *ws, struct inode *inode, if (a > BYTE_SET_THRESHOLD) return 2; - return 1; + a = byte_core_set_size(workspace); + if (a <= BYTE_CORE_SET_LOW) + return 3; + + if (a >= BYTE_CORE_SET_HIGH) + return 0; + + return 4; } const struct btrfs_compress_op btrfs_heuristic = {