Received: by 2002:ac0:946b:0:0:0:0:0 with SMTP id j40csp2751367imj; Mon, 11 Feb 2019 07:58:13 -0800 (PST) X-Google-Smtp-Source: AHgI3IbNoveEDcuzcj3vMrHPoG6AE039FwtdnldV8JqDHANFuxnFuVGwDpcOW0cwfkeF3G6zbCBp X-Received: by 2002:a62:6303:: with SMTP id x3mr38299030pfb.110.1549900693874; Mon, 11 Feb 2019 07:58:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549900693; cv=none; d=google.com; s=arc-20160816; b=sVNwwHqeKypjgpN58KUcrnQNU6QuuYWZ/bzkVAQLT8pCwUG7wzVFgmDuxE7IEvg3FS XpO+UCpqj/UJyCBXuApH6gDMzehF2f/oFhZgx7cMPryqZx5Sf/cUa8AIamfNEm2pt51P hdN+fwZ4QlBbOHFjoYD8B/zJWm+l49/x42+8zBm4R89YuSPoAeg5ZuefV/o8GnU3ZkSy lYX26UeSrRunYXjNpaPUp2wisyO9jK2Eu7/ZqLMUe+bMCgEPbAULNM6L8+c+P40Jzfbd diLQvPmXDoVkVK2dNbqRon8w4TpvyZE5DqnUa3+/KyI2JnvUvjCcAXo75HofpFBNQaUI jlbQ== 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:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=2Y3hGmM/uypylTK/36IHxYwC28gcUkJHC1rBvdREybg=; b=aXX+/O821UfqsKbrYW2YHQ9pwWN3bIUSFbYv348GBZzWCpJX2X9ikBnt90QrI0ZbQI tb7/fpnavXYz4o7/seCdar4CRk0TyRrr838Py0slSfg6x+Ez7LA7j11eycxcU789Y/3+ f37+9T7xhqL8QGGzTj4SGIuIINr7n137GgwO8rRnReblofu47mpl/WTwGmunnEnqBZVD EPSZaEEH6skNhBVlUnjy6qAXklfZALWtEAI55X1P8Jh+S5ttEJHX+QgaRV6ZAV4icFM1 6zBoSijTETQcjP+imAkrhKKS13qKnYAgpaV5u4mOsQ4cU+9jxFDPaXh8VeJZJgscEDDh psOw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=xvyl6iaw; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c26si9304084pfd.2.2019.02.11.07.57.56; Mon, 11 Feb 2019 07:58:13 -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; dkim=pass header.i=@kernel.org header.s=default header.b=xvyl6iaw; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729904AbfBKOdz (ORCPT + 99 others); Mon, 11 Feb 2019 09:33:55 -0500 Received: from mail.kernel.org ([198.145.29.99]:41696 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730726AbfBKOdt (ORCPT ); Mon, 11 Feb 2019 09:33:49 -0500 Received: from localhost (5356596B.cm-6-7b.dynamic.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 18DB921B69; Mon, 11 Feb 2019 14:33:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1549895627; bh=HhohTlTPyXUyaJqvgZKpN3UJwNH8c3FZXgPBPyPvfcw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=xvyl6iawAe8Gr6ilrOW21xZnKV3cA3s4iY4xYuTKC5fwh99k9N10/AlD+bUPyFYMP +cIEJGG+DX/VZct+NHRlrkcTIDRDxSp5NU+2r2lLzCkRHqDQ/DbhCpV5rrP+IMpAkZ WF8MBf8uteLG8OmqBF6iNn9w9ynMfeMkS3Sh76vk= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Waiman Long , Andrew Morton , Andrey Ryabinin , Alexander Potapenko , Dmitry Vyukov , Michal Hocko , Pasha Tatashin , Oscar Salvador , Linus Torvalds , Sasha Levin Subject: [PATCH 4.20 268/352] mm/page_alloc.c: dont call kasan_free_pages() at deferred mem init Date: Mon, 11 Feb 2019 15:18:15 +0100 Message-Id: <20190211141904.058280153@linuxfoundation.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190211141846.543045703@linuxfoundation.org> References: <20190211141846.543045703@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.20-stable review patch. If anyone has any objections, please let me know. ------------------ [ Upstream commit 3c0c12cc8f00ca5f81acb010023b8eb13e9a7004 ] When CONFIG_KASAN is enabled on large memory SMP systems, the deferrred pages initialization can take a long time. Below were the reported init times on a 8-socket 96-core 4TB IvyBridge system. 1) Non-debug kernel without CONFIG_KASAN [ 8.764222] node 1 initialised, 132086516 pages in 7027ms 2) Debug kernel with CONFIG_KASAN [ 146.288115] node 1 initialised, 132075466 pages in 143052ms So the page init time in a debug kernel was 20X of the non-debug kernel. The long init time can be problematic as the page initialization is done with interrupt disabled. In this particular case, it caused the appearance of following warning messages as well as NMI backtraces of all the cores that were doing the initialization. [ 68.240049] rcu: INFO: rcu_sched detected stalls on CPUs/tasks: [ 68.241000] rcu: 25-...0: (100 ticks this GP) idle=b72/1/0x4000000000000000 softirq=915/915 fqs=16252 [ 68.241000] rcu: 44-...0: (95 ticks this GP) idle=49a/1/0x4000000000000000 softirq=788/788 fqs=16253 [ 68.241000] rcu: 54-...0: (104 ticks this GP) idle=03a/1/0x4000000000000000 softirq=721/825 fqs=16253 [ 68.241000] rcu: 60-...0: (103 ticks this GP) idle=cbe/1/0x4000000000000000 softirq=637/740 fqs=16253 [ 68.241000] rcu: 72-...0: (105 ticks this GP) idle=786/1/0x4000000000000000 softirq=536/641 fqs=16253 [ 68.241000] rcu: 84-...0: (99 ticks this GP) idle=292/1/0x4000000000000000 softirq=537/537 fqs=16253 [ 68.241000] rcu: 111-...0: (104 ticks this GP) idle=bde/1/0x4000000000000000 softirq=474/476 fqs=16253 [ 68.241000] rcu: (detected by 13, t=65018 jiffies, g=249, q=2) The long init time was mainly caused by the call to kasan_free_pages() to poison the newly initialized pages. On a 4TB system, we are talking about almost 500GB of memory probably on the same node. In reality, we may not need to poison the newly initialized pages before they are ever allocated. So KASAN poisoning of freed pages before the completion of deferred memory initialization is now disabled. Those pages will be properly poisoned when they are allocated or freed after deferred pages initialization is done. With this change, the new page initialization time became: [ 21.948010] node 1 initialised, 132075466 pages in 18702ms This was still about double the non-debug kernel time, but was much better than before. Link: http://lkml.kernel.org/r/1544459388-8736-1-git-send-email-longman@redhat.com Signed-off-by: Waiman Long Reviewed-by: Andrew Morton Cc: Andrey Ryabinin Cc: Alexander Potapenko Cc: Dmitry Vyukov Cc: Michal Hocko Cc: Pasha Tatashin Cc: Oscar Salvador Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Sasha Levin --- mm/page_alloc.c | 37 +++++++++++++++++++++++++++++-------- 1 file changed, 29 insertions(+), 8 deletions(-) diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 995d1079f958..a29043ea9212 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -294,6 +294,32 @@ EXPORT_SYMBOL(nr_online_nodes); int page_group_by_mobility_disabled __read_mostly; #ifdef CONFIG_DEFERRED_STRUCT_PAGE_INIT +/* + * During boot we initialize deferred pages on-demand, as needed, but once + * page_alloc_init_late() has finished, the deferred pages are all initialized, + * and we can permanently disable that path. + */ +static DEFINE_STATIC_KEY_TRUE(deferred_pages); + +/* + * Calling kasan_free_pages() only after deferred memory initialization + * has completed. Poisoning pages during deferred memory init will greatly + * lengthen the process and cause problem in large memory systems as the + * deferred pages initialization is done with interrupt disabled. + * + * Assuming that there will be no reference to those newly initialized + * pages before they are ever allocated, this should have no effect on + * KASAN memory tracking as the poison will be properly inserted at page + * allocation time. The only corner case is when pages are allocated by + * on-demand allocation and then freed again before the deferred pages + * initialization is done, but this is not likely to happen. + */ +static inline void kasan_free_nondeferred_pages(struct page *page, int order) +{ + if (!static_branch_unlikely(&deferred_pages)) + kasan_free_pages(page, order); +} + /* Returns true if the struct page for the pfn is uninitialised */ static inline bool __meminit early_page_uninitialised(unsigned long pfn) { @@ -335,6 +361,8 @@ defer_init(int nid, unsigned long pfn, unsigned long end_pfn) return false; } #else +#define kasan_free_nondeferred_pages(p, o) kasan_free_pages(p, o) + static inline bool early_page_uninitialised(unsigned long pfn) { return false; @@ -1037,7 +1065,7 @@ static __always_inline bool free_pages_prepare(struct page *page, arch_free_page(page, order); kernel_poison_pages(page, 1 << order, 0); kernel_map_pages(page, 1 << order, 0); - kasan_free_pages(page, order); + kasan_free_nondeferred_pages(page, order); return true; } @@ -1605,13 +1633,6 @@ static int __init deferred_init_memmap(void *data) return 0; } -/* - * During boot we initialize deferred pages on-demand, as needed, but once - * page_alloc_init_late() has finished, the deferred pages are all initialized, - * and we can permanently disable that path. - */ -static DEFINE_STATIC_KEY_TRUE(deferred_pages); - /* * If this zone has deferred pages, try to grow it by initializing enough * deferred pages to satisfy the allocation specified by order, rounded up to -- 2.19.1