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=-6.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,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 CB7C5C43465 for ; Sat, 19 Sep 2020 16:18:58 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 18ADE21582 for ; Sat, 19 Sep 2020 16:18:57 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="i6jr004S" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 18ADE21582 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 4ADCC6B0037; Sat, 19 Sep 2020 12:18:57 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 45EF16B0055; Sat, 19 Sep 2020 12:18:57 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 374B26B005A; Sat, 19 Sep 2020 12:18:57 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0052.hostedemail.com [216.40.44.52]) by kanga.kvack.org (Postfix) with ESMTP id 22A1C6B0037 for ; Sat, 19 Sep 2020 12:18:57 -0400 (EDT) Received: from smtpin04.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id CE57F8249980 for ; Sat, 19 Sep 2020 16:18:56 +0000 (UTC) X-FDA: 77280319872.04.meat50_280622827135 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin04.hostedemail.com (Postfix) with ESMTP id B30B8800B662 for ; Sat, 19 Sep 2020 16:18:56 +0000 (UTC) X-HE-Tag: meat50_280622827135 X-Filterd-Recvd-Size: 4155 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf20.hostedemail.com (Postfix) with ESMTP for ; Sat, 19 Sep 2020 16:18:56 +0000 (UTC) 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=UtLIhuknFyVgzypgVMrilrLbQcc//rMRWCAqNplTMFw=; b=i6jr004Sx1Q6M4lYER+1trw9PV UJHcGIjVJMAmfeQG+N56N2SDIeDrPL0XfrYQ/+FmoKrJc3yo8Glyvc99/wgfIrpz//tP0I5pYQBPt 9JMHDBzXu5rDdb3nkSRDCdlTtn+47LLgN+39dg+qMyTkTVDBUmfwzQrTKhKP3gPBkNTf0X4qQ7MBH x5BnfatJ8xgm4CMQxPz2usJsz+isLKnW6hnLInP9WX/t2444SR9BgoXJVGJaTYdZ3bjiBYd8+owWT ZEKPl4qX5Dsdi5Q2PylRHQ/398TFCV6jHU26MTmGw78Vqx10ZhrbwDyK7NHpFY9uBdkiOJp8XGDvh CzyJ/u6w==; Received: from willy by casper.infradead.org with local (Exim 4.92.3 #3 (Red Hat Linux)) id 1kJfZX-00028j-Be; Sat, 19 Sep 2020 16:18:47 +0000 Date: Sat, 19 Sep 2020 17:18:47 +0100 From: Matthew Wilcox To: Hugh Dickins Cc: Andrew Morton , alex.shi@linux.alibaba.com, cai@lca.pw, hannes@cmpxchg.org, linux-mm@kvack.org, mhocko@suse.com, mike.kravetz@oracle.com, mm-commits@vger.kernel.org, shakeelb@google.com, shy828301@gmail.com, stable@vger.kernel.org, torvalds@linux-foundation.org Subject: Re: [patch 04/15] shmem: shmem_writepage() split unlikely i915 THP Message-ID: <20200919161847.GN32101@casper.infradead.org> References: <20200918211925.7e97f0ef63d92f5cfe5ccbc5@linux-foundation.org> <20200919042009.bomzxmrg7%akpm@linux-foundation.org> <20200919044408.GL32101@casper.infradead.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: 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, Sep 18, 2020 at 10:44:32PM -0700, Hugh Dickins wrote: > It behaves a lot better with this patch in than without it; but you're > right, only the head will get written to swap, and the tails left in > memory; with dirty cleared, so they may be left indefinitely (I've > not yet looked to see when if ever PageDirty might get set later). > > Hmm. It may just be a matter of restyling the i915 code with > > if (!page_mapped(page)) { > clear_page_dirty_for_io(page); > > but I don't want to rush to that conclusion - there might turn > out to be a good way of doing it at the shmem_writepage() end, but > probably only hacks available. I'll mull it over: it deserves some > thought about what would suit, if a THP arrived here some other way. I think the ultimate solution is to do as I have done for iomap and make ->writepage handle arbitrary sized pages. However, I don't know the swap I/O path particularly well, and I would rather not learn it just yet. How about this for a band-aid until we sort that out properly? Just mark the page as dirty before splitting it so subsequent iterations see the subpages as dirty. Arguably, we should use set_page_dirty() instead of SetPageDirty, but I don't think i915 cares. In particular, it uses an untagged iteration instead of searching for PAGECACHE_TAG_DIRTY. diff --git a/mm/shmem.c b/mm/shmem.c index 271548ca20f3..6231207ab1eb 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -1362,8 +1362,21 @@ static int shmem_writepage(struct page *page, struct writeback_control *wbc) swp_entry_t swap; pgoff_t index; - VM_BUG_ON_PAGE(PageCompound(page), page); BUG_ON(!PageLocked(page)); + + /* + * If /sys/kernel/mm/transparent_hugepage/shmem_enabled is "force", + * then drivers/gpu/drm/i915/gem/i915_gem_shmem.c gets huge pages, + * and its shmem_writeback() needs them to be split when swapping. + */ + if (PageTransCompound(page)) { + /* Ensure the subpages are still dirty */ + SetPageDirty(page); + if (split_huge_page(page) < 0) + goto redirty; + ClearPageDirty(page); + } + mapping = page->mapping; index = page->index; inode = mapping->host;