Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp3674799ybl; Mon, 13 Jan 2020 00:12:29 -0800 (PST) X-Google-Smtp-Source: APXvYqzdaC67fjjHQDvK38wWoWIM6YFQywCv2tJjoKOp22y/MKMKKUWTGWw9jG183dJZc2t4AQaz X-Received: by 2002:a05:6830:22e2:: with SMTP id t2mr12560818otc.129.1578903149074; Mon, 13 Jan 2020 00:12:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1578903149; cv=none; d=google.com; s=arc-20160816; b=Uo7kloaoyU8QQezuVxrR7LixUIYGQsIfcObI+KNRJH/VFMMNS+H9C7DZgwyf+FVqfc KCseVZrL25z705bk3H2cd0C9Ia4Kv9WrxV0kPPRQa7HYw6BWY/i+2iJrHtz6b470AAJZ Ivxi9P7RLX0XezdoLeC+kLXr5eBIwXfJPJXbCjfa1rFbB0DeDC0gxRUJ/1AQNZMQEgHo PEG9NKSc8Pnu3F+LrpjWwBu2XGWRiBhFCb32+l1xzN4NDLglPEiCVbTR52NgSfPJQYji 1rgDyfQtF8V3akE5CaNzIW9dYAm9WlaFscS8kn0RRA0rw9+WwDQauzOUytZ+POGd6LSv d2+Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=Uo6M8zXDEWnKlZatJf5m8wR1G2qfMoS0Tqjko0hve4I=; b=rR+U9xaYH+bszLFHOYdhKt13haWdlHagiiVpu0Rm3eo78l1jG7u5iIeMytdjQBC5vq NezbkYdPLPGOnt2k0hCTDjFvj8GR1EojnKkfrQflQ8dcY02aZmiMp7OVZLg/YadGpQso ASDX7u/CDgDEg8gAQMUwJYBiFyW1KRTBJqIlP6pD6xEr4QqSm/XS0uTzo2sjBD4Ol3OF dgHaDqE1XaRZgKFe+yy7KtjTRx31r3+BG/EW+65vrAOJ+q9QbaV0h+93vZQV2BAbYrLH uq1m28G4nkJwm2uWxswT52J2ZqBIj3N38EENRzIwswFTsuVXwKnEhQFak81l4YN1ptcf 3iCQ== 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=virtuozzo.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i13si6277180otc.228.2020.01.13.00.12.16; Mon, 13 Jan 2020 00:12:29 -0800 (PST) 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=virtuozzo.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728780AbgAMILX (ORCPT + 99 others); Mon, 13 Jan 2020 03:11:23 -0500 Received: from relay.sw.ru ([185.231.240.75]:36326 "EHLO relay.sw.ru" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728739AbgAMILW (ORCPT ); Mon, 13 Jan 2020 03:11:22 -0500 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 1iquoY-00005J-0F; Mon, 13 Jan 2020 11:11:10 +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> From: Kirill Tkhai Message-ID: <9420eab3-5e5e-150f-53c9-6cd40bacf859@virtuozzo.com> Date: Mon, 13 Jan 2020 11:11:09 +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: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 deferred >>> pages with local interrupts disabled. Which is introduced by >>> commit 3a2d7fa8a3d5 ("mm: disable interrupts while initializing deferred >>> pages"). >>> >>> But 'pgdatinit' kthread is possible be pined on the boot CPU (CPU#0 by >>> default), especially in small system with NRCPUS <= 2. In this case, the >>> interrupts are disabled on boot CPU during memory initialising, which >>> caused the tick_sched timer be blocked, leading to wall clock stuck. >>> >>> Fixes: commit 3a2d7fa8a3d5 ("mm: disable interrupts while initializing >>> deferred pages") >>> >>> Signed-off-by: Shile Zhang >>> --- >>>   include/linux/memory_hotplug.h | 16 ++++++++++++++-- >>>   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 @@ >>>   #include >>>   #include >>>   #include >>> +#include >>> +#include >>>     struct page; >>>   struct zone; >>> @@ -282,12 +284,22 @@ static inline bool movable_node_is_enabled(void) >>>   static inline >>>   void pgdat_resize_lock(struct pglist_data *pgdat, unsigned long *flags) >>>   { >>> -    spin_lock_irqsave(&pgdat->node_size_lock, *flags); >>> +    /* >>> +     * Disable local interrupts on boot CPU will stop the tick_sched >>> +     * timer, which will block jiffies(wall clock) update. >>> +     */ >>> +    if (current->cpu != get_boot_cpu_id()) >>> +        spin_lock_irqsave(&pgdat->node_size_lock, *flags); >>> +    else >>> +        spin_lock(&pgdat->node_size_lock); >>>   } >>>   static inline >>>   void pgdat_resize_unlock(struct pglist_data *pgdat, unsigned long *flags) >>>   { >>> -    spin_unlock_irqrestore(&pgdat->node_size_lock, *flags); >>> +    if (current->cpu != get_boot_cpu_id()) >>> +        spin_unlock_irqrestore(&pgdat->node_size_lock, *flags); >>> +    else >>> +        spin_unlock(&pgdat->node_size_lock); >>>   } >>>   static inline >>>   void pgdat_resize_init(struct pglist_data *pgdat) >> 1)Linux kernel is *preemptible*. Kernel with CONFIG_PREEMPT_RT option even may preempt >> *kernel* code in the middle of function. When you are executing a code containing >> pgdat_resize_lock() and pgdat_resize_unlock(), the process may migrate to another cpu >> between them. >> >> bool cpu               another cpu >> ---------------------------------- >> pgdat_resize_lock() >>    spin_lock() >>    --> migrate to another cpu >>                        pgdat_resize_unlock() >>                        spin_unlock_irqrestore() >> >> (Yes, in case of CONFIG_PREEMPT_RT, process is preemptible even after 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 encountered this issue > with "CONFIG_PREEMPT is not set". The thing is we simply shouldn't introduce such the primitives since the 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 this 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 statistics log > with wrong time calculate, but the wall clock is stuck. > So the 'systemd-analyze' command also give a wrong time as I mentioned 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 after a huge enough memory block is initialized? Something like: deferred_init_memmap() { while (spfn < epfn) { nr_pages += deferred_init_maxorder(&i, zone, &spfn, &epfn); local_irq_enable(); local_irq_disable(); } } Or, maybe, enable/disable interrupts somewhere inside deferred_init_maxorder(). >> Also, you may try to check that sched_clock() gives better results with 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 with interrupts >> disabled).