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=-0.5 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, FSL_HELO_FAKE,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=no 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 61965C352A4 for ; Wed, 12 Feb 2020 23:12:16 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 2424A21569 for ; Wed, 12 Feb 2020 23:12:16 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Dp1Nk18Z" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2424A21569 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id A418C6B04C3; Wed, 12 Feb 2020 18:12:15 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 9CA896B04C5; Wed, 12 Feb 2020 18:12:15 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8927D6B04C6; Wed, 12 Feb 2020 18:12:15 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0069.hostedemail.com [216.40.44.69]) by kanga.kvack.org (Postfix) with ESMTP id 6F3F56B04C3 for ; Wed, 12 Feb 2020 18:12:15 -0500 (EST) Received: from smtpin14.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 34F1E180AD80F for ; Wed, 12 Feb 2020 23:12:15 +0000 (UTC) X-FDA: 76483025430.14.bit50_139d6f5d66102 X-HE-Tag: bit50_139d6f5d66102 X-Filterd-Recvd-Size: 7138 Received: from mail-pj1-f65.google.com (mail-pj1-f65.google.com [209.85.216.65]) by imf43.hostedemail.com (Postfix) with ESMTP for ; Wed, 12 Feb 2020 23:12:14 +0000 (UTC) Received: by mail-pj1-f65.google.com with SMTP id m13so1536891pjb.2 for ; Wed, 12 Feb 2020 15:12:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=Tra7DkW4Ug7XOH+KIBkrjPoBiq7GSiJb0g4w8xR1qLU=; b=Dp1Nk18ZQOEKIuvucaP3mFLGhGNU+WNbsa6ok4EsqiH/zPfBTLJgNlur3OAyp2ZECq hNIYEHA7KfCg2SUnDHNLHt4GirxR8vHBz/M/k0KqkC7T9LF0SVz5cYeo+wlHwFTCf72N bNLaMvX/zYa1OC6eY3MpZnRMJPIa9MakGAMbOL9achr1odxxY4QegR7YJnjuZm4yw4In WyMujejgPqtlCsuHzuN1wUq8KGMcC2zMY8dj1/81hwZIF2e+4zn7d3jy/P0BsICq/ped hKEZXxQ8x5vs9Lu8oKhtpU5umlvvkyNZxLWGTDVWGdhpHQ+fQT636HoXr2Bukwc3R96D 3JjQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:from:to:cc:subject:message-id :references:mime-version:content-disposition:in-reply-to:user-agent; bh=Tra7DkW4Ug7XOH+KIBkrjPoBiq7GSiJb0g4w8xR1qLU=; b=iRnLyjUo5BLx0SruAG1Txzxn7YixrJ46uePhORqr8J4WqDYiOa/bT1fzyX/gG7LQqC 7cTC4gg4iqaU5WlDpGdhgMkTVJwokBw8ee9NfwW70Iutllbpq4fxodgGtkwnWLiUWmL3 YbzWJp16SoKNa8d7KNbrby0ZRL41phB8/RcioCcA5p3natC4ebyuVbwy6+/VD0qRFvRV WpV0v7c54QJuAVaFZYlBce4IytxeWJuWDeYgLWdJdLsX6sRe6+OqSHLn6CXnfJtqMWH0 ZgIkD7I9z78eQg50IqrwMoielTaj7oZqTlz+BD8nFeI3vH7kEow2jU25Jf8Pul/z0Ia8 Fy1g== X-Gm-Message-State: APjAAAWnwnop9aU8JKK/+nsAPErKqMKQhm1a+oElduki0MubZ9Iv9Ihr RliVHCo8SqhjKS8cgIOAKGMuToJi X-Google-Smtp-Source: APXvYqxq+wTt5eTDOqBxkwHZDh17Z5BbAhBV+PFDTOZA10znnMjHEg1B0gOvk3ml2wPVfquTYK4sfA== X-Received: by 2002:a17:90a:8547:: with SMTP id a7mr1763279pjw.0.1581549133392; Wed, 12 Feb 2020 15:12:13 -0800 (PST) Received: from google.com ([2620:15c:211:1:3e01:2939:5992:52da]) by smtp.gmail.com with ESMTPSA id z3sm283795pfz.155.2020.02.12.15.12.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Feb 2020 15:12:12 -0800 (PST) Date: Wed, 12 Feb 2020 15:12:10 -0800 From: Minchan Kim To: Andrew Morton Cc: Matthew Wilcox , Jan Kara , linux-mm , Josef Bacik , Johannes Weiner , LKML Subject: Re: [PATCH] mm: fix long time stall from mm_populate Message-ID: <20200212231210.GA233109@google.com> References: <20200211042536.GB242563@google.com> <20200211122323.GS8731@bombadil.infradead.org> <20200211163404.GC242563@google.com> <20200211172803.GA7778@bombadil.infradead.org> <20200211175731.GA185752@google.com> <20200212101804.GD25573@quack2.suse.cz> <20200212174015.GB93795@google.com> <20200212182851.GG7778@bombadil.infradead.org> <20200212195322.GA83146@google.com> <20200212142435.0b7e938fe8112fa35fcbcc71@linux-foundation.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200212142435.0b7e938fe8112fa35fcbcc71@linux-foundation.org> User-Agent: Mutt/1.10.1 (2018-07-13) 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 Wed, Feb 12, 2020 at 02:24:35PM -0800, Andrew Morton wrote: > On Wed, 12 Feb 2020 11:53:22 -0800 Minchan Kim wrote: > > > > That's definitely wrong. It'll clear PageReclaim and then pretend it did > > > nothing wrong. > > > > > > return !PageWriteback(page) || > > > test_and_clear_bit(PG_reclaim, &page->flags); > > > > > > > Much better, Thanks for the review, Matthew! > > If there is no objection, I will send two patches to Andrew. > > One is PageReadahead strict, the other is limit retry from mm_populate. > > With much more detailed changelogs, please! > > This all seems rather screwy. if a page is under writeback then it is > uptodate and we should be able to fault it in immediately. Hi Andrew, This description in cover-letter will work? If so, I will add each part below in each patch. Subject: [PATCH 0/3] fixing mm_populate long stall I got several reports major page fault takes several seconds sometime. When I review drop mmap_sem in page fault hanlder, I found several bugs. CPU 1 CPU 2 mm_populate for () .. ret = populate_vma_page_range __get_user_pages faultin_page handle_mm_fault filemap_fault do_async_mmap_readahead shrink_page_list pageout SetPageReclaim(=SetPageReadahead) writepage SetPageWriteback if (PageReadahead(page)) maybe_unlock_mmap_for_io up_read(mmap_sem) page_cache_async_readahead() if (PageWriteback(page)) return; here, since ret from populate_vma_page_range is zero, the loop continue to run with same address with previous iteration. It will repeat the loop until the page's writeout is done(ie, PG_writeback or PG_reclaim clear). We could fix the above specific case via adding PageWriteback. IOW, ret = populate_vma_page_range ... ... filemap_fault do_async_mmap_readahead if (!PageWriteback(page) && PageReadahead(page)) maybe_unlock_mmap_for_io up_read(mmap_sem) page_cache_async_readahead() if (PageWriteback(page)) return; That's a thing [3/3] is fixing here. Even though it could fix the problem effectively, it has still livelock problem theoretically because the page of faulty address could be reclaimed and then allocated/become readahead marker on other CPUs during faulty process is retrying in mm_populate's loop. [2/3] is fixing the such livelock via limiting retry count. There is another hole for the livelock or hang of the process as well as ageWriteback - ra_pages. mm_populate for () .. ret = populate_vma_page_range __get_user_pages faultin_page handle_mm_fault filemap_fault do_async_mmap_readahead if (PageReadahead(page)) maybe_unlock_mmap_for_io up_read(mmap_sem) page_cache_async_readahead() if (!ra->ra_pages) return; It will repeat the loop until ra->ra_pages become non-zero. [1/3] is fixing the problem. Jan Kara (1): mm: Don't bother dropping mmap_sem for zero size readahead Minchan Kim (2): mm: fix long time stall from mm_populate mm: make PageReadahead more strict include/linux/page-flags.h | 28 ++++++++++++++++++++++++++-- mm/filemap.c | 2 +- mm/gup.c | 9 +++++++-- mm/readahead.c | 6 ------ 4 files changed, 34 insertions(+), 11 deletions(-) -- 2.25.0.225.g125e21ebc7-goog