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 X-Spam-Level: X-Spam-Status: No, score=-8.3 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1D551C33CB1 for ; Wed, 15 Jan 2020 09:45:24 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id DCF8E24655 for ; Wed, 15 Jan 2020 09:45:23 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org DCF8E24655 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=virtuozzo.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 813A28E000D; Wed, 15 Jan 2020 04:45:23 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 7C6628E0003; Wed, 15 Jan 2020 04:45:23 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 701A48E000D; Wed, 15 Jan 2020 04:45:23 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0130.hostedemail.com [216.40.44.130]) by kanga.kvack.org (Postfix) with ESMTP id 5B1398E0003 for ; Wed, 15 Jan 2020 04:45:23 -0500 (EST) Received: from smtpin25.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with SMTP id 1A8CAA2A5 for ; Wed, 15 Jan 2020 09:45:23 +0000 (UTC) X-FDA: 76379385726.25.bikes26_4c032f4dae838 X-HE-Tag: bikes26_4c032f4dae838 X-Filterd-Recvd-Size: 7520 Received: from relay.sw.ru (relay.sw.ru [185.231.240.75]) by imf43.hostedemail.com (Postfix) with ESMTP for ; Wed, 15 Jan 2020 09:45:22 +0000 (UTC) Received: from dhcp-172-16-24-104.sw.ru ([172.16.24.104]) by relay.sw.ru with esmtp (Exim 4.92.3) (envelope-from ) id 1irfEj-0002LN-LS; Wed, 15 Jan 2020 12:45:17 +0300 Subject: Re: [PATCH RESEND] mm: fix tick_sched timer blocked by pgdat_resize_lock To: Shile Zhang , Andrew Morton , Pavel Tatashin Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org References: <20200110082510.172517-2-shile.zhang@linux.alibaba.com> <20200110093053.34777-1-shile.zhang@linux.alibaba.com> <1ee6088c-9e72-8824-3a9a-fc099d196faf@virtuozzo.com> <9420eab3-5e5e-150f-53c9-6cd40bacf859@virtuozzo.com> From: Kirill Tkhai Message-ID: Date: Wed, 15 Jan 2020 12:45:17 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.3.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: quoted-printable 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 14.01.2020 11:54, Shile Zhang wrote: >=20 >=20 > On 2020/1/13 16:11, Kirill Tkhai wrote: >> On 13.01.2020 03:54, Shile Zhang wrote: >>> >>> On 2020/1/10 19:42, Kirill Tkhai wrote: >>>> On 10.01.2020 12:30, Shile Zhang wrote: >>>>> When 'CONFIG_DEFERRED_STRUCT_PAGE_INIT' is set, 'pgdat_resize_lock' >>>>> will be called inside 'pgdatinit' kthread to initialise the deferre= d >>>>> pages with local interrupts disabled. Which is introduced by >>>>> commit 3a2d7fa8a3d5 ("mm: disable interrupts while initializing def= erred >>>>> pages"). >>>>> >>>>> But 'pgdatinit' kthread is possible be pined on the boot CPU (CPU#0= by >>>>> default), especially in small system with NRCPUS <=3D 2. In this ca= se, the >>>>> interrupts are disabled on boot CPU during memory initialising, whi= ch >>>>> caused the tick_sched timer be blocked, leading to wall clock stuck= . >>>>> >>>>> Fixes: commit 3a2d7fa8a3d5 ("mm: disable interrupts while initializ= ing >>>>> deferred pages") >>>>> >>>>> Signed-off-by: Shile Zhang >>>>> --- >>>>> =C2=A0=C2=A0 include/linux/memory_hotplug.h | 16 ++++++++++++++-- >>>>> =C2=A0=C2=A0 1 file changed, 14 insertions(+), 2 deletions(-) >>>>> >>>>> diff --git a/include/linux/memory_hotplug.h b/include/linux/memory_= hotplug.h >>>>> index ba0dca6aac6e..be69a6dc4fee 100644 >>>>> --- a/include/linux/memory_hotplug.h >>>>> +++ b/include/linux/memory_hotplug.h >>>>> @@ -6,6 +6,8 @@ >>>>> =C2=A0=C2=A0 #include >>>>> =C2=A0=C2=A0 #include >>>>> =C2=A0=C2=A0 #include >>>>> +#include >>>>> +#include >>>>> =C2=A0=C2=A0 =C2=A0 struct page; >>>>> =C2=A0=C2=A0 struct zone; >>>>> @@ -282,12 +284,22 @@ static inline bool movable_node_is_enabled(vo= id) >>>>> =C2=A0=C2=A0 static inline >>>>> =C2=A0=C2=A0 void pgdat_resize_lock(struct pglist_data *pgdat, unsi= gned long *flags) >>>>> =C2=A0=C2=A0 { >>>>> -=C2=A0=C2=A0=C2=A0 spin_lock_irqsave(&pgdat->node_size_lock, *flag= s); >>>>> +=C2=A0=C2=A0=C2=A0 /* >>>>> +=C2=A0=C2=A0=C2=A0=C2=A0 * Disable local interrupts on boot CPU wi= ll stop the tick_sched >>>>> +=C2=A0=C2=A0=C2=A0=C2=A0 * timer, which will block jiffies(wall cl= ock) update. >>>>> +=C2=A0=C2=A0=C2=A0=C2=A0 */ >>>>> +=C2=A0=C2=A0=C2=A0 if (current->cpu !=3D get_boot_cpu_id()) >>>>> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 spin_lock_irqsave(&pgda= t->node_size_lock, *flags); >>>>> +=C2=A0=C2=A0=C2=A0 else >>>>> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 spin_lock(&pgdat->node_= size_lock); >>>>> =C2=A0=C2=A0 } >>>>> =C2=A0=C2=A0 static inline >>>>> =C2=A0=C2=A0 void pgdat_resize_unlock(struct pglist_data *pgdat, un= signed long *flags) >>>>> =C2=A0=C2=A0 { >>>>> -=C2=A0=C2=A0=C2=A0 spin_unlock_irqrestore(&pgdat->node_size_lock, = *flags); >>>>> +=C2=A0=C2=A0=C2=A0 if (current->cpu !=3D get_boot_cpu_id()) >>>>> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 spin_unlock_irqrestore(= &pgdat->node_size_lock, *flags); >>>>> +=C2=A0=C2=A0=C2=A0 else >>>>> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 spin_unlock(&pgdat->nod= e_size_lock); >>>>> =C2=A0=C2=A0 } >>>>> =C2=A0=C2=A0 static inline >>>>> =C2=A0=C2=A0 void pgdat_resize_init(struct pglist_data *pgdat) >>>> 1)Linux kernel is *preemptible*. Kernel with CONFIG_PREEMPT_RT optio= n even may preempt >>>> *kernel* code in the middle of function. When you are executing a co= de containing >>>> pgdat_resize_lock() and pgdat_resize_unlock(), the process may migra= te to another cpu >>>> between them. >>>> >>>> bool cpu=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0 another cpu >>>> ---------------------------------- >>>> pgdat_resize_lock() >>>> =C2=A0=C2=A0=C2=A0 spin_lock() >>>> =C2=A0=C2=A0=C2=A0 --> migrate to another cpu >>>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 pgd= at_resize_unlock() >>>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 spi= n_unlock_irqrestore() >>>> >>>> (Yes, in case of CONFIG_PREEMPT_RT, process is preemptible even afte= r spin_lock() call). >>>> >>>> This looks like a bad helpers, and we should not introduce such the = design. >>> Hi Kirill, >>> >>> Thanks for your comments! >>> Sorry for I'm not very clear about this lock/unlock, but I encountere= d this issue >>> with "CONFIG_PREEMPT is not set". >> The thing is we simply shouldn't introduce such the primitives since t= he thread >> may migrate to another cpu, while you own the lock. This looks like a = buggy design. >> >>>> 2)I think there is no the problem this patch solves. Do we really th= is statistics? >>>> Can't we simple remove print message from deferred_init_memmap() and= solve this? >>> Sorry for I've not put this issue very clearly. It's *not* just one s= tatistics log >>> with wrong time calculate, but the wall clock is stuck. >>> So the 'systemd-analyze' command also give a wrong time as I mentione= d in the cover >>> letter. I don't think is OK just remove the log, it cannot solve the = wall clock latency. >> Have you tried temporary enabling interrupts in the middle of cycle af= ter a huge enough >> memory block is initialized? Something like: >> >> deferred_init_memmap() >> { >> =C2=A0=C2=A0=C2=A0=C2=A0while (spfn < epfn) { >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 nr_pages +=3D deferred_init= _maxorder(&i, zone, &spfn, &epfn); >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 local_irq_enable(); >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 local_irq_disable(); >> =C2=A0=C2=A0=C2=A0=C2=A0} >> } >=20 > Yes, I'd tried this for issue confirm, before I sent this patch. Likes = I mentioned the debug log in cover letter, I also add mdelay between loca= l_irq_enable/disable, this system jiffies is stuck without update. > So I think there must be problem to use spin_lock_irqsave in early boot= path on boot CPU. This time SMP is enabled. You have many threads are running. Interrupts a= re enabled and they occur. So, it's OK to disable interrupts for some time. My opinion is we should try to enable interrupts in the cycle after some = fixed amount of memory is initialized. Say, every 1GB. This should resolve two = problems: handling timer interrupt with update jiffies at time, and keeping the fix= for the issue, that Pavel fixed in 3a2d7fa8a3d5. >> Or, maybe, enable/disable interrupts somewhere inside deferred_init_ma= xorder(). >> >>>> Also, you may try to check that sched_clock() gives better results w= ith interrupts >>>> disabled (on x86 it uses rdtsc, when it's possible. But it also may = fallback to >>>> jiffies-based clock in some hardware cases, and they also won't go w= ith interrupts >>>> disabled). >=20