From mboxrd@z Thu Jan 1 00:00:00 1970 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=-8.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS 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 0BB67C47095 for ; Wed, 9 Jun 2021 10:08:05 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id AE6B961108 for ; Wed, 9 Jun 2021 10:08:04 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org AE6B961108 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=shutemov.name Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 4809F6B0036; Wed, 9 Jun 2021 06:08:04 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 431896B006E; Wed, 9 Jun 2021 06:08:04 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2AB826B0070; Wed, 9 Jun 2021 06:08:04 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0102.hostedemail.com [216.40.44.102]) by kanga.kvack.org (Postfix) with ESMTP id E98D66B0036 for ; Wed, 9 Jun 2021 06:08:03 -0400 (EDT) Received: from smtpin10.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 756628249980 for ; Wed, 9 Jun 2021 10:08:03 +0000 (UTC) X-FDA: 78233759646.10.CEDDA0F Received: from mail-lf1-f50.google.com (mail-lf1-f50.google.com [209.85.167.50]) by imf13.hostedemail.com (Postfix) with ESMTP id 799F7E000262 for ; Wed, 9 Jun 2021 10:07:59 +0000 (UTC) Received: by mail-lf1-f50.google.com with SMTP id f30so37172925lfj.1 for ; Wed, 09 Jun 2021 03:08:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=shutemov-name.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=ycBV7W+Z4gGupsDwiNMvurO0enCT2qnqxmC8+tIujTs=; b=ChMG4OAUVihcSMJETWizwykkGL+XM2iEOokvplS6iAWVZcqF70BtDu8kJeHcT0hZfo vbKH87Ek3+fn2RofGbTw91LmYM3u2zfqlD8Z9IhjO6z3IMKoByQmfudnZOqCi+drmUho l0g9lLnOLOZDmIN4rky27x0zI0NUk9n3PlPZWpxBfr7LrG7mmZDkz+mKksrpK37VJdNt vePXcdBNeAvgHmiEA3q7ijL/rqb7VYxytRbZXpAbP7A1K2yp5ax8hISa9EG2dkE3qEOY BfL1MyCSquTTL9B7F3acy6Fw/WY1vPoFJyLdfNIh9axIB4Zior60W/4/8djkmjl/nZ4T jwXg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=ycBV7W+Z4gGupsDwiNMvurO0enCT2qnqxmC8+tIujTs=; b=qXdM5V4sOsUV0UGkonYMQ1cT3lgy3Yn01icLyfAQ9OrPOcrVr9txK3f89rMQhes0Jp c1l/ilVr0LhBJtMsrzwyGMS4tI8HPuQ7kXPL7IAl8imqHopU3hQHCKlheLP4OXS919MD 6NwYc/FuqFPGy7S1/Q7x6r8i1CQ8NFjG7tV1KpBBpagTVqLn29zST713YWxEH6D6aPDO DP11Rpq7+orYw4FCzZpXJtQL1LjLMMdrNAOY4tYtRZEPA3ps1qdKk7uu/pQg5K4VsHAC v6oxDpfoWNEN0COWF2ytVah/MoC2cYdR63EPsTv92R9rWMoEddr2QBpqESdC56bpuOy/ 4p7A== X-Gm-Message-State: AOAM532vTMLOH0hT4x0f0JBZAfhCexL53DUDNOMakB0EaQk6lZina9VQ 8PGKtV1jzHfIXHyj6ipmKouU5A== X-Google-Smtp-Source: ABdhPJzuGkUvJj/AJoTCCtnNh2nfQU8KxExaJycKNJ8fsWv+zFzEpVWfSZ1IbjKpMTAAGyvlAy8tww== X-Received: by 2002:a05:6512:54b:: with SMTP id h11mr18858506lfl.236.1623233281541; Wed, 09 Jun 2021 03:08:01 -0700 (PDT) Received: from box.localdomain ([86.57.175.117]) by smtp.gmail.com with ESMTPSA id y17sm304690lfy.14.2021.06.09.03.08.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Jun 2021 03:08:00 -0700 (PDT) Received: by box.localdomain (Postfix, from userid 1000) id 43E0110265B; Wed, 9 Jun 2021 13:08:16 +0300 (+03) Date: Wed, 9 Jun 2021 13:08:16 +0300 From: "Kirill A. Shutemov" To: Yu Xu Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, hughd@google.com, akpm@linux-foundation.org, gavin.dg@linux.alibaba.com Subject: Re: [PATCH v2] mm, thp: use head page in __migration_entry_wait Message-ID: <20210609100816.tmgcy2vq4cmw7o7e@box.shutemov.name> References: <20210608120026.ugfh72ydjeba44bo@box.shutemov.name> <57e151a8-03b2-3458-0178-21edb4ce97d2@linux.alibaba.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <57e151a8-03b2-3458-0178-21edb4ce97d2@linux.alibaba.com> Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=shutemov-name.20150623.gappssmtp.com header.s=20150623 header.b=ChMG4OAU; spf=none (imf13.hostedemail.com: domain of kirill@shutemov.name has no SPF policy when checking 209.85.167.50) smtp.mailfrom=kirill@shutemov.name; dmarc=none X-Stat-Signature: h5w5yrdnuaffjd94tzczh6t74pnq4g5q X-Rspamd-Queue-Id: 799F7E000262 X-Rspamd-Server: rspam06 X-HE-Tag: 1623233279-639383 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: On Tue, Jun 08, 2021 at 09:22:28PM +0800, Yu Xu wrote: > On 6/8/21 8:00 PM, Kirill A. Shutemov wrote: > > On Tue, Jun 08, 2021 at 05:22:39PM +0800, Xu Yu wrote: > > > We notice that hung task happens in a conner but practical scenario when > > > CONFIG_PREEMPT_NONE is enabled, as follows. > > > > > > Process 0 Process 1 Process 2..Inf > > > split_huge_page_to_list > > > unmap_page > > > split_huge_pmd_address > > > __migration_entry_wait(head) > > > __migration_entry_wait(tail) > > > remap_page (roll back) > > > remove_migration_ptes > > > rmap_walk_anon > > > cond_resched > > > > > > Where __migration_entry_wait(tail) is occurred in kernel space, e.g., > > > copy_to_user in fstat, which will immediately fault again without > > > rescheduling, and thus occupy the cpu fully. > > > > > > When there are too many processes performing __migration_entry_wait on > > > tail page, remap_page will never be done after cond_resched. > > > > > > This makes __migration_entry_wait operate on the compound head page, > > > thus waits for remap_page to complete, whether the THP is split > > > successfully or roll back. > > > > > > Note that put_and_wait_on_page_locked helps to drop the page reference > > > acquired with get_page_unless_zero, as soon as the page is on the wait > > > queue, before actually waiting. So splitting the THP is only prevented > > > for a brief interval. > > > > > > Fixes: ba98828088ad ("thp: add option to setup migration entries during PMD split") > > > Suggested-by: Hugh Dickins > > > Signed-off-by: Gang Deng > > > Signed-off-by: Xu Yu > > > > Looks good to me: > > > > Acked-by: Kirill A. Shutemov > > > > But there's one quirk: if split succeed we effectively wait on wrong > > page to be unlocked. And it may take indefinite time if split_huge_page() > > was called on the head page. > > Inspired by you, I look into the codes, and have a new question (nothing > to do with this patch). > > If we split_huge_page_to_list on *tail* page (in fact, I haven't seen > that used yet), See ksm code for instance. > mm/huge_memory.c:2666 checks "VM_BUG_ON_PAGE(!PageLocked(head), head);" > in split_huge_page_to_list(), while > > mm/huge_memory.c:2497 does "unlock_page(subpage)", where subpage can > be head in this scenario, in __split_huge_page(). > > My confusion is > 1) how the pin on the @subpage is got outside split_huge_page_to_list()? > can we ever get tail page? This loop: for (i = 0; i < nr; i++) { struct page *subpage = head + i; if (subpage == page) continue; unlock_page(subpage); /* * Subpages may be freed if there wasn't any mapping * like if add_to_swap() is running on a lru page that * had its mapping zapped. And freeing these pages * requires taking the lru_lock so we do the put_page * of the tail pages after the split is complete. */ put_page(subpage); } We skip unlocking and unpinning the page split_huge_page() got called for. > > 2) head page is locked outside split_huge_page_to_list(), but unlocked > in __split_huge_page()? If called on tail page, yes. -- Kirill A. Shutemov