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 2D3D2C43334 for ; Wed, 13 Jul 2022 04:51:45 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 411BD9400FF; Wed, 13 Jul 2022 00:51:44 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3C10D9400E5; Wed, 13 Jul 2022 00:51:44 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2B0EE9400FF; Wed, 13 Jul 2022 00:51:44 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 1D4689400E5 for ; Wed, 13 Jul 2022 00:51:44 -0400 (EDT) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay11.hostedemail.com (Postfix) with ESMTP id DC9AF807A2 for ; Wed, 13 Jul 2022 04:51:43 +0000 (UTC) X-FDA: 79680853686.02.8B4422B Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by imf22.hostedemail.com (Postfix) with ESMTP id 902B2C0072 for ; Wed, 13 Jul 2022 04:51:39 +0000 (UTC) Received: from canpemm500002.china.huawei.com (unknown [172.30.72.53]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4LjQ916RC5zVffs; Wed, 13 Jul 2022 12:47:49 +0800 (CST) Received: from [10.174.177.76] (10.174.177.76) by canpemm500002.china.huawei.com (7.192.104.244) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Wed, 13 Jul 2022 12:51:31 +0800 Subject: Re: [mm-unstable PATCH v6 3/8] mm, hwpoison, hugetlb: support saving mechanism of raw error pages To: Naoya Horiguchi , CC: Andrew Morton , David Hildenbrand , Mike Kravetz , Liu Shixin , Yang Shi , Oscar Salvador , Muchun Song , Naoya Horiguchi , References: <20220712032858.170414-1-naoya.horiguchi@linux.dev> <20220712032858.170414-4-naoya.horiguchi@linux.dev> From: Miaohe Lin Message-ID: <0ba226e6-c297-d87d-f74e-9036a6121072@huawei.com> Date: Wed, 13 Jul 2022 12:51:30 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.6.0 MIME-Version: 1.0 In-Reply-To: <20220712032858.170414-4-naoya.horiguchi@linux.dev> Content-Type: text/plain; charset="utf-8" Content-Language: en-US Content-Transfer-Encoding: 7bit X-Originating-IP: [10.174.177.76] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To canpemm500002.china.huawei.com (7.192.104.244) X-CFilter-Loop: Reflected ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf22.hostedemail.com: domain of linmiaohe@huawei.com designates 45.249.212.188 as permitted sender) smtp.mailfrom=linmiaohe@huawei.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1657687902; 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=nHvxz4H7pbFRxuvLo9DhtlYDHW+jSPkgsU1vfnHTQPM=; b=Sk3vsIssyEQKtKfzCp4BRNIlgUjcy/IOqAakK4Q2D+LAGr9Fn9ZYyxG7E5SzaCEDjB2yIn XU0oOHonUxpJB4bpFnPlkN9jAVASOE3QIwNzW0SvURr3sl4OEuzSRXkTezLP9jWlnaT4u6 lNG7eOEVHvR5gTLrDtH7K1GqekGjqGk= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1657687902; a=rsa-sha256; cv=none; b=j/YJ4g7DQ4ib1aq+61lr5IUo8vwiVPE0M3rCLa/MRI9QAhv6zNMUOhdwEzEwnhpD2VS7f/ BIG4gIcmdC+bltX9RwC0N6x15wHRwlaTfgwskfS72tse5nYqkTlSk2j8BVYnrVWIAZ5p7D gDiBIteUTjoutm0kiYNZGiC3OK1eOxE= X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 902B2C0072 X-Stat-Signature: 99qqxbi8ic9s9cda631burqh4e8pn1qj Authentication-Results: imf22.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf22.hostedemail.com: domain of linmiaohe@huawei.com designates 45.249.212.188 as permitted sender) smtp.mailfrom=linmiaohe@huawei.com X-Rspam-User: X-HE-Tag: 1657687899-36327 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 2022/7/12 11:28, Naoya Horiguchi wrote: > From: Naoya Horiguchi > > When handling memory error on a hugetlb page, the error handler tries to > dissolve and turn it into 4kB pages. If it's successfully dissolved, > PageHWPoison flag is moved to the raw error page, so that's all right. > However, dissolve sometimes fails, then the error page is left as > hwpoisoned hugepage. It's useful if we can retry to dissolve it to save > healthy pages, but that's not possible now because the information about > where the raw error pages is lost. > > Use the private field of a few tail pages to keep that information. The > code path of shrinking hugepage pool uses this info to try delayed dissolve. > In order to remember multiple errors in a hugepage, a singly-linked list > originated from SUBPAGE_INDEX_HWPOISON-th tail page is constructed. Only > simple operations (adding an entry or clearing all) are required and the > list is assumed not to be very long, so this simple data structure should > be enough. > > If we failed to save raw error info, the hwpoison hugepage has errors on > unknown subpage, then this new saving mechanism does not work any more, > so disable saving new raw error info and freeing hwpoison hugepages. > > Signed-off-by: Naoya Horiguchi > Reported-by: kernel test robot This patch looks good to me with some nits below. > --- ... > +static int hugetlb_set_page_hwpoison(struct page *hpage, struct page *page) > +{ > + struct llist_head *head; > + struct raw_hwp_page *raw_hwp; > + struct llist_node *t, *tnode; > + int ret = TestSetPageHWPoison(hpage) ? -EHWPOISON : 0; > + > + /* > + * Once the hwpoison hugepage has lost reliable raw error info, > + * there is little meaning to keep additional error info precisely, > + * so skip to add additional raw error info. > + */ > + if (HPageRawHwpUnreliable(hpage)) > + return -EHWPOISON; > + head = raw_hwp_list_head(hpage); > + llist_for_each_safe(tnode, t, head->first) { > + struct raw_hwp_page *p = container_of(tnode, struct raw_hwp_page, node); > + > + if (p->page == page) > + return -EHWPOISON; > + } > + > + raw_hwp = kmalloc(sizeof(struct raw_hwp_page), GFP_ATOMIC); > + if (raw_hwp) { > + raw_hwp->page = page; > + llist_add(&raw_hwp->node, head); > + /* the first error event will be counted in action_result(). */ > + if (ret) > + num_poisoned_pages_inc(); > + } else { > + /* > + * Failed to save raw error info. We no longer trace all > + * hwpoisoned subpages, and we need refuse to free/dissolve > + * this hwpoisoned hugepage. > + */ > + SetHPageRawHwpUnreliable(hpage); IMHO, when HPageRawHwpUnreliable is set, we can simply free the raw_hwp_list here to save some memory as they're not used anymore. > + } > + return ret; > +} > + > +void hugetlb_clear_page_hwpoison(struct page *hpage) > +{ > + struct llist_head *head; > + struct llist_node *t, *tnode; > + > + if (!HPageRawHwpUnreliable(hpage)) > + ClearPageHWPoison(hpage); > + head = raw_hwp_list_head(hpage); > + llist_for_each_safe(tnode, t, head->first) { > + struct raw_hwp_page *p = container_of(tnode, struct raw_hwp_page, node); > + > + SetPageHWPoison(p->page); > + kfree(p); > + } > + llist_del_all(head); > +} > + > /* > * Called from hugetlb code with hugetlb_lock held. > * > @@ -1698,7 +1771,7 @@ int __get_huge_page_for_hwpoison(unsigned long pfn, int flags) > goto out; > } > > - if (TestSetPageHWPoison(head)) { > + if (hugetlb_set_page_hwpoison(head, page)) { > ret = -EHWPOISON; > goto out; > } > @@ -1710,7 +1783,6 @@ int __get_huge_page_for_hwpoison(unsigned long pfn, int flags) > return ret; > } > > -#ifdef CONFIG_HUGETLB_PAGE > /* > * Taking refcount of hugetlb pages needs extra care about race conditions > * with basic operations like hugepage allocation/free/demotion. > @@ -1751,7 +1823,7 @@ static int try_memory_failure_hugetlb(unsigned long pfn, int flags, int *hugetlb > lock_page(head); > > if (hwpoison_filter(p)) { > - ClearPageHWPoison(head); > + hugetlb_clear_page_hwpoison(head); If the code reach here, the hugetlb page should be poisoned first time or it will return in above "res == -EHWPOISON" case. So ClearPageHWPoison should be fine here. But this change will do the same thing while making the code more consistent. So it should be fine. :) > res = -EOPNOTSUPP; > goto out; > } > Anyway, for what it worth, Reviewed-by: Miaohe Lin Thanks!