Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp5015754pxj; Wed, 9 Jun 2021 07:20:53 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxkRm4+8Oyf1UUnVYUIRX09HrSaTOUzcSQ638Hd1hgMfxkrXAq5NajE2O9U5ElA2WfnqH8Z X-Received: by 2002:a05:6402:1590:: with SMTP id c16mr30944871edv.7.1623248452894; Wed, 09 Jun 2021 07:20:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623248452; cv=none; d=google.com; s=arc-20160816; b=yfpti5XVOimTABKedfi3AQKhCRGe8OQv9oKuwPUFCEu5PheKvHUacaemI9xgx9rAgD TNtGAH6bDhm88UfzGY8NaQgYlNXbAl+/GfK9Y9L24LQUWIKmtwZidZc8UtkcyNvsnU8i 6t7Uj3FV94TIEME21bBNoDSQjOwyvg7QdFROiv6GNOntN1NHK4SAPeGciAfY22NdCKjp KWRKUktA6hrKL4SPh4pZv9yQDFL/387ZiiVCKBtvCxAT0cGIMb7tf2ZpPiq4d0aU/yHD 2G1IkpEpqtLx1uQ3U7lCH8IhSs4rvz135PTcfb9xAdz18HUN4uFyzlygiScbRKwQENU2 pt+w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=ycBV7W+Z4gGupsDwiNMvurO0enCT2qnqxmC8+tIujTs=; b=dDO9d1iZI0l0+MFhaA6MTmC+LE1GfON82EQ1hRtBUKBkTgB1ePnWYiZithq5oRAIft hd12yrFb9aWRHRfXMmVblWDylLfAoR5GKRLiEj5yA/XoWz/l5yaFTwHC41SF3zfQtous FPr4hQi7y0Yyg00bdL+rxo2ORE7tsWTbutxMFI4g2vao3k9NyoWW/54ozGN8HYCBXO/b 5Iuaed8kbbso1/Fa6JhjgEuS1mw/f9QYiWtPBsqOQtZbkmZRZYkrXmLMV3UoZozeiPXO vD608TWQQBQ3MPe7PIOVQseXihoyd86R5NOElfNRr0yJFiDk6ZDz3Sc+Zpk5wze9syqP 5lxA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@shutemov-name.20150623.gappssmtp.com header.s=20150623 header.b=ChMG4OAU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id lr17si2542483ejb.104.2021.06.09.07.20.28; Wed, 09 Jun 2021 07:20:52 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@shutemov-name.20150623.gappssmtp.com header.s=20150623 header.b=ChMG4OAU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238651AbhFIKLL (ORCPT + 99 others); Wed, 9 Jun 2021 06:11:11 -0400 Received: from mail-lf1-f48.google.com ([209.85.167.48]:44691 "EHLO mail-lf1-f48.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238652AbhFIKLI (ORCPT ); Wed, 9 Jun 2021 06:11:08 -0400 Received: by mail-lf1-f48.google.com with SMTP id r198so33797255lff.11 for ; Wed, 09 Jun 2021 03:09: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=t3QlApg1EKvArWPN89SS8TdQ0swDpOciJ7Rrs8C/7eWow4nAP5r4Y0XUXoKcMAqMFZ xC8xTXuEWC022WuhiLkKr+7YbiLOsfvuhKHi1pdjMEvHOH5AbLHidYd44ZBmlSJ4LbMF LQnevdtU3/tj53Hm7Ds6yUGstTLk7oqTQTzCclI6MERpzxzxYKxJMlPyMuFWlNbNwb89 C0cDcESGx5TBwWq53fRPWKILRmncMozRLc8dv5z9UjYPpojmTgb/IU0qq6LFeE9A66iW krTIyATOPqegahKffkmUjnS5AXwfFhP2+IuFxouWRX0sQhQf6+mhmBJIDQIFstRkpk8e ZW9Q== X-Gm-Message-State: AOAM530trncN00DP59woJXi2DEU2fHi4ddif68njalZhoqiGTipZV4LS upxG1gZSdT05eZWFGX9VNqd8/g== 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> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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