From patchwork Mon Jan 4 06:58: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: 11996219 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 14263C433DB for ; Mon, 4 Jan 2021 07:01:17 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 8E27E2087E for ; Mon, 4 Jan 2021 07:01:16 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8E27E2087E 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 B81C46B00A0; Mon, 4 Jan 2021 02:01:15 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id B318D8D0002; Mon, 4 Jan 2021 02:01:15 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A210B8D0001; Mon, 4 Jan 2021 02:01:15 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0027.hostedemail.com [216.40.44.27]) by kanga.kvack.org (Postfix) with ESMTP id 88C426B00A0 for ; Mon, 4 Jan 2021 02:01:15 -0500 (EST) Received: from smtpin01.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 41314824805A for ; Mon, 4 Jan 2021 07:01:15 +0000 (UTC) X-FDA: 77667196110.01.jail32_060edac274ce Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin01.hostedemail.com (Postfix) with ESMTP id 24BF41004764C for ; Mon, 4 Jan 2021 07:01:15 +0000 (UTC) X-HE-Tag: jail32_060edac274ce X-Filterd-Recvd-Size: 3737 Received: from mail-pj1-f42.google.com (mail-pj1-f42.google.com [209.85.216.42]) by imf01.hostedemail.com (Postfix) with ESMTP for ; Mon, 4 Jan 2021 07:01:14 +0000 (UTC) Received: by mail-pj1-f42.google.com with SMTP id iq13so9461282pjb.3 for ; Sun, 03 Jan 2021 23:01:14 -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:mime-version :content-transfer-encoding; bh=KfWnBt9oMWkYekWPdC8T/NbKzeZ/tVaqKYGZLAFF0lk=; b=XnrcvtLGW3NnmKsqgZ99vjzAVDjrRuk7oMv+sz+YCA19t+irHF982MYUr3KSKp3/Cd KgZnj0IAKDQnVPHC2tiQHJGHTadqblujYH4Q5KMhq6meBiKVCfod9fKE/j2BaXZ9Vaj0 r0/lFIln/I+0uRa2SUhr2oN692OsEe3ElgM6thaJQGJk8SjC44XCHr1lWbCi0P1mOLm+ bdjP74QFrbcxTJoA60I4BaMYZBs7y83siX8r/7OO5XMEdUmFm6WmaYx7T9gr793fV3aO wZFKORYiFB5oGansXHiLmsourUDqryOD3eeB4ZFszlN3U1lzBwnNSs8aWmr/VCPCrDin DNSQ== 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:mime-version :content-transfer-encoding; bh=KfWnBt9oMWkYekWPdC8T/NbKzeZ/tVaqKYGZLAFF0lk=; b=lxA1YbEttcVKEDWADzwzU8WGpG+4bPVmgtySltQN5q02kMFWrq3yH4hm7XPuRkCg6A 5PgsxrcAQmI/0jXz+MmfTlTEPRufeNiw/bjHiDs0iLxsLCfaTCYkIAVSx8JNsowSLF8v nBw/Dy7vaPK0wR4oZA1muaEobN09pUD/+n+IrjT7gxFPFCjl5BK9lD80OvaoNdxiVqkH GCcSjwu+g5Y66VDZn/L3WtH961Ltk+j4HWi12AEkKO/9UHo6VKmQAd7X9qE/fiZ1oXW4 jm8ThQm7IBLUhflb77CMOeg65511Gla0dUcL1RKmQg/35+rODiVEgoNj2CqtaIc8tr/B 2scg== X-Gm-Message-State: AOAM533MlKQAcLBQqodHCZU+t+CJuQsUxLlB2jKrZse4kJiJdDoS/KAk W0W53WmEDaT0gBZ64NpvEaE/6w== X-Google-Smtp-Source: ABdhPJwefBRpU311LeHDKfh1oqafHOF8ar7PhHcu5bep1BOfGProsLsWyVlvDYGkE6kgdWnVTM/1jA== X-Received: by 2002:a17:90b:2317:: with SMTP id mt23mr28669952pjb.2.1609743673362; Sun, 03 Jan 2021 23:01:13 -0800 (PST) Received: from localhost.localdomain ([240e:b1:e401:3::6]) by smtp.gmail.com with ESMTPSA id v1sm36306648pga.63.2021.01.03.23.00.41 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 03 Jan 2021 23:01:12 -0800 (PST) From: Muchun Song To: mike.kravetz@oracle.com, akpm@linux-foundation.org Cc: hillf.zj@alibaba-inc.com, n-horiguchi@ah.jp.nec.com, ak@linux.intel.com, yongjun_wei@trendmicro.com.cn, mhocko@suse.cz, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Muchun Song Subject: [PATCH 1/6] mm: migrate: do not migrate HugeTLB page whose refcount is one Date: Mon, 4 Jan 2021 14:58:38 +0800 Message-Id: <20210104065843.5658-1-songmuchun@bytedance.com> X-Mailer: git-send-email 2.21.0 (Apple Git-122) 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 Mon Jan 4 06:58: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: 11996221 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 9B708C433E0 for ; Mon, 4 Jan 2021 07:01:39 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 30F2E21D79 for ; Mon, 4 Jan 2021 07:01:39 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 30F2E21D79 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 7AE816B00A3; Mon, 4 Jan 2021 02:01:38 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 75F938D0002; Mon, 4 Jan 2021 02:01:38 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 650178D0001; Mon, 4 Jan 2021 02:01:38 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0135.hostedemail.com [216.40.44.135]) by kanga.kvack.org (Postfix) with ESMTP id 4D3586B00A3 for ; Mon, 4 Jan 2021 02:01:38 -0500 (EST) Received: from smtpin15.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 11649180AD80F for ; Mon, 4 Jan 2021 07:01:38 +0000 (UTC) X-FDA: 77667197076.15.coach80_3301e63274ce Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin15.hostedemail.com (Postfix) with ESMTP id E14271814B0C1 for ; Mon, 4 Jan 2021 07:01:37 +0000 (UTC) X-HE-Tag: coach80_3301e63274ce X-Filterd-Recvd-Size: 4235 Received: from mail-pg1-f177.google.com (mail-pg1-f177.google.com [209.85.215.177]) by imf34.hostedemail.com (Postfix) with ESMTP for ; Mon, 4 Jan 2021 07:01:37 +0000 (UTC) Received: by mail-pg1-f177.google.com with SMTP id g15so18444689pgu.9 for ; Sun, 03 Jan 2021 23:01:36 -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=s/SmIjUY1iXgmpYVoTEFRvKyqR5z81Ow+60craOQ1V8=; b=eX/7BvY+k8Ogg2yVzYJp4S1E7wxS+1ns6iztHR1qdNGA0tGUFYHIX6VbfvCb80bFFn cP54FoMdobERR5RY7H6uMyhUl/qW0RHUbRWsgVXjR/iPwtz348CFIea3xrDoRVa2lFuc kDESclSiyB99S7MiaC7PePmiBzmZdrH9o4O/S3+gaQ4KIk9aoqO17qIDhxc4aMfw7Zuz 3+s+aNHffdQo8PERgbFflMQKiUBCjT3JT7XrhVg1hrxJ3oyvmWh2lDM9pOe+mTLxwQ+G T97FRiYo4p/m0IRbeMzD0XRUSXXQ7tQP5zYNdwpDpFTFKc2vhhu5ISpqPvWaZOxsjdDS d7bg== 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=s/SmIjUY1iXgmpYVoTEFRvKyqR5z81Ow+60craOQ1V8=; b=mMl3z1erf7merooLngodYYa3dZxBI0SYDxj8DzcBe3Uwxm0Nx82MME/SrvAn3Tdofk AEOXbgkYRVxP5Dg1rDuF7CRZU674oU8US/7pOQnCMl8Gz6CJ/VnFFFezVWjreprXQqos svNBE6P+H7DnMIC6A7erMQLTyAF7lGbXJP2ZPcMOHJY2UQmu6Qd04/IS9SojmMgNXaJV 4iLv+M3ElgpwAUZmqsMOfvERTbTNh5cOJVjHyFLyZwVT9szhx2f+5XDb29OcapSBp+XN UJZxQE23S/7u07dtjaM5vJ3ippwmpnVeqaQnv5SIEYIE0u5X1lN1GLDcGWTtJ4oPj6ZB NmXw== X-Gm-Message-State: AOAM5309YTbaO92PUrW23M/EZFquo51pl5UtQLT22lYoM8nNDopzVLdp jODtl3dS/ZUuS0yLApHfD+uzow== X-Google-Smtp-Source: ABdhPJwY5jsG9Aek0pLNoLlUr8MTESblTrmvgVjTEfEY1zFB3mN+RiZLmSk00JPfpWzizO3Zi3ocQw== X-Received: by 2002:a05:6a00:1481:b029:197:fc39:f646 with SMTP id v1-20020a056a001481b0290197fc39f646mr44458467pfu.57.1609743696095; Sun, 03 Jan 2021 23:01:36 -0800 (PST) Received: from localhost.localdomain ([240e:b1:e401:3::6]) by smtp.gmail.com with ESMTPSA id v1sm36306648pga.63.2021.01.03.23.01.14 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 03 Jan 2021 23:01:35 -0800 (PST) From: Muchun Song To: mike.kravetz@oracle.com, akpm@linux-foundation.org Cc: hillf.zj@alibaba-inc.com, n-horiguchi@ah.jp.nec.com, ak@linux.intel.com, yongjun_wei@trendmicro.com.cn, mhocko@suse.cz, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Muchun Song Subject: [PATCH 2/6] hugetlbfs: fix cannot migrate the fallocated HugeTLB page Date: Mon, 4 Jan 2021 14:58:39 +0800 Message-Id: <20210104065843.5658-2-songmuchun@bytedance.com> X-Mailer: git-send-email 2.21.0 (Apple Git-122) In-Reply-To: <20210104065843.5658-1-songmuchun@bytedance.com> References: <20210104065843.5658-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. Fixes: 70c3547e36f5 (hugetlbfs: add hugetlbfs_fallocate()) Signed-off-by: Muchun Song --- fs/hugetlbfs/inode.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c index b5c109703daa..2aceb085d202 100644 --- a/fs/hugetlbfs/inode.c +++ b/fs/hugetlbfs/inode.c @@ -737,10 +737,11 @@ static long hugetlbfs_fallocate(struct file *file, int mode, loff_t offset, /* * unlock_page because locked by add_to_page_cache() - * page_put due to reference from alloc_huge_page() + * put_page() (which is in the putback_active_hugepage()) + * due to reference from alloc_huge_page() */ unlock_page(page); - put_page(page); + putback_active_hugepage(page); } if (!(mode & FALLOC_FL_KEEP_SIZE) && offset + len > inode->i_size) From patchwork Mon Jan 4 06:58:40 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Muchun Song X-Patchwork-Id: 11996223 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 5033BC433DB for ; Mon, 4 Jan 2021 07:02:36 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id B70CB21D79 for ; Mon, 4 Jan 2021 07:02:35 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B70CB21D79 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 2F3E58D0001; Mon, 4 Jan 2021 02:02:35 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 2CA476B00AD; Mon, 4 Jan 2021 02:02:35 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1DFE28D0001; Mon, 4 Jan 2021 02:02:35 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0064.hostedemail.com [216.40.44.64]) by kanga.kvack.org (Postfix) with ESMTP id 08AAA6B00AB for ; Mon, 4 Jan 2021 02:02:35 -0500 (EST) Received: from smtpin06.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id AFFD9362C for ; Mon, 4 Jan 2021 07:02:34 +0000 (UTC) X-FDA: 77667199428.06.arch83_19004a9274ce Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin06.hostedemail.com (Postfix) with ESMTP id 954C010043ABD for ; Mon, 4 Jan 2021 07:02:34 +0000 (UTC) X-HE-Tag: arch83_19004a9274ce X-Filterd-Recvd-Size: 7364 Received: from mail-pl1-f179.google.com (mail-pl1-f179.google.com [209.85.214.179]) by imf33.hostedemail.com (Postfix) with ESMTP for ; Mon, 4 Jan 2021 07:02:34 +0000 (UTC) Received: by mail-pl1-f179.google.com with SMTP id v3so14009597plz.13 for ; Sun, 03 Jan 2021 23:02:33 -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=Ecn176xO4zQ8Y5+qvJO+NXfQmQmbZVPueFRQXY2zG70=; b=V1viqRcLBhAjMI4s5hkLwNzsHo44mZ1JVGTUfwxULDQ4QljgyDmKFC7FWmn5TTH6Sx OCeUI59t+P/ZcDGB60unp9LOjdx5uwLi8PxK6IuO7n5b1teoQDHDUq8OXtp7K7WySchi 5r8YZA+2YSFbwY1YdjU1RoPe1YGiEJSVH4Lc2tIVDFxCTJDL6iKXy9WgAFNsygxk/izN N+Pcs5HnmXZxLZwHBB7IDlFDZ8RWKR0aXdVYHtHjPv+jcqvqS2S4Czad3Z00iGBc3Set pbHT3VLWs30Kk3+NDES94Y4BM5SIDCw1xtAB4eVrFsJjVs00HWyFm0/q/aUESg6fL6B9 C7kg== 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=Ecn176xO4zQ8Y5+qvJO+NXfQmQmbZVPueFRQXY2zG70=; b=I3/TYp0fftnGK3P3alk5xR2AMScCVe3v+Ov8ecUhj28KvkgnRjKxUa1ZjdV9vVRAQy DmcxGM/45bTv8HQ2IY3f453lJyerfpnFURQimpe9tBRdHXQIeU//9822Z4q03BSDTNJG CDL8YVOjGzoGJPXXCzfsnqAzdKots3nzrdAETBmLHgCbv01LH4Qj2YXhFX7P/L0Z4TXt aJezgCPCUm080/kzx+IJaDrsDvwfD5jyHKL0/iraXSTw3abIWfekITk+qYzD/dAvuKdK aLBPVPIwUgSVzfC6Fc+DP1WXiuDNjLbfwzo0lyHyXwT5BcP5Ep77yO1AYE0V8uGB8zg5 HttQ== X-Gm-Message-State: AOAM5331sSKQcmIobNaPoysE0iP7jRbjqyvZEqTrNpWYI1/zYPk5xKyj bEy3gNQbzy0knYFg07Ml8GZiLA== X-Google-Smtp-Source: ABdhPJxoUVmQraBDL53NIFbrMpNmkyyk7mkatnVzcuLbK4z/W+93TnPT0tjGcq72noGrgnbp0oofLg== X-Received: by 2002:a17:902:b948:b029:dc:102c:b4a with SMTP id h8-20020a170902b948b02900dc102c0b4amr62777604pls.3.1609743753038; Sun, 03 Jan 2021 23:02:33 -0800 (PST) Received: from localhost.localdomain ([240e:b1:e401:3::6]) by smtp.gmail.com with ESMTPSA id v1sm36306648pga.63.2021.01.03.23.02.05 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 03 Jan 2021 23:02:32 -0800 (PST) From: Muchun Song To: mike.kravetz@oracle.com, akpm@linux-foundation.org Cc: hillf.zj@alibaba-inc.com, n-horiguchi@ah.jp.nec.com, ak@linux.intel.com, yongjun_wei@trendmicro.com.cn, mhocko@suse.cz, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Muchun Song Subject: [PATCH 3/6] mm: hugetlb: fix a race between freeing and dissolving the page Date: Mon, 4 Jan 2021 14:58:40 +0800 Message-Id: <20210104065843.5658-3-songmuchun@bytedance.com> X-Mailer: git-send-email 2.21.0 (Apple Git-122) In-Reply-To: <20210104065843.5658-1-songmuchun@bytedance.com> References: <20210104065843.5658-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 | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index 1f3bf1710b66..72608008f8b4 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 page_private(head) == -1UL; +} + +static inline void SetPageHugeFreed(struct page *head) +{ + set_page_private(head + 4, -1UL); +} + +static inline void ClearPageHugeFreed(struct page *head) +{ + set_page_private(head + 4, 0); +} + /* 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; @@ -1504,6 +1521,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 +1788,36 @@ 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; + + /* + * 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) + * enqueue_huge_page(page) + * // It is wrong, the page is already freed + * spin_unlock(&hugetlb_lock) + * + * The race window 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. + */ + 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 Mon Jan 4 06:58:41 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Muchun Song X-Patchwork-Id: 11996225 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 E2AF6C433DB for ; Mon, 4 Jan 2021 07:03:53 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 667FB2087E for ; Mon, 4 Jan 2021 07:03:53 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 667FB2087E 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 009826B00AD; Mon, 4 Jan 2021 02:03:53 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id ED3818D0003; Mon, 4 Jan 2021 02:03:52 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DE8948D0002; Mon, 4 Jan 2021 02:03:52 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0073.hostedemail.com [216.40.44.73]) by kanga.kvack.org (Postfix) with ESMTP id C8E5C6B00AD for ; Mon, 4 Jan 2021 02:03:52 -0500 (EST) Received: from smtpin30.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 49818362A for ; Mon, 4 Jan 2021 07:03:52 +0000 (UTC) X-FDA: 77667202704.30.fruit84_4d15cad274ce Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin30.hostedemail.com (Postfix) with ESMTP id 29120180B3AB8 for ; Mon, 4 Jan 2021 07:03:52 +0000 (UTC) X-HE-Tag: fruit84_4d15cad274ce X-Filterd-Recvd-Size: 5067 Received: from mail-pj1-f41.google.com (mail-pj1-f41.google.com [209.85.216.41]) by imf06.hostedemail.com (Postfix) with ESMTP for ; Mon, 4 Jan 2021 07:03:51 +0000 (UTC) Received: by mail-pj1-f41.google.com with SMTP id v1so9477653pjr.2 for ; Sun, 03 Jan 2021 23:03: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=pO8eETMUuHslv7dgCvzXTlqPBwMMUJJFuNV+syZPPjo=; b=XX9nqxXjuf6vW9b2nopnCN21CK6HjbXrGfgHP1xJ+/xyeFEj6p/6SIm7sD0l2Hkaa9 d5d9f3VtSdHToGhL8wY1d59oxbbvVzB/U75YqxD5wYLzl7UoKjsqqPMbrNsQ74DyjUj3 sYAVf4KfRCEFTi7p5/epvifmtzeCTE+b90WhcHZ7DrIxm7ML79c9zaQvO9LS7Vj/pQ6t /2Z/4d7zZVOvqIM4HmiOTEiV9b4Ae8PajOlEb5wqC80XzkPvs+U/rBLLcbUS+DU68ccH fLm+KTglAN+jpQcbpIyDyJPHAvb6aDfPYtdwHn71sUXuM/ji7QNqh/UISDq11a5NcvEx DQIA== 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=pO8eETMUuHslv7dgCvzXTlqPBwMMUJJFuNV+syZPPjo=; b=PC0h6qNogd2YOiBEkYknME7IvKq0yQS+pb5/6JEilCbFPjC+5W8CWli3CEW1aFwaZD AiV31I96S8dsFL8g51IRq4+V6Tw/2nCcdbsyNktQu/NXdRQ4yaKTgmtfYydHCgt32fEr WbxZT1GBy/dqA62KnrpknO4syvx+ejt9+tsl0f3scsdU1pY3ZIx4eMYVVKFvMyNYwk6p Mew9wWNtVukc9WiE76DftDa8S8PLnGcOfQLA37iJj9PhTspBj/Y9Rk7uMQaeMLxQ70ZH 5sVRfw/IMQTvtqHdoRkHLh/RjqEAPptnTg525ORu3EiI70hc2oe8jaSxhIFbIsnCk7cu Ngtw== X-Gm-Message-State: AOAM530HXBs/xTetAnnj5BGmReOjo/maGJtm1uEdKK9ffVG7n1AGL8Q/ nyrWMAhcClCY6JRhiyKcHnAT1A== X-Google-Smtp-Source: ABdhPJwqbxBxS5PJMCHoPtWr4TCCnEdAuUTeeZ5VgymgtCsqQHhK6TjTED8OZyw4Vu33BJFsAmKZfQ== X-Received: by 2002:a17:90b:23d6:: with SMTP id md22mr28061594pjb.206.1609743830555; Sun, 03 Jan 2021 23:03:50 -0800 (PST) Received: from localhost.localdomain ([240e:b1:e401:3::6]) by smtp.gmail.com with ESMTPSA id v1sm36306648pga.63.2021.01.03.23.02.33 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 03 Jan 2021 23:03:49 -0800 (PST) From: Muchun Song To: mike.kravetz@oracle.com, akpm@linux-foundation.org Cc: hillf.zj@alibaba-inc.com, n-horiguchi@ah.jp.nec.com, ak@linux.intel.com, yongjun_wei@trendmicro.com.cn, mhocko@suse.cz, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Muchun Song Subject: [PATCH 4/6] mm: hugetlb: add return -EAGAIN for dissolve_free_huge_page Date: Mon, 4 Jan 2021 14:58:41 +0800 Message-Id: <20210104065843.5658-4-songmuchun@bytedance.com> X-Mailer: git-send-email 2.21.0 (Apple Git-122) In-Reply-To: <20210104065843.5658-1-songmuchun@bytedance.com> References: <20210104065843.5658-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 | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index 72608008f8b4..db00ae375d2a 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -1763,10 +1763,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) { @@ -1815,8 +1816,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, @@ -1857,7 +1860,10 @@ 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) + goto retry; if (rc) break; } From patchwork Mon Jan 4 06:58:42 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Muchun Song X-Patchwork-Id: 11996227 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 5442EC433DB for ; Mon, 4 Jan 2021 07:04:18 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id ED0E420DD4 for ; Mon, 4 Jan 2021 07:04:17 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org ED0E420DD4 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 583E98D0003; Mon, 4 Jan 2021 02:04:17 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 543128D0002; Mon, 4 Jan 2021 02:04:17 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 473858D0003; Mon, 4 Jan 2021 02:04:17 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0001.hostedemail.com [216.40.44.1]) by kanga.kvack.org (Postfix) with ESMTP id 32F578D0002 for ; Mon, 4 Jan 2021 02:04:17 -0500 (EST) Received: from smtpin10.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id E4EE0824805A for ; Mon, 4 Jan 2021 07:04:16 +0000 (UTC) X-FDA: 77667203712.10.sound93_2e15ffe274ce Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin10.hostedemail.com (Postfix) with ESMTP id C759F16A0D1 for ; Mon, 4 Jan 2021 07:04:16 +0000 (UTC) X-HE-Tag: sound93_2e15ffe274ce X-Filterd-Recvd-Size: 4998 Received: from mail-pj1-f52.google.com (mail-pj1-f52.google.com [209.85.216.52]) by imf38.hostedemail.com (Postfix) with ESMTP for ; Mon, 4 Jan 2021 07:04:16 +0000 (UTC) Received: by mail-pj1-f52.google.com with SMTP id j13so10255807pjz.3 for ; Sun, 03 Jan 2021 23:04:16 -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=cdofCMrJggOBDwndwOMcw9p8TURVKPl7TRF1bXWpuHc=; b=aO/iHhlqeDxAdcVAauKRuxsfxa53axv5jXOjkx2H1E3acuFc1j0hmtjQIyKCHBbHdq 3FIJJEqknwwg8BkrSycQgeqDvwp6qVqUX6uIiXxWA4lnz31JaswTjCfX/EHb4n4eH96T Sw15jb0AqfnZrj5Hp9nOj+CKl8N4nCFojlYELfu1OW9QbQt1PpsiJ0b01i2L4rOzIzWk eYc7nqGoxtraxVFZpSZk0pjL1mmbJ2Hk7ur555woz7092ZnKLnxi09UTfO3ODpu2BbUt QjLHKTWg9i/F5S6zxsbN4oiM4aQLFz9YrO2Kd90hDv8Ua4JCnpTcnUXVlA2UXZcUu1id kzTA== 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=cdofCMrJggOBDwndwOMcw9p8TURVKPl7TRF1bXWpuHc=; b=GqNUCs6KLn/sZ4tcU5KOdqqPTr+Ra3w87Hc1pbF6ViyG8yw2/QTLNzGyT0eXrWmKjy NKlyY2KhQEbWqR+ifseiI35IglcTNCzd3QyPXj/i+Ci4ECYclwi247sSmrw0j7qnWcUh i6e6KdbBg9d6aqnJWEdnbgKYojDC6cYvgO3UzjLpU5tOihkTsqZSauhi+8GTGWhGg584 DIcDDK6XyEu/30rQHBOP5ZzE5OXDcZqFTgSmW0cj0jtbsSShBwOIFJ6ggN4YTs+Sx6aJ AngBuXsBN0AvQYJI936k019OnofUR/d/k9MLGeQ7VbWpiLP0gXlvxwRjiJg23yW1JNZr W8ug== X-Gm-Message-State: AOAM532D6FR9FNjbirp7Vxfnb1eel94ZlQHXoPuUHUf8TbJDN/j15dLV zpFwdxWOhv65ulHXlih8v+Pyow== X-Google-Smtp-Source: ABdhPJxzEpkaSXh/zCVLNlge5Wt3FV4tJQi4XZyc7KdMDbLQNQ845ylTEScxlIBO4YlKMLmldQpMYw== X-Received: by 2002:a17:90a:df81:: with SMTP id p1mr29396285pjv.158.1609743855735; Sun, 03 Jan 2021 23:04:15 -0800 (PST) Received: from localhost.localdomain ([240e:b1:e401:3::6]) by smtp.gmail.com with ESMTPSA id v1sm36306648pga.63.2021.01.03.23.03.54 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 03 Jan 2021 23:04:15 -0800 (PST) From: Muchun Song To: mike.kravetz@oracle.com, akpm@linux-foundation.org Cc: hillf.zj@alibaba-inc.com, n-horiguchi@ah.jp.nec.com, ak@linux.intel.com, yongjun_wei@trendmicro.com.cn, mhocko@suse.cz, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Muchun Song Subject: [PATCH 5/6] mm: hugetlb: fix a race between isolating and freeing page Date: Mon, 4 Jan 2021 14:58:42 +0800 Message-Id: <20210104065843.5658-5-songmuchun@bytedance.com> X-Mailer: git-send-email 2.21.0 (Apple Git-122) In-Reply-To: <20210104065843.5658-1-songmuchun@bytedance.com> References: <20210104065843.5658-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 --- mm/hugetlb.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index db00ae375d2a..5c2f64f53177 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 Mon Jan 4 06:58:43 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Muchun Song X-Patchwork-Id: 11996229 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 10DE9C433DB for ; Mon, 4 Jan 2021 07:04:42 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 81B332087E for ; Mon, 4 Jan 2021 07:04:41 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 81B332087E 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 1D9728D0005; Mon, 4 Jan 2021 02:04:41 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 1631B8D0002; Mon, 4 Jan 2021 02:04:41 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0533F8D0005; Mon, 4 Jan 2021 02:04:40 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0148.hostedemail.com [216.40.44.148]) by kanga.kvack.org (Postfix) with ESMTP id DE88D8D0002 for ; Mon, 4 Jan 2021 02:04:40 -0500 (EST) Received: from smtpin26.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id A0D32181AEF07 for ; Mon, 4 Jan 2021 07:04:40 +0000 (UTC) X-FDA: 77667204720.26.moon92_2705991274ce Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin26.hostedemail.com (Postfix) with ESMTP id 850821804B667 for ; Mon, 4 Jan 2021 07:04:40 +0000 (UTC) X-HE-Tag: moon92_2705991274ce X-Filterd-Recvd-Size: 4051 Received: from mail-pj1-f46.google.com (mail-pj1-f46.google.com [209.85.216.46]) by imf34.hostedemail.com (Postfix) with ESMTP for ; Mon, 4 Jan 2021 07:04:40 +0000 (UTC) Received: by mail-pj1-f46.google.com with SMTP id z12so9483899pjn.1 for ; Sun, 03 Jan 2021 23:04:38 -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=EISNFuU48YmH5mVT0GE+4yn3CQnSse+shUM8yzbBpaU=; b=Xmgjt/nOSUnyWkfS8V2b6zGYX7FQPWtZlXXQ7l8c1xqvRCoxP1WJyxx6yRZgHZrNW9 FKgtJ/N/l8uSXO6qVfmgrUa8iZGRMmnithwfYa7bZ/vmHcu6QYCD+ksPXncP0yNug6eY UV3Gf7fJfNBcBQpmN9xaNylvpe/6bxIYLrW4cKsg7J0OmLio0Ipyuzl6zGnCddM2wDSo UMidatDFEY9JKZgpquEhsuVdTG7WVm7uIwkXPUqhA09KItm3Kyhoe1keIKuZJGjd/Q4J Z5TxBks0c6M/mnN+AXgvJk1/m1UqJ4s/Q/hPRtwKPFVVM1bPPIJeP1xmKwtpZ8PwtoT1 5Esw== 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=EISNFuU48YmH5mVT0GE+4yn3CQnSse+shUM8yzbBpaU=; b=rVebqShLv/JNaPP/C/V8dRKlti9E5Gtt8qtMh0+qTArYGWENKNFB5BSbZVUg0N38Uy /9RKpMxyBYriB4PhEecXOIM8PJGSBAhzGfFw7eXJ/Xjs/JIKIeBDIdYRmsEgc4bVMCrn b3al7XADkQV/w9bftHz4shHS/nawLB9Ud+7lYj9MyqdTQQFGXWwNvNAruHfR/2p/HQI8 UHnuqE9/f/rUynof9y4kJxMw+Sk9YDlfbSlgDMittLvW0FW76lhNgftOuaupAM1JxdNQ 060GpyFslBdDOYRQPKp2isYBxCB6+P9MSD/fjayiddgpvsKH4b+zmNouQaFUyhppLYz5 X3rQ== X-Gm-Message-State: AOAM531dMQubWPjhyYC9n5Ywf6DkmHvWhYsHUnFrIfu/FIQGZpqXpaxQ PqKi9aMfxRprcCjtnr6feAiNVw== X-Google-Smtp-Source: ABdhPJzXfcHe/DNDgrNLYCLPvvRR9GsslU5gGbg4vZuATckt8jlYAfPJ+tgaqY3zitTmNw/PBZ+wDQ== X-Received: by 2002:a17:90a:db4e:: with SMTP id u14mr27912006pjx.184.1609743877588; Sun, 03 Jan 2021 23:04:37 -0800 (PST) Received: from localhost.localdomain ([240e:b1:e401:3::6]) by smtp.gmail.com with ESMTPSA id v1sm36306648pga.63.2021.01.03.23.04.16 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 03 Jan 2021 23:04:37 -0800 (PST) From: Muchun Song To: mike.kravetz@oracle.com, akpm@linux-foundation.org Cc: hillf.zj@alibaba-inc.com, n-horiguchi@ah.jp.nec.com, ak@linux.intel.com, yongjun_wei@trendmicro.com.cn, mhocko@suse.cz, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Muchun Song Subject: [PATCH 6/6] mm: hugetlb: remove VM_BUG_ON_PAGE from page_huge_active Date: Mon, 4 Jan 2021 14:58:43 +0800 Message-Id: <20210104065843.5658-6-songmuchun@bytedance.com> X-Mailer: git-send-email 2.21.0 (Apple Git-122) In-Reply-To: <20210104065843.5658-1-songmuchun@bytedance.com> References: <20210104065843.5658-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 --- mm/hugetlb.c | 1 - 1 file changed, 1 deletion(-) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index 5c2f64f53177..4c8631114e88 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -1360,7 +1360,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]); }