Received: by 2002:a25:ca44:0:0:0:0:0 with SMTP id a65csp2608633ybg; Fri, 31 Jul 2020 05:22:54 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwMHy+s7u12zgVugVMunrHz3/VfB4hj0BUnaMXBySJB6eB/FddBcOry50+b7TseAIgH3UXk X-Received: by 2002:a17:906:6558:: with SMTP id u24mr3652392ejn.364.1596198174278; Fri, 31 Jul 2020 05:22:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1596198174; cv=none; d=google.com; s=arc-20160816; b=xR8a2uPnhvrkMGe8/yV+O3w+2nxRt4hTPOr4Aa9B1ZkgOzDZPh/oxEeJKsO6MbNfm4 5g6NiswGNDOKF16yUR5xOjBMqbeO4vxZVVWIVZUu87GqkGL+u33Ej4oAGItQaTKQlq1O 5LnnCMDxmRXeLUhZTJiosX+gOUSa1pP0B4yn9XdXHEHspK224Qeki56+x36gq+8H+Iqs Pk+jeI+obYCAwv6mQ4o+RuFEdWJJxs3HIpXB45bhrsZeezWQaAwJKwxJSfeS22p05kfi jZvFpd7vSgMl8/PIgW4MALBtH8BeKrkSiW8IupWk7FdPcl4euBNzC2ADKGBHwioUk3Lt qq4Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=xft2h5FohjfWqnBcTKXmA02wYQ8Sl17A7am29j5Mcz4=; b=SqR/LokyxsN4/Tb1NC5hcLOSzuIgFcqhC4e/a8naDlJY7LdNoXKcLidcbs1oX/sUGY /KGaJlyFy0Jkkr84cmsz6I/Fa43i5z7ovFTkAMC4YbbBt0JjyE+B826Fz5VmX3IeFRs6 zUOuD/4PEb397OjIYXQpgyLV0Lk3JwLVGP64t3tTfJncxdafYWgsllB+VloZbAtuKWNs Xx1iWggvTEpjbxM8234nMzhWU7nVLNBEL4DpHT0X+BxhykAHgQxg7TbIP2KuLaOu4JFx cTaK5uTBtuuo2bdmtYfXgxosexy8KID8nbRfTtlGO0ohKlsOjjqxToVX/zY5Rwk4lynV jbUw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=XsLxJoNa; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id v1si5196944ejd.418.2020.07.31.05.22.31; Fri, 31 Jul 2020 05:22:54 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=XsLxJoNa; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1733227AbgGaMVu (ORCPT + 99 others); Fri, 31 Jul 2020 08:21:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59226 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1733200AbgGaMVt (ORCPT ); Fri, 31 Jul 2020 08:21:49 -0400 Received: from mail-pj1-x1041.google.com (mail-pj1-x1041.google.com [IPv6:2607:f8b0:4864:20::1041]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4B20AC061574 for ; Fri, 31 Jul 2020 05:21:49 -0700 (PDT) Received: by mail-pj1-x1041.google.com with SMTP id t6so3813919pjr.0 for ; Fri, 31 Jul 2020 05:21:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=xft2h5FohjfWqnBcTKXmA02wYQ8Sl17A7am29j5Mcz4=; b=XsLxJoNaCXyJMenZtH47jIDCecoY0NPI+oIT8mRxAwzFTQwvpVYtgrQmDqoCxZQS2j OkQkZGa3bB3lohBRuKB4KlRF1cx/nqhc0jF/j4qh/VIokvCJE/16aoZ5M9AZTi0NuXX3 ZVZOFHbJ9fQLxe5QccT/2LDXZuD33zVxYF4GPW5RRutWLf5Q9SES9ZTablJGOKNbEa0G 4rfMnwIjlYFSHvnXE10SIrnzcMOPyUJxusBJGs9YEXWBYjVEt0pfqwuMxr4KYzzUtQ3M n78Up05OOiIafcJ4Nm6qBQV/6LafOamSVbp03LF4yxx8MKuKXcUS6Bwsjbvhu0uaPTeD jhFA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=xft2h5FohjfWqnBcTKXmA02wYQ8Sl17A7am29j5Mcz4=; b=IYpJF2OZrnsyfMCPh1WOCKIGdQqOZDbBZXTeHxffprF+OZL8uuziPP039YTUKkjyOP Ifc8jCMHACMi7ZRs0PJycWsjq/gsqtkXZLmH98S0YEZ8svpzs6TX+6huJqdP9+aE8Zuo SQpYSv1s38e4LUUPDPLYmtLGmNsJqCcOm9Zm/ftztfgClYXIFDstZzU7yo17jlVDp2gU bB2+8b30E3iaDkNt06+8Bz3fpEDfbGj6k1pj67KH+YmHUlRUhIJWigxf/W8GUDHONuPG ClcsOs8kJpo8uwoUyG51S+/vt/vi9ygPuHpzTVq9pPJ7c4Hk0tJ7Daqs8JwswGEbIgZj Q/ew== X-Gm-Message-State: AOAM532UxgjF2jJrsUhFIMwbq68W6S74rsO8oD1vUIQAU2lHklZ9GmCb v/yaplJg7MfDZ1/3NZQ7PQ== X-Received: by 2002:a17:90b:4d0f:: with SMTP id mw15mr3787072pjb.174.1596198108893; Fri, 31 Jul 2020 05:21:48 -0700 (PDT) Received: from ip-172-31-41-194.ap-northeast-1.compute.internal (ec2-52-199-21-241.ap-northeast-1.compute.amazonaws.com. [52.199.21.241]) by smtp.gmail.com with ESMTPSA id m19sm3675692pjv.34.2020.07.31.05.21.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 31 Jul 2020 05:21:48 -0700 (PDT) From: nao.horiguchi@gmail.com To: linux-mm@kvack.org Cc: mhocko@kernel.org, akpm@linux-foundation.org, mike.kravetz@oracle.com, osalvador@suse.de, tony.luck@intel.com, david@redhat.com, aneesh.kumar@linux.vnet.ibm.com, zeil@yandex-team.ru, cai@lca.pw, naoya.horiguchi@nec.com, linux-kernel@vger.kernel.org Subject: [PATCH v5 10/16] mm,hwpoison: Unify THP handling for hard and soft offline Date: Fri, 31 Jul 2020 12:21:06 +0000 Message-Id: <20200731122112.11263-11-nao.horiguchi@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200731122112.11263-1-nao.horiguchi@gmail.com> References: <20200731122112.11263-1-nao.horiguchi@gmail.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Oscar Salvador Place the THP's page handling in a helper and use it from both hard and soft-offline machinery, so we get rid of some duplicated code. Signed-off-by: Oscar Salvador Signed-off-by: Naoya Horiguchi --- mm/memory-failure.c | 48 +++++++++++++++++++++------------------------ 1 file changed, 22 insertions(+), 26 deletions(-) diff --git v5.8-rc7-mmotm-2020-07-27-18-18/mm/memory-failure.c v5.8-rc7-mmotm-2020-07-27-18-18_patched/mm/memory-failure.c index 7c0a2f8cfe0c..803f4b2ac510 100644 --- v5.8-rc7-mmotm-2020-07-27-18-18/mm/memory-failure.c +++ v5.8-rc7-mmotm-2020-07-27-18-18_patched/mm/memory-failure.c @@ -1103,6 +1103,25 @@ static int identify_page_state(unsigned long pfn, struct page *p, return page_action(ps, p, pfn); } +static int try_to_split_thp_page(struct page *page, const char *msg) +{ + lock_page(page); + if (!PageAnon(page) || unlikely(split_huge_page(page))) { + unsigned long pfn = page_to_pfn(page); + + unlock_page(page); + if (!PageAnon(page)) + pr_info("%s: %#lx: non anonymous thp\n", msg, pfn); + else + pr_info("%s: %#lx: thp split failed\n", msg, pfn); + put_page(page); + return -EBUSY; + } + unlock_page(page); + + return 0; +} + static int memory_failure_hugetlb(unsigned long pfn, int flags) { struct page *p = pfn_to_page(pfn); @@ -1325,21 +1344,8 @@ int memory_failure(unsigned long pfn, int flags) } if (PageTransHuge(hpage)) { - lock_page(p); - if (!PageAnon(p) || unlikely(split_huge_page(p))) { - unlock_page(p); - if (!PageAnon(p)) - pr_err("Memory failure: %#lx: non anonymous thp\n", - pfn); - else - pr_err("Memory failure: %#lx: thp split failed\n", - pfn); - if (TestClearPageHWPoison(p)) - num_poisoned_pages_dec(); - put_page(p); + if (try_to_split_thp_page(p, "Memory Failure") < 0) return -EBUSY; - } - unlock_page(p); VM_BUG_ON_PAGE(!page_count(p), p); } @@ -1844,19 +1850,9 @@ static int soft_offline_in_use_page(struct page *page) int mt; struct page *hpage = compound_head(page); - if (!PageHuge(page) && PageTransHuge(hpage)) { - lock_page(page); - if (!PageAnon(page) || unlikely(split_huge_page(page))) { - unlock_page(page); - if (!PageAnon(page)) - pr_info("soft offline: %#lx: non anonymous thp\n", page_to_pfn(page)); - else - pr_info("soft offline: %#lx: thp split failed\n", page_to_pfn(page)); - put_page(page); + if (!PageHuge(page) && PageTransHuge(hpage)) + if (try_to_split_thp_page(page, "soft offline") < 0) return -EBUSY; - } - unlock_page(page); - } /* * Setting MIGRATE_ISOLATE here ensures that the page will be linked -- 2.17.1