From patchwork Wed Aug 23 22:45: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: 9918591 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 31BF4600C5 for ; Wed, 23 Aug 2017 22:46:10 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2528228A7E for ; Wed, 23 Aug 2017 22:46:10 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 19EF628A9F; Wed, 23 Aug 2017 22:46:10 +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 B0E3328A7E for ; Wed, 23 Aug 2017 22:46:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751185AbdHWWqH (ORCPT ); Wed, 23 Aug 2017 18:46:07 -0400 Received: from mail-wm0-f65.google.com ([74.125.82.65]:33048 "EHLO mail-wm0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751128AbdHWWqD (ORCPT ); Wed, 23 Aug 2017 18:46:03 -0400 Received: by mail-wm0-f65.google.com with SMTP id b79so973612wmf.0 for ; Wed, 23 Aug 2017 15:46:02 -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=hKb7DeQ1UYYQIzt/EgrJ0yFbgRgXhAAM5uzrmSADfTo=; b=pxC0ObAjL+FGBC6oYM4WkIUd2xv/PVXn0/ly5eJ9QspAnYv9PUqGBWZVK90ev4uND0 lcusC/CqB0KMcNDsEYlJJOshq6UajOyQCbnl1sZ38M2jCWGFTYqSsIHYNX4/M72mYLAm TS0mOwMlnV7c7pXS2q/jytn9NY9to2qFpYS9NjrIxaT5vEFvIwJe2iCBZlyCu/t1uDGj HruZvllg3esomoJ6gv+1V5dbOl89k1FNaW/n4Zg6vxtVjGm/Yi+hVxiO7Io6Y5VjalMz AwNVJ4tWbVVuoL7vTIWUS4dZXmGU9Xs8JgmqVnNHJ5EUEf4dFS0worhaUGHlPX3i1J1Z EEug== 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=hKb7DeQ1UYYQIzt/EgrJ0yFbgRgXhAAM5uzrmSADfTo=; b=kjIgu7wRS5ELO9OFhAJfNK/7ocxQySljPcwPpwLu5lD2gzW7+y36hYRYgHCJopYNyy q80r57rZPCCODz32MqJJsMlMWJXNWcOGTApe6oE1BReYguxfYu1i+9MWXoFempJBR1Gz VxrT/glr62xO+H//pqFaubUOAykW8Act8JW/8JE3bsbRIX8L0IX3f0RTWGjkhSyehE3E BxKfqDtBoucNgJI1i0dsPq/TPWheoOZugP8zirUAngxTfC6EQBEWeV21CY+YZ27MFD4k WQQuo/dNLjS2AYiGVIvdKozfOhkMp01NO/pw+vZv8FhunwSMHvGJT+TVlapHaH4FyZ9y +wkQ== X-Gm-Message-State: AHYfb5hnbAdk9/c7o1rAsECX9xyVMrkbFp1/o460dsvOwgzIG0F/l1CT Joo0nX7dxt4Dz/4W X-Received: by 10.28.55.193 with SMTP id e184mr2511021wma.75.1503528361886; Wed, 23 Aug 2017 15:46:01 -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.46.00 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 23 Aug 2017 15:46:01 -0700 (PDT) From: Timofey Titovets To: linux-btrfs@vger.kernel.org Cc: Timofey Titovets Subject: [PATCH v6 6/6] Btrfs: heuristic add byte core set calculation Date: Thu, 24 Aug 2017 01:45:45 +0300 Message-Id: <20170823224545.16375-7-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 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 4815d1becf7e..8a5397b74597 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; @@ -167,7 +209,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 = {