Received: by 2002:ac0:98c7:0:0:0:0:0 with SMTP id g7-v6csp176554imd; Wed, 31 Oct 2018 16:51:40 -0700 (PDT) X-Google-Smtp-Source: AJdET5fAiQEx57ZWr+gV95im0DvsvTsZ265GpFKicn5u+FODZMA6PFWoEQw24Z+I54smHAKEdkbz X-Received: by 2002:a17:902:6184:: with SMTP id u4-v6mr5400435plj.291.1541029900220; Wed, 31 Oct 2018 16:51:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1541029900; cv=none; d=google.com; s=arc-20160816; b=vQ97J/P/QpQxptlcGKYQMU7Lq6pZXMM7ba0yrDmif4CNrWVph8IQHRyp9sjxPDlhAA f5QNV78cy/CX5b1TbJa+9l3tWBxPrAWvBuJ+Qxabb1GhjLvjbLtLV6YFCt3qTOnZCAIi jLsvdEAun/DAHvfxUsxbfs1ydKDqtV+gnQ8z9xNE3Xz4C8ghaA1EWEr+qPNDg1+zSXOG GVCiqdkQe0ccPFvCOvVeQoNIkBpYoXZqK2oeTXpruEf7uNluXbQ8ABHj8lC21zzU2BNt 1LhHJSEdvO/xL3FVJtc4d5d/+TYpIaj1WLKp8tGB1F/H8zwfRoHucFopVdoYZQpR1aNE lDpg== 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; bh=+UN9WAlyAEd1rHaVjk5i/P+7oFV9Y7nahZa5UfGhzjk=; b=Z78WlqFXvRFIuOs8HyTPqieZVf0PR5dsaZ2FgRb/EESrxxIx4RMvG/EH9IcvkasR97 /8FiXOapx+hw7P6hE6NB+CYgQdENIoau2o2jry54YaRKFtKpmdAS+8P5kP9LgtroW6hn LeMdNpbbcxr90WUvIFs0ipk6K+vPBHm723FU8PDO9f4RWK75RZxUWCwq8KiQ9efat32L B9qqdua/87UO1BHj3/9H9aFdpWMhStazLiWgb0zDisioXJnfq8BmawKD0Q30kVQYJjHW 9/1UBgW4WT1jHFNZPEDG5GNIivbi1QWVngknM+P0oFcLGJvK5IC05yrP7AYWF1jMkh2C Vu3Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=DNlNTCbV; 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=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p6-v6si28251727pgd.312.2018.10.31.16.51.25; Wed, 31 Oct 2018 16:51:40 -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=@kernel.org header.s=default header.b=DNlNTCbV; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728504AbeKAIuQ (ORCPT + 99 others); Thu, 1 Nov 2018 04:50:16 -0400 Received: from mail.kernel.org ([198.145.29.99]:53896 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728302AbeKAIGp (ORCPT ); Thu, 1 Nov 2018 04:06:45 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 5492720847; Wed, 31 Oct 2018 23:06:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1541027194; bh=d/cCpngJZP2Z64V1gm6LunSqQ1BiPpcrNH28VDpTI8A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DNlNTCbVeSmqNvVrOKWPSkGp+DeTA3mw05MVwGQJgnNFsxOaBkDGucJV009l2FKnb iBGwxENdgPuKX8+stYa8Q/kV+x+NpoPGuWbovnOFM9TStMC2JERafBZiLFQlGmHTer CTjCiwBc4R/rtIHTGzWIFAcOmoSU3dj8wpY1zT8o= From: Sasha Levin To: stable@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Paolo Valente , Jens Axboe , Sasha Levin Subject: [PATCH AUTOSEL 4.19 058/146] block, bfq: correctly charge and reset entity service in all cases Date: Wed, 31 Oct 2018 19:04:13 -0400 Message-Id: <20181031230541.28822-58-sashal@kernel.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181031230541.28822-1-sashal@kernel.org> References: <20181031230541.28822-1-sashal@kernel.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Paolo Valente [ Upstream commit cbeb869a3d1110450186b738199963c5e68c2a71 ] BFQ schedules entities (which represent either per-process queues or groups of queues) as a function of their timestamps. In particular, as a function of their (virtual) finish times. The finish time of an entity is computed as a function of the budget assigned to the entity, assuming, tentatively, that the entity, once in service, will receive an amount of service equal to its budget. Then, when the entity is expired because it finishes to be served, this finish time is updated as a function of the actual service received by the entity. This allows the entity to be correctly charged with only the service received, and then to be correctly re-scheduled. Yet an entity may receive service also while not being the entity in service (in the scheduling environment of its parent entity), for several reasons. If the entity remains with no backlog while receiving this 'unofficial' service, then it is expired. Also on such an expiration, the finish time of the entity should be updated to account for only the service actually received by the entity. Unfortunately, such an update is not performed for an entity expiring without being the entity in service. In a similar vein, the service counter of the entity in service is reset when the entity is expired, to be ready to be used for next service cycle. This reset too should be performed also in case an entity is expired because it remains empty after receiving service while not being the entity in service. But in this case the reset is not performed. This commit performs the above update of the finish time and reset of the service received, also for an entity expiring while not being the entity in service. Signed-off-by: Paolo Valente Signed-off-by: Jens Axboe Signed-off-by: Sasha Levin --- block/bfq-wf2q.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/block/bfq-wf2q.c b/block/bfq-wf2q.c index ae52bff43ce4..ff7c2d470bb8 100644 --- a/block/bfq-wf2q.c +++ b/block/bfq-wf2q.c @@ -1181,10 +1181,17 @@ bool __bfq_deactivate_entity(struct bfq_entity *entity, bool ins_into_idle_tree) st = bfq_entity_service_tree(entity); is_in_service = entity == sd->in_service_entity; - if (is_in_service) { - bfq_calc_finish(entity, entity->service); + bfq_calc_finish(entity, entity->service); + + if (is_in_service) sd->in_service_entity = NULL; - } + else + /* + * Non in-service entity: nobody will take care of + * resetting its service counter on expiration. Do it + * now. + */ + entity->service = 0; if (entity->tree == &st->active) bfq_active_extract(st, entity); -- 2.17.1