Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 44BB6C61DA4 for ; Tue, 7 Feb 2023 02:30:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229718AbjBGCaA (ORCPT ); Mon, 6 Feb 2023 21:30:00 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33688 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229447AbjBGC36 (ORCPT ); Mon, 6 Feb 2023 21:29:58 -0500 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E6C2E3430F for ; Mon, 6 Feb 2023 18:29:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=SASaUnYdxhNK3uDt7Eh9RINEEFziNC6Cq2V1+B/g2OY=; b=WLZaBcaJ5P/wG6jQQ4o2uEYgrB jnmuzERagNZXMiDSga9F0Yr9YyhdHtNPVTjqA2xLJbgTYL39VEzQ1NPMcORpHp9l1oM9tz3yBbPuQ A3C0E6bbIml9q6+UoP5cW09zwUFPN5YyakV1FavAZU9txjE7POxC8T40FCBXrS0GP2T1FYxzR0vYV 3SxGpY4EaCtQQFbczKLDCBeb1A8+oyXE+gFJgwBuo0fTpMFca0Wc2oWnKlCCxPckAgHCTcLQhp6hh zzIZl1pPaq+nBEV0SNuMhWs+9wgZ7gimLJjdfGjxnBeoBh8aH3uRvPi0Q7q4C9HkdRNhsdEg633gz sOv8UGXQ==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1pPDjo-00HMol-5u; Tue, 07 Feb 2023 02:29:40 +0000 Date: Tue, 7 Feb 2023 02:29:40 +0000 From: Matthew Wilcox To: David Stevens Cc: Peter Xu , linux-mm@kvack.org, Andrew Morton , "Kirill A . Shutemov" , Yang Shi , David Hildenbrand , Hugh Dickins , linux-kernel@vger.kernel.org Subject: Re: [PATCH v2] mm/khugepaged: skip shmem with userfaultfd Message-ID: References: <20230206112856.1802547-1-stevensd@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Feb 07, 2023 at 10:37:06AM +0900, David Stevens wrote: > On Tue, Feb 7, 2023 at 6:50 AM Matthew Wilcox wrote: > > On Mon, Feb 06, 2023 at 03:52:19PM -0500, Peter Xu wrote: > > > The problem is khugepaged will release pgtable lock during collapsing, so > > > AFAICT there can be a race where some other thread tries to insert pages > > > into page cache in parallel with khugepaged right after khugepaged released > > > the page cache lock. > > > > > > For example, it seems to me new page cache can be inserted when khugepaged > > > is copying small page content to the new hpage. > > This particular race can't happen with either patch, since the missing > page cache entries are filled when we create the multi-index entry for > hpage. Can too. for (index = start; index < end; index++) { ... if (xa_is_value(page) || !PageUptodate(page)) { xas_unlock_irq(&xas); /* swap in or instantiate fallocated page */ if (shmem_get_folio(mapping->host, index, &folio, SGP_NOALLOC)) { result = SCAN_FAIL; goto xa_unlocked; } ... So we start the iteration, and then a page fault happens in one of the indices we've already examined, but we don't have the page on the list. It's a nice wide race too because we're bringing the page in from swap.