Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp2055288ybp; Thu, 10 Oct 2019 01:20:33 -0700 (PDT) X-Google-Smtp-Source: APXvYqyykS9UKilEJP7CtKwjGkPvSTJ4hbu0JvcjEo1r8wztJNP/Vs0sUtOpcCuDkyiA+tD+hkb2 X-Received: by 2002:a05:6402:88d:: with SMTP id e13mr6784163edy.246.1570695633184; Thu, 10 Oct 2019 01:20:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570695633; cv=none; d=google.com; s=arc-20160816; b=j1QDyZxYMtWkVYdZC5fijsWpOVp3n6rERhBuGJ16WAQV8uk2M1f4PPnc/dnn1aSQTg qd2Vrve4e0dnj9m4wyQ1RffnUKEQT6g01dqVUrJSBa21HKwuGYnIsYmZQeY9xep1XcVo iRwzrsMVPfPBtaaMq5ALiOzV0mPb9ZFoIT0ZaZO729J9myqJZ3uBAweeYY1kH7cWT8hA ixGDLII5rwsbX2aJ82MokLVdJRKzXVqc6B+zHcUTtIe7W+QMZJhP1dD48t4N9bo7KO4I oJ5RBko5oJnWdHbZ37KPrsIa/6wOnsCCFP6/MyUqDkhjOjZk7+mNzf2j2SQWuBriL8h6 G3mg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=utApHrGe/awDdIqfPvOOXzUlqASS6rak8FxfwZ5Sv4Y=; b=l24KWIxGMeOD8lPQij6JFJ9kt86j+PtESq/ZWz+VtVm7v2MAI2c+pbwJXgcX1zzIcE AvXVrlDLi5FyHw1Rx0BXwFTYYnvWP4Z2eZgjhJQFGv/L18r1NITbwKpD7ZrewGySPSoR txFS8dgkkHZpeAmC5O95uFO4IMLaO3eHY3XK23YdRG0T+LPY5BQi9fKSWKG1mv3YhsK3 4LS/DITyZ/WyQWVTvMKYIGaVsf2diIwdO5mvLvx9EM5f6frLu58qyDnEB+Y/gddXUSGq Tik1hOSAK8tL1wA4X9PkfSjL9HrtAKs1jz6atxN+bOibEGUlWcxh4bo2amrW/oji+uRI GGfw== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u2si2722027ejr.332.2019.10.10.01.20.09; Thu, 10 Oct 2019 01:20:33 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1733193AbfJJISG (ORCPT + 99 others); Thu, 10 Oct 2019 04:18:06 -0400 Received: from mx1.redhat.com ([209.132.183.28]:55637 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1733135AbfJJISG (ORCPT ); Thu, 10 Oct 2019 04:18:06 -0400 Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 1E23981F11 for ; Thu, 10 Oct 2019 08:18:05 +0000 (UTC) Received: by mail-wr1-f69.google.com with SMTP id l12so2361329wrm.6 for ; Thu, 10 Oct 2019 01:18:05 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=utApHrGe/awDdIqfPvOOXzUlqASS6rak8FxfwZ5Sv4Y=; b=gtpqS7Wh9HRiBzL3CtUfrrnLJmpBvkTiRXn+H6HkOKtfw9/6TWPdj3lYyRoJDEDODb sACmyNrJ494ACwCXJ41N956waEc6fRl/ZrR+ZKVZvpEyaNT+7QF3Z82VkRy+90sDw1Zn RvK5wD3JSD43z5tXtPK43qUIwf+S7fA0p3SFWR2fXQlzMf9M4BQVVQcZVVvZDP2rRH9b QJh8rkrzBjgdhOOGCmtqkvLhqwjaUPGiYB2ut6NGi8a2XUK0XBcGWsG+nO/vhUxif29S dVcxU7cEDGOiYpJZ+XitKSUQBNAE1Vb/R33L4/krTXfcM8WdZNL+qgQTkggfScXo6LSM ZYaQ== X-Gm-Message-State: APjAAAW7QBdZOLhxPDrWl5+NkbvHuGMlEwcGhLe9xOF9K0GrH1GBMQzt 79WmGIo8Wb6ebCWHGrKx9zNsHM20AkUelSySB+6V8BGdp0XuUsK+UuPsEf4N/UNJ0Sy8R8/HGHf 4IYRinkmM+5410nWc1BFY5nFG X-Received: by 2002:a5d:67c4:: with SMTP id n4mr7159890wrw.39.1570695483666; Thu, 10 Oct 2019 01:18:03 -0700 (PDT) X-Received: by 2002:a5d:67c4:: with SMTP id n4mr7159846wrw.39.1570695483209; Thu, 10 Oct 2019 01:18:03 -0700 (PDT) Received: from localhost.localdomain ([151.29.237.241]) by smtp.gmail.com with ESMTPSA id 79sm5830782wmb.7.2019.10.10.01.18.01 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 10 Oct 2019 01:18:02 -0700 (PDT) Date: Thu, 10 Oct 2019 10:18:00 +0200 From: Juri Lelli To: Scott Wood Cc: Sebastian Andrzej Siewior , Thomas Gleixner , Steven Rostedt , Peter Zijlstra , Daniel Bristot de Oliveira , Clark Williams , linux-kernel@vger.kernel.org, linux-rt-users@vger.kernel.org Subject: Re: [PATCH RT 5/8] sched/deadline: Reclaim cpuset bandwidth in .migrate_task_rq() Message-ID: <20191010081800.GK19588@localhost.localdomain> References: <20190727055638.20443-1-swood@redhat.com> <20190727055638.20443-6-swood@redhat.com> <20190927081141.GB31660@localhost.localdomain> <9a4cc499e6de4690c682c03c0c880363fe3c9307.camel@redhat.com> <20190930071233.GE31660@localhost.localdomain> <9acc5f1bd0fe06acb2b7b518c5ef1f082e89ad63.camel@redhat.com> <20191001085209.GA6481@localhost.localdomain> <20191009072745.GI19588@localhost.localdomain> <9c12342ed1e6d180fae3348409fabb9fc045361d.camel@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <9c12342ed1e6d180fae3348409fabb9fc045361d.camel@redhat.com> User-Agent: Mutt/1.11.3 (2019-02-01) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 09/10/19 14:12, Scott Wood wrote: > On Wed, 2019-10-09 at 09:27 +0200, Juri Lelli wrote: > > On 09/10/19 01:25, Scott Wood wrote: > > > On Tue, 2019-10-01 at 10:52 +0200, Juri Lelli wrote: > > > > On 30/09/19 11:24, Scott Wood wrote: > > > > > On Mon, 2019-09-30 at 09:12 +0200, Juri Lelli wrote: > > > > > > > > [...] > > > > > > > > > > Hummm, I was actually more worried about the fact that we call > > > > > > free_old_ > > > > > > cpuset_bw_dl() only if p->state != TASK_WAKING. > > > > > > > > > > Oh, right. :-P Not sure what I had in mind there; we want to call > > > > > it > > > > > regardless. > > > > > > > > > > I assume we need rq->lock in free_old_cpuset_bw_dl()? So something > > > > > like > > > > > > > > I think we can do with rcu_read_lock_sched() (see > > > > dl_task_can_attach()). > > > > > > RCU will keep dl_bw from being freed under us (we're implicitly in an > > > RCU > > > sched read section due to atomic context). It won't stop rq->rd from > > > changing, but that could have happened before we took rq->lock. If the > > > cpu > > > the task was running on was removed from the cpuset, and that raced with > > > the > > > task being moved to a different cpuset, couldn't we end up erroneously > > > subtracting from the cpu's new root domain (or failing to subtract at > > > all if > > > the old cpu's new cpuset happens to be the task's new cpuset)? I don't > > > see > > > anything that forces tasks off of the cpu when a cpu is removed from a > > > cpuset (though maybe I'm not looking in the right place), so the race > > > window > > > could be quite large. In any case, that's an existing problem that's > > > not > > > going to get solved in this patchset. > > > > OK. So, mainline has got cpuset_read_lock() which should be enough to > > guard against changes to rd(s). > > > > I agree that rq->lock is needed here. > > My point was that rq->lock isn't actually helping, because rq->rd could have > changed before rq->lock is acquired (and it's still the old rd that needs > the bandwidth subtraction). cpuset_mutex/cpuset_rwsem helps somewhat, > though there's still a problem due to the subtraction not happening until > the task is woken up (by which time cpuset_mutex may have been released and > further reconfiguration could have happened). This would be an issue even > without lazy migrate, since in that case ->set_cpus_allowed() can get > deferred, but this patch makes the window much bigger. > > The right solution is probably to explicitly track the rd for which a task > has a pending bandwidth subtraction (if any), and to continue doing it from > set_cpus_allowed() if the task is not migrate-disabled. In the meantime, I > think we should drop this patch from the patchset -- without it, lazy > migrate disable doesn't really make the race situation any worse than it > already was. I'm OK with dropping it for now (as we also have other possible issues as you point out below), but I really wonder what would be a solution here. Problem is that if a domain(s) reconfiguration happened while the task was migrate disabled, and we let the reconf destroy/rebuild domains, the old rd could be gone by the time the task gets migrate enabled again and the task could continue running, w/o its bandwidth been accounted for, in a new rd since the migrate enable instant, no? :-/ > BTW, what happens to the bw addition in dl_task_can_attach() if a subsequent > can_attach fails and the whole operation is cancelled? Oh, yeah, that doesn't look good. :-( Maybe we can use cancel_attach() to fix things up? Thanks, Juri