From patchwork Wed Jan 6 08:47:34 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Muchun Song X-Patchwork-Id: 12001131 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 30428C433E0 for ; Wed, 6 Jan 2021 08:49:46 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id B82A423107 for ; Wed, 6 Jan 2021 08:49:45 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B82A423107 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=bytedance.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 469438D00F5; Wed, 6 Jan 2021 03:49:45 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 418958D0090; Wed, 6 Jan 2021 03:49:45 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2E0A18D00F5; Wed, 6 Jan 2021 03:49:45 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0047.hostedemail.com [216.40.44.47]) by kanga.kvack.org (Postfix) with ESMTP id 1293E8D0090 for ; Wed, 6 Jan 2021 03:49:45 -0500 (EST) Received: from smtpin19.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id D548E365C for ; Wed, 6 Jan 2021 08:49:44 +0000 (UTC) X-FDA: 77674727088.19.lift93_3e00da8274e0 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin19.hostedemail.com (Postfix) with ESMTP id B781E1AD1BA for ; Wed, 6 Jan 2021 08:49:44 +0000 (UTC) X-HE-Tag: lift93_3e00da8274e0 X-Filterd-Recvd-Size: 3979 Received: from mail-pl1-f180.google.com (mail-pl1-f180.google.com [209.85.214.180]) by imf24.hostedemail.com (Postfix) with ESMTP for ; Wed, 6 Jan 2021 08:49:44 +0000 (UTC) Received: by mail-pl1-f180.google.com with SMTP id t6so1234739plq.1 for ; Wed, 06 Jan 2021 00:49:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=EFKJSs8Uw2qVkTfChSTguLsyINtR2C6KwmPPD3vJNks=; b=QzxUz3LBxD+LD/LGS4gpuONiFu9PnmrSYsvkGbjhKmkC0fdySJgrgsYNQv3nFsJebo bx4ZKaHKV2z0UWknW0n1ym6XrnwJKBaQdvIHyKZXlf+G74/SrbpSBaqDLvkLqrsRHquu Yb5StZdj/bzOJxEaJzoXfqaKI/SmEbyiouldh1715V8vizroo2STwOpl3kIHk4lGkdFH eKAofVYlGutq5/36516cYdj7QZ2HP44H5eU8k/EgffGlxfRMLmFXd0hbMsZ81QWL9uYb EF2XOODsnxnNAFph2UbvKRYBGWyCV23dMBuOMq3bpwa/1uGecxzOGPo4CCyoz3gcj2FB PRzw== 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:mime-version:content-transfer-encoding; bh=EFKJSs8Uw2qVkTfChSTguLsyINtR2C6KwmPPD3vJNks=; b=fAyMrKYu4pI/Neq7L0NhQpMYxad3wBPjnRicIbrGIHitCkyw9dDh1DIaO5mxLKJ1Lk EfUUyxY6HDUYRJCtDyLKe/3nvKUduM8Ds6pp82GSHdveQefNsfy9Me212gKTblMFWiJf mf8CnqqlbnD5EiTC6gnYj/dw/hoYODyfuDlbjPuIj/Am4GcwA+uFeeyrsykgDFNXjEFX WDNBGph2GBndYdy2UVVrc/Owlz+Ibxke7miAnoi06ElqXcR7TN7nnGd66MwojVjzjzF5 Z56JgIN/FtOwndxTWZQ2ToCFE+ECIZ6Jc5blZ03QySQDu9MYnpNga8/WIblXNKG/Xk3t q0VQ== X-Gm-Message-State: AOAM532+mVI0iE32UbY6vJWvplTan4XS8HivyGCqCHq1Wc1njmlVnofa y3XADmJDeSBuA7h1Eoz1ZcW9pQ== X-Google-Smtp-Source: ABdhPJzITf3AUbohjO7HdzweaiVQS+Z3gBxO7k/zuZ+qw6GyYiCTZN5Voph+bWWIdBlBn4zEEtPVqg== X-Received: by 2002:a17:90a:6587:: with SMTP id k7mr3379913pjj.154.1609922983278; Wed, 06 Jan 2021 00:49:43 -0800 (PST) Received: from localhost.localdomain ([139.177.225.232]) by smtp.gmail.com with ESMTPSA id h8sm1851806pjc.2.2021.01.06.00.49.39 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 06 Jan 2021 00:49:42 -0800 (PST) From: Muchun Song To: mike.kravetz@oracle.com, akpm@linux-foundation.org Cc: n-horiguchi@ah.jp.nec.com, ak@linux.intel.com, mhocko@suse.cz, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Muchun Song , Yang Shi Subject: [PATCH v2 1/6] mm: migrate: do not migrate HugeTLB page whose refcount is one Date: Wed, 6 Jan 2021 16:47:34 +0800 Message-Id: <20210106084739.63318-2-songmuchun@bytedance.com> X-Mailer: git-send-email 2.21.0 (Apple Git-122) In-Reply-To: <20210106084739.63318-1-songmuchun@bytedance.com> References: <20210106084739.63318-1-songmuchun@bytedance.com> MIME-Version: 1.0 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: If the refcount is one when it is migrated, it means that the page was freed from under us. So we are done and do not need to migrate. Signed-off-by: Muchun Song Reviewed-by: Mike Kravetz Acked-by: Yang Shi --- mm/migrate.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/mm/migrate.c b/mm/migrate.c index 4385f2fb5d18..a6631c4eb6a6 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -1279,6 +1279,12 @@ static int unmap_and_move_huge_page(new_page_t get_new_page, return -ENOSYS; } + if (page_count(hpage) == 1) { + /* page was freed from under us. So we are done. */ + putback_active_hugepage(hpage); + return MIGRATEPAGE_SUCCESS; + } + new_hpage = get_new_page(hpage, private); if (!new_hpage) return -ENOMEM; From patchwork Wed Jan 6 08:47:35 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Muchun Song X-Patchwork-Id: 12001133 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A2EDAC433E0 for ; Wed, 6 Jan 2021 08:49:53 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 32A262310A for ; Wed, 6 Jan 2021 08:49:53 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 32A262310A Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=bytedance.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 970C38D00F7; Wed, 6 Jan 2021 03:49:52 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 8F97C8D0090; Wed, 6 Jan 2021 03:49:52 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7F3548D00F7; Wed, 6 Jan 2021 03:49:52 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0036.hostedemail.com [216.40.44.36]) by kanga.kvack.org (Postfix) with ESMTP id 62E3F8D0090 for ; Wed, 6 Jan 2021 03:49:52 -0500 (EST) Received: from smtpin06.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 2FD21180AD806 for ; Wed, 6 Jan 2021 08:49:52 +0000 (UTC) X-FDA: 77674727424.06.body75_48144df274e0 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin06.hostedemail.com (Postfix) with ESMTP id 11CED1005636C for ; Wed, 6 Jan 2021 08:49:52 +0000 (UTC) X-HE-Tag: body75_48144df274e0 X-Filterd-Recvd-Size: 5085 Received: from mail-pf1-f177.google.com (mail-pf1-f177.google.com [209.85.210.177]) by imf48.hostedemail.com (Postfix) with ESMTP for ; Wed, 6 Jan 2021 08:49:51 +0000 (UTC) Received: by mail-pf1-f177.google.com with SMTP id h186so1346428pfe.0 for ; Wed, 06 Jan 2021 00:49:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=2O4sxrXuT0FCcMIizj5iDb7GOKunPmY/8SboAcivvpk=; b=tL0RH2+wEpb73hSGTr5n++pp7wHB2R912i/VX7pZGK9rTl/lStD7TAjFG+sgUhhd2a 6wvTSDvLPhx0zh+TOBbOhqULN6HmKhMB0f/qBHf5RBy2rJGRnuHTNQFtRU85OJADmqyM alj3qkG58MjGF5GCE8NWdQ1GHaWl8/94FO7aQgewbux+bWT+qXTQlyvirheOHevKsdZz Ezd2upXDgd4c3OdEeVcbUGgQY6niBMHT79fesO+VUV3kN/kc5UNdJPF8cj0ZpzQcnR7e NyYfHcEjO+zz01i5tYKAsXFQUTHwuVpWGT49BLEgdi/coidjeZtAkioyu91s0lHXW35t AWyw== 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:mime-version:content-transfer-encoding; bh=2O4sxrXuT0FCcMIizj5iDb7GOKunPmY/8SboAcivvpk=; b=kNav2eUdCVqUtkVXR5DmxkRtcNrjOgoHaYNo3eg99mkr+H2WX0QwdOLUuk1L1AOPF9 jV6/4UjjSzXKioKkYW8iOt9V+JD0AQfLBx/zZCPkkEpgSsd3bi//44dt4x20ScX/rgdL VyUxMwX77KGDdYI2kY2zSGegGAUXAPF/89BZnN++R0ncgKGOF8bTSPBXcvYUsaqisWHy +qZAJrTNWB7rgWMcii+XHNDgG+c03tzFL1Y6+Pf5u5h59xaMkvXajCMg3TA4KWJJthL0 Dqh1C1D72MklWIErMh6htt9d0Th5OtJrG1M3c2kE2k+p0U6z7E36FOP4VjFtnCBqBbuH 4SoQ== X-Gm-Message-State: AOAM532pjImCn1UdMEEJVTgyFALcYx75lxRkWpg9K50cduRxAQD52rBM tsQEuUGjKiyNw/jes4pO0rAeEg== X-Google-Smtp-Source: ABdhPJzMj0ckWNNfDTFqbQ0rHX8F9/Up1U2wEFuSO1s/Se1yI95wuu1Xwl5VTX8hRXrSbpZ9nqsSew== X-Received: by 2002:a62:7ed2:0:b029:19d:9461:2b30 with SMTP id z201-20020a627ed20000b029019d94612b30mr2914866pfc.14.1609922987055; Wed, 06 Jan 2021 00:49:47 -0800 (PST) Received: from localhost.localdomain ([139.177.225.232]) by smtp.gmail.com with ESMTPSA id h8sm1851806pjc.2.2021.01.06.00.49.43 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 06 Jan 2021 00:49:46 -0800 (PST) From: Muchun Song To: mike.kravetz@oracle.com, akpm@linux-foundation.org Cc: n-horiguchi@ah.jp.nec.com, ak@linux.intel.com, mhocko@suse.cz, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Muchun Song Subject: [PATCH v2 2/6] mm: hugetlbfs: fix cannot migrate the fallocated HugeTLB page Date: Wed, 6 Jan 2021 16:47:35 +0800 Message-Id: <20210106084739.63318-3-songmuchun@bytedance.com> X-Mailer: git-send-email 2.21.0 (Apple Git-122) In-Reply-To: <20210106084739.63318-1-songmuchun@bytedance.com> References: <20210106084739.63318-1-songmuchun@bytedance.com> MIME-Version: 1.0 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: Because we only can isolate a active page via isolate_huge_page() and hugetlbfs_fallocate() forget to mark it as active, we cannot isolate and migrate those pages. Only export set_page_huge_active, just leave clear_page_huge_active as static. Because there are no external users. Fixes: 70c3547e36f5 (hugetlbfs: add hugetlbfs_fallocate()) Signed-off-by: Muchun Song --- fs/hugetlbfs/inode.c | 3 ++- include/linux/hugetlb.h | 2 ++ mm/hugetlb.c | 2 +- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c index b5c109703daa..21c20fd5f9ee 100644 --- a/fs/hugetlbfs/inode.c +++ b/fs/hugetlbfs/inode.c @@ -735,9 +735,10 @@ static long hugetlbfs_fallocate(struct file *file, int mode, loff_t offset, mutex_unlock(&hugetlb_fault_mutex_table[hash]); + set_page_huge_active(page); /* * unlock_page because locked by add_to_page_cache() - * page_put due to reference from alloc_huge_page() + * put_page() due to reference from alloc_huge_page() */ unlock_page(page); put_page(page); diff --git a/include/linux/hugetlb.h b/include/linux/hugetlb.h index ebca2ef02212..b5807f23caf8 100644 --- a/include/linux/hugetlb.h +++ b/include/linux/hugetlb.h @@ -770,6 +770,8 @@ static inline void huge_ptep_modify_prot_commit(struct vm_area_struct *vma, } #endif +void set_page_huge_active(struct page *page); + #else /* CONFIG_HUGETLB_PAGE */ struct hstate {}; diff --git a/mm/hugetlb.c b/mm/hugetlb.c index 1f3bf1710b66..4741d60f8955 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -1348,7 +1348,7 @@ bool page_huge_active(struct page *page) } /* never called for tail page */ -static void set_page_huge_active(struct page *page) +void set_page_huge_active(struct page *page) { VM_BUG_ON_PAGE(!PageHeadHuge(page), page); SetPagePrivate(&page[1]); From patchwork Wed Jan 6 08:47:36 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Muchun Song X-Patchwork-Id: 12001135 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D14E1C433DB for ; Wed, 6 Jan 2021 08:49:54 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 69C8B23107 for ; Wed, 6 Jan 2021 08:49:54 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 69C8B23107 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=bytedance.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id DDF8A8D00F6; Wed, 6 Jan 2021 03:49:52 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id D67D28D0090; Wed, 6 Jan 2021 03:49:52 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A0DDA8D00F8; Wed, 6 Jan 2021 03:49:52 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0031.hostedemail.com [216.40.44.31]) by kanga.kvack.org (Postfix) with ESMTP id 7B8198D00F6 for ; Wed, 6 Jan 2021 03:49:52 -0500 (EST) Received: from smtpin21.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 3E5F6181AEF15 for ; Wed, 6 Jan 2021 08:49:52 +0000 (UTC) X-FDA: 77674727424.21.leg53_2b16795274e0 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin21.hostedemail.com (Postfix) with ESMTP id 2061D180442C0 for ; Wed, 6 Jan 2021 08:49:52 +0000 (UTC) X-HE-Tag: leg53_2b16795274e0 X-Filterd-Recvd-Size: 7328 Received: from mail-pl1-f172.google.com (mail-pl1-f172.google.com [209.85.214.172]) by imf27.hostedemail.com (Postfix) with ESMTP for ; Wed, 6 Jan 2021 08:49:51 +0000 (UTC) Received: by mail-pl1-f172.google.com with SMTP id x18so1219631pln.6 for ; Wed, 06 Jan 2021 00:49:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=lJ6hRAKquF055Y1OoIKyzC/uqe2sOAj6aTfGxl8Ov5o=; b=lwRKGn/TMdWvGDwbh+I3PhFr+hVFNVubFO6mDlXQmjWeArVJAjaxvGB7GjgPg/Xl7Q Tr+8YP3+L1Qvii6CxDgJPvhJTSlQDOZXvOhEN+S1aqTHX/EsTK4EdwYBXhxz7Ag5RrOE GCce0HX0TIONUeffpf/dD9VmexumkkMbQ7AlUtgKxOu9i7Q7Qe0DuVJ8i5hF2+XD3r7F yY4OyX7HFREnzFvY/PJoENi/WP3Pzt4MPLmPYQNy8CElxM5KuVEdiiUJYGbnIEMdrg70 1qRYZf8tfpYydljgGoDAY/CToBQjp5wK8ihPmgDkA9eR9/h9ZsHVlmIS0aN1ZrfSX0Bq sP1Q== 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:mime-version:content-transfer-encoding; bh=lJ6hRAKquF055Y1OoIKyzC/uqe2sOAj6aTfGxl8Ov5o=; b=R5TvG5/KaBkSCxBv1mb2NfKZWSTErdqthSw/PtxqbYRK9g5h43z9IRP3F/yd+34Zv1 jsmUG5yRbUtNk8GWbUfpkPTc1zDuc6fgM6pq/7kRLcX4cZQ50FmoCIZmrMsBzI3VtYmq 4WdwmnB0iZ3lGl4CSHJzXbPjZvC9phzNl+UGjPI7zK5v/+u6PG/UFGRnD6+pztdvLFxV UxEYfpkiU7CxVK+oKfnFpw+m8x/H0b2ZshOOj1vjyKjfvp4fjvoNx41eYR/fuCXIN1HZ vHYb8OiphkSMnEIxdULG72RUTxQgo74cDhXb9k4/fuAIh1ZS14stfX1Xjryo2J+E3yy9 SG4w== X-Gm-Message-State: AOAM532sR+Qyxnn9FMihinXWCchNa81GCWsBRGB6D4aLf2j41EbAwspL EM3wIxAF0j/+jM3W453dtjKGrA== X-Google-Smtp-Source: ABdhPJzoLjhNr+suJcN6OMvbPP4mPjlFSjx8Cv3PSxcwuIgyqps+XldiscytJCAnQg0qL+Ae0XhHog== X-Received: by 2002:a17:902:ed45:b029:da:c274:d7ac with SMTP id y5-20020a170902ed45b02900dac274d7acmr3281653plb.69.1609922990839; Wed, 06 Jan 2021 00:49:50 -0800 (PST) Received: from localhost.localdomain ([139.177.225.232]) by smtp.gmail.com with ESMTPSA id h8sm1851806pjc.2.2021.01.06.00.49.47 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 06 Jan 2021 00:49:50 -0800 (PST) From: Muchun Song To: mike.kravetz@oracle.com, akpm@linux-foundation.org Cc: n-horiguchi@ah.jp.nec.com, ak@linux.intel.com, mhocko@suse.cz, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Muchun Song Subject: [PATCH v2 3/6] mm: hugetlb: fix a race between freeing and dissolving the page Date: Wed, 6 Jan 2021 16:47:36 +0800 Message-Id: <20210106084739.63318-4-songmuchun@bytedance.com> X-Mailer: git-send-email 2.21.0 (Apple Git-122) In-Reply-To: <20210106084739.63318-1-songmuchun@bytedance.com> References: <20210106084739.63318-1-songmuchun@bytedance.com> MIME-Version: 1.0 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: There is a race condition between __free_huge_page() and dissolve_free_huge_page(). CPU0: CPU1: // page_count(page) == 1 put_page(page) __free_huge_page(page) dissolve_free_huge_page(page) spin_lock(&hugetlb_lock) // PageHuge(page) && !page_count(page) update_and_free_page(page) // page is freed to the buddy spin_unlock(&hugetlb_lock) spin_lock(&hugetlb_lock) clear_page_huge_active(page) enqueue_huge_page(page) // It is wrong, the page is already freed spin_unlock(&hugetlb_lock) The race windows is between put_page() and spin_lock() which is in the __free_huge_page(). We should make sure that the page is already on the free list when it is dissolved. Fixes: c8721bbbdd36 ("mm: memory-hotplug: enable memory hotplug to handle hugepage") Signed-off-by: Muchun Song --- mm/hugetlb.c | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index 4741d60f8955..8ff138c17129 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -79,6 +79,21 @@ DEFINE_SPINLOCK(hugetlb_lock); static int num_fault_mutexes; struct mutex *hugetlb_fault_mutex_table ____cacheline_aligned_in_smp; +static inline bool PageHugeFreed(struct page *head) +{ + return (unsigned long)head[3].mapping == -1U; +} + +static inline void SetPageHugeFreed(struct page *head) +{ + head[3].mapping = (void *)-1U; +} + +static inline void ClearPageHugeFreed(struct page *head) +{ + head[3].mapping = NULL; +} + /* Forward declaration */ static int hugetlb_acct_memory(struct hstate *h, long delta); @@ -1028,6 +1043,7 @@ static void enqueue_huge_page(struct hstate *h, struct page *page) list_move(&page->lru, &h->hugepage_freelists[nid]); h->free_huge_pages++; h->free_huge_pages_node[nid]++; + SetPageHugeFreed(page); } static struct page *dequeue_huge_page_node_exact(struct hstate *h, int nid) @@ -1044,6 +1060,7 @@ static struct page *dequeue_huge_page_node_exact(struct hstate *h, int nid) list_move(&page->lru, &h->hugepage_activelist); set_page_refcounted(page); + ClearPageHugeFreed(page); h->free_huge_pages--; h->free_huge_pages_node[nid]--; return page; @@ -1291,6 +1308,17 @@ static inline void destroy_compound_gigantic_page(struct page *page, unsigned int order) { } #endif +/* + * Because we reuse the mapping field of some tail page structs, we should + * reset those mapping to initial value before @head is freed to the buddy + * allocator. The invalid value will be checked in the free_tail_pages_check(). + */ +static inline void reset_tail_page_mapping(struct hstate *h, struct page *head) +{ + if (!hstate_is_gigantic(h)) + head[3].mapping = TAIL_MAPPING; +} + static void update_and_free_page(struct hstate *h, struct page *page) { int i; @@ -1298,6 +1326,7 @@ static void update_and_free_page(struct hstate *h, struct page *page) if (hstate_is_gigantic(h) && !gigantic_page_runtime_supported()) return; + reset_tail_page_mapping(h, page); h->nr_huge_pages--; h->nr_huge_pages_node[page_to_nid(page)]--; for (i = 0; i < pages_per_huge_page(h); i++) { @@ -1504,6 +1533,7 @@ static void prep_new_huge_page(struct hstate *h, struct page *page, int nid) spin_lock(&hugetlb_lock); h->nr_huge_pages++; h->nr_huge_pages_node[nid]++; + ClearPageHugeFreed(page); spin_unlock(&hugetlb_lock); } @@ -1770,6 +1800,14 @@ int dissolve_free_huge_page(struct page *page) int nid = page_to_nid(head); if (h->free_huge_pages - h->resv_huge_pages == 0) goto out; + + /* + * We should make sure that the page is already on the free list + * when it is dissolved. + */ + if (unlikely(!PageHugeFreed(head))) + goto out; + /* * Move PageHWPoison flag from head page to the raw error page, * which makes any subpages rather than the error page reusable. From patchwork Wed Jan 6 08:47:37 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Muchun Song X-Patchwork-Id: 12001137 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BF59CC433E0 for ; Wed, 6 Jan 2021 08:49:57 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 46DEC23107 for ; Wed, 6 Jan 2021 08:49:57 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 46DEC23107 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=bytedance.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id C5E618D00F8; Wed, 6 Jan 2021 03:49:56 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id B6F4B8D0090; Wed, 6 Jan 2021 03:49:56 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 99ACE8D00F8; Wed, 6 Jan 2021 03:49:56 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0087.hostedemail.com [216.40.44.87]) by kanga.kvack.org (Postfix) with ESMTP id 759608D0090 for ; Wed, 6 Jan 2021 03:49:56 -0500 (EST) Received: from smtpin22.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 3C172181AEF15 for ; Wed, 6 Jan 2021 08:49:56 +0000 (UTC) X-FDA: 77674727592.22.sea82_0801f9f274e0 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin22.hostedemail.com (Postfix) with ESMTP id 0E35F18038E67 for ; Wed, 6 Jan 2021 08:49:56 +0000 (UTC) X-HE-Tag: sea82_0801f9f274e0 X-Filterd-Recvd-Size: 5374 Received: from mail-pj1-f42.google.com (mail-pj1-f42.google.com [209.85.216.42]) by imf26.hostedemail.com (Postfix) with ESMTP for ; Wed, 6 Jan 2021 08:49:55 +0000 (UTC) Received: by mail-pj1-f42.google.com with SMTP id w1so2274626pjc.0 for ; Wed, 06 Jan 2021 00:49:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=90s6LK3gLF/6oFq+lOVMbrh8BJ60hxrqeIvsRF2lESM=; b=x3RU16oGuaT9sj2vIkIgRGzTxCPsAJdSnMd8sWAyflNmD0NnMx1rKjuocHYi397T9D RF+7WdL0V2t096pAAfJkwWwOl36sla9UeFGrx5nfzIaIPZV/J9pnj0/4icH7FiUKBqgN ldv+68PZgSRVHgvJ+pxM9ZgSUVLak8lEKUfZ0bIHj9lQH0McLpydQItaiBCUb2fo6lWE owYdYy9m0KdlGsCroggp8cUG7c6GIkamaMe/S80o2Jn/D4raYVvsEqvHxHBEJzHfR6rh nBuZhve0ItidW5g8AruxveGDuIczgSLUQzP5qi9doNPuQ51oNJ1+hp8/rLUA6Ce0QIar 5u7Q== 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:mime-version:content-transfer-encoding; bh=90s6LK3gLF/6oFq+lOVMbrh8BJ60hxrqeIvsRF2lESM=; b=MFrRVJquQG0yW02HqyLmNIuikfwrZUTUJIMpd8+EiRHx/ZEJleU6PF7m3JegM5frC7 nxdyi/SdetXEQqR5gZWvUHDSUHN91/cfADRxGV0imLb9NY930vW9AD1ED1wjg5GHdf4K vHpI/0i5IIKiSFBjdYRuw9Y6GZXnIcoWM8IPdSnJduzLUDFLp/pDJpr2mjtVgraVi0+n N2KUuTs6FMmDBEujBAAmkv3u87zyVdpPsFHFTguqOBGvRgyGZvTZMjWcYu6l9PtcE9j7 YbeadMoJjYa86NSRsFsssASWP/Pm/VWlHGd7LSc39807MRx7mwo3v+KvBfby8UO0yn9m 8Ukw== X-Gm-Message-State: AOAM532iizU4INXsFEcpm+rrOiCCNzEjtvvzsadIw4V7xi2KZgX4FcdB pmZSZIBMo6Q7OCJK1AVl5TO2IA== X-Google-Smtp-Source: ABdhPJwzdYvHQSuz/lHuo7gp/98j1oFQJ+7wjSIWQAntgC/87EdZgm6Fv43aPtl5McyEwfidSM/5KQ== X-Received: by 2002:a17:90b:4a03:: with SMTP id kk3mr3237244pjb.97.1609922994744; Wed, 06 Jan 2021 00:49:54 -0800 (PST) Received: from localhost.localdomain ([139.177.225.232]) by smtp.gmail.com with ESMTPSA id h8sm1851806pjc.2.2021.01.06.00.49.51 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 06 Jan 2021 00:49:54 -0800 (PST) From: Muchun Song To: mike.kravetz@oracle.com, akpm@linux-foundation.org Cc: n-horiguchi@ah.jp.nec.com, ak@linux.intel.com, mhocko@suse.cz, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Muchun Song Subject: [PATCH v2 4/6] mm: hugetlb: add return -EAGAIN for dissolve_free_huge_page Date: Wed, 6 Jan 2021 16:47:37 +0800 Message-Id: <20210106084739.63318-5-songmuchun@bytedance.com> X-Mailer: git-send-email 2.21.0 (Apple Git-122) In-Reply-To: <20210106084739.63318-1-songmuchun@bytedance.com> References: <20210106084739.63318-1-songmuchun@bytedance.com> MIME-Version: 1.0 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: When dissolve_free_huge_page() races with __free_huge_page(), we can do a retry. Because the race window is small. Signed-off-by: Muchun Song --- mm/hugetlb.c | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index 8ff138c17129..bf02e81e3953 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -1775,10 +1775,11 @@ static int free_pool_huge_page(struct hstate *h, nodemask_t *nodes_allowed, * 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) + * -EAGAIN: race with __free_huge_page() and can do a retry + * -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) { @@ -1805,8 +1806,10 @@ int dissolve_free_huge_page(struct page *page) * We should make sure that the page is already on the free list * when it is dissolved. */ - if (unlikely(!PageHugeFreed(head))) + if (unlikely(!PageHugeFreed(head))) { + rc = -EAGAIN; goto out; + } /* * Move PageHWPoison flag from head page to the raw error page, @@ -1825,6 +1828,14 @@ int dissolve_free_huge_page(struct page *page) } out: spin_unlock(&hugetlb_lock); + + /* + * If the freeing of the HugeTLB page is put on a work queue, we should + * flush the work before retrying. + */ + if (unlikely(rc == -EAGAIN)) + flush_work(&free_hpage_work); + return rc; } @@ -1847,7 +1858,12 @@ int dissolve_free_huge_pages(unsigned long start_pfn, unsigned long end_pfn) for (pfn = start_pfn; pfn < end_pfn; pfn += 1 << minimum_order) { page = pfn_to_page(pfn); +retry: rc = dissolve_free_huge_page(page); + if (rc == -EAGAIN) { + cpu_relax(); + goto retry; + } if (rc) break; } From patchwork Wed Jan 6 08:47:38 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Muchun Song X-Patchwork-Id: 12001139 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C623DC433E0 for ; Wed, 6 Jan 2021 08:50:01 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 441AB23107 for ; Wed, 6 Jan 2021 08:50:01 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 441AB23107 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=bytedance.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id BE2528D00F9; Wed, 6 Jan 2021 03:50:00 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id B6B1C8D0090; Wed, 6 Jan 2021 03:50:00 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A33968D00F9; Wed, 6 Jan 2021 03:50:00 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0106.hostedemail.com [216.40.44.106]) by kanga.kvack.org (Postfix) with ESMTP id 8AA8F8D0090 for ; Wed, 6 Jan 2021 03:50:00 -0500 (EST) Received: from smtpin10.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 54F24180AD815 for ; Wed, 6 Jan 2021 08:50:00 +0000 (UTC) X-FDA: 77674727760.10.flock08_2610423274e0 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin10.hostedemail.com (Postfix) with ESMTP id 38CFA169F9A for ; Wed, 6 Jan 2021 08:50:00 +0000 (UTC) X-HE-Tag: flock08_2610423274e0 X-Filterd-Recvd-Size: 5043 Received: from mail-pf1-f172.google.com (mail-pf1-f172.google.com [209.85.210.172]) by imf28.hostedemail.com (Postfix) with ESMTP for ; Wed, 6 Jan 2021 08:49:59 +0000 (UTC) Received: by mail-pf1-f172.google.com with SMTP id a188so1312766pfa.11 for ; Wed, 06 Jan 2021 00:49:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Gaj9ZStUW1Kcj7p4H5CS7rdzKDeUaqkavvNxRg/B5lU=; b=uz+8u529Ju4Davf4ms3sZJcBtnV2a2dvUB9ZF74eLw3nZbjez+6lgG/ipr5t2GVRLJ +8DXAWfRC+zJ3/C1eLukbnCdEnSehR2D1xe8cCGv1KbMcjSaTCAEu0WspHVlSBn7v1g6 bEjQBxpJZ3x8u9qPS1EXoFf/oyBJoRTzjbG7bikMJKUOa2eO+D4DIT7eVQwiQltoLs8q Q4K6+YvpxgHcdJA4FFN6Xk7Y2nVZm7PxPX6kxUwF/xKU7ktOilebxRvUPGVLheS003tX EFY3N9OpSc09x94kEbYXiysL48mE5x4eUVMNWQYF+U4B9iktfHoBFC+SgrLOB2+VL/tY px3w== 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:mime-version:content-transfer-encoding; bh=Gaj9ZStUW1Kcj7p4H5CS7rdzKDeUaqkavvNxRg/B5lU=; b=ZwitFLL+8z7TwJquGeNutsFIYeUtxwKNdYjNgaAg5mv2TZkk57pg1IR6DSig/AvRo5 Qr+CKkrmqyC0zKcIRy+hMLR/D3Kj3EVlMGXE5274oOdMMarh9FfF+tZ9DDf8fXis6+CG Bhu00Ml5KhVq6wC1+aP/5a0WWZutzqpZhsd3I0jl4Fz5KaxnAW14rSh/Mqsu1+9K2JJn dOVG56PuMsBU7hgUoAqB52+i0LbFtkYuSOlRiNa9gDs6cn/g7x0Diu7SF40LgpFgvEUz fIWMx8aArnnhnFh7n+p4PMQq3F5vkdxZvQMMiTz4QjWzoJ0C5RID0duYXb3p3FettsFg 5ZkA== X-Gm-Message-State: AOAM532SeNgBHx6Mbso3q6AnSdY6AhAVdWxOH5WbnBpggCU6ImuhVGZ5 iGTs6w9einqpp/gZTEEPYKFUGw== X-Google-Smtp-Source: ABdhPJzi9OJPuY3J1ix6rvK+ht+c9cNIMgTTmC4RoiVzCxv+LwiA2oLfrLqS4wTl/lcsDyO5xsT+ug== X-Received: by 2002:aa7:9046:0:b029:1a4:aa3b:1f31 with SMTP id n6-20020aa790460000b02901a4aa3b1f31mr2777943pfo.77.1609922998700; Wed, 06 Jan 2021 00:49:58 -0800 (PST) Received: from localhost.localdomain ([139.177.225.232]) by smtp.gmail.com with ESMTPSA id h8sm1851806pjc.2.2021.01.06.00.49.55 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 06 Jan 2021 00:49:58 -0800 (PST) From: Muchun Song To: mike.kravetz@oracle.com, akpm@linux-foundation.org Cc: n-horiguchi@ah.jp.nec.com, ak@linux.intel.com, mhocko@suse.cz, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Muchun Song Subject: [PATCH v2 5/6] mm: hugetlb: fix a race between isolating and freeing page Date: Wed, 6 Jan 2021 16:47:38 +0800 Message-Id: <20210106084739.63318-6-songmuchun@bytedance.com> X-Mailer: git-send-email 2.21.0 (Apple Git-122) In-Reply-To: <20210106084739.63318-1-songmuchun@bytedance.com> References: <20210106084739.63318-1-songmuchun@bytedance.com> MIME-Version: 1.0 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: There is a race between isolate_huge_page() and __free_huge_page(). CPU0: CPU1: if (PageHuge(page)) put_page(page) __free_huge_page(page) spin_lock(&hugetlb_lock) update_and_free_page(page) set_compound_page_dtor(page, NULL_COMPOUND_DTOR) spin_unlock(&hugetlb_lock) isolate_huge_page(page) // trigger BUG_ON VM_BUG_ON_PAGE(!PageHead(page), page) spin_lock(&hugetlb_lock) page_huge_active(page) // trigger BUG_ON VM_BUG_ON_PAGE(!PageHuge(page), page) spin_unlock(&hugetlb_lock) When we isolate a HugeTLB page on CPU0. Meanwhile, we free it to the buddy allocator on CPU1. Then, we can trigger a BUG_ON on CPU0. Because it is already freed to the buddy allocator. Fixes: c8721bbbdd36 ("mm: memory-hotplug: enable memory hotplug to handle hugepage") Signed-off-by: Muchun Song Reviewed-by: Mike Kravetz Acked-by: Michal Hocko --- mm/hugetlb.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index bf02e81e3953..67200dd25b1d 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -5587,9 +5587,9 @@ bool isolate_huge_page(struct page *page, struct list_head *list) { bool ret = true; - VM_BUG_ON_PAGE(!PageHead(page), page); spin_lock(&hugetlb_lock); - if (!page_huge_active(page) || !get_page_unless_zero(page)) { + if (!PageHeadHuge(page) || !page_huge_active(page) || + !get_page_unless_zero(page)) { ret = false; goto unlock; } From patchwork Wed Jan 6 08:47:39 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Muchun Song X-Patchwork-Id: 12001141 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C67B0C433E9 for ; Wed, 6 Jan 2021 08:50:05 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 45E2F23107 for ; Wed, 6 Jan 2021 08:50:05 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 45E2F23107 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=bytedance.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id BE2828D00FA; Wed, 6 Jan 2021 03:50:04 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id B6A808D0090; Wed, 6 Jan 2021 03:50:04 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9977D8D00FA; Wed, 6 Jan 2021 03:50:04 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0242.hostedemail.com [216.40.44.242]) by kanga.kvack.org (Postfix) with ESMTP id 8087D8D0090 for ; Wed, 6 Jan 2021 03:50:04 -0500 (EST) Received: from smtpin05.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 50F4940D7 for ; Wed, 6 Jan 2021 08:50:04 +0000 (UTC) X-FDA: 77674727928.05.cave47_230fce3274e0 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin05.hostedemail.com (Postfix) with ESMTP id 33A1618034A7D for ; Wed, 6 Jan 2021 08:50:04 +0000 (UTC) X-HE-Tag: cave47_230fce3274e0 X-Filterd-Recvd-Size: 4043 Received: from mail-pj1-f44.google.com (mail-pj1-f44.google.com [209.85.216.44]) by imf05.hostedemail.com (Postfix) with ESMTP for ; Wed, 6 Jan 2021 08:50:03 +0000 (UTC) Received: by mail-pj1-f44.google.com with SMTP id n3so2275475pjm.1 for ; Wed, 06 Jan 2021 00:50:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ZzyixQGA22PztCHoWMVb3aoY+aYlev25PUQfD61xRIU=; b=c1h2czxUSUbpHsdB4iBoOCMv92fTBJlrTNNN8pZTRAkAVXAMpC7mvGeNEujZTSK7ES 9lVAhDo1svl3YRAnZ8TQ+fL4pj6wKKHoiH4JzVA7TNDRza61TbLNEqODnH1kqlG0SRof QkSyY89PQ3YMT8FqXRFF87g1AKBBRor7qUoNTzqnfLYq+1vwBsIimaiyAj6h7YzDDsOl wTKSkO/ZE+Md2PT5bw/8f6elxhgmnZNDadXoxnX65sgMOMHhRi29DR0eqQ4KgtKClqWY bifB2nrVqj3dgL/Y0j/dfXnF0B4GflTvaXIRMI3hjPbHNl0BFRhfW3+Ekh8LEZ2L3hvV umBg== 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:mime-version:content-transfer-encoding; bh=ZzyixQGA22PztCHoWMVb3aoY+aYlev25PUQfD61xRIU=; b=BsXivCisaMJBnMLVGy0v5EWowufYHglakrUdyyvtrrCpvDByIrarNBO6Cccn7i8Cek hPdSqpEomCXGI2JFIvJiVxEhwfIRF/uSa41Q70Lkb+ZS40oGAVKwJ9UzylhRecil1K8X 8jjhpVF85+Hlwmk9+EOj8tmA1KI9buTghFvdrExtsKVJLKmjalPYKrlbLKGxDZ9tV3GL wVxqeO+DQ5JMBbAoHuzRQ0kHAmU/Al91GnmjbnNK5388D99MgQefh1PDv6JbzOmITInk eb731yvSpVXlxgPZ4SyOXdRxDOhIEscqaYw70rRr9b3FZZedMTqEBBuXLM32TGJ0zgGr AXYQ== X-Gm-Message-State: AOAM532mOBRHQAo6I6NDyumbuojS+MGVDUmjCIQo+2J1gV6ykMfXgqX9 3fVkxnTDJ8B7ba9nzWz2GmMPCQ== X-Google-Smtp-Source: ABdhPJypfVLEzKgsmoKlg4BWX+DeSaJaZcfQVkmc7fId0VbM26E/aLydbaqPJl7gy+SNKpR4XNHETg== X-Received: by 2002:a17:90a:f194:: with SMTP id bv20mr3315484pjb.11.1609923002773; Wed, 06 Jan 2021 00:50:02 -0800 (PST) Received: from localhost.localdomain ([139.177.225.232]) by smtp.gmail.com with ESMTPSA id h8sm1851806pjc.2.2021.01.06.00.49.59 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 06 Jan 2021 00:50:02 -0800 (PST) From: Muchun Song To: mike.kravetz@oracle.com, akpm@linux-foundation.org Cc: n-horiguchi@ah.jp.nec.com, ak@linux.intel.com, mhocko@suse.cz, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Muchun Song Subject: [PATCH v2 6/6] mm: hugetlb: remove VM_BUG_ON_PAGE from page_huge_active Date: Wed, 6 Jan 2021 16:47:39 +0800 Message-Id: <20210106084739.63318-7-songmuchun@bytedance.com> X-Mailer: git-send-email 2.21.0 (Apple Git-122) In-Reply-To: <20210106084739.63318-1-songmuchun@bytedance.com> References: <20210106084739.63318-1-songmuchun@bytedance.com> MIME-Version: 1.0 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: The page_huge_active() can be called from scan_movable_pages() which do not hold a reference count to the HugeTLB page. So when we call page_huge_active() from scan_movable_pages(), the HugeTLB page can be freed parallel. Then we will trigger a BUG_ON which is in the page_huge_active() when CONFIG_DEBUG_VM is enabled. Just remove the VM_BUG_ON_PAGE. Fixes: 7e1f049efb86 ("mm: hugetlb: cleanup using paeg_huge_active()") Signed-off-by: Muchun Song Reviewed-by: Mike Kravetz Acked-by: Michal Hocko --- mm/hugetlb.c | 1 - 1 file changed, 1 deletion(-) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index 67200dd25b1d..7a24ed28ec4f 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -1372,7 +1372,6 @@ struct hstate *size_to_hstate(unsigned long size) */ bool page_huge_active(struct page *page) { - VM_BUG_ON_PAGE(!PageHuge(page), page); return PageHead(page) && PagePrivate(&page[1]); }