From patchwork Fri Oct 21 08:46:09 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kefeng Wang X-Patchwork-Id: 6561 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4242:0:0:0:0:0 with SMTP id s2csp565600wrr; Fri, 21 Oct 2022 01:32:46 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4TA/F6oiMxOlxvgWoEZDdpKX+s3C75XIjaYVCu+6HmLGszE9b5LtHHiY1nQxcG3z2skXtM X-Received: by 2002:a05:6402:2b8b:b0:43a:5475:f1ae with SMTP id fj11-20020a0564022b8b00b0043a5475f1aemr16178847edb.363.1666341166375; Fri, 21 Oct 2022 01:32:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666341166; cv=none; d=google.com; s=arc-20160816; b=rk9Bd36nb0Yoy2zo3glZzGcr3nKlDqoQpAWrBjDKnBRimASPMnbLnTU2vlr9OXCOHb JrO8adzmc5/1wHFzoKw/btLT72AluAUvlWzxKDLdYiUTr6JDDB2ajZ2LT1XW4iIvL09n 6vlQ5kFKMeeEWFdY9XxVYB2MwYiwHP3ikPxDrZQotL4BYFUySeLJ76NFQoABrEg1BNn9 SR8E17HgPRZe2zgVUi23XGvw1MdbzF1803x/dAnRJ6bYZt5tROnt0Uq1ypWws90WaTck cPZ7Fome4Jed+R1AEx3qv9I11gRqkxbQ06irRMW33++mnULZoQ0ay0843riS6EYWyu7X xrkA== 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; bh=SvtD7TEzG/7RYfxd+tmpCjijSpKb3RLAE436DHlzYsE=; b=nss6F45Gwda6+X1dJA/LiCgUjAiX/fAivM3rkiYOAxxnXmWY0fNtCq/fEzW1OTEwdl 1O0QO/ZViurRBsHNYX3fHwb0MPNsuZduAsFrd2SbXgLsbmBWpVGggJ2blMQelMXZqm/J Rkgh0NJ80eDcg6KEGg7StrqHbYkYvOQa4BPQwvGLMbV30FZNlMFsCyKwOEEeLwdS6qhl ScY8ebVgCkChIP4OBg+YkECEJcvCFA+iELb4xMEwzOGaQLsIR7ZJthS+lll5b6BPXbdY q6woSoWCoRCv/hPupcmIeOISA90Hmef5up1e8JDtxIA2GPWRCTsSVeMosUgyv4ZzLulw 4/aA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id dn10-20020a17090794ca00b00791a84056d9si6840984ejc.751.2022.10.21.01.32.21; Fri, 21 Oct 2022 01:32:46 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229931AbiJUI1Z (ORCPT + 99 others); Fri, 21 Oct 2022 04:27:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45154 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229746AbiJUI1G (ORCPT ); Fri, 21 Oct 2022 04:27:06 -0400 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8766D202711 for ; Fri, 21 Oct 2022 01:27:05 -0700 (PDT) Received: from dggpemm500020.china.huawei.com (unknown [172.30.72.53]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4MtyCy4cKBzpVWk; Fri, 21 Oct 2022 16:23:42 +0800 (CST) Received: from dggpemm500001.china.huawei.com (7.185.36.107) by dggpemm500020.china.huawei.com (7.185.36.49) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Fri, 21 Oct 2022 16:27:01 +0800 Received: from localhost.localdomain.localdomain (10.175.113.25) 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.31; Fri, 21 Oct 2022 16:27:01 +0800 From: Kefeng Wang To: Naoya Horiguchi , Andrew Morton CC: Miaohe Lin , , , Kefeng Wang Subject: [PATCH 1/3] mm: memory-failure: make put_ref_page() more useful Date: Fri, 21 Oct 2022 16:46:09 +0800 Message-ID: <20221021084611.53765-1-wangkefeng.wang@huawei.com> X-Mailer: git-send-email 2.35.3 MIME-Version: 1.0 X-Originating-IP: [10.175.113.25] X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To dggpemm500001.china.huawei.com (7.185.36.107) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS autolearn=ham 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747285354880454042?= X-GMAIL-MSGID: =?utf-8?q?1747285354880454042?= Pass pfn/flags to put_ref_page(), then check MF_COUNT_INCREASED and drop refcount to make the code look cleaner. Signed-off-by: Kefeng Wang Acked-by: Naoya Horiguchi Reviewed-by: Miaohe Lin --- mm/memory-failure.c | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/mm/memory-failure.c b/mm/memory-failure.c index bead6bccc7f2..b94152abb1c9 100644 --- a/mm/memory-failure.c +++ b/mm/memory-failure.c @@ -1913,17 +1913,25 @@ static inline unsigned long free_raw_hwp_pages(struct page *hpage, bool flag) } #endif /* CONFIG_HUGETLB_PAGE */ +/* Drop the extra refcount in case we come from madvise() */ +static void put_ref_page(unsigned long pfn, int flags) +{ + struct page *page; + + if (!(flags & MF_COUNT_INCREASED)) + return; + + page = pfn_to_page(pfn); + if (page) + put_page(page); +} + static int memory_failure_dev_pagemap(unsigned long pfn, int flags, struct dev_pagemap *pgmap) { - struct page *page = pfn_to_page(pfn); int rc = -ENXIO; - if (flags & MF_COUNT_INCREASED) - /* - * Drop the extra refcount in case we come from madvise(). - */ - put_page(page); + put_ref_page(pfn, flags); /* device metadata space is not recoverable */ if (!pgmap_pfn_valid(pgmap, pfn)) @@ -2516,12 +2524,6 @@ static int soft_offline_in_use_page(struct page *page) return ret; } -static void put_ref_page(struct page *page) -{ - if (page) - put_page(page); -} - /** * soft_offline_page - Soft offline a page. * @pfn: pfn to soft-offline @@ -2550,19 +2552,17 @@ int soft_offline_page(unsigned long pfn, int flags) { int ret; bool try_again = true; - struct page *page, *ref_page = NULL; + struct page *page; WARN_ON_ONCE(!pfn_valid(pfn) && (flags & MF_COUNT_INCREASED)); if (!pfn_valid(pfn)) return -ENXIO; - if (flags & MF_COUNT_INCREASED) - ref_page = pfn_to_page(pfn); /* Only online pages can be soft-offlined (esp., not ZONE_DEVICE). */ page = pfn_to_online_page(pfn); if (!page) { - put_ref_page(ref_page); + put_ref_page(pfn, flags); return -EIO; } @@ -2570,7 +2570,7 @@ int soft_offline_page(unsigned long pfn, int flags) if (PageHWPoison(page)) { pr_info("%s: %#lx page already poisoned\n", __func__, pfn); - put_ref_page(ref_page); + put_ref_page(pfn, flags); mutex_unlock(&mf_mutex); return 0; }