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=-3.5 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,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 CFF5FC43461 for ; Fri, 28 Aug 2020 14:55:34 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 923B62086A for ; Fri, 28 Aug 2020 14:55:34 +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="SevHSY8r" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 923B62086A 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 34C146B0003; Fri, 28 Aug 2020 10:55:34 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2FC516B0006; Fri, 28 Aug 2020 10:55:34 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 212B46B0007; Fri, 28 Aug 2020 10:55:34 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0229.hostedemail.com [216.40.44.229]) by kanga.kvack.org (Postfix) with ESMTP id 0BC4B6B0003 for ; Fri, 28 Aug 2020 10:55:34 -0400 (EDT) Received: from smtpin14.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id B7D8A1E13 for ; Fri, 28 Aug 2020 14:55:33 +0000 (UTC) X-FDA: 77200276146.14.tramp42_5815e0d27076 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin14.hostedemail.com (Postfix) with ESMTP id 810DD1822987B for ; Fri, 28 Aug 2020 14:55:33 +0000 (UTC) X-HE-Tag: tramp42_5815e0d27076 X-Filterd-Recvd-Size: 3213 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf48.hostedemail.com (Postfix) with ESMTP for ; Fri, 28 Aug 2020 14:55:32 +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=b8+tOP8Z4nVPZ/rLNwsC2XMswr5qEkpSjmbJQXMiFgw=; b=SevHSY8rPsozb7JW0VDtWX67iG oPoZJCPDYgvXvYw6EGMVwwzMbVqlN+x6+TRdDkp1o4tAh8jEw04GF0jxYEZg+i4UyOvgOnzhZpo79 4idwGveXT36eRdwBlHp91US+xJi9ACtyxp7ePM76QXBBFJq+QkeL/EzaduUW1VVoRFsQ2vD2TLmuT d2pK1ITrHUUUV8Hdmhb1JEmivNm2EmBJ4tIzJISIlVbfgT7Ycpiw7Xv3G1nE5fMy9gWykocL7LRzM gYW5BQ45r3uD7NorTXOhD0CpXb4Q3CmyeBpNUCIhn9kC8IJMWQcFIBTIlMCvR6GxuBpIe1PRowy+K dhrqT1gw==; Received: from willy by casper.infradead.org with local (Exim 4.92.3 #3 (Red Hat Linux)) id 1kBfmq-0002Bn-AZ; Fri, 28 Aug 2020 14:55:28 +0000 Date: Fri, 28 Aug 2020 15:55:28 +0100 From: Matthew Wilcox To: linux-mm@kvack.org Cc: Hugh Dickins , Yang Shi Subject: Re: Is shmem page accounting wrong on split? Message-ID: <20200828145528.GO14765@casper.infradead.org> References: <20200828142546.GN14765@casper.infradead.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200828142546.GN14765@casper.infradead.org> X-Rspamd-Queue-Id: 810DD1822987B X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam01 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, Aug 28, 2020 at 03:25:46PM +0100, Matthew Wilcox wrote: > If I understand truncate of a shmem THP correctly ... > > Let's suppose the file has a single 2MB page at index 0, and is being > truncated down to 7 bytes in size. > > shmem_setattr() > i_size_write(7); > shmem_truncate_range(7, -1); > shmem_undo_range(7, -1) > start = 1; > page = &head[1]; > shmem_punch_compound(); > split_huge_page() > end = DIV_ROUND_UP(i_size_read(mapping->host), PAGE_SIZE); # == 1 > __split_huge_page(..., 1, ...); > __delete_from_page_cache(&head[1], ...); > truncate_inode_page(page); > delete_from_page_cache(page) > __delete_from_page_cache(&head[1]) > > I think the solution is to call truncate_inode_page() from within > shmem_punch_compound() if we don't call split_huge_page(). I came across > this while reusing all this infrastructure for the XFS THP patchset, > so I'm not in a great position to test this patch. Oh, this works for truncate, but not hole-punch. __split_huge_page() won't call __delete_from_page_cache() for pages below the end of the file. So maybe this instead? It's a bit cheesy ... maybe split_huge_page() could return 1 to indicate that it actually disposed of the page passed in? +++ b/mm/shmem.c @@ -827,7 +827,7 @@ static bool shmem_punch_compound(struct page *page, pgoff_t start, pgoff_t end) return true; /* Try to split huge page, so we can truly punch the hole or truncate */ - return split_huge_page(page) >= 0; + return split_huge_page(page) >= 0 && end < -1; } /*