From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6092FECAAA1 for ; Fri, 9 Sep 2022 12:12:32 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A7B4E8D0003; Fri, 9 Sep 2022 08:12:31 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A2B068D0002; Fri, 9 Sep 2022 08:12:31 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8F2968D0003; Fri, 9 Sep 2022 08:12:31 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 7F41D8D0002 for ; Fri, 9 Sep 2022 08:12:31 -0400 (EDT) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 371AEC022B for ; Fri, 9 Sep 2022 12:12:31 +0000 (UTC) X-FDA: 79892434902.27.D3A9594 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by imf17.hostedemail.com (Postfix) with ESMTP id B1E0740085 for ; Fri, 9 Sep 2022 12:12:30 +0000 (UTC) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id ADF5BB82348; Fri, 9 Sep 2022 12:12:28 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 045D9C433D7; Fri, 9 Sep 2022 12:12:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1662725547; bh=j260rCTWpcx6TsZ7QFclBNBl3Kwk7+ZchUYUFiDMh7I=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=bjX5b1gNVQb9BUKj4LL5fRoHn/BKgKWDLK4pzAgeTLroTxzAFTx8j5+5w8ysWuiYk XRVr6MTMj92+zwcw1QOlyXX0C9AVqfiTk1BMMH0f5/3wdndxCXWkjrsT921T5KvbxZ RBLb7kYzkE5VanfLK79LlBKQZMAVoYat48sDHvLg2mLQ5QromD33RCVD6gr2hLh0aM 0sA9B0MDmfbDKzaRbAlee/O6BOTGwUQsUQf5heZ1GYZWQiQzsK2ET8MiDi7CCqCRab pB2QEpxIiqjsksLVqsxVnbgaKm0I5mTsLChtqdDE6BmW32YzZeEJj/DTzEZQZwBifa fLypLyfMmEJoQ== Date: Fri, 9 Sep 2022 14:12:24 +0200 From: Frederic Weisbecker To: Marcelo Tosatti Cc: atomlin@redhat.com, cl@linux.com, tglx@linutronix.de, mingo@kernel.org, peterz@infradead.org, pauld@redhat.com, neelx@redhat.com, oleksandr@natalenko.name, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: Re: [PATCH v7 2/3] tick/sched: Ensure quiet_vmstat() is called when the idle tick was stopped too Message-ID: <20220909121224.GA220905@lothringen> References: <20220817191346.287594886@redhat.com> <20220817191524.201253713@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220817191524.201253713@redhat.com> ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1662725550; a=rsa-sha256; cv=none; b=2eAbi1gq/E9vUg2p/V8rOuvHAnYv4R9Iah6bRHJ+az8sNEyut/BopoarINnb1ikkuYJ2xe xrhp+JfC6u8fzUsHWvup8vYfVEuP/liOxWMTW1zFTnSgYWL2/qHhaZre5gPhiKn+Nbh7XW 37KS8ZJNgqZnCBExFLsPsPswTR7Muxg= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=bjX5b1gN; spf=pass (imf17.hostedemail.com: domain of frederic@kernel.org designates 145.40.68.75 as permitted sender) smtp.mailfrom=frederic@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1662725550; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=cg5t3eSYbM6pO1xSec0AwIt7jCfLKQBVYxPmzWqOlmw=; b=OmoN2RjpY9DU/Yt1QOOt6GFPi3Z4/kNJ4C57hyAQMbV8l7hzHirrpmeN9u5bCHxCNJwQZR CCKNFI0x46Ul6+mpavQItseG8L88HnF4QkInVTA0SxUTz7FZO+jabQrkYaPk1KhSuEvlC+ GYoQp3nVPO3WgnXFx2rnVXKegO8TkaM= X-Stat-Signature: 8eumiqtcfzobshogxgzj8a481y35uesc X-Rspam-User: X-Rspamd-Queue-Id: B1E0740085 X-Rspamd-Server: rspam07 Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=bjX5b1gN; spf=pass (imf17.hostedemail.com: domain of frederic@kernel.org designates 145.40.68.75 as permitted sender) smtp.mailfrom=frederic@kernel.org; dmarc=pass (policy=none) header.from=kernel.org X-HE-Tag: 1662725550-786686 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Wed, Aug 17, 2022 at 04:13:48PM -0300, Marcelo Tosatti wrote: > From: Aaron Tomlin > > In the context of the idle task and an adaptive-tick mode/or a nohz_full > CPU, quiet_vmstat() can be called: before stopping the idle tick, > entering an idle state and on exit. In particular, for the latter case, > when the idle task is required to reschedule, the idle tick can remain > stopped Since quiet_vmstat() is only called when ts->tick_stopped = false, this can only happen if the idle loop did not enter into dynticks idle mode but the exiting idle task eventually stops the tick (tick_nohz_idle_update_tick()). This can happen for example if we enter the idle loop with a timer callback pending in one jiffies, then once that timer fires, which wakes up a task, we exit the idle loop and then tick_nohz_idle_update_tick() doesn't see any timer callback pending left and the tick can be stopped. Or am I missing something? > and the timer expiration time endless i.e., KTIME_MAX. Now, > indeed before a nohz_full CPU enters an idle state, CPU-specific vmstat > counters should be processed to ensure the respective values have been > reset and folded into the zone specific 'vm_stat[]'. That being said, it > can only occur when: the idle tick was previously stopped, and > reprogramming of the timer is not required. > > A customer provided some evidence which indicates that the idle tick was > stopped; albeit, CPU-specific vmstat counters still remained populated. > Thus one can only assume quiet_vmstat() was not invoked on return to the > idle loop. > > If I understand correctly, I suspect this divergence might erroneously > prevent a reclaim attempt by kswapd. If the number of zone specific free > pages are below their per-cpu drift value then > zone_page_state_snapshot() is used to compute a more accurate view of > the aforementioned statistic. Thus any task blocked on the NUMA node > specific pfmemalloc_wait queue will be unable to make significant > progress via direct reclaim unless it is killed after being woken up by > kswapd (see throttle_direct_reclaim()). > > Consider the following theoretical scenario: > > 1. CPU Y migrated running task A to CPU X that was > in an idle state i.e. waiting for an IRQ - not > polling; marked the current task on CPU X to > need/or require a reschedule i.e., set > TIF_NEED_RESCHED and invoked a reschedule IPI to > CPU X (see sched_move_task()) CPU Y is nohz_full right? > > 2. CPU X acknowledged the reschedule IPI from CPU Y; > generic idle loop code noticed the > TIF_NEED_RESCHED flag against the idle task and > attempts to exit of the loop and calls the main > scheduler function i.e. __schedule(). > > Since the idle tick was previously stopped no > scheduling-clock tick would occur. > So, no deferred timers would be handled > > 3. Post transition to kernel execution Task A > running on CPU Y, indirectly released a few pages > (e.g. see __free_one_page()); CPU Y's > 'vm_stat_diff[NR_FREE_PAGES]' was updated and zone > specific 'vm_stat[]' update was deferred as per the > CPU-specific stat threshold > > 4. Task A does invoke exit(2) and the kernel does > remove the task from the run-queue; the idle task > was selected to execute next since there are no > other runnable tasks assigned to the given CPU > (see pick_next_task() and pick_next_task_idle()) This happens on CPU X, right? > > 5. On return to the idle loop since the idle tick > was already stopped and can remain so (see [1] > below) e.g. no pending soft IRQs, no attempt is > made to zero and fold CPU Y's vmstat counters > since reprogramming of the scheduling-clock tick > is not required/or needed (see [2]) And now back to CPU Y, confused... [...] > Index: linux-2.6/kernel/time/tick-sched.c > =================================================================== > --- linux-2.6.orig/kernel/time/tick-sched.c > +++ linux-2.6/kernel/time/tick-sched.c > @@ -26,6 +26,7 @@ > #include > #include > #include > +#include > > #include > > @@ -519,6 +520,20 @@ void __tick_nohz_task_switch(void) > } > } > > +void __tick_nohz_user_enter_prepare(void) > +{ > + struct tick_sched *ts; > + > + if (tick_nohz_full_cpu(smp_processor_id())) { > + ts = this_cpu_ptr(&tick_cpu_sched); > + > + if (ts->tick_stopped) > + quiet_vmstat(); Wasn't it supposed to be part of the quiescing in task isolation mode? Because currently vmstat is a deferrable timer but that deferrability may not apply to nohz_full anymore (outside idle). And quiet_vmstat() doesn't cancel the timer so you'll still get the disturbance. See this patch: https://lore.kernel.org/lkml/20220725104356.GA2950296@lothringen/ > + rcu_nocb_flush_deferred_wakeup(); > + } > +} > > +EXPORT_SYMBOL_GPL(__tick_nohz_user_enter_prepare); > + > /* Get the boot-time nohz CPU list from the kernel parameters. */ > void __init tick_nohz_full_setup(cpumask_var_t cpumask) > { > @@ -890,6 +905,9 @@ static void tick_nohz_stop_tick(struct t > ts->do_timer_last = 0; > } > > + /* Attempt to fold when the idle tick is stopped or not */ > + quiet_vmstat(); > + > /* Skip reprogram of event if its not changed */ > if (ts->tick_stopped && (expires == ts->next_tick)) { > /* Sanity check: make sure clockevent is actually programmed */ But that chunk looks good. Thanks. > @@ -911,7 +929,6 @@ static void tick_nohz_stop_tick(struct t > */ > if (!ts->tick_stopped) { > calc_load_nohz_start(); > - quiet_vmstat(); > > ts->last_tick = hrtimer_get_expires(&ts->sched_timer); > ts->tick_stopped = 1; > >