From patchwork Wed May 26 20:12:38 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Shi X-Patchwork-Id: 12282687 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=-13.6 required=3.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED,DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,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 81926C47082 for ; Wed, 26 May 2021 20:12:45 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id E0B4D61378 for ; Wed, 26 May 2021 20:12:44 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E0B4D61378 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 764C46B0036; Wed, 26 May 2021 16:12:44 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 73BD46B006E; Wed, 26 May 2021 16:12:44 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5DC306B0070; Wed, 26 May 2021 16:12:44 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0136.hostedemail.com [216.40.44.136]) by kanga.kvack.org (Postfix) with ESMTP id 2BF9E6B0036 for ; Wed, 26 May 2021 16:12:44 -0400 (EDT) Received: from smtpin19.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id BC6CAAF76 for ; Wed, 26 May 2021 20:12:43 +0000 (UTC) X-FDA: 78184480206.19.3823B43 Received: from mail-pg1-f170.google.com (mail-pg1-f170.google.com [209.85.215.170]) by imf25.hostedemail.com (Postfix) with ESMTP id D3BF1600025E for ; Wed, 26 May 2021 20:12:35 +0000 (UTC) Received: by mail-pg1-f170.google.com with SMTP id j12so1890098pgh.7 for ; Wed, 26 May 2021 13:12:43 -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:mime-version :content-transfer-encoding; bh=R308Tm4caxn19xHGz7pM0TIdOHBZX3XBvF5WMLnOo9U=; b=su8nF9w7LG7RnLnxTJbBNyaATWpFMrKEJCHE7SdSa00HBUrStRUCnNfpgq4JHx4C0f X9w12/DuTnwdaRq2aAs3UDFwr3igZ94bOa1idnj1yDWuIQvT0eVkNYZS3gX/TrdOG7Lr yq6o94mQmUsErNU5drbsLi2mJDbq1NY1CiDUXh+zYs83gVujRCvwQWOwxUaR3LRVf6rh WGJmhrsL5Rzd5Q6dL0QfedErmMAyF5Uz/YQgf3Y8GDBcvElwCtS2k6fACnZ3TicqS663 wqigc54lktNjc0+BSoaNcVvCeLPzdgiSuzhAk3OatQaRoMDYpsaZ/36mA+3J8kcDIm3g 3a3w== 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=R308Tm4caxn19xHGz7pM0TIdOHBZX3XBvF5WMLnOo9U=; b=Y9jKQYTCueSjkUsaqLt4UOV21PF20W9uTY+vLl1SeOWeIepx9U0zjqh91Wo0n3Rn0f 0gJ08rpRm8lhDxHJ/KYkLex1jIE78ls80Yi3hzuG1hrSRt1+9teZ9YMWptC/1HlYnsaa wIDPeJQHu1xnh119FcJP3kWBmYxCQDasf9kaqkv/qt3mZvXlu8TplKyaSRiQn2Ggyzn8 HpuV5DwLYbQPeHT9k+eIAkrtKqg0joAQ126+r4tF718O/OCIw0mMC1klwBho4pWZ9xHU MtwxaUjxLcX6HP9Cj1dXH6patbedTzTL0Mw/OaUz+P4WfsKrmS0LXJZnV09DLyI/0n2A s0GQ== X-Gm-Message-State: AOAM532QqqqOh87hVE5Iawma8XU3ohlTCqGhdkkMjrGokavi6N+K9Mrd 4Cj3PNQIvqG53sEgUfUMr4w= X-Google-Smtp-Source: ABdhPJzhf/IYwO7BYcCY5iHQZhKv6DVWDkg/OqHSWo7V1NWvN26I0L9N6h/f2AGybqiyzbUXZPF3lg== X-Received: by 2002:aa7:9001:0:b029:2d4:9408:9998 with SMTP id m1-20020aa790010000b02902d494089998mr166302pfo.9.1622059962522; Wed, 26 May 2021 13:12:42 -0700 (PDT) Received: from localhost.localdomain (c-73-93-239-127.hsd1.ca.comcast.net. [73.93.239.127]) by smtp.gmail.com with ESMTPSA id m14sm76733pff.17.2021.05.26.13.12.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 May 2021 13:12:41 -0700 (PDT) From: Yang Shi To: hughd@google.com, ziy@nvidia.com, kirill.shutemov@linux.intel.com, minchan@kernel.org, naoya.horiguchi@nec.com, wangyugui@e16-tech.com, akpm@linux-foundation.org Cc: shy828301@gmail.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [v4 PATCH 1/2] mm: thp: replace DEBUG_VM BUG with VM_WARN when unmap fails for split Date: Wed, 26 May 2021 13:12:38 -0700 Message-Id: <20210526201239.3351-1-shy828301@gmail.com> X-Mailer: git-send-email 2.26.2 MIME-Version: 1.0 Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=gmail.com header.s=20161025 header.b=su8nF9w7; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf25.hostedemail.com: domain of shy828301@gmail.com designates 209.85.215.170 as permitted sender) smtp.mailfrom=shy828301@gmail.com X-Stat-Signature: k3g9rypyjaeamzk7wfeku4miiefqh9sz X-Rspamd-Queue-Id: D3BF1600025E X-Rspamd-Server: rspam02 X-HE-Tag: 1622059955-84760 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 debugging the bug reported by Wang Yugui [1], try_to_unmap() may fail, but the first VM_BUG_ON_PAGE() just checks page_mapcount() however it may miss the failure when head page is unmapped but other subpage is mapped. Then the second DEBUG_VM BUG() that check total mapcount would catch it. This may incur some confusion. And this is not a fatal issue, so consolidate the two DEBUG_VM checks into one VM_WARN_ON_ONCE_PAGE(). [1] https://lore.kernel.org/linux-mm/20210412180659.B9E3.409509F4@e16-tech.com/ Reviewed-by: Zi Yan Signed-off-by: Yang Shi Acked-by: Hugh Dickins Acked-by: Kirill A. Shutemov --- v4: Updated the subject and commit log per Hugh. Reordered the patches per Hugh. v3: Incorporated the comments from Hugh. Keep Zi Yan's reviewed-by tag since there is no fundamental change against v2. v2: Removed dead code and updated the comment of try_to_unmap() per Zi Yan. mm/huge_memory.c | 24 +++++++----------------- 1 file changed, 7 insertions(+), 17 deletions(-) diff --git a/mm/huge_memory.c b/mm/huge_memory.c index 19195fca1aee..8827f82c5302 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -2336,15 +2336,15 @@ static void unmap_page(struct page *page) { enum ttu_flags ttu_flags = TTU_IGNORE_MLOCK | TTU_RMAP_LOCKED | TTU_SPLIT_HUGE_PMD; - bool unmap_success; VM_BUG_ON_PAGE(!PageHead(page), page); if (PageAnon(page)) ttu_flags |= TTU_SPLIT_FREEZE; - unmap_success = try_to_unmap(page, ttu_flags); - VM_BUG_ON_PAGE(!unmap_success, page); + try_to_unmap(page, ttu_flags); + + VM_WARN_ON_ONCE_PAGE(page_mapped(page), page); } static void remap_page(struct page *page, unsigned int nr) @@ -2655,7 +2655,7 @@ int split_huge_page_to_list(struct page *page, struct list_head *list) struct deferred_split *ds_queue = get_deferred_split_queue(head); struct anon_vma *anon_vma = NULL; struct address_space *mapping = NULL; - int count, mapcount, extra_pins, ret; + int extra_pins, ret; pgoff_t end; VM_BUG_ON_PAGE(is_huge_zero_page(head), head); @@ -2714,7 +2714,6 @@ int split_huge_page_to_list(struct page *page, struct list_head *list) } unmap_page(head); - VM_BUG_ON_PAGE(compound_mapcount(head), head); /* block interrupt reentry in xa_lock and spinlock */ local_irq_disable(); @@ -2732,9 +2731,7 @@ int split_huge_page_to_list(struct page *page, struct list_head *list) /* Prevent deferred_split_scan() touching ->_refcount */ spin_lock(&ds_queue->split_queue_lock); - count = page_count(head); - mapcount = total_mapcount(head); - if (!mapcount && page_ref_freeze(head, 1 + extra_pins)) { + if (page_ref_freeze(head, 1 + extra_pins)) { if (!list_empty(page_deferred_list(head))) { ds_queue->split_queue_len--; list_del(page_deferred_list(head)); @@ -2754,16 +2751,9 @@ int split_huge_page_to_list(struct page *page, struct list_head *list) __split_huge_page(page, list, end); ret = 0; } else { - if (IS_ENABLED(CONFIG_DEBUG_VM) && mapcount) { - pr_alert("total_mapcount: %u, page_count(): %u\n", - mapcount, count); - if (PageTail(page)) - dump_page(head, NULL); - dump_page(page, "total_mapcount(head) > 0"); - BUG(); - } spin_unlock(&ds_queue->split_queue_lock); -fail: if (mapping) +fail: + if (mapping) xa_unlock(&mapping->i_pages); local_irq_enable(); remap_page(head, thp_nr_pages(head));