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=-5.2 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_SANE_1 autolearn=unavailable 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 DB9A9C5DF63 for ; Wed, 6 Nov 2019 15:05:28 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id A3E82217F5 for ; Wed, 6 Nov 2019 15:05:28 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A3E82217F5 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=suse.cz Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 3F4726B0003; Wed, 6 Nov 2019 10:05:28 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 3AE556B0006; Wed, 6 Nov 2019 10:05:28 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 293A96B0007; Wed, 6 Nov 2019 10:05:28 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0251.hostedemail.com [216.40.44.251]) by kanga.kvack.org (Postfix) with ESMTP id 0EB256B0003 for ; Wed, 6 Nov 2019 10:05:28 -0500 (EST) Received: from smtpin05.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with SMTP id 71CA9181AEF1E for ; Wed, 6 Nov 2019 15:05:27 +0000 (UTC) X-FDA: 76126176294.05.wheel34_69b1f2b537d21 X-HE-Tag: wheel34_69b1f2b537d21 X-Filterd-Recvd-Size: 4963 Received: from mx1.suse.de (mx2.suse.de [195.135.220.15]) by imf23.hostedemail.com (Postfix) with ESMTP for ; Wed, 6 Nov 2019 15:05:26 +0000 (UTC) X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id F0AA5AC18; Wed, 6 Nov 2019 15:05:24 +0000 (UTC) Received: by quack2.suse.cz (Postfix, from userid 1000) id A02211E4353; Wed, 6 Nov 2019 16:05:24 +0100 (CET) Date: Wed, 6 Nov 2019 16:05:24 +0100 From: Jan Kara To: Josef Bacik Cc: snazy@snazy.de, Jan Kara , Johannes Weiner , Vlastimil Babka , Michal Hocko , "Kirill A. Shutemov" , Randy Dunlap , linux-kernel@vger.kernel.org, Linux MM , Andrew Morton , "Potyra, Stefan" Subject: Re: mlockall(MCL_CURRENT) blocking infinitely Message-ID: <20191106150524.GL16085@quack2.suse.cz> References: <707b72c6dac76c534dcce60830fa300c44f53404.camel@gmx.de> <20191025135749.GK17610@dhcp22.suse.cz> <20191025140029.GL17610@dhcp22.suse.cz> <20191105182211.GA33242@cmpxchg.org> <20191106120315.GF16085@quack2.suse.cz> <4edf4dea97f6c1e3c7d4fed0e12c3dc6dff7575f.camel@gmx.de> <20191106145608.ucvuwsuyijvkxz22@macbook-pro-91.dhcp.thefacebook.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20191106145608.ucvuwsuyijvkxz22@macbook-pro-91.dhcp.thefacebook.com> 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 06-11-19 09:56:09, Josef Bacik wrote: > On Wed, Nov 06, 2019 at 02:45:43PM +0100, Robert Stupp wrote: > > On Wed, 2019-11-06 at 13:03 +0100, Jan Kara wrote: > > > On Tue 05-11-19 13:22:11, Johannes Weiner wrote: > > > > What I don't quite understand yet is why the fault path doesn't > > > > make > > > > progress eventually. We must drop the mmap_sem without changing the > > > > state in any way. How can we keep looping on the same page? > > > > > > That may be a slight suboptimality with Josef's patches. If the page > > > is marked as PageReadahead, we always drop mmap_sem if we can and > > > start > > > readahead without checking whether that makes sense or not in > > > do_async_mmap_readahead(). OTOH page_cache_async_readahead() then > > > clears > > > PageReadahead so the only way how I can see we could loop like this > > > is when > > > file->ra->ra_pages is 0. Not sure if that's what's happening through. > > > We'd > > > need to find which of the paths in filemap_fault() calls > > > maybe_unlock_mmap_for_io() to tell more. > > > > Yes, ra_pages==0 > > Attached the dmesg + smaps outputs > > > > > > Ah ok I see what's happening, __get_user_pages() returns 0 if we get an EBUSY > from faultin_page, and then __mm_populate does nend = nstart + ret * PAGE_SIZE, > which just leaves us where we are. > > We need to handle the non-blocking and the locking separately in __mm_populate > so we know what's going on. Jan's fix for the readahead thing is definitely > valid as well, but this will keep us from looping forever in other retry cases. I don't think this will work. AFAICS faultin_page() just checks whether 'nonblocking' is != NULL but doesn't ever look at its value... Honestly the whole interface is rather weird like lots of things around gup(). Honza > > diff --git a/mm/gup.c b/mm/gup.c > index 8f236a335ae9..ac625805d569 100644 > --- a/mm/gup.c > +++ b/mm/gup.c > @@ -1237,6 +1237,7 @@ int __mm_populate(unsigned long start, unsigned long len, int ignore_errors) > unsigned long end, nstart, nend; > struct vm_area_struct *vma = NULL; > int locked = 0; > + int nonblocking = 1; > long ret = 0; > > end = start + len; > @@ -1268,7 +1269,7 @@ int __mm_populate(unsigned long start, unsigned long len, int ignore_errors) > * double checks the vma flags, so that it won't mlock pages > * if the vma was already munlocked. > */ > - ret = populate_vma_page_range(vma, nstart, nend, &locked); > + ret = populate_vma_page_range(vma, nstart, nend, &nonblocking); > if (ret < 0) { > if (ignore_errors) { > ret = 0; > @@ -1276,6 +1277,14 @@ int __mm_populate(unsigned long start, unsigned long len, int ignore_errors) > } > break; > } > + > + /* > + * We dropped the mmap_sem, so we need to re-lock, and the next > + * loop around we won't drop because nonblocking is now 0. > + */ > + if (!nonblocking) > + locked = 0; > + > nend = nstart + ret * PAGE_SIZE; > ret = 0; > } -- Jan Kara SUSE Labs, CR