Received: by 2002:a05:6602:2086:0:0:0:0 with SMTP id a6csp4457562ioa; Wed, 27 Apr 2022 04:25:53 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyEGTtLAFmGKW54wvgjPnvyV5skYRBOLx3pCxOghLjhuLuQe16yNWWrYVHxCabHXxsMKJx3 X-Received: by 2002:a17:902:bc8c:b0:156:bc64:fa47 with SMTP id bb12-20020a170902bc8c00b00156bc64fa47mr27928775plb.135.1651058752856; Wed, 27 Apr 2022 04:25:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651058752; cv=none; d=google.com; s=arc-20160816; b=gJpbNWlFQSUUyg5GoeqaSxDgxxgSnoKQBOxA584bwn2XNhFMVAa/1Jskl5FduCJ/XC 9DbEhp5QMzDo3HB0dg3XS6H80uIMlJBuXAytWEqKEzBCJBWvnGGSz4PVoFRB4FlkuN3A xZDehs8NUhT1KiE6Murrq6a7pqhOMa6giLSaBzMGnHl/X+x2YYZjWAs+5CN6Obe3AHT8 vRd32kCW8xGtfY94b3m53a2pglWqTm1AIKeNzh6k5O9qw81/vzzJCHfrEKmP1D4pH/j5 b9fGxpm4tmGYoA2SjsxME+kf5u+8IRx6H/vTJWI1u4lO3W9OpgIdj/gMgrjurLDG/C+6 3DRw== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=vhFv468URMziQMW888ZYB3zUqaYOfFeInA7ZUvxhWkc=; b=O4/581SYFj68lalE33iTGEqhqMaoxVSWgngW0EnYWyj08816x9zJdPIA63/1f9UTTb rj27HypuS1fQ4gI1MuyGUCejqX13ilf2WjZchPced7vP7o1nmGo/3YcGHPHExdmx50+J VWr1TMPEX+lSjGDJwjkzzMTQOKANA+97nV0kAR25Td+VLg65fe5dL4hWrxT0IFZLbqgD nkoZihFBb10K3MnDeRvX2MFz554p4H9YU/0yOyG8MXl4KdjKkZxAUxCw7wBIc4+1C3Oc 9QH3j9O1Rz4EuXUGjk/LeOrvey/zLP7vZj9EE34Hl0uJPYXNR0bbXH5znk2QSU+Zf+be zMHw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=FIkAxocm; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id m5-20020a170902f64500b00158e5bfcc7dsi1396358plg.136.2022.04.27.04.25.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Apr 2022 04:25:52 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=FIkAxocm; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id AF91E374D66; Wed, 27 Apr 2022 03:22:21 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1357669AbiD0EcL (ORCPT + 99 others); Wed, 27 Apr 2022 00:32:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49744 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1357666AbiD0EcJ (ORCPT ); Wed, 27 Apr 2022 00:32:09 -0400 Received: from out2.migadu.com (out2.migadu.com [188.165.223.204]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D31094A901 for ; Tue, 26 Apr 2022 21:28:58 -0700 (PDT) X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1651033737; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=vhFv468URMziQMW888ZYB3zUqaYOfFeInA7ZUvxhWkc=; b=FIkAxocmKdaKVf5IxSOBZWld4OyWK+kxFY3MwdXcu6ZQBpNw203KwgWMbt+dNNyuZSUFkx fZ6F9Iu6x7FM54n99F6JvN0fC8yTDgxwtGGhEV1XNgxY77wfRgdSMRbaIIPisBRPaGfuFf z0TkMtNqa1+2tjPtjsnsUwno22b75aY= From: Naoya Horiguchi To: linux-mm@kvack.org Cc: Andrew Morton , Miaohe Lin , David Hildenbrand , Mike Kravetz , Yang Shi , Oscar Salvador , Muchun Song , Naoya Horiguchi , linux-kernel@vger.kernel.org Subject: [RFC PATCH v1 1/4] mm, hwpoison, hugetlb: introduce SUBPAGE_INDEX_HWPOISON to save raw error page Date: Wed, 27 Apr 2022 13:28:38 +0900 Message-Id: <20220427042841.678351-2-naoya.horiguchi@linux.dev> In-Reply-To: <20220427042841.678351-1-naoya.horiguchi@linux.dev> References: <20220427042841.678351-1-naoya.horiguchi@linux.dev> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT X-Migadu-Auth-User: linux.dev X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 but 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 page is lost. Use the private field of a tail page to keep that information. The code path of shrinking hugepage pool used this info to try delayed dissolve. Signed-off-by: Naoya Horiguchi --- include/linux/hugetlb.h | 24 ++++++++++++++++++++++++ mm/hugetlb.c | 9 +++++++++ mm/memory-failure.c | 2 ++ 3 files changed, 35 insertions(+) diff --git a/include/linux/hugetlb.h b/include/linux/hugetlb.h index ac2a1d758a80..689e69cb556b 100644 --- a/include/linux/hugetlb.h +++ b/include/linux/hugetlb.h @@ -42,6 +42,9 @@ enum { SUBPAGE_INDEX_CGROUP, /* reuse page->private */ SUBPAGE_INDEX_CGROUP_RSVD, /* reuse page->private */ __MAX_CGROUP_SUBPAGE_INDEX = SUBPAGE_INDEX_CGROUP_RSVD, +#endif +#ifdef CONFIG_CGROUP_HUGETLB + SUBPAGE_INDEX_HWPOISON, #endif __NR_USED_SUBPAGE, }; @@ -784,6 +787,27 @@ extern int dissolve_free_huge_page(struct page *page); extern int dissolve_free_huge_pages(unsigned long start_pfn, unsigned long end_pfn); +#ifdef CONFIG_MEMORY_FAILURE +/* + * pointer to raw error page is located in hpage[SUBPAGE_INDEX_HWPOISON].private + */ +static inline struct page *hugetlb_page_hwpoison(struct page *hpage) +{ + return (void *)page_private(hpage + SUBPAGE_INDEX_HWPOISON); +} + +static inline void hugetlb_set_page_hwpoison(struct page *hpage, + struct page *page) +{ + set_page_private(hpage + SUBPAGE_INDEX_HWPOISON, (unsigned long)page); +} +#else +static inline struct page *hugetlb_page_hwpoison(struct page *hpage) +{ + return NULL; +} +#endif + #ifdef CONFIG_ARCH_ENABLE_HUGEPAGE_MIGRATION #ifndef arch_hugetlb_migration_supported static inline bool arch_hugetlb_migration_supported(struct hstate *h) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index f8e048b939c7..6867ea8345d1 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -1547,6 +1547,15 @@ static void __update_and_free_page(struct hstate *h, struct page *page) return; } + if (unlikely(PageHWPoison(page))) { + struct page *raw_error = hugetlb_page_hwpoison(page); + + if (raw_error && raw_error != page) { + SetPageHWPoison(raw_error); + ClearPageHWPoison(page); + } + } + for (i = 0; i < pages_per_huge_page(h); i++, subpage = mem_map_next(subpage, page, i)) { subpage->flags &= ~(1 << PG_locked | 1 << PG_error | diff --git a/mm/memory-failure.c b/mm/memory-failure.c index 3e36fc19c4d1..73948a00ad4a 100644 --- a/mm/memory-failure.c +++ b/mm/memory-failure.c @@ -1535,6 +1535,8 @@ int __get_huge_page_for_hwpoison(unsigned long pfn, int flags) goto out; } + hugetlb_set_page_hwpoison(head, page); + return ret; out: if (count_increased) -- 2.25.1