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 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6E4ACC05027 for ; Thu, 2 Feb 2023 06:54:44 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9892A6B0071; Thu, 2 Feb 2023 01:54:43 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 939896B0072; Thu, 2 Feb 2023 01:54:43 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 800AC6B0073; Thu, 2 Feb 2023 01:54:43 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 712E56B0071 for ; Thu, 2 Feb 2023 01:54:43 -0500 (EST) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 22B9C12023A for ; Thu, 2 Feb 2023 06:54:43 +0000 (UTC) X-FDA: 80421438846.28.7247C33 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by imf10.hostedemail.com (Postfix) with ESMTP id A8E9BC0007 for ; Thu, 2 Feb 2023 06:54:38 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=none; spf=pass (imf10.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.188 as permitted sender) smtp.mailfrom=wangkefeng.wang@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1675320881; a=rsa-sha256; cv=none; b=nOwhwPGqGIAAGpPFqiFaUIoMlHKxIqiFtV3CHpi5AL3dw202c4fQoE+3o2OOEfZF0dn1KV RSz8NLJTIWVfS8xdilsGUMqeqsynZQnFxLp5tvHIqVa1tyNzOsDQjHxlge/6tMzsd30/Cx dL+GKxY9a2UIQv8eWHNND10zhGFBX04= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=none; spf=pass (imf10.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.188 as permitted sender) smtp.mailfrom=wangkefeng.wang@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1675320881; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ubdKPQbtQtJCfZm/ogncqhAE31g96nFpUHex5U7KzA8=; b=oOQ1ZkMhXgqHYIZz2tiBUylAa56GYC1ZOSkePCuHkoYKl/MxJMtdMYiMHLYYvub2t/NayW izGKfFJtfXkxOGAChwUpGD9ZXRn2omexnMAmpQ3x+2VzF/8S7oI+/5dCazsi0Zz1dzUEPy wtUtvTJkGdV0Muc0i7xSJ/cVo3HPsX4= Received: from dggpemm500001.china.huawei.com (unknown [172.30.72.56]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4P6qGT5gV9zRrCN; Thu, 2 Feb 2023 14:52:17 +0800 (CST) Received: from [10.174.177.243] (10.174.177.243) by dggpemm500001.china.huawei.com (7.185.36.107) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Thu, 2 Feb 2023 14:54:31 +0800 Message-ID: <5b505753-0eae-1718-b87a-1293a4ff5291@huawei.com> Date: Thu, 2 Feb 2023 14:54:31 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.5.1 Subject: Re: [PATCH v2 1/3] mm: memory-failure: Add memory failure stats to sysfs Content-Language: en-US To: Jiaqi Yan , , CC: , , , , References: <20230120034622.2698268-1-jiaqiyan@google.com> <20230120034622.2698268-2-jiaqiyan@google.com> From: Kefeng Wang In-Reply-To: <20230120034622.2698268-2-jiaqiyan@google.com> Content-Type: text/plain; charset="UTF-8"; format=flowed Content-Transfer-Encoding: 7bit X-Originating-IP: [10.174.177.243] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To dggpemm500001.china.huawei.com (7.185.36.107) X-CFilter-Loop: Reflected X-Rspam-User: X-Rspamd-Queue-Id: A8E9BC0007 X-Rspamd-Server: rspam01 X-Stat-Signature: kfk4y6o1wxqkj36zfew9mipog7md7yxh X-HE-Tag: 1675320878-682618 X-HE-Meta: U2FsdGVkX19GjD4462kCHEhpTWR5Du88KMZqto7nhkvC9JDv/dIXoIVxx7chDx51kjK/lgC4NIq/lopENiYWBQhCkNH9d90tuJMPmMtnzpGBLAGT4LN+Wn2dHgXGyF9SrkpwiPMqL4I09q5VQ2iATPSeDGqjytD7hd8OCjLRDy6ZRTpZmoYitwUXKg4rMhNAsN5e+Hb7/PpFu00CJKgp0KCA7Grjs720JoUkq0jbznw0jIMX8q7LNb5R011fTWyEuQFbTnrKNdXjcW8sTkdIiqnEqknnuQYJrSGtHQGpn5BDw1cDJdKwERVEb3Y+nVqnCR3NOJ88EiS1bmGgQFxvfXwtET46r0mY3FF2EVi+wDVxnNBcJWTb+i1Pb/BrQj9s3CLaINoh4pluv/eZDDOvzqvDMfIlaMZKI1DiebFCZeR8HMInZaG7W5ZpV/If4+qGajsZFN6fK2MDMjlF6WgZC5DE4QiC9O96+OqGGg7aDccRkoJ2DmK/zYOy7CVmRqcbqsve+P6xnQHLbHtMFCI7pKRhdfc/l1WNOyjBRwC/REg4YzdtE3+MXZYtmA1QOhTpl5roYyABGnDFxTJ/jkdmK+9yNIQ5Jp2owiAhIBNNpg8bAL1RSafApAjX32kcxcE9DW8rOMGA5lhEYe94jP4quwQyK4FtWZLcIvEbr+JS0JnCu/J/okeyKCKumxCWjBrfgqaNe/A+YK7fmDIEQExvOne/o2B0jwWTQdIGFYSqPlg82KKfthxB0ofQOopJPSRp72o3eJL0+c126yyxX2F6JpDxzodV3uO3sgdgaCODgskU1nOm9vNfGIcaJf/Klr1/AIqDTU+3EQCv2TqFtViIFcfxQMQTin21XsAKtR2a5eeV8TAbww4EWzLg9gvoFpusK5AFRbiBmZSWnMsO6csbtMENz5LsFU+bBS06sLjqLasjkH6zIWqGkz8aJKPyV3DoDjuOCDoSe39hnCmGtyI LZ8d/FAU +sFMRqKmH0R1tB5qZb8POZLjj1mvzoLxqBPcTLjc4Ntw1BfawbfXBuPRytrYAZKxBf3TCk/PWklWn2ohS/iRWyWN/6ifFexA2A6PwHs+ptSG9IuS6k5z5ZBuuzcbLZ0P9BmR3l6/tVVfDMyRts0zQYWYdnYcPX50+XZVtt8QWCcZVzqU= 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 2023/1/20 11:46, Jiaqi Yan wrote: > Today kernel provides following memory error info to userspace, but each > has its own disadvantage > * HardwareCorrupted in /proc/meminfo: number of bytes poisoned in total, > not per NUMA node stats though > * ras:memory_failure_event: only available after explicitly enabled > * /dev/mcelog provides many useful info about the MCEs, but > doesn't capture how memory_failure recovered memory MCEs > * kernel logs: userspace needs to process log text > > Exposes per NUMA node memory error stats as sysfs entries: > > /sys/devices/system/node/node${X}/memory_failure/total > /sys/devices/system/node/node${X}/memory_failure/recovered > /sys/devices/system/node/node${X}/memory_failure/ignored > /sys/devices/system/node/node${X}/memory_failure/failed > /sys/devices/system/node/node${X}/memory_failure/delayed > > These counters describe how many raw pages are poisoned and after the > attempted recoveries by the kernel, their resolutions: how many are > recovered, ignored, failed, or delayed respectively. The following > math holds for the statistics: > * total = recovered + ignored + failed + delayed > > Acked-by: David Rientjes > Signed-off-by: Jiaqi Yan > --- > drivers/base/node.c | 3 +++ > include/linux/mm.h | 5 +++++ > include/linux/mmzone.h | 28 ++++++++++++++++++++++++++++ > mm/memory-failure.c | 35 +++++++++++++++++++++++++++++++++++ > 4 files changed, 71 insertions(+) > > diff --git a/drivers/base/node.c b/drivers/base/node.c > index faf3597a96da..b46db17124f3 100644 > --- a/drivers/base/node.c > +++ b/drivers/base/node.c > @@ -586,6 +586,9 @@ static const struct attribute_group *node_dev_groups[] = { > &node_dev_group, > #ifdef CONFIG_HAVE_ARCH_NODE_DEV_GROUP > &arch_node_dev_group, > +#endif > +#ifdef CONFIG_MEMORY_FAILURE > + &memory_failure_attr_group, > #endif > NULL > }; > diff --git a/include/linux/mm.h b/include/linux/mm.h > index f3f196e4d66d..888576884eb9 100644 > --- a/include/linux/mm.h > +++ b/include/linux/mm.h > @@ -3521,6 +3521,11 @@ enum mf_action_page_type { > MF_MSG_UNKNOWN, > }; > > +/* > + * Sysfs entries for memory failure handling statistics. > + */ > +extern const struct attribute_group memory_failure_attr_group; > + This should move under CONFIG_MEMORY_FAILURE > #if defined(CONFIG_TRANSPARENT_HUGEPAGE) || defined(CONFIG_HUGETLBFS) > extern void clear_huge_page(struct page *page, > unsigned long addr_hint, > diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h > index cd28a100d9e4..2c537b31fa7b 100644 > --- a/include/linux/mmzone.h > +++ b/include/linux/mmzone.h > @@ -1110,6 +1110,31 @@ struct deferred_split { > }; > #endif > > +#ifdef CONFIG_MEMORY_FAILURE > +/* > + * Per NUMA node memory failure handling statistics. > + */ > +struct memory_failure_stats { > + /* > + * Number of raw pages poisoned. > + * Cases not accounted: memory outside kernel control, offline page, > + * arch-specific memory_failure (SGX), hwpoison_filter() filtered > + * error events, and unpoison actions from hwpoison_unpoison. > + */ > + unsigned long total; > + /* > + * Recovery results of poisoned raw pages handled by memory_failure, > + * in sync with mf_result. > + * total = ignored + failed + delayed + recovered. > + * total * PAGE_SIZE * #nodes = /proc/meminfo/HardwareCorrupted. > + */ > + unsigned long ignored; > + unsigned long failed; > + unsigned long delayed; > + unsigned long recovered; > +}; > +#endif > + > /* > * On NUMA machines, each NUMA node would have a pg_data_t to describe > * it's memory layout. On UMA machines there is a single pglist_data which > @@ -1253,6 +1278,9 @@ typedef struct pglist_data { > #ifdef CONFIG_NUMA > struct memory_tier __rcu *memtier; > #endif > +#ifdef CONFIG_MEMORY_FAILURE > + struct memory_failure_stats mf_stats; > +#endif > } pg_data_t; > > #define node_present_pages(nid) (NODE_DATA(nid)->node_present_pages) > diff --git a/mm/memory-failure.c b/mm/memory-failure.c > index c77a9e37e27e..c628f1db3a4d 100644 > --- a/mm/memory-failure.c > +++ b/mm/memory-failure.c > @@ -87,6 +87,41 @@ inline void num_poisoned_pages_sub(unsigned long pfn, long i) > memblk_nr_poison_sub(pfn, i); > } > > +/** > + * MF_ATTR_RO - Create sysfs entry for each memory failure statistics. > + * @_name: name of the file in the per NUMA sysfs directory. > + */ > +#define MF_ATTR_RO(_name) \ > +static ssize_t _name##_show(struct device *dev, \ > + struct device_attribute *attr, \ > + char *buf) \ > +{ \ > + struct memory_failure_stats *mf_stats = \ > + &NODE_DATA(dev->id)->mf_stats; \ > + return sprintf(buf, "%lu\n", mf_stats->_name); \ > +} \ > +static DEVICE_ATTR_RO(_name) > + > +MF_ATTR_RO(total); > +MF_ATTR_RO(ignored); > +MF_ATTR_RO(failed); > +MF_ATTR_RO(delayed); > +MF_ATTR_RO(recovered); > + > +static struct attribute *memory_failure_attr[] = { > + &dev_attr_total.attr, > + &dev_attr_ignored.attr, > + &dev_attr_failed.attr, > + &dev_attr_delayed.attr, > + &dev_attr_recovered.attr, > + NULL, > +}; > + > +const struct attribute_group memory_failure_attr_group = { > + .name = "memory_failure", > + .attrs = memory_failure_attr, > +}; > + > /* > * Return values: > * 1: the page is dissolved (if needed) and taken off from buddy,