Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp482901pxf; Wed, 10 Mar 2021 10:05:02 -0800 (PST) X-Google-Smtp-Source: ABdhPJzWd5OOsKItex1eCWzEe3j9c1pjNqyMTYiG8G3QNcFmqO9ibd1TgbUWtUg5PedvFGdOQnS6 X-Received: by 2002:a17:906:73c2:: with SMTP id n2mr5033083ejl.224.1615399502261; Wed, 10 Mar 2021 10:05:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1615399502; cv=none; d=google.com; s=arc-20160816; b=fDpUlZd4NaZT5k29HOlJ7FM2h2oZvnbnHCRZhcuWRc/EdY44xg6z2bUuHwV/9aSUUh uAloJdCyeROWjMQJedh02+XdLX5H2fu2eDiLWn3kazOJfnAMeQ+YSQ3FctTVF1oyrNYC YJaMbgrYdJP8JY9FKKIvxT+FAuLkG1na/OUPDMd3kQu1Vup6BDeMZnbxP8a46jemsvSK I8ttuqJnk4b9AEW6nPm+LMRHlBo1WmtO1iddrgG4usF7lWjxTv/IHnslF/zMU1A+s+AG G5vOpJuvE3U13pnSHJrxWYVERoLxcgnsweQidQBwiE9HIt3sVqqt7CsSgkCumv88OD9l qweA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:sender:dkim-signature; bh=9jmoenAGMFpKHfMNt6zq7dsNBrDUYlAgJfLcxbv2cwY=; b=ldKAxVZ+ewDGZvfUVnd5XkUEFA/gmtd9SRiNTbMPWDAsMokqMeUjgLW2LnoLEX8aPc 3zQIUGk07Frxr8AeKA7xx02K7QjU7xmuS/snftPY6ak12az468Mm1eEHjG0OC0YR/ihi WC3LZ37Zpi6JYML0OqIx0Xb+vbsvyH30Vm0FEQLT1f2jDwDq0NbzqVgSqX5EFWHjJh14 mKd1ygJvT5I43poiTr+ftQo568u05txhzYMT/vVTK9/Pguul2cPxyQzEbn6AfWiB5vHB ljqoYgsTxBd6GJAKSmkAVfhZgz+RoSjSCIVphsTlsy1/DXJ6A/HKICrhlF0v64v1D+pn sDpQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=DSDRCT2G; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id m2si55252ejb.357.2021.03.10.10.04.39; Wed, 10 Mar 2021 10:05:02 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=DSDRCT2G; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232828AbhCJSBa (ORCPT + 99 others); Wed, 10 Mar 2021 13:01:30 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49422 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232387AbhCJSBJ (ORCPT ); Wed, 10 Mar 2021 13:01:09 -0500 Received: from mail-pg1-x52b.google.com (mail-pg1-x52b.google.com [IPv6:2607:f8b0:4864:20::52b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A6E61C061760 for ; Wed, 10 Mar 2021 10:01:09 -0800 (PST) Received: by mail-pg1-x52b.google.com with SMTP id e6so11902892pgk.5 for ; Wed, 10 Mar 2021 10:01:09 -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=9jmoenAGMFpKHfMNt6zq7dsNBrDUYlAgJfLcxbv2cwY=; b=DSDRCT2Gn+BkaXVqZYpRnM7Vhl8kTYeebkTTSNqc3y/R+hb3F3LaGSctN8hAACu8uU elN/UzMtTqpKCHQBiyFOJiubnRHsoveuM8VqSRjPWzZDXq9XiecLx5mVmSz/LKqtLqZo 7HvM9Z6lk92sjl9yJ1au8+pZSyqWM1fvkiUl4mcGLdPtzy1JlMdTFUYrIw1GcPSYBFUd tPwipmpQRHoZn0H4A3vkjF38cUtcDdmrcm1AcoijWUlVE4uG5V/+u5XP0uUREbfQ/2im Fc3Ligirw05nZA5HdqP4gXTnEGNs4ETlwRS7lgHm2onoBfgaTTeaV4em9NDqSAKHe8mH XQbg== 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=9jmoenAGMFpKHfMNt6zq7dsNBrDUYlAgJfLcxbv2cwY=; b=MR20fNUIJ5TTSkuvP8I6c2ddXW8R+m1WOKsaMrTG+0s47Kx4KAL8yeP0mUBZ7L+Ofc Z7Uo/jEKRXPvfSYfSV33OIFYNoSL6g0pxAjhTkDUJIFGiG3ptdRe78SUE9/9K7Kgy55L pVN7j7yhBYaIR1nqaNf2JqW3pinHZ3cbJ6vgHV3f8tdcZjEUHlDuBRsK98NfJaEWNRc0 NiIqWQG2KuD+YjvrvTH7HNSbqDYQGT99LKCTNGgKo7dbcUWDoufbLG9ZKStpp3oztk5o 2Bl+ykXbGar+Po8PreihXPbdDquH2hsZeDQm4isc3eLuehMjHes/im03zxkzJEG+hsWJ h3jg== X-Gm-Message-State: AOAM530RCGMH09y2Q91je0PmU50dvMdPtFpQ8ff/j3vjaSlfQnhw4qzV +AYUo2zK0tHKh24SV/cbZg4= X-Received: by 2002:a63:cd09:: with SMTP id i9mr3806659pgg.407.1615399269162; Wed, 10 Mar 2021 10:01:09 -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 35sm217683pgr.14.2021.03.10.10.01.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Mar 2021 10:01:08 -0800 (PST) Sender: Minchan Kim From: Minchan Kim To: Andrew Morton Cc: linux-mm , LKML , John Dias , Michal Hocko , David Hildenbrand , Jason Baron , Minchan Kim Subject: [PATCH v3] mm: page_alloc: dump migrate-failed pages Date: Wed, 10 Mar 2021 10:01:04 -0800 Message-Id: <20210310180104.517886-1-minchan@kernel.org> X-Mailer: git-send-email 2.30.1.766.gb4fecdf3b7-goog MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 dump_migrate_failure_pages +p" > control Admin could disable it. echo "func dump_migrate_failure_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 --- * 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 | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 3e4b29ee2b1e..f42f3e208794 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -8453,6 +8453,27 @@ 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)) +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; + + WARN(1, "failed callstack"); + 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 +8517,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; } -- 2.30.1.766.gb4fecdf3b7-goog