Received: by 2002:a05:7412:2a8c:b0:e2:908c:2ebd with SMTP id u12csp3486173rdh; Thu, 28 Sep 2023 13:07:48 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG9tug4Hury3a7sNP/bDSp5b9VIfu3H/GlKcaKnom+Iiv8qOkYEkmIrEQl2XIai4KT9obD/ X-Received: by 2002:a05:6a00:130b:b0:690:c887:8cd8 with SMTP id j11-20020a056a00130b00b00690c8878cd8mr2119609pfu.32.1695931668252; Thu, 28 Sep 2023 13:07:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695931668; cv=none; d=google.com; s=arc-20160816; b=0al0gd5hQnJZAdbS11+Llf/hMdasqd+Krcc/A/bT+Lw2j1BPxbrS6SrZ8YLzyRHkmh 7pUEdsvzmY7id4yCiI25wgGU4MSJrfit6yjG7vYVWD+/E0vaWpGBi8tc3QMNra9Kyzys PtNqP47pWu97znYK0ROR4A6q2CUKXGyb43VxtyinxU2Hf7VF+7H7C0yCgppMbGkt4pJb 4tVI690PFuYO5EclLZ8Vm7l6HnLrK/M26C6PszbI+Tj5qX6yUF7REPkGjc+R03ApA6vZ 8elwLB9DV7aahKJgB1rHEQZhQHu93BBWWx+vjQveJJltzB92FvCuUUsJgf3XxbxVknb7 v4Zg== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=DjqSRzwtcmbZCSdKBG680ING+E16TFEDXl3yu9hsx/4=; fh=3m5ywMWLfOmz80QT23p1vqAQvmuMbWv7fLVKHOU8cQQ=; b=LHcML6J6O94rcP34jW8f6TSKuVUNu1e9FR2AOhbNQKIxxhljGrcFIxCoQuSzIO3OlH uUALYSxalOgiMXfUfYXkuQeQB++YGL0dpLqPmh33nc1ydyjCRTjTfx5KkczXKJ3YuyUL HfiaYi4K5pS/0MeOIIveKUzsbJQXHJMophOvCku2l5ZjBePGP6QazoP6wlhCrYrmK+sv 3+tDHRFrnAnBy82WrhbJ0tEkYfnq+7DL7OmFBxcJaHZwSvvu9KXGgcTwal76XM92HNhe 0fPZZjqS/YBxftpD9B7t6cIyCV9aKu4q4YYKYBTqWnMEnFcvl9ow8QBvsMln0lNwzcDM d8eQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linbit-com.20230601.gappssmtp.com header.s=20230601 header.b=C8M0DdeX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from howler.vger.email (howler.vger.email. [23.128.96.34]) by mx.google.com with ESMTPS id f7-20020a056a001ac700b0068fdfe29f0asi20480623pfv.88.2023.09.28.13.07.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Sep 2023 13:07:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) client-ip=23.128.96.34; Authentication-Results: mx.google.com; dkim=pass header.i=@linbit-com.20230601.gappssmtp.com header.s=20230601 header.b=C8M0DdeX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id 8B39E84DBA38; Thu, 28 Sep 2023 02:39:55 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231898AbjI1Jjs (ORCPT + 99 others); Thu, 28 Sep 2023 05:39:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60510 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231910AbjI1JjV (ORCPT ); Thu, 28 Sep 2023 05:39:21 -0400 Received: from mail-wr1-x432.google.com (mail-wr1-x432.google.com [IPv6:2a00:1450:4864:20::432]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B0079CDD for ; Thu, 28 Sep 2023 02:39:02 -0700 (PDT) Received: by mail-wr1-x432.google.com with SMTP id ffacd0b85a97d-307d58b3efbso10917499f8f.0 for ; Thu, 28 Sep 2023 02:39:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linbit-com.20230601.gappssmtp.com; s=20230601; t=1695893941; x=1696498741; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=DjqSRzwtcmbZCSdKBG680ING+E16TFEDXl3yu9hsx/4=; b=C8M0DdeXPslPvE2nDGk1T6oVddJq0OD10kcrqDGNu7AEzn3VKwgw/N2JL8t2Oazj60 DYz0MAh1+2PoNkVNK3IuowcCZ3+nAUi9jvLlVQM0r7zsOb5CqxRcaJTjKYEADq37DNeS lf0ly9rWlXyHxvqRiUuVAW0mPvwoRLSqc6nuYDYk8qBPBqWDTVft0e2Xsz0+1K1MllFq 8wtJlqyoC6+mcjhHiKx7Dc4DDEsTMPdMgxR/nEmVEzO+LCpOtCWFkx84vtgnHBlSHV+x w9lGMMf57GBh5lVof3OxqQqyQJQqERyhZxelnkSB/HZWZcnGSzCizQABp/wjTVrVdh6G nsKg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695893941; x=1696498741; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=DjqSRzwtcmbZCSdKBG680ING+E16TFEDXl3yu9hsx/4=; b=Vh2BTS6BjnCPMXgYbsT+IGauTnc4Cv2UiILKuZHruPo+5WKtdAeKeuUecWxnT0uEoi Khx0kfV28Z0xqcqjuIJlmggwKvPlE8oOQ44KKdIsbu5PPk8U+af0so4lDoKVL12KeNRR I6NupZHcZjMPWyt+wKBC1mqgtdOjQU2PnoFAjS1elhHTcEAwq+X4YfNP1XCtbS1qy53/ 6GwZYNlEG4oxhRl/NHSQzBf73Vm3ebYvueWCFzwk6ltvsTGuBJquQ1m/YDXXcvAxiybN qbuHfzNuzvZ3a/vNUmvP7ZdRPz8bmV00Jrd5653Hk1iRRrMPV2K5MKUILlSzIXdDjZFS ukew== X-Gm-Message-State: AOJu0Yx8fNColeO6Kvq/PQjA/SSwVYSrjye88sexyvqsDAbfe9GQNZHW tn+7ot2MvEoCXQLs3t5KdQejNQ== X-Received: by 2002:adf:dc90:0:b0:319:7134:a3cf with SMTP id r16-20020adfdc90000000b003197134a3cfmr617107wrj.31.1695893941024; Thu, 28 Sep 2023 02:39:01 -0700 (PDT) Received: from localhost.localdomain (213-225-13-130.nat.highway.a1.net. [213.225.13.130]) by smtp.gmail.com with ESMTPSA id f4-20020a5d50c4000000b0031fa870d4b3sm18931449wrt.60.2023.09.28.02.38.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Sep 2023 02:39:00 -0700 (PDT) From: =?UTF-8?q?Christoph=20B=C3=B6hmwalder?= To: Jens Axboe Cc: Philipp Reisner , Lars Ellenberg , drbd-dev@lists.linbit.com, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, Christoph Hellwig , Joel Colledge , =?UTF-8?q?Christoph=20B=C3=B6hmwalder?= Subject: [PATCH 2/5] drbd: Add new per-resource "worker" thread Date: Thu, 28 Sep 2023 11:38:49 +0200 Message-ID: <20230928093852.676786-3-christoph.boehmwalder@linbit.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230928093852.676786-1-christoph.boehmwalder@linbit.com> References: <20230928093852.676786-1-christoph.boehmwalder@linbit.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,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-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Thu, 28 Sep 2023 02:39:55 -0700 (PDT) Out-of-tree fixes folded in: - drbd: allow to dequeue batches of work at a time (partial backport) - drbd: Keep "worker" alive while resource exists - Flush the work queue before stopping the worker thread Originally-from: Andreas Gruenbacher Reviewed-by: Joel Colledge Signed-off-by: Christoph Böhmwalder --- drivers/block/drbd/drbd_int.h | 4 +++ drivers/block/drbd/drbd_main.c | 5 ++++ drivers/block/drbd/drbd_nl.c | 2 +- drivers/block/drbd/drbd_sender.c | 46 ++++++++++++++++++++++++++++++++ 4 files changed, 56 insertions(+), 1 deletion(-) diff --git a/drivers/block/drbd/drbd_int.h b/drivers/block/drbd/drbd_int.h index a53e63af23f1..fe7e93a4dfa6 100644 --- a/drivers/block/drbd/drbd_int.h +++ b/drivers/block/drbd/drbd_int.h @@ -603,6 +603,9 @@ struct drbd_resource { enum write_ordering_e write_ordering; cpumask_var_t cpu_mask; + + struct drbd_work_queue work; + struct drbd_thread worker; }; struct drbd_thread_timing_details @@ -1428,6 +1431,7 @@ extern void drbd_md_endio(struct bio *bio); extern void drbd_peer_request_endio(struct bio *bio); extern void drbd_request_endio(struct bio *bio); extern int drbd_sender(struct drbd_thread *thi); +extern int drbd_worker(struct drbd_thread *thi); enum drbd_ret_code drbd_resync_after_valid(struct drbd_device *device, int o_minor); void drbd_resync_after_changed(struct drbd_device *device); extern void drbd_start_resync(struct drbd_device *device, enum drbd_conns side); diff --git a/drivers/block/drbd/drbd_main.c b/drivers/block/drbd/drbd_main.c index a14c1e9ee327..bb5de1e1ca9f 100644 --- a/drivers/block/drbd/drbd_main.c +++ b/drivers/block/drbd/drbd_main.c @@ -2329,6 +2329,8 @@ void drbd_free_resource(struct drbd_resource *resource) { struct drbd_connection *connection, *tmp; + drbd_flush_workqueue(&resource->work); + drbd_thread_stop(&resource->worker); for_each_connection_safe(connection, tmp, resource) { list_del(&connection->connections); drbd_debugfs_connection_cleanup(connection); @@ -2564,6 +2566,9 @@ struct drbd_resource *drbd_create_resource(const char *name) mutex_init(&resource->conf_update); mutex_init(&resource->adm_mutex); spin_lock_init(&resource->req_lock); + drbd_init_workqueue(&resource->work); + drbd_thread_init(resource, &resource->worker, drbd_worker, "worker"); + drbd_thread_start(&resource->worker); drbd_debugfs_resource_add(resource); return resource; diff --git a/drivers/block/drbd/drbd_nl.c b/drivers/block/drbd/drbd_nl.c index a5844819d1c3..9d9ced46f968 100644 --- a/drivers/block/drbd/drbd_nl.c +++ b/drivers/block/drbd/drbd_nl.c @@ -1900,7 +1900,7 @@ int drbd_adm_attach(struct sk_buff *skb, struct genl_info *info) */ wait_event(device->misc_wait, !atomic_read(&device->ap_pending_cnt) || drbd_suspended(device)); /* and for any other previously queued work */ - drbd_flush_workqueue(&connection->sender_work); + drbd_flush_workqueue(&device->resource->work); rv = _drbd_request_state(device, NS(disk, D_ATTACHING), CS_VERBOSE); retcode = (enum drbd_ret_code)rv; diff --git a/drivers/block/drbd/drbd_sender.c b/drivers/block/drbd/drbd_sender.c index fcc8a43efdca..0c482d45a52a 100644 --- a/drivers/block/drbd/drbd_sender.c +++ b/drivers/block/drbd/drbd_sender.c @@ -2239,3 +2239,49 @@ int drbd_sender(struct drbd_thread *thi) return 0; } + +int drbd_worker(struct drbd_thread *thi) +{ + LIST_HEAD(work_list); + struct drbd_resource *resource = thi->resource; + struct drbd_work *w; + + while (get_t_state(thi) == RUNNING) { + drbd_thread_current_set_cpu(thi); + + if (list_empty(&work_list)) { + wait_event_interruptible(resource->work.q_wait, + dequeue_work_batch(&resource->work, &work_list)); + } + + if (signal_pending(current)) { + flush_signals(current); + if (get_t_state(thi) == RUNNING) { + drbd_warn(resource, "Worker got an unexpected signal\n"); + continue; + } + break; + } + + if (get_t_state(thi) != RUNNING) + break; + + + while (!list_empty(&work_list)) { + w = list_first_entry(&work_list, struct drbd_work, list); + list_del_init(&w->list); + w->cb(w, 0); + } + } + + do { + while (!list_empty(&work_list)) { + w = list_first_entry(&work_list, struct drbd_work, list); + list_del_init(&w->list); + w->cb(w, 1); + } + dequeue_work_batch(&resource->work, &work_list); + } while (!list_empty(&work_list)); + + return 0; +} -- 2.41.0