From patchwork Wed Aug 23 00:26: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: 9916417 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 D910F603F9 for ; Wed, 23 Aug 2017 00:27:25 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C8CC02891E for ; Wed, 23 Aug 2017 00:27:25 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BDC8F2892C; Wed, 23 Aug 2017 00:27:25 +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 AFA0D287E3 for ; Wed, 23 Aug 2017 00:27:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752841AbdHWA1K (ORCPT ); Tue, 22 Aug 2017 20:27:10 -0400 Received: from mail-wr0-f195.google.com ([209.85.128.195]:33579 "EHLO mail-wr0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752801AbdHWA1J (ORCPT ); Tue, 22 Aug 2017 20:27:09 -0400 Received: by mail-wr0-f195.google.com with SMTP id a47so157936wra.0 for ; Tue, 22 Aug 2017 17:27:08 -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=RofK/LJvRPg5nPuAFvukblFx0hn5U30pm/WwQdrYZDU=; b=T2ROTbj8sVcuklc7T/2vabyH7CDRs/ZYL/eYo9rK5slTCqAHVMNNjcxxQszTm+omwQ eh+M64A6JKpJ6bIoUjIbVRnHUvGzx3P3w4Sszpg8bhBlPzBy25GG2U+dfg5w7LlhDc9x lL0Ipvn3zEcPOLygsecWpQS1xlr6eyFbtLpcbZcEYr7TpkfcWkmFRodO/horK4asehnO QSXHMGwDSqYhJig/V41JMqY8ixO5jf3sR9abyzPeFXvUJBjZ78iMb49LJEOs6ud7SzPp cIMm0drOwEETm71b4q/L4qixhFP6OZwNqWRiPxpRK26+kOt30lz5n59tEWg9X6rtCid9 Q1Eg== 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=RofK/LJvRPg5nPuAFvukblFx0hn5U30pm/WwQdrYZDU=; b=M1YO9xx51RvDkcwnZm6q0ib+lBI5vgdJ5wmb3CVwk4PqDXOmIp7dfCztO3o/Z7W218 9V/xLT4qKoqM6p84y+g21lpd8thczsJJNxhfepac/G6XghcwtLZfdyBAYdfgJCzrIiE3 C3x6fceiuA5y9W5sEOFuk2dMZqlCQaI9iimUwIw/ffVnjwbVLLkP2n7uIfF+yown58rT GkPxeLdDFWfo0ksBaIHAKIa7N/0N3f1HpU6NB0UpcqBvzPuH4GH4SBFI+tKOP740pHoY 4IiJ641RYmwg8ERSxGNHWsi8CUZrRDqsf5xZApHWB9wFUhaIXFzFka6UAQ+4Xhae0KSc 9f6g== X-Gm-Message-State: AHYfb5ioDod52lih1/xuT9Us1K8Qpwbwizmt+bez1E9JF8SNh/XS3hlD nRgJeSoDvR0XXlEA X-Received: by 10.223.148.38 with SMTP id 35mr502005wrq.24.1503448027362; Tue, 22 Aug 2017 17:27:07 -0700 (PDT) Received: from titovetst-l.itransition.corp (nat3-minsk-pool-46-53-180-190.telecom.by. [46.53.180.190]) by smtp.gmail.com with ESMTPSA id k45sm136926wre.1.2017.08.22.17.27.06 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 22 Aug 2017 17:27:06 -0700 (PDT) From: Timofey Titovets To: linux-btrfs@vger.kernel.org Cc: Timofey Titovets Subject: [PATCH v5 1/6] Btrfs: heuristic make use compression workspaces Date: Wed, 23 Aug 2017 03:26:45 +0300 Message-Id: <20170823002650.3133-2-nefelim4ag@gmail.com> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20170823002650.3133-1-nefelim4ag@gmail.com> References: <20170823002650.3133-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 Move heuristic to external file Implement compression workspaces support for heuristic resources Signed-off-by: Timofey Titovets --- fs/btrfs/Makefile | 2 +- fs/btrfs/compression.c | 18 +++++-------- fs/btrfs/compression.h | 7 ++++- fs/btrfs/heuristic.c | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 84 insertions(+), 13 deletions(-) create mode 100644 fs/btrfs/heuristic.c -- 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/Makefile b/fs/btrfs/Makefile index 128ce17a80b0..6fa8479dff43 100644 --- a/fs/btrfs/Makefile +++ b/fs/btrfs/Makefile @@ -9,7 +9,7 @@ btrfs-y += super.o ctree.o extent-tree.o print-tree.o root-tree.o dir-item.o \ export.o tree-log.o free-space-cache.o zlib.o lzo.o \ compression.o delayed-ref.o relocation.o delayed-inode.o scrub.o \ reada.o backref.o ulist.o qgroup.o send.o dev-replace.o raid56.o \ - uuid-tree.o props.o hash.o free-space-tree.o + uuid-tree.o props.o hash.o free-space-tree.o heuristic.o btrfs-$(CONFIG_BTRFS_FS_POSIX_ACL) += acl.o btrfs-$(CONFIG_BTRFS_FS_CHECK_INTEGRITY) += check-integrity.o diff --git a/fs/btrfs/compression.c b/fs/btrfs/compression.c index 883ecc58fd0d..f0aaf27bcc95 100644 --- a/fs/btrfs/compression.c +++ b/fs/btrfs/compression.c @@ -704,6 +704,7 @@ static struct { static const struct btrfs_compress_op * const btrfs_compress_op[] = { &btrfs_zlib_compress, &btrfs_lzo_compress, + &btrfs_heuristic, }; void __init btrfs_init_compress(void) @@ -1065,18 +1066,13 @@ int btrfs_decompress_buf2page(const char *buf, unsigned long buf_start, */ 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; + int ret; + enum btrfs_compression_type type = BTRFS_HEURISTIC; + struct list_head *workspace = find_workspace(type); - while (index <= end_index) { - page = find_get_page(inode->i_mapping, index); - kmap(page); - kunmap(page); - put_page(page); - index++; - } + ret = btrfs_compress_op[type-1]->heuristic(workspace, inode, + start, end); + free_workspace(type, workspace); return ret; } diff --git a/fs/btrfs/compression.h b/fs/btrfs/compression.h index 3b1b0ac15fdc..10e9ffa6dfa4 100644 --- a/fs/btrfs/compression.h +++ b/fs/btrfs/compression.h @@ -99,7 +99,8 @@ enum btrfs_compression_type { BTRFS_COMPRESS_NONE = 0, BTRFS_COMPRESS_ZLIB = 1, BTRFS_COMPRESS_LZO = 2, - BTRFS_COMPRESS_TYPES = 2, + BTRFS_HEURISTIC = 3, + BTRFS_COMPRESS_TYPES = 3, }; struct btrfs_compress_op { @@ -123,10 +124,14 @@ struct btrfs_compress_op { struct page *dest_page, unsigned long start_byte, size_t srclen, size_t destlen); + + int (*heuristic)(struct list_head *workspace, + struct inode *inode, u64 start, u64 end); }; extern const struct btrfs_compress_op btrfs_zlib_compress; extern const struct btrfs_compress_op btrfs_lzo_compress; +extern const struct btrfs_compress_op btrfs_heuristic; int btrfs_compress_heuristic(struct inode *inode, u64 start, u64 end); diff --git a/fs/btrfs/heuristic.c b/fs/btrfs/heuristic.c new file mode 100644 index 000000000000..96ae3e9334bc --- /dev/null +++ b/fs/btrfs/heuristic.c @@ -0,0 +1,70 @@ +/* + * Copyright (c) 2017 + * All rights reserved. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public + * License v2 as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + */ + +#include +#include +#include +#include +#include +#include +#include "compression.h" + +struct workspace { + struct list_head list; +}; + +static void heuristic_free_workspace(struct list_head *ws) +{ + struct workspace *workspace = list_entry(ws, struct workspace, list); + kfree(workspace); +} + +static struct list_head *heuristic_alloc_workspace(void) +{ + struct workspace *workspace; + + workspace = kzalloc(sizeof(*workspace), GFP_KERNEL); + if (!workspace) + return ERR_PTR(-ENOMEM); + + INIT_LIST_HEAD(&workspace->list); + + return &workspace->list; +} + +static int heuristic(struct list_head *ws, struct inode *inode, + u64 start, u64 end) +{ + struct page *page; + u64 index, index_end; + u8 *input_data; + + index = start >> PAGE_SHIFT; + index_end = end >> PAGE_SHIFT; + + for (; index <= index_end; index++) { + page = find_get_page(inode->i_mapping, index); + input_data = kmap(page); + kunmap(page); + put_page(page); + } + + return 1; +} + +const struct btrfs_compress_op btrfs_heuristic = { + .alloc_workspace = heuristic_alloc_workspace, + .free_workspace = heuristic_free_workspace, + .heuristic = heuristic, +};