From patchwork Thu Mar 11 18:30:47 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Minchan Kim X-Patchwork-Id: 12132461 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=-16.8 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT 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 7E733C433E0 for ; Thu, 11 Mar 2021 18:30:56 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 03B6064FD6 for ; Thu, 11 Mar 2021 18:30:55 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 03B6064FD6 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 55E9C8D02DD; Thu, 11 Mar 2021 13:30:55 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 50EED8D02B2; Thu, 11 Mar 2021 13:30:55 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3AF7D8D02DD; Thu, 11 Mar 2021 13:30:55 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0123.hostedemail.com [216.40.44.123]) by kanga.kvack.org (Postfix) with ESMTP id 1ED6F8D02B2 for ; Thu, 11 Mar 2021 13:30:55 -0500 (EST) Received: from smtpin12.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id D6A1482499A8 for ; Thu, 11 Mar 2021 18:30:54 +0000 (UTC) X-FDA: 77908434828.12.844974B Received: from mail-pj1-f47.google.com (mail-pj1-f47.google.com [209.85.216.47]) by imf17.hostedemail.com (Postfix) with ESMTP id 602E24080F59 for ; Thu, 11 Mar 2021 18:30:53 +0000 (UTC) Received: by mail-pj1-f47.google.com with SMTP id w8so3882626pjf.4 for ; Thu, 11 Mar 2021 10:30:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=XRdnc5SDeTexTqP3MNLjYUShpFLyOV3cOuJK17cu5t0=; b=Eaj7BV16iNhjkvv7eG9kOZ8zk1a4xmieMjdQxgljP4biZbBHY2uAqoNmKGJGJEJnEA M2cSgRjJLVejPbnNJ+rVEnXl90dYWv7w2tzA2lpPxnOz1hUtTemOZVy9V1pYWryz3JAt LFRGGfy4fHK0c3A1cjcc167ElOkhu33LZjXeap50pWivUFVnh9yfdiNY7cFNeWoHCaap /4NNFips0lYMT2/J3+MKl0dSyYdbHMkiI4eipFaLHZuOhM0bdeNSybJ6auM6NpIQ+3yj DGxQ67VcvpXgEavIpyT2nVj0OHfFzZCH8OPefqyplYFZNft1+Z8Bc3X0odViHIOieVPq 7Wpw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :mime-version:content-transfer-encoding; bh=XRdnc5SDeTexTqP3MNLjYUShpFLyOV3cOuJK17cu5t0=; b=CuSOM7n/DC7tMNSmV7KZFOA5xy9YGOWjll7kD74WOQ/+03Goy7nBXBZBz3WklS88IM UIoZxfDIE5yHHsjljE1bzVu6RMjp+u41RuXPMwiXBmBoBf1gIh6cojlTINvRXUeVqlRf 6wgI1Xo4+MnL8BXyilz+fU24pQdFaGtZavu+BHEqpelq+4bFRtuAFAg2ym9Y+onBc2Zn zNsfURT1kAr0Fu9sKQ9mPeCZ9TDWeq5ve9LmBLkUzy7p2emopFaYSlLEpIVt0D1ujqCt ILA0F3pNnrURBWu8OG7zMi7T2CRGBuac1pOGb0oqBGrHT+z1tPK6Henwwdg3VdaEHfuJ m3uQ== X-Gm-Message-State: AOAM532a8AwgeMsl++KYQLqbvEZewrk7N1LKXS5uB676E6PJyEH9j4Yf axxyIM1o/atqCXU3mCly2IQ= X-Google-Smtp-Source: ABdhPJzqBu2Y0YEvVsaYJofwr2522kQDsScN0UT+21p/DRbEssyzHF6cjwld6nLX4UJ+uxf3JZzCQg== X-Received: by 2002:a17:902:6b42:b029:e6:733a:332 with SMTP id g2-20020a1709026b42b02900e6733a0332mr856614plt.35.1615487453005; Thu, 11 Mar 2021 10:30:53 -0800 (PST) Received: from bbox-1.mtv.corp.google.com ([2620:15c:211:201:64cb:74c7:f2c:e5e0]) by smtp.gmail.com with ESMTPSA id k127sm3308590pfd.63.2021.03.11.10.30.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Mar 2021 10:30:51 -0800 (PST) From: Minchan Kim To: Andrew Morton Cc: linux-mm , LKML , John Dias , Michal Hocko , David Hildenbrand , Jason Baron , Minchan Kim Subject: [PATCH v4] mm: page_alloc: dump migrate-failed pages Date: Thu, 11 Mar 2021 10:30:47 -0800 Message-Id: <20210311183047.805891-1-minchan@kernel.org> X-Mailer: git-send-email 2.31.0.rc2.261.g7f71774620-goog MIME-Version: 1.0 X-Stat-Signature: fdk6uk1i8ugh888z6jpir3bjzo6azzyh X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 602E24080F59 Received-SPF: none (gmail.com>: No applicable sender policy available) receiver=imf17; identity=mailfrom; envelope-from=""; helo=mail-pj1-f47.google.com; client-ip=209.85.216.47 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1615487453-348891 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: Currently, debugging CMA allocation failures is quite limited. The most commong source of these failures seems to be page migration which doesn't provide any useful information on the reason of the failure by itself. alloc_contig_range can report those failures as it holds a list of migrate-failed pages. page refcount, mapcount with page flags on dump_page are helpful information to deduce the culprit. Furthermore, dump_page_owner was super helpful to find long term pinner who initiated the page allocation. The reason it approach with dynamic debug is the debug message could emit lots of noises as alloc_contig_range calls more frequently since it's a best effort allocator. There are two ifdefery conditions to support common dyndbg options: - CONFIG_DYNAMIC_DEBUG_CORE && DYNAMIC_DEBUG_MODULE It aims for supporting the feature with only specific file with adding ccflags. - CONFIG_DYNAMIC_DEBUG It aims for supporting the feature with system wide globally. A simple example to enable the feature: Admin could enable the dump like this(by default, disabled) echo "func alloc_contig_dump_pages +p" > control Admin could disable it. echo "func alloc_contig_dump_pages =_" > control Detail goes Documentation/admin-guide/dynamic-debug-howto.rst A concern is utility functions in dump_page uses inconsistent loglevels. __dump_page: KERN_WARNING __dump_page_owner: KERN_ALERT stack_trace_print: KERN_DEFAULT There are bunch of places to use the inconsistent loglevel utility functions(e.g., just grep dump_page/strace_trace_print). It's unfortunate but here we are. It could be addressed different patchset. Signed-off-by: Minchan Kim Reviewed-by: David Hildenbrand --- * from v3 - https://lore.kernel.org/linux-mm/20210310180104.517886-1-minchan@kernel.org * add dyndgb usage comment - akpm * use dumpstack instead of warn_on - david * from v2 - https://lore.kernel.org/linux-mm/20210308202047.1903802-1-minchan@kernel.org/ * remove ratelimit - mhocko * from v1 - https://lore.kernel.org/linux-mm/20210217163603.429062-1-minchan@kernel.org/ * use dynamic debugging with system wide instead of per-call site - mhocko mm/page_alloc.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 3e4b29ee2b1e..76fc202cb105 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -8453,6 +8453,36 @@ static unsigned long pfn_max_align_up(unsigned long pfn) pageblock_nr_pages)); } +#if defined(CONFIG_DYNAMIC_DEBUG) || \ + (defined(CONFIG_DYNAMIC_DEBUG_CORE) && defined(DYNAMIC_DEBUG_MODULE)) +/* + * usage) + * dyndbg_dir="/sys/kernel/debug/dynamic_debug" + * To enable: + * echo "func alloc_contig_dump_pages +p" > $dyndbg_dir/control + * To disable: + * echo "func alloc_contig_dump_pages =_" > $dyndbg_dir/control + * For detail, read dynamic-debug-howto.rst + */ +static void alloc_contig_dump_pages(struct list_head *page_list) +{ + DEFINE_DYNAMIC_DEBUG_METADATA(descriptor, + "migrate failure"); + + if (DYNAMIC_DEBUG_BRANCH(descriptor)) { + struct page *page; + + dump_stack(); + list_for_each_entry(page, page_list, lru) + dump_page(page, "migration failure"); + } +} +#else +static inline void alloc_contig_dump_pages(struct list_head *page_list) +{ +} +#endif + /* [start, end) must belong to a single zone. */ static int __alloc_contig_migrate_range(struct compact_control *cc, unsigned long start, unsigned long end) @@ -8496,6 +8526,7 @@ static int __alloc_contig_migrate_range(struct compact_control *cc, NULL, (unsigned long)&mtc, cc->mode, MR_CONTIG_RANGE); } if (ret < 0) { + alloc_contig_dump_pages(&cc->migratepages); putback_movable_pages(&cc->migratepages); return ret; }