From patchwork Fri Aug 25 09:18:40 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Timofey Titovets X-Patchwork-Id: 9921509 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 C7307600C5 for ; Fri, 25 Aug 2017 09:19:38 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BFC1626D05 for ; Fri, 25 Aug 2017 09:19:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B4A7E27D4D; Fri, 25 Aug 2017 09:19:38 +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 37F1726D05 for ; Fri, 25 Aug 2017 09:19:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755208AbdHYJTO (ORCPT ); Fri, 25 Aug 2017 05:19:14 -0400 Received: from mail-wr0-f194.google.com ([209.85.128.194]:35515 "EHLO mail-wr0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754565AbdHYJTL (ORCPT ); Fri, 25 Aug 2017 05:19:11 -0400 Received: by mail-wr0-f194.google.com with SMTP id a47so1117256wra.2 for ; Fri, 25 Aug 2017 02:19:10 -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=QZraYfRTnYK8czVnxgOlkGoxozteMldCkQeA+jQ8DBQ=; b=ivUmsj9r89HAwSH2sNW8hIBLRGXr8XHVpJuLRxqEzikC09/6Oz0G1hEM/VJf684Jsa Kjz0KezrftBQ8nQVtywwLFEIbXgSuXDzDXDXzkRW7dxK3nJOUpLQB+o0DQ1FWxtWlhh7 B9dc4sg5f7zITSaDxGl/a1MZA8qYvp2rkDY3DfDPAF6zgjJoA9z+WcBxN3RUEXp0GNbh MpMwnK0EdWIEmM0kGeQOhWI+8P4BDHdIayNbANxyYMDpTosqTnoGHC+wHA+m98L0AXER 1LoEN4pVT6ttsBgBf+GRf7EZjHfynFr7gsxZXQL1SCNGt6HUf64x2s82dt0or7wl4yHj gB5g== 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=QZraYfRTnYK8czVnxgOlkGoxozteMldCkQeA+jQ8DBQ=; b=smY2Dgaf84/b5VaGB5lKnSys4jZjli3icDL4Z0gmgW9GoJH5pmQjcBj6aFbddx+bYH Hb7gGjpEKiEOq5o0XZiFA6L8SBEn0zu5+Jmlnv1rOcT/YNXlUOCLhpLVAjcKyWs6Y/w7 V4/w80dvb3YcLP9/SIZW4X2URHBpWMyxXC5lJ+emBtPncBPZ+ohcYvVoe+1TrVHzVUcO JUoOFdLiTc/C0C3xSnVfN0zTmuWYtXoJueVaiNCHwM0mxuACfuI7YsjzF+sVho8Pul5P E0w2iftjpUNZIx7t4oEVN8xoPYsdaGKjPZjsfgySNQcN00wO7t3HRP1KMPP5cQbri83n VBMg== X-Gm-Message-State: AHYfb5iXHFNUoWkYP/y41qrnt50md3M2Pjxmxn6lx9ckAIuYTm8qUYsS sj0qbOyPCIGoBGsL X-Received: by 10.223.187.211 with SMTP id z19mr151023wrg.83.1503652749797; Fri, 25 Aug 2017 02:19:09 -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.08 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 25 Aug 2017 02:19:09 -0700 (PDT) From: Timofey Titovets To: linux-btrfs@vger.kernel.org Cc: Timofey Titovets Subject: [PATCH v7 1/6] Btrfs: heuristic make use compression workspaces Date: Fri, 25 Aug 2017 12:18:40 +0300 Message-Id: <20170825091845.4120-2-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 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 | 73 ++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 87 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..92f9335bafd4 --- /dev/null +++ b/fs/btrfs/heuristic.c @@ -0,0 +1,73 @@ +/* + * 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; + + index = start >> PAGE_SHIFT; + index_end = end >> PAGE_SHIFT; + + /* Don't miss unaligned end */ + if (!IS_ALIGNED(end, PAGE_SIZE)) + index_end++; + + for (; index < index_end; index++) { + page = find_get_page(inode->i_mapping, index); + 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, +};