Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3925422imu; Mon, 28 Jan 2019 13:27:28 -0800 (PST) X-Google-Smtp-Source: ALg8bN7D36ljS1dPyoLHznpEbh0vBx0d7CVcKGCcOyiUk08UP6tSAmMrp2Hc48g/3eS7xtQJq2J7 X-Received: by 2002:a62:c42:: with SMTP id u63mr23068945pfi.73.1548710848330; Mon, 28 Jan 2019 13:27:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548710848; cv=none; d=google.com; s=arc-20160816; b=fFZxhk+7VhQZSsaH8s9kVT46WyLHZyBnT1UzNZvU99j878AUqQIspfRxn9YTadvxnu UGy06VLeWFskIzEkQ8h8tWHlQNp6BSi+a1mdvZRJMrFip8jDYJXV+hbertGk0faTaZK0 5BvBkWGtvvSC0WVIeQXNdw3Sy++WZDhHpbtNrFNDS2EokpGDhO1Ir3jzcX5ncUB0jHU0 KUcSjGNlJOuQN2Tf5lsnx1KTn/BvA8yCGbdrn+G2nfkWQaH6lXLaONHjNE+1vJb1YAAx rXu7Ak/OVONlKacjPu2xeDUuxOxmJiuWMfNgy3PnbTi0xyWTUFX1ONtG9YQ9eSXi4i0r 2EAg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=UiLjqvhWknXTEAjd/auwTYxNB5iT2kzVZ+BxEPsbB3w=; b=l+T/v3LLHzoSWhcadJHOpyP8uexSgGGX/KhIjbqRr4fhsN1kPgYDwchxlmwYM0/Nzf OOl6aO9dNhmSf+LYk5qYJYjQjqcK0gcT569b7XbWi15U2JLzmMzW/Rlnyfid2qx6zeLG u+QVb+Qoj6CuUyEFzzTMp17nIfk17qiLvAESmAk+7szS8QJhzpa7uPenj6wJcD/wDRhH LZcxk/MCrYYrVVikLyuUS2iEpeNdfr8x107Ly5Le/5cAlwRytUUarKDpUWLvpuzxaPTy 5SgodUNp45bdNrHhmMp80+PSN43etSJogY7KdmILfMMxiY1kNppHjE24jHEmwadbQRF3 +swQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w10si32670300pgj.214.2019.01.28.13.27.12; Mon, 28 Jan 2019 13:27:28 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728370AbfA1VYz (ORCPT + 99 others); Mon, 28 Jan 2019 16:24:55 -0500 Received: from mail-yb1-f194.google.com ([209.85.219.194]:36597 "EHLO mail-yb1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728316AbfA1VYw (ORCPT ); Mon, 28 Jan 2019 16:24:52 -0500 Received: by mail-yb1-f194.google.com with SMTP id 64so2823085ybf.3; Mon, 28 Jan 2019 13:24:52 -0800 (PST) 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=UiLjqvhWknXTEAjd/auwTYxNB5iT2kzVZ+BxEPsbB3w=; b=XkQ2oMmLQBulRrWUEJLqxCBMmAbzhT+M3UUGPkYtyMBDIIJEhKfdxK2/ET/AxiHFwT CmEyNPkfOipSDQnoPaHqIOqwNSPidxksoR1MS6BuoVmlBiO9wazAmm42KaYljwLcvRSb mxKm+SRwq1yB6qmzzOCl0GO9r4FCxc8Sum3VJ5XMTel22tRKXInaIj3dCKw2UIXQmvtU YQcUipuhU33G9vp2+n1EwkqlxXmCViNHOUHRHTJvQNtvgYU41cb7PLHED7UyfvW88orN 9HSooDK9hnYTX5t/R3Qd/nCE0v3sVpiG/30HGskHemPfn7HK3F/Jr8vXe1kRkwBmZ6so SNUg== X-Gm-Message-State: AJcUukeFSeZipqm5k0hTB4GQtZ6iJa9XX2XADNCEbu2fPfDSh28MflCv 6UbO6lD8Ep3D9HLOF9uPvwA= X-Received: by 2002:a25:c304:: with SMTP id t4mr23111882ybf.359.1548710691713; Mon, 28 Jan 2019 13:24:51 -0800 (PST) Received: from dennisz-mbp.thefacebook.com ([199.201.65.135]) by smtp.gmail.com with ESMTPSA id a7sm24170415ywb.18.2019.01.28.13.24.50 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 28 Jan 2019 13:24:50 -0800 (PST) From: Dennis Zhou To: David Sterba , Josef Bacik , Chris Mason , Omar Sandoval , Nick Terrell Cc: kernel-team@fb.com, linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org, Dennis Zhou Subject: [PATCH 05/11] btrfs: add helper methods for workspace manager init and cleanup Date: Mon, 28 Jan 2019 16:24:31 -0500 Message-Id: <20190128212437.11597-6-dennis@kernel.org> X-Mailer: git-send-email 2.13.5 In-Reply-To: <20190128212437.11597-1-dennis@kernel.org> References: <20190128212437.11597-1-dennis@kernel.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Workspace manager init and cleanup code is open coded inside a for loop over the compression types. This forces each compression type to rely on the same workspace manager implementation. This patch creates helper methods that will be the generic implementation for btrfs workspace management. Signed-off-by: Dennis Zhou --- fs/btrfs/compression.c | 81 ++++++++++++++++++++++-------------------- 1 file changed, 42 insertions(+), 39 deletions(-) diff --git a/fs/btrfs/compression.c b/fs/btrfs/compression.c index b7e986e16640..63fa3eaeeacc 100644 --- a/fs/btrfs/compression.c +++ b/fs/btrfs/compression.c @@ -797,31 +797,41 @@ static const struct btrfs_compress_op * const btrfs_compress_op[] = { &btrfs_zstd_compress, }; -void __init btrfs_init_compress(void) +static void btrfs_init_workspace_manager(int type) { + struct workspace_manager *wsman = &wsm[type]; struct list_head *workspace; - int i; - for (i = 0; i < BTRFS_COMPRESS_TYPES; i++) { - wsm[i].ops = btrfs_compress_op[i]; + wsman->ops = btrfs_compress_op[type]; - INIT_LIST_HEAD(&wsm[i].idle_ws); - spin_lock_init(&wsm[i].ws_lock); - atomic_set(&wsm[i].total_ws, 0); - init_waitqueue_head(&wsm[i].ws_wait); + INIT_LIST_HEAD(&wsman->idle_ws); + spin_lock_init(&wsman->ws_lock); + atomic_set(&wsman->total_ws, 0); + init_waitqueue_head(&wsman->ws_wait); - /* - * Preallocate one workspace for each compression type so - * we can guarantee forward progress in the worst case - */ - workspace = wsm[i].ops->alloc_workspace(); - if (IS_ERR(workspace)) { - pr_warn("BTRFS: cannot preallocate compression workspace, will try later\n"); - } else { - atomic_set(&wsm[i].total_ws, 1); - wsm[i].free_ws = 1; - list_add(workspace, &wsm[i].idle_ws); - } + /* + * Preallocate one workspace for each compression type so + * we can guarantee forward progress in the worst case + */ + workspace = wsman->ops->alloc_workspace(); + if (IS_ERR(workspace)) { + pr_warn("BTRFS: cannot preallocate compression workspace, will try later\n"); + } else { + atomic_set(&wsman->total_ws, 1); + wsman->free_ws = 1; + list_add(workspace, &wsman->idle_ws); + } +} + +static void btrfs_cleanup_workspace_manager(struct workspace_manager *wsman) +{ + struct list_head *ws; + + while (!list_empty(&wsman->idle_ws)) { + ws = wsman->idle_ws.next; + list_del(ws); + wsman->ops->free_workspace(ws); + atomic_dec(&wsman->total_ws); } } @@ -941,24 +951,6 @@ static void free_workspace(int type, struct list_head *workspace) cond_wake_up(ws_wait); } -/* - * cleanup function for module exit - */ -static void free_workspaces(void) -{ - struct list_head *workspace; - int i; - - for (i = 0; i < BTRFS_COMPRESS_TYPES; i++) { - while (!list_empty(&wsm[i].idle_ws)) { - workspace = wsm[i].idle_ws.next; - list_del(workspace); - wsm[i].ops->free_workspace(workspace); - atomic_dec(&wsm[i].total_ws); - } - } -} - /* * Given an address space and start and length, compress the bytes into @pages * that are allocated on demand. @@ -1051,9 +1043,20 @@ int btrfs_decompress(int type, unsigned char *data_in, struct page *dest_page, return ret; } +void __init btrfs_init_compress(void) +{ + int i; + + for (i = 0; i < BTRFS_COMPRESS_TYPES; i++) + btrfs_init_workspace_manager(i); +} + void __cold btrfs_exit_compress(void) { - free_workspaces(); + int i; + + for (i = 0; i < BTRFS_COMPRESS_TYPES; i++) + btrfs_cleanup_workspace_manager(&wsm[i]); } /* -- 2.17.1