Received: by 2002:ab2:6203:0:b0:1f5:f2ab:c469 with SMTP id o3csp1004224lqt; Fri, 19 Apr 2024 18:49:05 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWBA//cCwXqCY+/aFsWE8rAftc2cY41JmKNYDnFIx0yvRLuOmwj9L2XjVjxJNc9jy1k4bFyn01TBhu/X45bUexFV/NzQ61N+w0ZvLLtFw== X-Google-Smtp-Source: AGHT+IG6FRgrofPSJu7Ps8TEE+wyariFUAA8Qn9cVbgcUgWkeARwKy40awEBQqhes833HhW8qLZV X-Received: by 2002:a05:6a00:130e:b0:6ec:fc71:3be2 with SMTP id j14-20020a056a00130e00b006ecfc713be2mr4685492pfu.21.1713577745020; Fri, 19 Apr 2024 18:49:05 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713577745; cv=pass; d=google.com; s=arc-20160816; b=JPSzbpEqs5LYUMzSB19tbwlHKbqAdYwmq8P7k5ia/B37a15L+M92FQhEjrc6wC6A9/ mpLqTUBF6tpAV3CvY+u/kMdJH8EdhtUFdx5f/WtFwqBpKHsBf2dhzlTF43ckIWKDKlpQ A28gUw9F5E9lakttsaWjCA0yKg+z3x6i3v3d7t3Gttb2pC/qsGBNcia9rsN12mI79E87 BP6niIXu4k/OA1t0hR7hml1+7mjl4TyiA7wUMMONkTPf7JYHfbMHKEQt8mUr5uE6MNxQ S1Usgb+dsrfS8fFu+Z419bYMeM7Mimvb0ZIHv73U+HdMX+OpN9xGzpi/3YBAwzHDkrYX 2DTg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:user-agent:date:message-id:from :references:cc:to:subject; bh=BWE/BNRMU6OwY1cIulop+yTmygjSfrTAfkHj19jASe0=; fh=f8o9oFli7BZIo63RTmew/AAZE1qtEJBSLcRF7zkH8T4=; b=Wfk76lrnG5oqdlAIk7ZRaZtwYvwWQfgDQiVKBVFyHcFoNJpFVDops1Eid2AKNdr6db e+tX0OTzZOswa85WFWvPoDlOqNdo55kK/kwSZyoaw/DuxaUdmZIxce0jNo/mJdoZklIr 8eaNKAephRCznaTaTI5UWA9ydv7g/N/6VzBaQTpL5zLdny+MmN00fNYHcaDNCtVtF1Pi sAOG1eBJMP1DwmL7F1mUhwo/1BA5tS9ekA/sjhKIGNja1Q21MBxgET+wQp+Vc43sunGl yvTz/Dz7Z2fkfXVDCBIi8NF/XVlGx8zYG/9bfWMztB83gMRgJIFgt1/HfaAC58jKHzHM IkfA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=huaweicloud.com); spf=pass (google.com: domain of linux-kernel+bounces-152077-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-152077-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id o9-20020a056a001b4900b006ed99532c2asi4080283pfv.296.2024.04.19.18.49.04 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Apr 2024 18:49:05 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-152077-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; arc=pass (i=1 spf=pass spfdomain=huaweicloud.com); spf=pass (google.com: domain of linux-kernel+bounces-152077-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-152077-linux.lists.archive=gmail.com@vger.kernel.org" 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 A49902822B4 for ; Sat, 20 Apr 2024 01:49:04 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6B689D535; Sat, 20 Apr 2024 01:48:30 +0000 (UTC) Received: from dggsgout11.his.huawei.com (unknown [45.249.212.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B84F7DDB1; Sat, 20 Apr 2024 01:48:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.51 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713577709; cv=none; b=FVVeZxur4IZr0sMDuo92lnRxAxcK5C0VJoCxwsm9kNxLhxf4Uhuvzqdcr/veYgwdVHLl+KPMhA9VCItOr3sPo0YgKb8LsVN7h3S1UqqWvJrSFQPVzdo31peFj4AJuxRLoDbgloJeDkFY2baKfEOOw0fvC4L59+Fk9dSOQ0OK0wU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713577709; c=relaxed/simple; bh=PRyhg7e+mN6SBwakmbZV54xUMWp9H3k8cyG0AlwU5UQ=; h=Subject:To:Cc:References:From:Message-ID:Date:MIME-Version: In-Reply-To:Content-Type; b=XyiFC0FAwiLWn3Ln8c66D6mNNYu5Y5k/bUn/H07+mQZQpLnIhRi79oBdAEcMmLpbvD8ncJ0710Q0yeXYA3pkGAud+wx+LwJ7vByl2cSKFJ824zb+ofT78zAgIW96tBhhR34FeXQYb7j/AEtxCCE2tgGDAaHPhEVsgIGHLOrrDcQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com; spf=pass smtp.mailfrom=huaweicloud.com; arc=none smtp.client-ip=45.249.212.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huaweicloud.com Received: from mail.maildlp.com (unknown [172.19.163.216]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4VLvY94bfyz4f3lWJ; Sat, 20 Apr 2024 09:48:13 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id A6A581A0DE0; Sat, 20 Apr 2024 09:48:22 +0800 (CST) Received: from [10.174.176.73] (unknown [10.174.176.73]) by APP1 (Coremail) with SMTP id cCh0CgBHGBHkHiNmgGPIKQ--.24502S3; Sat, 20 Apr 2024 09:48:22 +0800 (CST) Subject: Re: [PATCH] blk-throttle: fix repeat limit on bio with BIO_BPS_THROTTLED To: zhoutaiyu , tj@kernel.org Cc: josef@toxicpanda.com, axboe@kernel.dk, cgroups@vger.kernel.org, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, "yukuai (C)" References: <20240419120747.38031-1-zhoutaiyu@kuaishou.com> From: Yu Kuai Message-ID: Date: Sat, 20 Apr 2024 09:48:20 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.8.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 In-Reply-To: <20240419120747.38031-1-zhoutaiyu@kuaishou.com> Content-Type: text/plain; charset=gbk; format=flowed Content-Transfer-Encoding: 8bit X-CM-TRANSID:cCh0CgBHGBHkHiNmgGPIKQ--.24502S3 X-Coremail-Antispam: 1UD129KBjvJXoWxWr1Uur45Cr4fKFyruFW3Jrb_yoW5Gw17pr WxuF4UJw1kXF4qkr45Kr1agF93t3yxAryUAas3J3yayFW3Wry2gr1UZF18A3y0vFs7GayU ZFs7Xr93G3WjyrJanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUyEb4IE77IF4wAFF20E14v26r4j6ryUM7CY07I20VC2zVCF04k2 6cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28lY4IEw2IIxxk0rwA2F7IY1VAKz4 vEj48ve4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_Ar0_tr1l84ACjcxK6xIIjxv20xvEc7Cj xVAFwI0_Gr1j6F4UJwA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x 0267AKxVW0oVCq3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG 6I80ewAv7VC0I7IYx2IY67AKxVWUJVWUGwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFV Cjc4AY6r1j6r4UM4x0Y48IcVAKI48JMxk0xIA0c2IEe2xFo4CEbIxvr21l42xK82IYc2Ij 64vIr41l4I8I3I0E4IkC6x0Yz7v_Jr0_Gr1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s026x 8GjcxK67AKxVWUGVWUWwC2zVAF1VAY17CE14v26r1q6r43MIIYrxkI7VAKI48JMIIF0xvE 2Ix0cI8IcVAFwI0_Jr0_JF4lIxAIcVC0I7IYx2IY6xkF7I0E14v26r1j6r4UMIIF0xvE42 xK8VAvwI8IcIk0rVWrZr1j6s0DMIIF0xvEx4A2jsIE14v26r1j6r4UMIIF0xvEx4A2jsIE c7CjxVAFwI0_Jr0_GrUvcSsGvfC2KfnxnUUI43ZEXa7IU1zuWJUUUUU== X-CM-SenderInfo: 51xn3trlr6x35dzhxuhorxvhhfrp/ Hi, ?? 2024/04/19 20:07, zhoutaiyu ะด??: > 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. I don't understand here, split bio should be throttled by iops limit again, this is expected. If you mean that that throtl time calculated by iops_limit is wrong, you need to provide more informatiom. > > 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 What? 8:0 and 8:16? > 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)) No, this change is wrong. Split IO will not be throttled by iops limit anymore. Thanks, Kuai > break; > > /* if above limits, break to queue */ >