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.8 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS 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 54359CA9EA0 for ; Sat, 19 Oct 2019 01:17:16 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id DC753222C6 for ; Sat, 19 Oct 2019 01:17:15 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=kernel.org header.i=@kernel.org header.b="nCA1LfoL" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org DC753222C6 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=linux-foundation.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 5C49F8E0005; Fri, 18 Oct 2019 21:17:15 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 59B728E0003; Fri, 18 Oct 2019 21:17:15 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4B1F18E0005; Fri, 18 Oct 2019 21:17:15 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0006.hostedemail.com [216.40.44.6]) by kanga.kvack.org (Postfix) with ESMTP id 2981C8E0003 for ; Fri, 18 Oct 2019 21:17:15 -0400 (EDT) Received: from smtpin06.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with SMTP id C53EA81D6 for ; Sat, 19 Oct 2019 01:17:14 +0000 (UTC) X-FDA: 76058770788.06.spark17_796dd11f16505 X-HE-Tag: spark17_796dd11f16505 X-Filterd-Recvd-Size: 2948 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by imf46.hostedemail.com (Postfix) with ESMTP for ; Sat, 19 Oct 2019 01:17:14 +0000 (UTC) Received: from localhost.localdomain (c-73-231-172-41.hsd1.ca.comcast.net [73.231.172.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id DDBAD222C5; Sat, 19 Oct 2019 01:17:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1571447833; bh=YSDA0LTaYm8hf+ryniy6+Xi/I6lsN9xC1wzmmMaHRqw=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=nCA1LfoLCIO49G4uoXUsN/ZE/0GmrUfc7zMv3nVdr4yhB18lVhrw6QknGKxs116+f Me1B/Jo/gRiELN1blfBonF3x1X6ah3hp2jo5Vgywhuwty/vV/d3l2ja1EM2kXxgDWZ xYN7TwUYohNvp+RkX2ZzG9wRZNxSmiliUDbsaNRo= Date: Fri, 18 Oct 2019 18:17:12 -0700 From: Andrew Morton To: Song Liu Cc: , , , , , , Johannes Weiner , Hugh Dickins Subject: Re: [PATCH v3] mm,thp: recheck each page before collapsing file THP Message-Id: <20191018181712.91dd9e9f9941642300e1b8d9@linux-foundation.org> In-Reply-To: <20191018180345.4188310-1-songliubraving@fb.com> References: <20191018180345.4188310-1-songliubraving@fb.com> X-Mailer: Sylpheed 3.5.1 (GTK+ 2.24.31; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit 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 Fri, 18 Oct 2019 11:03:45 -0700 Song Liu wrote: > In collapse_file(), after locking the page, it is necessary to recheck > that the page is up-to-date. Add PageUptodate() check for both shmem THP > and file THP. > > Current khugepaged should not try to collapse dirty file THP, because it > is limited to read only text. Add a PageDirty check and warning for file > THP. This is added after page_mapping() check, because if the page is > truncated, it might be dirty. When fixing a bug, please always fully describe the end-user visible effects of that bug. This is vital information for people who are considering the fix for backporting. I'm suspecting that you've found a race condition which can trigger a VM_BUG_ON_PAGE(), which is rather serious. But that was just a wild guess. Please don't make us wildly guess :( The old code looked rather alarming: } else if (!PageUptodate(page)) { xas_unlock_irq(&xas); wait_on_page_locked(page); if (!trylock_page(page)) { result = SCAN_PAGE_LOCK; goto xa_unlocked; } get_page(page); We don't have a ref on that page. After we've released the xarray lock we have no business playing with *page at all, correct?