From patchwork Thu Aug 31 06:10:18 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Valente X-Patchwork-Id: 111359 Delivered-To: patch@linaro.org Received: by 10.140.95.112 with SMTP id h103csp2073081qge; Wed, 30 Aug 2017 23:11:36 -0700 (PDT) X-Received: by 10.99.120.136 with SMTP id t130mr1196602pgc.176.1504159896011; Wed, 30 Aug 2017 23:11:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1504159896; cv=none; d=google.com; s=arc-20160816; b=F+0IVJlR2TBkYRQHjeQ58W15GbkXTf+3X3yWaZJg0gDL591HuOQZEkLOccVaO/aCx5 pjT5+Oj8Ni7djjIptiW2QEw0KHPEIqcKgotGWw70Qmakg5DHAYr3VpFHx/ZjnLzfZkht CD4/OGOsMAtfSgrSwVqine+92l+LbrUno8AocdOSDkRc9bJJh4iDZqpOm+q2mct9cDQ+ P8KnLdRVqyMOafRfA3tod80gaSlzFeQH9jJtjZgI5tCovhVL+WyVl4envsleyO6tSo1K TyU8w3Nh6Bp7RpY1/ZOZsLeKFMdJzyVwFesv+m/v40ByUgXNGbiCaNNnzibzEgDsx4tu MgyQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=XmbMzpbuqNXuYwNQzkW3qSu4aCN9oZ6f/iV6jXtvvaE=; b=jaTQ3Z6A3ILq5vzzoFefqjWkTVVnqCukvrkxeawuGvhP+esiQTy6Mq5RMl8vC+5iCV 581Y6nlC4cY02LiIjDr7WV8wwLGuoQnrdCklmB3fEq2R8Iw0osATbXWVACC70Zc87fkO uxOvrFy/uEx2sgnFU4x3V0JShCJGWpXBX/ByCxfszT44ucA/eWS+SHE0a/DEbYV2f2Hn Dz+fQd5zayNJAUsQR+n2CphzzZfxQW9AGT0+b16fv+CslELuI8BxPgBd7y7UkBkF7Bg5 rrOfaJYJKuBLEPg2oa284BZekQnoQaj6jNGudp21yybbfr5pyKcEfk2H5Mai0jGbXxfV ALiw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=hQSOVVdy; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y3si4852538pfd.614.2017.08.30.23.11.35; Wed, 30 Aug 2017 23:11:35 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=hQSOVVdy; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751525AbdHaGLe (ORCPT + 26 others); Thu, 31 Aug 2017 02:11:34 -0400 Received: from mail-wm0-f52.google.com ([74.125.82.52]:37523 "EHLO mail-wm0-f52.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751349AbdHaGKv (ORCPT ); Thu, 31 Aug 2017 02:10:51 -0400 Received: by mail-wm0-f52.google.com with SMTP id u26so22504171wma.0 for ; Wed, 30 Aug 2017 23:10:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=XmbMzpbuqNXuYwNQzkW3qSu4aCN9oZ6f/iV6jXtvvaE=; b=hQSOVVdylQDzA26b0f/cZmQV0vZAqL6i+YdFK4mS9SCtW7qBPfQjqgknAcR4SB9CuY kJS9wBIG06HC2y2oJpwA+fHqF0Sv2rOYkJd1E28fm9esQ0qjkTuvzNPyr9ZOqOyNpqif t8nFTyHPnzfB2Scgcy4lBAW/T5behJvfYydzA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=XmbMzpbuqNXuYwNQzkW3qSu4aCN9oZ6f/iV6jXtvvaE=; b=la9IApA73PXsJ9ORMdjpEB34W+R4vFshWRK3IxmEB2V7mRtfjQlHPSvL/KEEorKX40 gJynBo8lb24xB3Jd9FbJZ47ngfuclteuAOhFiCi3+3wNHZHLzjm5FE5bBmaQ7QQZ/Qzb Psl0zuiY11WmS9FDajN6m9WC4E8RXMi7eahjHMq4v1pYF0UUEvX3r9ZU3O1+bm6ugNFl tSt3HX8cXFbsmyFQVwUtXCIgeHPISFmL2znaM+JxJrL5p3xmNgdSotBIfCuKODiH8zyn H5OxlZ7ZsVKu19qSAgt8UTrydZ0l/SAZnUW3pcz/NLCLtf6Ubuw/cjNrTNXPW7M5sXgE TGDQ== X-Gm-Message-State: AHYfb5jCiC9wD/Pmu3wgnyPoWlrIOhDJ9dpWzNQa/rqdiRWL6fkLZhwQ PSpRPPjAndD+oDUm X-Received: by 10.28.51.136 with SMTP id z130mr2436815wmz.2.1504159850367; Wed, 30 Aug 2017 23:10:50 -0700 (PDT) Received: from localhost.localdomain ([185.14.8.94]) by smtp.gmail.com with ESMTPSA id t8sm6676897wrg.21.2017.08.30.23.10.48 (version=TLS1 cipher=AES128-SHA bits=128/128); Wed, 30 Aug 2017 23:10:49 -0700 (PDT) From: Paolo Valente To: Jens Axboe Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, ulf.hansson@linaro.org, broonie@kernel.org, mgorman@techsingularity.net, lee.tibbert@gmail.com, oleksandr@natalenko.name, Paolo Valente Subject: [PATCH BUGFIX/IMPROVEMENT 1/3] block, bfq: make lookup_next_entity push up vtime on expirations Date: Thu, 31 Aug 2017 08:10:18 +0200 Message-Id: <20170831061020.4426-2-paolo.valente@linaro.org> X-Mailer: git-send-email 2.10.0 In-Reply-To: <20170831061020.4426-1-paolo.valente@linaro.org> References: <20170831061020.4426-1-paolo.valente@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org To provide a very smooth service, bfq starts to serve a bfq_queue only if the queue is 'eligible', i.e., if the same queue would have started to be served in the ideal, perfectly fair system that bfq simulates internally. This is obtained by associating each queue with a virtual start time, and by computing a special system virtual time quantity: a queue is eligible only if the system virtual time has reached the virtual start time of the queue. Finally, bfq guarantees that, when a new queue must be set in service, there is always at least one eligible entity for each active parent entity in the scheduler. To provide this guarantee, the function __bfq_lookup_next_entity pushes up, for each parent entity on which it is invoked, the system virtual time to the minimum among the virtual start times of the entities in the active tree for the parent entity (more precisely, the push up occurs if the system virtual time happens to be lower than all such virtual start times). There is however a circumstance in which __bfq_lookup_next_entity cannot push up the system virtual time for a parent entity, even if the system virtual time is lower than the virtual start times of all the child entities in the active tree. It happens if one of the child entities is in service. In fact, in such a case, there is already an eligible entity, the in-service one, even if it may not be not present in the active tree (because in-service entities may be removed from the active tree). Unfortunately, in the last re-design of the hierarchical-scheduling engine, the reset of the pointer to the in-service entity for a given parent entity--reset to be done as a consequence of the expiration of the in-service entity--always happens after the function __bfq_lookup_next_entity has been invoked. This causes the function to think that there is still an entity in service for the parent entity, and then that the system virtual time cannot be pushed up, even if actually such a no-more-in-service entity has already been properly reinserted into the active tree (or in some other tree if no more active). Yet, the system virtual time *had* to be pushed up, to be ready to correctly choose the next queue to serve. Because of the lack of this push up, bfq may wrongly set in service a queue that had been speculatively pre-computed as the possible next-in-service queue, but that would no more be the one to serve after the expiration and the reinsertion into the active trees of the previously in-service entities. This commit addresses this issue by making __bfq_lookup_next_entity properly push up the system virtual time if an expiration is occurring. Signed-off-by: Paolo Valente Tested-by: Lee Tibbert Tested-by: Oleksander Natalenko --- block/bfq-iosched.c | 4 ++-- block/bfq-iosched.h | 4 ++-- block/bfq-wf2q.c | 58 +++++++++++++++++++++++++++++++++++++++-------------- 3 files changed, 47 insertions(+), 19 deletions(-) -- 2.10.0 diff --git a/block/bfq-iosched.c b/block/bfq-iosched.c index 436b6ca..a10f147 100644 --- a/block/bfq-iosched.c +++ b/block/bfq-iosched.c @@ -720,7 +720,7 @@ static void bfq_updated_next_req(struct bfq_data *bfqd, entity->budget = new_budget; bfq_log_bfqq(bfqd, bfqq, "updated next rq: new budget %lu", new_budget); - bfq_requeue_bfqq(bfqd, bfqq); + bfq_requeue_bfqq(bfqd, bfqq, false); } } @@ -2563,7 +2563,7 @@ static void __bfq_bfqq_expire(struct bfq_data *bfqd, struct bfq_queue *bfqq) bfq_del_bfqq_busy(bfqd, bfqq, true); } else { - bfq_requeue_bfqq(bfqd, bfqq); + bfq_requeue_bfqq(bfqd, bfqq, true); /* * Resort priority tree of potential close cooperators. */ diff --git a/block/bfq-iosched.h b/block/bfq-iosched.h index 859f0a8..3e2659c 100644 --- a/block/bfq-iosched.h +++ b/block/bfq-iosched.h @@ -817,7 +817,6 @@ extern const int bfq_timeout; struct bfq_queue *bic_to_bfqq(struct bfq_io_cq *bic, bool is_sync); void bic_set_bfqq(struct bfq_io_cq *bic, struct bfq_queue *bfqq, bool is_sync); struct bfq_data *bic_to_bfqd(struct bfq_io_cq *bic); -void bfq_requeue_bfqq(struct bfq_data *bfqd, struct bfq_queue *bfqq); void bfq_pos_tree_add_move(struct bfq_data *bfqd, struct bfq_queue *bfqq); void bfq_weights_tree_add(struct bfq_data *bfqd, struct bfq_entity *entity, struct rb_root *root); @@ -917,7 +916,8 @@ void __bfq_bfqd_reset_in_service(struct bfq_data *bfqd); void bfq_deactivate_bfqq(struct bfq_data *bfqd, struct bfq_queue *bfqq, bool ins_into_idle_tree, bool expiration); void bfq_activate_bfqq(struct bfq_data *bfqd, struct bfq_queue *bfqq); -void bfq_requeue_bfqq(struct bfq_data *bfqd, struct bfq_queue *bfqq); +void bfq_requeue_bfqq(struct bfq_data *bfqd, struct bfq_queue *bfqq, + bool expiration); void bfq_del_bfqq_busy(struct bfq_data *bfqd, struct bfq_queue *bfqq, bool expiration); void bfq_add_bfqq_busy(struct bfq_data *bfqd, struct bfq_queue *bfqq); diff --git a/block/bfq-wf2q.c b/block/bfq-wf2q.c index 3183b39..138732e 100644 --- a/block/bfq-wf2q.c +++ b/block/bfq-wf2q.c @@ -44,7 +44,8 @@ static unsigned int bfq_class_idx(struct bfq_entity *entity) BFQ_DEFAULT_GRP_CLASS - 1; } -static struct bfq_entity *bfq_lookup_next_entity(struct bfq_sched_data *sd); +static struct bfq_entity *bfq_lookup_next_entity(struct bfq_sched_data *sd, + bool expiration); static bool bfq_update_parent_budget(struct bfq_entity *next_in_service); @@ -54,6 +55,8 @@ static bool bfq_update_parent_budget(struct bfq_entity *next_in_service); * @new_entity: if not NULL, pointer to the entity whose activation, * requeueing or repositionig triggered the invocation of * this function. + * @expiration: id true, this function is being invoked after the + * expiration of the in-service entity * * This function is called to update sd->next_in_service, which, in * its turn, may change as a consequence of the insertion or @@ -72,7 +75,8 @@ static bool bfq_update_parent_budget(struct bfq_entity *next_in_service); * entity. */ static bool bfq_update_next_in_service(struct bfq_sched_data *sd, - struct bfq_entity *new_entity) + struct bfq_entity *new_entity, + bool expiration) { struct bfq_entity *next_in_service = sd->next_in_service; bool parent_sched_may_change = false; @@ -130,7 +134,7 @@ static bool bfq_update_next_in_service(struct bfq_sched_data *sd, if (replace_next) next_in_service = new_entity; } else /* invoked because of a deactivation: lookup needed */ - next_in_service = bfq_lookup_next_entity(sd); + next_in_service = bfq_lookup_next_entity(sd, expiration); if (next_in_service) { parent_sched_may_change = !sd->next_in_service || @@ -1134,10 +1138,12 @@ static void __bfq_activate_requeue_entity(struct bfq_entity *entity, * @requeue: true if this is a requeue, which implies that bfqq is * being expired; thus ALL its ancestors stop being served and must * therefore be requeued + * @expiration: true if this function is being invoked in the expiration path + * of the in-service queue */ static void bfq_activate_requeue_entity(struct bfq_entity *entity, bool non_blocking_wait_rq, - bool requeue) + bool requeue, bool expiration) { struct bfq_sched_data *sd; @@ -1145,7 +1151,8 @@ static void bfq_activate_requeue_entity(struct bfq_entity *entity, sd = entity->sched_data; __bfq_activate_requeue_entity(entity, sd, non_blocking_wait_rq); - if (!bfq_update_next_in_service(sd, entity) && !requeue) + if (!bfq_update_next_in_service(sd, entity, expiration) && + !requeue) break; } } @@ -1201,6 +1208,8 @@ bool __bfq_deactivate_entity(struct bfq_entity *entity, bool ins_into_idle_tree) * bfq_deactivate_entity - deactivate an entity representing a bfq_queue. * @entity: the entity to deactivate. * @ins_into_idle_tree: true if the entity can be put into the idle tree + * @expiration: true if this function is being invoked in the expiration path + * of the in-service queue */ static void bfq_deactivate_entity(struct bfq_entity *entity, bool ins_into_idle_tree, @@ -1229,7 +1238,7 @@ static void bfq_deactivate_entity(struct bfq_entity *entity, * then, since entity has just been * deactivated, a new one must be found. */ - bfq_update_next_in_service(sd, NULL); + bfq_update_next_in_service(sd, NULL, expiration); if (sd->next_in_service || sd->in_service_entity) { /* @@ -1288,7 +1297,7 @@ static void bfq_deactivate_entity(struct bfq_entity *entity, __bfq_requeue_entity(entity); sd = entity->sched_data; - if (!bfq_update_next_in_service(sd, entity) && + if (!bfq_update_next_in_service(sd, entity, expiration) && !expiration) /* * next_in_service unchanged or not causing @@ -1423,12 +1432,14 @@ __bfq_lookup_next_entity(struct bfq_service_tree *st, bool in_service) /** * bfq_lookup_next_entity - return the first eligible entity in @sd. * @sd: the sched_data. + * @expiration: true if we are on the expiration path of the in-service queue * * This function is invoked when there has been a change in the trees - * for sd, and we need know what is the new next entity after this - * change. + * for sd, and we need to know what is the new next entity to serve + * after this change. */ -static struct bfq_entity *bfq_lookup_next_entity(struct bfq_sched_data *sd) +static struct bfq_entity *bfq_lookup_next_entity(struct bfq_sched_data *sd, + bool expiration) { struct bfq_service_tree *st = sd->service_tree; struct bfq_service_tree *idle_class_st = st + (BFQ_IOPRIO_CLASSES - 1); @@ -1455,8 +1466,24 @@ static struct bfq_entity *bfq_lookup_next_entity(struct bfq_sched_data *sd) * class, unless the idle class needs to be served. */ for (; class_idx < BFQ_IOPRIO_CLASSES; class_idx++) { + /* + * If expiration is true, then bfq_lookup_next_entity + * is being invoked as a part of the expiration path + * of the in-service queue. In this case, even if + * sd->in_service_entity is not NULL, + * sd->in_service_entiy at this point is actually not + * in service any more, and, if needed, has already + * been properly queued or requeued into the right + * tree. The reason why sd->in_service_entity is still + * not NULL here, even if expiration is true, is that + * sd->in_service_entiy is reset as a last step in the + * expiration path. So, if expiration is true, tell + * __bfq_lookup_next_entity that there is no + * sd->in_service_entity. + */ entity = __bfq_lookup_next_entity(st + class_idx, - sd->in_service_entity); + sd->in_service_entity && + !expiration); if (entity) break; @@ -1569,7 +1596,7 @@ struct bfq_queue *bfq_get_next_queue(struct bfq_data *bfqd) for_each_entity(entity) { struct bfq_sched_data *sd = entity->sched_data; - if (!bfq_update_next_in_service(sd, NULL)) + if (!bfq_update_next_in_service(sd, NULL, false)) break; } @@ -1617,16 +1644,17 @@ void bfq_activate_bfqq(struct bfq_data *bfqd, struct bfq_queue *bfqq) struct bfq_entity *entity = &bfqq->entity; bfq_activate_requeue_entity(entity, bfq_bfqq_non_blocking_wait_rq(bfqq), - false); + false, false); bfq_clear_bfqq_non_blocking_wait_rq(bfqq); } -void bfq_requeue_bfqq(struct bfq_data *bfqd, struct bfq_queue *bfqq) +void bfq_requeue_bfqq(struct bfq_data *bfqd, struct bfq_queue *bfqq, + bool expiration) { struct bfq_entity *entity = &bfqq->entity; bfq_activate_requeue_entity(entity, false, - bfqq == bfqd->in_service_queue); + bfqq == bfqd->in_service_queue, expiration); } /* From patchwork Thu Aug 31 06:10:19 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Valente X-Patchwork-Id: 111357 Delivered-To: patch@linaro.org Received: by 10.140.95.112 with SMTP id h103csp2072458qge; Wed, 30 Aug 2017 23:11:03 -0700 (PDT) X-Received: by 10.84.194.131 with SMTP id h3mr1401426pld.196.1504159863333; Wed, 30 Aug 2017 23:11:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1504159863; cv=none; d=google.com; s=arc-20160816; b=ZX/CfpuF6QEEctLUHbZH9BGEQw8+8FZYibL84wURDUkS7lVcFfbiSBmMkaKvoDxzwT VWT98pw0mxhDjA/c1qsSCvBtxYiZRnsXuYt5J7ozUfk0byYWW3FCorlJTtV6UCkbxOrN r4G4K89lquEZADCU2VDBS4qlp5EjJDDwprX0hE985GRib1A2kdrcBxVcq/ClA+iejESD Z15Vo0sG0F8XQAZssiPVgHKj1nr5Glm9BEosL1cp4my1HEfyfhinN/XCVkCT/Iz1MMxW dg19AVqJFUhuOvQUjkkkN4p3lXO51WUkcW2mmNbCZPFXDBvEwiQqWDF3EIN+5qrGQ5UI ZWpQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=Q+NJI0nO1+RlOxxT55ldhSl+HqyGd2iiyCvFJqV6zZc=; b=Vx4rlFwKtR18utzXfA/9hEtu2LqPXm0GwmzFfS6Pau58hWsRraqO896YV9sKn7HIuR FJEUJbnz6oIrEdX06Q0rsB0jVkvbJFItRU136uQIFa7MigDSzWouNGvjAxi1cRno86XL siApUWHxGrduIojWcHUM4VZOPr17dVK1FBk9Bm0MKuLnM0ISVscDRDkPGGlu22EQAJYl K7DpnAkaxa2uiFPIBc99DIkTEF/Y8Bel8+vjCGpESCEuawXWn2SkHuuJ9s8ZwFhXwON5 hs9rdx8zxnOnuSZKlZCrySqh76eEujrCeH3CyFVOvDH3mK2FpLIbwD0NK5vMrTZAYo33 vNnw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=cNfQ/vbY; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g12si6167747pln.291.2017.08.30.23.11.02; Wed, 30 Aug 2017 23:11:03 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=cNfQ/vbY; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751483AbdHaGK7 (ORCPT + 26 others); Thu, 31 Aug 2017 02:10:59 -0400 Received: from mail-wm0-f51.google.com ([74.125.82.51]:35480 "EHLO mail-wm0-f51.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751397AbdHaGKx (ORCPT ); Thu, 31 Aug 2017 02:10:53 -0400 Received: by mail-wm0-f51.google.com with SMTP id a80so21720202wma.0 for ; Wed, 30 Aug 2017 23:10:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=Q+NJI0nO1+RlOxxT55ldhSl+HqyGd2iiyCvFJqV6zZc=; b=cNfQ/vbYxS62EN/kaUrFzeBGf8WR7plGCp/58EE/Sdic5dRrnuay2h8DFqV9UfmfPG BVdYyCcCbR8QpjFFvoxWM7EdsqefD5cM1Uz8b+qNRZvGNN7xyyfz0swa9DnBy+q08Ym8 gQm2glBNyYxhOJc23PIewieXPjr+U7MYB0lps= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=Q+NJI0nO1+RlOxxT55ldhSl+HqyGd2iiyCvFJqV6zZc=; b=ssbmCW/Cvt2bkM4RKMaLG4dHZdmRsBhaB4S4RdF/tcsTW/M2oH29Ock22w+ZEuOFaf 2HJOG0m0iE5OVRafbDa9la/ZTJAKF1CEoNt8bHAzka1j77sclhAps4bw6c7bQocnK226 GFk5ARP/JbCDugGKX+mLP16V1Xet2v68g5TRvsxa8iro41V4iGnul59Opv0z6ZpYLgYu ZdLtZUj2aELTTBO5hDPmj+737Ca0Ae54w98QPDA9uxud3js0S2jmSEHniliDK+D1+jt0 ksyp2zY59XLLRX/2IPHGDxBblXHwzASY3ACOcmPY0rIOWZHe556+1pCLA6nSDfI+NuAx S8Ew== X-Gm-Message-State: AHYfb5i3f/DJHQCEHrtqZda/4JNlbBZAKAvaIDqfDtlBJyeFXW4EHg0t IL4Fh5Ix6NlPRxiOzj1nnw== X-Received: by 10.28.12.206 with SMTP id 197mr2920987wmm.18.1504159852258; Wed, 30 Aug 2017 23:10:52 -0700 (PDT) Received: from localhost.localdomain ([185.14.8.94]) by smtp.gmail.com with ESMTPSA id t8sm6676897wrg.21.2017.08.30.23.10.50 (version=TLS1 cipher=AES128-SHA bits=128/128); Wed, 30 Aug 2017 23:10:51 -0700 (PDT) From: Paolo Valente To: Jens Axboe Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, ulf.hansson@linaro.org, broonie@kernel.org, mgorman@techsingularity.net, lee.tibbert@gmail.com, oleksandr@natalenko.name, Paolo Valente Subject: [PATCH BUGFIX/IMPROVEMENT 2/3] block, bfq: remove direct switch to an entity in higher class Date: Thu, 31 Aug 2017 08:10:19 +0200 Message-Id: <20170831061020.4426-3-paolo.valente@linaro.org> X-Mailer: git-send-email 2.10.0 In-Reply-To: <20170831061020.4426-1-paolo.valente@linaro.org> References: <20170831061020.4426-1-paolo.valente@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org If the function bfq_update_next_in_service is invoked as a consequence of the activation or requeueing of an entity, say E, and finds out that E belongs to a higher-priority class than that of the current next-in-service entity, then it sets next_in_service directly to E. But this may lead to anomalous schedules, because E may happen not be eligible for service, because its virtual start time is higher than the system virtual time for its service tree. This commit addresses this issue by simply removing this direct switch. Signed-off-by: Paolo Valente Tested-by: Lee Tibbert Tested-by: Oleksander Natalenko --- block/bfq-wf2q.c | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) -- 2.10.0 diff --git a/block/bfq-wf2q.c b/block/bfq-wf2q.c index 138732e..eeaf326 100644 --- a/block/bfq-wf2q.c +++ b/block/bfq-wf2q.c @@ -86,9 +86,8 @@ static bool bfq_update_next_in_service(struct bfq_sched_data *sd, * or repositiong of an entity that does not coincide with * sd->next_in_service, then a full lookup in the active tree * can be avoided. In fact, it is enough to check whether the - * just-modified entity has a higher priority than - * sd->next_in_service, or, even if it has the same priority - * as sd->next_in_service, is eligible and has a lower virtual + * just-modified entity has the same priority as + * sd->next_in_service, is eligible and has a lower virtual * finish time than sd->next_in_service. If this compound * condition holds, then the new entity becomes the new * next_in_service. Otherwise no change is needed. @@ -104,9 +103,8 @@ static bool bfq_update_next_in_service(struct bfq_sched_data *sd, /* * If there is already a next_in_service candidate - * entity, then compare class priorities or timestamps - * to decide whether to replace sd->service_tree with - * new_entity. + * entity, then compare timestamps to decide whether + * to replace sd->service_tree with new_entity. */ if (next_in_service) { unsigned int new_entity_class_idx = @@ -114,10 +112,6 @@ static bool bfq_update_next_in_service(struct bfq_sched_data *sd, struct bfq_service_tree *st = sd->service_tree + new_entity_class_idx; - /* - * For efficiency, evaluate the most likely - * sub-condition first. - */ replace_next = (new_entity_class_idx == bfq_class_idx(next_in_service) @@ -125,10 +119,7 @@ static bool bfq_update_next_in_service(struct bfq_sched_data *sd, !bfq_gt(new_entity->start, st->vtime) && bfq_gt(next_in_service->finish, - new_entity->finish)) - || - new_entity_class_idx < - bfq_class_idx(next_in_service); + new_entity->finish)); } if (replace_next) From patchwork Thu Aug 31 06:10:20 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Valente X-Patchwork-Id: 111358 Delivered-To: patch@linaro.org Received: by 10.140.95.112 with SMTP id h103csp2072796qge; Wed, 30 Aug 2017 23:11:20 -0700 (PDT) X-Received: by 10.84.217.10 with SMTP id o10mr1367379pli.75.1504159880136; Wed, 30 Aug 2017 23:11:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1504159880; cv=none; d=google.com; s=arc-20160816; b=Lkoi5irrYSslHhY/kg4LbdL0fh2I8WK+CagupXn9sJ86UIGWQstcaQCIkhTAUvFGRz KNCR+pMpHdKOYtjcQD99QIqdwaO2fcnDrrVX7+AQHgysJByyeurr9se4UpZW4E0zxFat D4OUnxh5lbnD6IhkSfse+yvrZLq1I63njl8uaMjPde/QbfDMneZZvBzhnE3pn6qGUmxC PiSl9o1cSZgh5FGanYaah5DuAFw/3cJCPXHKvlOY88/UmcjDz4fkKyJHzgNx760q/n3u mtUcyRChdjIXxlwFN3zQ6lUtFHT4bR/hLBsB+mykKRFwOTfxzRemrRTiRZ/lURfE6rMU kMWg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=tFlb0gTtD3R9ZfOW4b3rsoVbqESDnjC4fYXlTnwXMi8=; b=p2PYJ9/52ZXCZA/DTLHmT+qIzNjhH/CmS6kbD/tDRVf3aVAdNMFOohaJCXSRFu6Erj mT9TaziBgtsxt/rOBVmZ0sLNOuDbhpxYkeE1dYenE9H5DaBRLZsOxPw4uEd33ZmtCpyT EoEmZSyVc+N3n/sg1x3lWl0JxME+TVr7clecIl3S09ClKuakZ5XER8SPrbCvrStoxWeE HBpCPQy/iRnW+SJUjB6gmElrDrIvxGDWsZk3ImdRyIIQ68nXV6N55RVqDQSSBeg8BRfm auBgPYkuTiHjNqoCFv7qNsV3Thu4Ffxv+8DYgzyVwajh6tyMigs4XLEzhyUF4I4QK/Ne CafA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Fs58h5Vy; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h15si6255291plk.820.2017.08.30.23.11.17; Wed, 30 Aug 2017 23:11:20 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Fs58h5Vy; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751457AbdHaGLP (ORCPT + 26 others); Thu, 31 Aug 2017 02:11:15 -0400 Received: from mail-wm0-f50.google.com ([74.125.82.50]:33205 "EHLO mail-wm0-f50.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751417AbdHaGK4 (ORCPT ); Thu, 31 Aug 2017 02:10:56 -0400 Received: by mail-wm0-f50.google.com with SMTP id r202so6107193wmd.0 for ; Wed, 30 Aug 2017 23:10:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=tFlb0gTtD3R9ZfOW4b3rsoVbqESDnjC4fYXlTnwXMi8=; b=Fs58h5VyAXQfRN2FUukaD6fnNaK72Y0k1FVlf7XAZrPQLUjqdoW1a5+3uDSOKlZhea N3+NgSw9GOOSDptILosil9f1cd3+2bv3+LzCGUK/EqZiG+SRvaQ8Ht17zygA2vE4rQB5 KmaJ7YnqTPF94DhkuJwk94q6LyvBrMsbAsi2E= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=tFlb0gTtD3R9ZfOW4b3rsoVbqESDnjC4fYXlTnwXMi8=; b=IC4s8/IDBzbMTuKDlGeemtyPrYtrzl+2FtidfBMt/CMTGIUv1obTy4HHhn93lk3DtY 0Vj7aKAR8ikFGVSY/2qYA0fwZpO3h4vThHICzxpXGuf45E4nlHHtbhFKw/dWhJcu3s8I yEP83wsaWKhbQHq1QDzVyYFNez+cvi8hHyW8JK+eJ5+voaShvmDDF8x2+48i7pOOecia /1VWT12QP7cZRiZ0jFIsfsf3yA7zYA/9aCRsS7qvIFZ96SLn3sJDhT0Okxk6a/QUoMEm cpxY76Yvt6hHPXsOM9WRkbmltz6+r8nQLNAGVe+A+YNErgaEYe7P0SG+cWFyb8LCPSTs 7kbA== X-Gm-Message-State: AHYfb5gzUkae0UXGohDFb+Wg3/DkvYlSQ9HE7i6ISLCGdmOUItxQjxzd 5si+86U3FbBnUg8b X-Received: by 10.28.14.73 with SMTP id 70mr2488289wmo.34.1504159854260; Wed, 30 Aug 2017 23:10:54 -0700 (PDT) Received: from localhost.localdomain ([185.14.8.94]) by smtp.gmail.com with ESMTPSA id t8sm6676897wrg.21.2017.08.30.23.10.52 (version=TLS1 cipher=AES128-SHA bits=128/128); Wed, 30 Aug 2017 23:10:53 -0700 (PDT) From: Paolo Valente To: Jens Axboe Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, ulf.hansson@linaro.org, broonie@kernel.org, mgorman@techsingularity.net, lee.tibbert@gmail.com, oleksandr@natalenko.name, Paolo Valente Subject: [PATCH BUGFIX/IMPROVEMENT 3/3] block, bfq: guarantee update_next_in_service always returns an eligible entity Date: Thu, 31 Aug 2017 08:10:20 +0200 Message-Id: <20170831061020.4426-4-paolo.valente@linaro.org> X-Mailer: git-send-email 2.10.0 In-Reply-To: <20170831061020.4426-1-paolo.valente@linaro.org> References: <20170831061020.4426-1-paolo.valente@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org If the function bfq_update_next_in_service is invoked as a consequence of the activation or requeueing of an entity, say E, then it doesn't invoke bfq_lookup_next_entity to get the next-in-service entity. In contrast, it follows a shorter path: if E happens to be eligible (see commit "bfq-sq-mq: make lookup_next_entity push up vtime on expirations" for details on eligibility) and to have a lower virtual finish time than the current candidate as next-in-service entity, then E directly becomes the next-in-service entity. Unfortunately, there is a corner case for which this shorter path makes bfq_update_next_in_service choose a non eligible entity: it occurs if both E and the current next-in-service entity happen to be non eligible when bfq_update_next_in_service is invoked. In this case, E is not set as next-in-service, and, since bfq_lookup_next_entity is not invoked, the state of the parent entity is not updated so as to end up with an eligible entity as the proper next-in-service entity. In this respect, next-in-service is actually allowed to be non eligible while some queue is in service: since no system-virtual-time push-up can be performed in that case (see again commit "bfq-sq-mq: make lookup_next_entity push up vtime on expirations" for details), next-in-service is chosen, speculatively, as a function of the possible value that the system virtual time may get after a push up. But the correctness of the schedule breaks if next-in-service is still a non eligible entity when it is time to set in service the next entity. Unfortunately, this may happen in the above corner case. This commit fixes this problem by making bfq_update_next_in_service invoke bfq_lookup_next_entity not only if the above shorter path cannot be taken, but also if the shorter path is taken but fails to yield an eligible next-in-service entity. Signed-off-by: Paolo Valente Tested-by: Lee Tibbert Tested-by: Oleksander Natalenko --- block/bfq-wf2q.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) -- 2.10.0 diff --git a/block/bfq-wf2q.c b/block/bfq-wf2q.c index eeaf326..add54f2 100644 --- a/block/bfq-wf2q.c +++ b/block/bfq-wf2q.c @@ -80,6 +80,7 @@ static bool bfq_update_next_in_service(struct bfq_sched_data *sd, { struct bfq_entity *next_in_service = sd->next_in_service; bool parent_sched_may_change = false; + bool change_without_lookup = false; /* * If this update is triggered by the activation, requeueing @@ -99,7 +100,7 @@ static bool bfq_update_next_in_service(struct bfq_sched_data *sd, * set to true, and left as true if * sd->next_in_service is NULL. */ - bool replace_next = true; + change_without_lookup = true; /* * If there is already a next_in_service candidate @@ -112,7 +113,7 @@ static bool bfq_update_next_in_service(struct bfq_sched_data *sd, struct bfq_service_tree *st = sd->service_tree + new_entity_class_idx; - replace_next = + change_without_lookup = (new_entity_class_idx == bfq_class_idx(next_in_service) && @@ -122,15 +123,16 @@ static bool bfq_update_next_in_service(struct bfq_sched_data *sd, new_entity->finish)); } - if (replace_next) + if (change_without_lookup) next_in_service = new_entity; - } else /* invoked because of a deactivation: lookup needed */ + } + + if (!change_without_lookup) /* lookup needed */ next_in_service = bfq_lookup_next_entity(sd, expiration); - if (next_in_service) { + if (next_in_service) parent_sched_may_change = !sd->next_in_service || bfq_update_parent_budget(next_in_service); - } sd->next_in_service = next_in_service;