From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.4 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4502FC4338F for ; Fri, 6 Aug 2021 02:35:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2B43961186 for ; Fri, 6 Aug 2021 02:35:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242421AbhHFCfe (ORCPT ); Thu, 5 Aug 2021 22:35:34 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:21292 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242572AbhHFCf0 (ORCPT ); Thu, 5 Aug 2021 22:35:26 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1628217311; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=KoTBXnxTCgtcpMcenMo0YB1o8xf/RjrOXhf88bzrOLU=; b=he8QAqXSrVQa1hCmk09B390QBw5n9V82e6R538OSoipuy2Ls2flnc1JRMyL9KXf/GyK/d7 5blliN/to/cZPx7rtMjBymGbajzJcxs24UVs9+K/ZKPr+UIjLmz264LRZ8+HVfat3E4nLf LqOF46hlYu7XCWLGrAZppeDaugFfn1k= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-351-TrK-u0ZWO4y3mVlf1AP4kg-1; Thu, 05 Aug 2021 22:35:08 -0400 X-MC-Unique: TrK-u0ZWO4y3mVlf1AP4kg-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 20696871805; Fri, 6 Aug 2021 02:35:07 +0000 (UTC) Received: from localhost (ovpn-12-45.pek2.redhat.com [10.72.12.45]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5FAFB6A057; Fri, 6 Aug 2021 02:35:05 +0000 (UTC) From: Ming Lei To: Jens Axboe Cc: linux-kernel@vger.kernel.org, linux-block@vger.kernel.org, Christoph Hellwig , Dan Schatzberg , Ming Lei Subject: [PATCH V3 5/7] loop: improve loop_process_work Date: Fri, 6 Aug 2021 10:34:21 +0800 Message-Id: <20210806023423.131060-6-ming.lei@redhat.com> In-Reply-To: <20210806023423.131060-1-ming.lei@redhat.com> References: <20210806023423.131060-1-ming.lei@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org Avoid to acquire the spinlock for handling every loop command, and hold lock once for taking all commands. Acked-by: Dan Schatzberg Signed-off-by: Ming Lei --- drivers/block/loop.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/drivers/block/loop.c b/drivers/block/loop.c index 6d9cfd47b7a2..c9a28483433b 100644 --- a/drivers/block/loop.c +++ b/drivers/block/loop.c @@ -2238,21 +2238,26 @@ static void loop_process_work(struct loop_worker *worker, { int orig_flags = current->flags; struct loop_cmd *cmd; + LIST_HEAD(list); current->flags |= PF_LOCAL_THROTTLE | PF_MEMALLOC_NOIO; + spin_lock(&lo->lo_work_lock); - while (!list_empty(cmd_list)) { - cmd = container_of( - cmd_list->next, struct loop_cmd, list_entry); - list_del(cmd_list->next); - spin_unlock(&lo->lo_work_lock); + again: + list_splice_init(cmd_list, &list); + spin_unlock(&lo->lo_work_lock); - loop_handle_cmd(cmd); - cond_resched(); + while (!list_empty(&list)) { + cmd = list_first_entry(&list, struct loop_cmd, list_entry); + list_del_init(&cmd->list_entry); - spin_lock(&lo->lo_work_lock); + loop_handle_cmd(cmd); } + spin_lock(&lo->lo_work_lock); + if (!list_empty(cmd_list)) + goto again; + /* * We only add to the idle list if there are no pending cmds * *and* the worker will not run again which ensures that it -- 2.31.1