Received: by 2002:ab2:6203:0:b0:1f5:f2ab:c469 with SMTP id o3csp591576lqt; Fri, 19 Apr 2024 05:14:09 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUD8HIsTH8FITZyGlE3WIzaxFGFBcS0zAiQvcgfyC7St/H47gRBs96N80CBYilF/AKyqmsuOPZM66Xrgr48suV1OI2LYuoXNw0hpoirGA== X-Google-Smtp-Source: AGHT+IHTyNuDVcka7PfTQq7NqpFsSCPWpt9i7ULIsRRV3yrjb1YgvQ5A2nKNMCOKovPUvLo+4alO X-Received: by 2002:a05:6a20:438f:b0:1a7:51f6:87e6 with SMTP id i15-20020a056a20438f00b001a751f687e6mr2437668pzl.54.1713528848821; Fri, 19 Apr 2024 05:14:08 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713528848; cv=pass; d=google.com; s=arc-20160816; b=EQFXp+HN8mBrP2jv2da7XLwCEg6y9etuNDy7yX6uGybJ45sSgO+iw2RCE5DZlSswF0 TG89QUAO4PTroEMO9BQCH2Fvciwrmad2YyT1JGKBSewJ5qKS5/t9lgmfHOjKTsq6Rpg4 jgXdO/jOO9T5tGMgrLs6K8igno5iIWcH4babeAPolbnauIQtw74Uis4QyQnE+vafSgmk 964vzcL9IAXDf8b2qEfxspdgDhO9ESgRS5wQ8L7+Yb4bruokZ5f2V2tTMA0DOHSVJaie /MP7jW1ghYinLtlDP2OBrbQWasUdRggOSlTz0/os0yZQzjnh3grHj/d6YIo3S/izKguD D2ng== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=0ojQK3AKejzo96bSCef2HP/0kdeYSr7fp5rz2r2c22s=; fh=ncTLfLr7CDA+EpmzSqBM4nIQ/uSkBsLxn2nPC66vOk0=; b=gH/fAin6UyPWXcnnHB788FUecc8cj8NygN11tLxbT3g1fukHAXdMx8Zq1bARWrH0aj V5M9SCBYgNDGWESW0/JFpQhxqojP4AfQnSwWiFElRV4J2N7+Y3dcS9Jc2Rbdy4ICN6RX yYK9ceWq6k1DvnQoYXTht0z6SGpS9KUEy7pq9j70YoSJIHGiSX6PD/NXp+eD/kLXclBv ZHwQs9k1kIRdAdZGCuAJgKjnDDb1H4BcWTUmkppf/6XH0dhD5TBLgwwK4hLctjh1wr7I cQzJi+4mmVt8XGWScIaZyDmJHIZ7rkMyndhHtABceMEI1tLe2nLrN2LTwqWW1ihf+uBO NApA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kuaishou.com header.s=dkim header.b=eidpqVcu; arc=pass (i=1 spf=pass spfdomain=kuaishou.com dkim=pass dkdomain=kuaishou.com dmarc=pass fromdomain=kuaishou.com); spf=pass (google.com: domain of linux-kernel+bounces-151399-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-151399-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kuaishou.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id lb1-20020a056a004f0100b006ead1509816si3165003pfb.341.2024.04.19.05.14.08 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Apr 2024 05:14:08 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-151399-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kuaishou.com header.s=dkim header.b=eidpqVcu; arc=pass (i=1 spf=pass spfdomain=kuaishou.com dkim=pass dkdomain=kuaishou.com dmarc=pass fromdomain=kuaishou.com); spf=pass (google.com: domain of linux-kernel+bounces-151399-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-151399-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kuaishou.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 72C772828AB for ; Fri, 19 Apr 2024 12:14:08 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A387D85631; Fri, 19 Apr 2024 12:13:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=kuaishou.com header.i=@kuaishou.com header.b="eidpqVcu" Received: from mailhk01.kuaishou.com (mailhk01.kuaishou.com [129.226.226.143]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E0689839F1; Fri, 19 Apr 2024 12:13:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=129.226.226.143 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713528838; cv=none; b=O4rkD9S15iNl2e+wCYxGeoY4GBJmMZkRYohLjQk5MDZWHFlDIrHI0VxkJyGdbPSeP2VSj37dBHdDEZruRXea4I8LyxHiftR/f8Px/rcq6P7XF8EvzC+nKfSqLaWAq3llSg2TNpcXISyRcClpnYteduiOtFpAcBTJFf9RrhS68aU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713528838; c=relaxed/simple; bh=kQXlIm+hk7ZcDtTEmOfJwkpRlUhwn8EeE4YRTcIyaZg=; h=From:To:CC:Subject:Date:Message-ID:MIME-Version:Content-Type; b=dUd0oexIxvJbJvFFzvJIf21gTEpyd2F+9Y+QdNMJprwMwY4aHxYMjTZdiADJ+jsRUINX/bSGJSVNoTn+q39YvjY4SGgKh4EKEShKO5tjoCUgS/hEQMDZYnjIxAZr0w+AtwwL9aZ1ggg31wk6hxyovM/TT8bWYx891UOPenXDgMc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=kuaishou.com; spf=pass smtp.mailfrom=kuaishou.com; dkim=pass (1024-bit key) header.d=kuaishou.com header.i=@kuaishou.com header.b=eidpqVcu; arc=none smtp.client-ip=129.226.226.143 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=kuaishou.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=kuaishou.com Received: from bjm7-spam02.kuaishou.com (smtpcn03.kuaishou.com [103.107.217.217]) by mailhk01.kuaishou.com (Postfix) with ESMTP id B3F2461579; Fri, 19 Apr 2024 20:08:06 +0800 (CST) Received: from bjm7-pm-mail01.kuaishou.com (unknown [172.28.1.1]) by bjm7-spam02.kuaishou.com (Postfix) with ESMTPS id 42EBF19226D0D; Fri, 19 Apr 2024 20:07:51 +0800 (CST) DKIM-Signature: v=1; a=rsa-sha256; d=kuaishou.com; s=dkim; c=relaxed/relaxed; t=1713528471; h=from:subject:to:date:message-id; bh=0ojQK3AKejzo96bSCef2HP/0kdeYSr7fp5rz2r2c22s=; b=eidpqVcu7qp9qlJL/Ie4vWLUzzqvlJXH5h0f2IXPG5NEstSyRYUfwR71cOcNlTebaG5fobPr0uQ U2GO9iDZe+2HXf2R3CsI2b55oRPbyFxZEhwMVBab8B836foaZ+FwTQ2Din/O+aIUCxQKWdjbWuINE 13KaaF0k1iPXIqGmO/Y= Received: from rack-retrieve19671.idchb1az3.hb1.kwaidc.com (172.28.1.32) by bjm7-pm-mail01.kuaishou.com (172.28.1.1) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.20; Fri, 19 Apr 2024 20:07:50 +0800 From: zhoutaiyu To: CC: , , , , Subject: [PATCH] blk-throttle: fix repeat limit on bio with BIO_BPS_THROTTLED Date: Fri, 19 Apr 2024 20:07:47 +0800 Message-ID: <20240419120747.38031-1-zhoutaiyu@kuaishou.com> X-Mailer: git-send-email 2.35.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: bjm7-pm-mail09.kuaishou.com (172.28.1.91) To bjm7-pm-mail01.kuaishou.com (172.28.1.1) Give a concrete example, a bio is throtted because of reaching bps limit. It is then dispatched to request layer after a delay. In the request layer, it is split and the split bio flagged with BIO_BPS_THROTTLED will re-enter blkthrottle. The bio with BIO_BPS_THROTTLED should not be throttled for its bytes again. However, when the bps_limit and iops_limit are both set and sq->queue is not empty, the bio will be throttled again even the tg is still within iops limit. Test scrips: cgpath=/sys/fs/cgroup/blkio/test0 mkdir -p $cgpath echo "8:0 10485760" > $cgpath/blkio.throttle.write_bps_device echo "8:16 100000" > $cgpath/blkio.throttle.write_iops_device for ((i=0;i<50;i++));do fio -rw=write -direct=1 -bs=4M -iodepth=8 -size=200M -numjobs=1 \ -time_based=1 -runtime=30 -name=testt_$i -filename=testf_$i > /dev/null & echo $! > $cgpath/tasks done The output of iostat: Device: ... wMB/s ... sdb ... 3.75 ... sdb ... 2.50 ... sdb ... 3.75 ... sdb ... 2.50 ... sdb ... 3.75 ... In order to fix this problem, early throttled the bio only when sq->queue is no empty and the bio is not flagged with BIO_BPS_THROTTLED. Signed-off-by: zhoutaiyu --- block/blk-throttle.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/block/blk-throttle.c b/block/blk-throttle.c index f4850a6..499c006 100644 --- a/block/blk-throttle.c +++ b/block/blk-throttle.c @@ -913,7 +913,8 @@ static bool tg_may_dispatch(struct throtl_grp *tg, struct bio *bio, * queued. */ BUG_ON(tg->service_queue.nr_queued[rw] && - bio != throtl_peek_queued(&tg->service_queue.queued[rw])); + bio != throtl_peek_queued(&tg->service_queue.queued[rw]) && + !bio_flagged(bio, BIO_BPS_THROTTLED)); /* If tg->bps = -1, then BW is unlimited */ if ((bps_limit == U64_MAX && iops_limit == UINT_MAX) || @@ -2201,7 +2202,7 @@ bool __blk_throtl_bio(struct bio *bio) throtl_downgrade_check(tg); throtl_upgrade_check(tg); /* throtl is FIFO - if bios are already queued, should queue */ - if (sq->nr_queued[rw]) + if (sq->nr_queued[rw] && !bio_flagged(bio, BIO_BPS_THROTTLED)) break; /* if above limits, break to queue */ -- 1.8.3.1