From patchwork Sun Feb 26 16:02:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ammar Faizi X-Patchwork-Id: 5872 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp2001877wrd; Sun, 26 Feb 2023 08:04:22 -0800 (PST) X-Google-Smtp-Source: AK7set/SNZ1MKzztOM+03e8e0sGOshYuiisQVlTKj4hPI2fGSUOegl/vVn/VgDjP5r2wSozn8/Yc X-Received: by 2002:a17:906:7394:b0:8b1:2614:dea6 with SMTP id f20-20020a170906739400b008b12614dea6mr25943756ejl.1.1677427462151; Sun, 26 Feb 2023 08:04:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1677427462; cv=none; d=google.com; s=arc-20160816; b=NIiCwLzIo/h/tg6XwHS3VzAUhPUbS2BvcAO5ydMYo2zL148Pe1oX/E8wIZCacmxRpt ht7fO/P6zm/Bwz0vwKeUnkbFdHmUeYCmnFQGyarl+6XA0nzH2imDXNWpZU+HKFiWR7qg 8R9Pp3gEXv6JMWmq2p8UcE5YH/knxOe3SXfMSCORIvB6cmY3xrwZJPYPna93YOiWTeTC lH5kZaVf4nvjgBqp4HXbLLuZjFciZQs2t2GBdmoODONaVmkrZpPq3EDHLEI9JodXAEcS F8wFYf3DH/OYVlLI3ws4O8jCUBtTw7rRtSRA9ed0/V6ggOeA+3cupjMaBt/5amKq9mxo O0Ew== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=3gLnfKLoZyvD0UiVi53/wJD8iHaRv3poodmw86gvuCE=; b=P9b9oRfUSL7G8vSb9uxUJMpXeRcqC9Ftcf4CWs8ueZ+5pqMLaON4RMa6zNK86MuUOY etdD05ky12+or5V/7U1B4PqsSGHlTGIpEMWcX9FUq1QGE+M1P79t3s/Ir1gmoejfAxwj MDQi9iui9NaS/Z/iXZcievv1vrluk06dEFCkgAu5+BE3aKp3s0FhX/jHkVAmIxdPMGXP hatrWEQZhBfTlXfbC/cIkEE1mWlk7Aa2bRW1uF4NQIdythTnzydoIKIvhtYYz4tueuRm jkI9XH1SR3SEzqJ1yAaoXtCPG4oZQqUf9paXdKQuA7pHX72VC4RoX7wHbE2jz2+3CXQ1 OI+w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gnuweeb.org header.s=default header.b=Cbwp9hG1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnuweeb.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i27-20020a170906251b00b008d28622c8d9si4988617ejb.728.2023.02.26.08.03.59; Sun, 26 Feb 2023 08:04:22 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gnuweeb.org header.s=default header.b=Cbwp9hG1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnuweeb.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229545AbjBZQDd (ORCPT + 99 others); Sun, 26 Feb 2023 11:03:33 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53468 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229563AbjBZQDc (ORCPT ); Sun, 26 Feb 2023 11:03:32 -0500 Received: from gnuweeb.org (gnuweeb.org [51.81.211.47]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8BE6BF746; Sun, 26 Feb 2023 08:03:19 -0800 (PST) Received: from localhost.localdomain (unknown [182.253.183.169]) by gnuweeb.org (Postfix) with ESMTPSA id 99D5E8319A; Sun, 26 Feb 2023 16:03:13 +0000 (UTC) X-GW-Data: lPqxHiMPbJw1wb7CM9QUryAGzr0yq5atzVDdxTR0iA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gnuweeb.org; s=default; t=1677427398; bh=wfVxdCU0WiYOKtzPo+vOA/+kkGOosWbPqZrRb2tJROM=; h=From:To:Cc:Subject:Date:From; b=Cbwp9hG1ztLu//tbm0WTi431HwgTqf/o6Ow6TTH8vqx4fqBSXmIB2kIZZUPjAgabw ETlx2MqhF+NzRe5c8bb7KfXKbL8522tCQdYTzzjbMhGpZXdCmy0yzsL3QDvfMpQFbf LRYLl2SrLHb9hldByAo0hFw0yc8k9oq5GPWsFxFyAcs8PVDwF6YO8Of49NVShJtr15 MX8He954Co/SrT29kA0TVceGBZ9A+A1iPsg04NnEvBQbZMHE/bKmkafFxJM71fFjf/ 87buMqh/YyudR1WduVho1V7Jb21UQAhSZ2eQ3TWies9fOi/J9flnTRrz4ODQh+kH1A AHmkD8Y2Iw3aQ== From: Ammar Faizi To: Chris Mason , Josef Bacik , David Sterba , Tejun Heo Cc: Ammar Faizi , Lai Jiangshan , Filipe Manana , Linux Btrfs Mailing List , Linux Kernel Mailing List , Linux Fsdevel Mailing List , GNU/Weeb Mailing List Subject: [RFC PATCH v1 0/6] Introducing `wq_cpu_set` mount option for btrfs Date: Sun, 26 Feb 2023 23:02:53 +0700 Message-Id: <20230226160259.18354-1-ammarfaizi2@gnuweeb.org> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_PASS,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1758910178396721209?= X-GMAIL-MSGID: =?utf-8?q?1758910178396721209?= Hi, This is an RFC patchset that introduces the `wq_cpu_set` mount option. This option lets the user specify a CPU set that the Btrfs workqueues will use. Btrfs workqueues can slow sensitive user tasks down because they can use any online CPU to perform heavy workloads on an SMP system. Add a mount option to isolate the Btrfs workqueues to a set of CPUs. It is helpful to avoid sensitive user tasks being preempted by Btrfs heavy workqueues. This option is similar to the taskset bitmask except that the comma separator is replaced with a dot. The reason for this is that the mount option parser uses commas to separate mount options. Figure (the CPU usage when `wq_cpu_set` is used VS when it is not): https://gist.githubusercontent.com/ammarfaizi2/a10f8073e58d1712c1ed49af83ae4ad1/raw/a4f7cbc4eb163db792a669d570ff542495e8c704/wq_cpu_set.png A simple stress testing: 1. Open htop. 2. Open a new terminal. 3. Mount and perform a heavy workload on the mounted Btrfs filesystem. ## Test without wq_cpu_set sudo mount -t btrfs -o rw,compress-force=zstd:15,commit=1500 /dev/sda2 hdd/a; cp -rf /path/folder_with_many_large_files/ hdd/a/test; sync; # See the CPU usage in htop. sudo umount hdd/a; ## Test wq_cpu_set sudo mount -t btrfs -o rw,compress-force=zstd:15,commit=1500,wq_cpu_set=0.4.1.5 /dev/sda2 hdd/a; cp -rf /path/folder_with_many_large_files/ hdd/a/test; sync; # See the CPU usage in htop. sudo umount hdd/a; Signed-off-by: Ammar Faizi --- Ammar Faizi (6): workqueue: Add set_workqueue_cpumask() helper function btrfs: Change `mount_opt` type in `struct btrfs_fs_info` to `u64` btrfs: Create btrfs CPU set struct and helpers btrfs: Add wq_cpu_set=%s mount option btrfs: Adjust the default thread pool size when `wq_cpu_set` option is used btrfs: Add `BTRFS_DEFAULT_MAX_THREAD_POOL_SIZE` macro fs/btrfs/async-thread.c | 51 ++++++++++++++++++++ fs/btrfs/async-thread.h | 3 ++ fs/btrfs/disk-io.c | 6 ++- fs/btrfs/fs.c | 97 +++++++++++++++++++++++++++++++++++++++ fs/btrfs/fs.h | 12 ++++- fs/btrfs/super.c | 83 +++++++++++++++++++++++++++++++++ include/linux/workqueue.h | 3 ++ kernel/workqueue.c | 19 ++++++++ 8 files changed, 271 insertions(+), 3 deletions(-) base-commit: 2fcd07b7ccd5fd10b2120d298363e4e6c53ccf9c