Received: by 2002:a25:d7c1:0:0:0:0:0 with SMTP id o184csp1803199ybg; Sat, 19 Oct 2019 02:51:12 -0700 (PDT) X-Google-Smtp-Source: APXvYqxB/mbwSTrfOtk0514w/5Zm248HRLv63w0QD5CfEuaJaizK3UwuCBP0FLSaNjMZj3yzdgP/ X-Received: by 2002:a17:906:585a:: with SMTP id h26mr965322ejs.329.1571478672263; Sat, 19 Oct 2019 02:51:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571478672; cv=none; d=google.com; s=arc-20160816; b=HA36Didqe1MbHaMX6vEShvg7SGsvMkq9CSSYtG933r6WnIXhF79MK3LQany6BJatfv YeOx+gfOtjaNLj/yWVufgyQ36gBp25WUqatS+3dARMR84835zQAsniJfcmKdGJYYx/9Q 4VEhnMBpVK0uu4cO6zklmcXBElziOTWwKRaoApmWZUkjoLHhsNFjV7byJ6EVq4TA2Fpy odJMUyBK8J3yyMOOJNw519l1vFsSg0S+tOaDvc2v0Ba0JMvBnkYESn9sgl4soj6mQ1Rt Ixyrkw3lYfXuRIeRmkVYJpt8b0Scwf+vcaTDD3UFaBsgMcG8NyBGmVybzu7vSQMguwqi gQHQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=Nki1NGxroOLsDd98e295iNsP7wsqcABl33Hza4gGajE=; b=cQNLtCTY0g/CKqeMr9S7+FA/xFKSWRx9XuWzoTstLU0m/R+TJaywf4m5yfaFBkO47e BJiZR0L8YObGijvvzpqtLkq4RNouzN15all9/7AIhP1eKuGI//rqrvXBF+fLRjiDXOML GLcghAV76BRQzKJUwJtrAEejUxMy3jRdTM+R/otr8bpgOjPoDxBiZzIbb/xdgGhTk2td yYEVUq+EkPBFLPldWuhF7rcgtmqTBaCQaM5P6Wcg51eq+i+Q+O6q2fFJknD5KuUICDY7 Z4tbNewhY8qZGN4/I/HgzFAGE0CBW7mGCHZ9rvQ/cKoVmM0rLRl2mbToa6FTdmamRMkQ U6mw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=nCA1LfoL; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m1si5031904eji.86.2019.10.19.02.50.48; Sat, 19 Oct 2019 02:51:12 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=nCA1LfoL; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725945AbfJSBRO (ORCPT + 99 others); Fri, 18 Oct 2019 21:17:14 -0400 Received: from mail.kernel.org ([198.145.29.99]:46232 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725800AbfJSBRN (ORCPT ); Fri, 18 Oct 2019 21:17:13 -0400 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 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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?