Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp3055144ybi; Tue, 2 Jul 2019 01:15:01 -0700 (PDT) X-Google-Smtp-Source: APXvYqytIiHjUtfrvD9fPYj6GsB9fa0YFCwTz1jbE4zRUVrZcDqVOONq605jCeF2cTPo3Dx8ZHkE X-Received: by 2002:a63:6ecf:: with SMTP id j198mr29251237pgc.437.1562055301529; Tue, 02 Jul 2019 01:15:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562055301; cv=none; d=google.com; s=arc-20160816; b=TOSnsVVabB5v1Uv8yeZpEXH9WG4Sj5J1XKKkkSX0rXj6ZWGEJowW4vwH7bO1zkKGtt Xl6tjIfBCGH0Cx6O+p+X2cC+zdro/ls65rSX+gldB4fbc/Yuq0Qv19u0i2cqigwDqjPk Q+qb0DH/Sai4s7SM4Z6OtzxWdUe8k6WEEM6dppevRY7OVYHdG9KZhlkAPP1cKtwe0HgZ zPWpra7yeDn7KytJ/vSek8yFqdWvEuG9zID5G8VqsBh3i+D9nff6fPnfa34E3SkJN1uC P+mF+o2bJO68WI5WOuUNFGyBEKWjYpkTkSTTrijHfidrjtoI0dbOAmofQ4jnA7JnQ1b0 mTFQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=DCrYqTWiikXkEXB9KdN2gQSaAs0utWi9bHPDktp9tSw=; b=VLCFly9ojVXxm6sgDcDWYvRb+t+dSDiqw1Z6VQXvms9EUFnq69/aL4uwa4xaleF6ZS q6xjgd54i5yXr/rBtgHxHRpbm8zkLRhBDv3YoBYvcEHeI1PCvNVW2SAGWXZPrVldUFLY 6SeXqZNNKQp1V80ShGN8/1fkAp3+gthYYeL05gAEZRXcl+kmofdnnqtTvu8F6JPSTPpX kKQa6Kt9D4xbdultJaFdgqzwXaBX+2KO5ePw2bKr1plAsTGZzTR9gr9AAt1zcpnIAPHR Vqzu566CcTAih+PXFmffNJP3je67qS6gtcbQENuCMcB1Q7ulnyomr9ZUyRvH68R4fE8Q xKfA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=PAo9sP6V; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id gb4si12637459plb.429.2019.07.02.01.14.47; Tue, 02 Jul 2019 01:15:01 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=PAo9sP6V; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728193AbfGBIMz (ORCPT + 99 others); Tue, 2 Jul 2019 04:12:55 -0400 Received: from mail.kernel.org ([198.145.29.99]:33330 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727643AbfGBIMu (ORCPT ); Tue, 2 Jul 2019 04:12:50 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id BE07820665; Tue, 2 Jul 2019 08:12:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1562055169; bh=Z0XCsJ+5mTRDINcSV7Sao44MlHUB4G73F9YpQhFyVMo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=PAo9sP6Vhpan2D4cipYvLJA98aRs+dGHjwf01Eb/vfAs/cfwAFTV7nUeAR2uh8PF5 kyS0lXby9HOADL1BI+8UEKl0uSLe6oIaoC1XF7dvdw7Xu8j0vUuPlnaT05Fhl9PsZT kqrYz5Z05TKupE2j0mzcqozYNZw7Nikm/8hO1dow= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Naoya Horiguchi , "Chen, Jerry T" , Mike Kravetz , Oscar Salvador , Michal Hocko , Xishi Qiu , "Zhuo, Qiuxu" , Andrew Morton , Linus Torvalds Subject: [PATCH 4.19 37/72] mm: hugetlb: soft-offline: dissolve_free_huge_page() return zero on !PageHuge Date: Tue, 2 Jul 2019 10:01:38 +0200 Message-Id: <20190702080126.593773732@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190702080124.564652899@linuxfoundation.org> References: <20190702080124.564652899@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Naoya Horiguchi commit faf53def3b143df11062d87c12afe6afeb6f8cc7 upstream. madvise(MADV_SOFT_OFFLINE) often returns -EBUSY when calling soft offline for hugepages with overcommitting enabled. That was caused by the suboptimal code in current soft-offline code. See the following part: ret = migrate_pages(&pagelist, new_page, NULL, MPOL_MF_MOVE_ALL, MIGRATE_SYNC, MR_MEMORY_FAILURE); if (ret) { ... } else { /* * We set PG_hwpoison only when the migration source hugepage * was successfully dissolved, because otherwise hwpoisoned * hugepage remains on free hugepage list, then userspace will * find it as SIGBUS by allocation failure. That's not expected * in soft-offlining. */ ret = dissolve_free_huge_page(page); if (!ret) { if (set_hwpoison_free_buddy_page(page)) num_poisoned_pages_inc(); } } return ret; Here dissolve_free_huge_page() returns -EBUSY if the migration source page was freed into buddy in migrate_pages(), but even in that case we actually has a chance that set_hwpoison_free_buddy_page() succeeds. So that means current code gives up offlining too early now. dissolve_free_huge_page() checks that a given hugepage is suitable for dissolving, where we should return success for !PageHuge() case because the given hugepage is considered as already dissolved. This change also affects other callers of dissolve_free_huge_page(), which are cleaned up together. [n-horiguchi@ah.jp.nec.com: v3] Link: http://lkml.kernel.org/r/1560761476-4651-3-git-send-email-n-horiguchi@ah.jp.nec.comLink: http://lkml.kernel.org/r/1560154686-18497-3-git-send-email-n-horiguchi@ah.jp.nec.com Fixes: 6bc9b56433b76 ("mm: fix race on soft-offlining") Signed-off-by: Naoya Horiguchi Reported-by: Chen, Jerry T Tested-by: Chen, Jerry T Reviewed-by: Mike Kravetz Reviewed-by: Oscar Salvador Cc: Michal Hocko Cc: Xishi Qiu Cc: "Chen, Jerry T" Cc: "Zhuo, Qiuxu" Cc: [4.19+] Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Greg Kroah-Hartman --- mm/hugetlb.c | 29 ++++++++++++++++++++--------- mm/memory-failure.c | 5 +---- 2 files changed, 21 insertions(+), 13 deletions(-) --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -1489,16 +1489,29 @@ static int free_pool_huge_page(struct hs /* * Dissolve a given free hugepage into free buddy pages. This function does - * nothing for in-use (including surplus) hugepages. Returns -EBUSY if the - * dissolution fails because a give page is not a free hugepage, or because - * free hugepages are fully reserved. + * nothing for in-use hugepages and non-hugepages. + * This function returns values like below: + * + * -EBUSY: failed to dissolved free hugepages or the hugepage is in-use + * (allocated or reserved.) + * 0: successfully dissolved free hugepages or the page is not a + * hugepage (considered as already dissolved) */ int dissolve_free_huge_page(struct page *page) { int rc = -EBUSY; + /* Not to disrupt normal path by vainly holding hugetlb_lock */ + if (!PageHuge(page)) + return 0; + spin_lock(&hugetlb_lock); - if (PageHuge(page) && !page_count(page)) { + if (!PageHuge(page)) { + rc = 0; + goto out; + } + + if (!page_count(page)) { struct page *head = compound_head(page); struct hstate *h = page_hstate(head); int nid = page_to_nid(head); @@ -1543,11 +1556,9 @@ int dissolve_free_huge_pages(unsigned lo for (pfn = start_pfn; pfn < end_pfn; pfn += 1 << minimum_order) { page = pfn_to_page(pfn); - if (PageHuge(page) && !page_count(page)) { - rc = dissolve_free_huge_page(page); - if (rc) - break; - } + rc = dissolve_free_huge_page(page); + if (rc) + break; } return rc; --- a/mm/memory-failure.c +++ b/mm/memory-failure.c @@ -1857,11 +1857,8 @@ static int soft_offline_in_use_page(stru static int soft_offline_free_page(struct page *page) { - int rc = 0; - struct page *head = compound_head(page); + int rc = dissolve_free_huge_page(page); - if (PageHuge(head)) - rc = dissolve_free_huge_page(page); if (!rc) { if (set_hwpoison_free_buddy_page(page)) num_poisoned_pages_inc();