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=-12.9 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1, USER_IN_DEF_DKIM_WL 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 9DE00C433E6 for ; Fri, 28 Aug 2020 17:09:10 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 4349320776 for ; Fri, 28 Aug 2020 17:09:10 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="neqKKanl" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4349320776 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id C68366B0005; Fri, 28 Aug 2020 13:09:09 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C1D608D0001; Fri, 28 Aug 2020 13:09:09 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B2E8E6B0008; Fri, 28 Aug 2020 13:09:09 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0132.hostedemail.com [216.40.44.132]) by kanga.kvack.org (Postfix) with ESMTP id 98DD96B0005 for ; Fri, 28 Aug 2020 13:09:09 -0400 (EDT) Received: from smtpin09.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 333D1180AD820 for ; Fri, 28 Aug 2020 17:09:09 +0000 (UTC) X-FDA: 77200612818.09.ball92_3a1479427077 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin09.hostedemail.com (Postfix) with ESMTP id 11FD4180AD80F for ; Fri, 28 Aug 2020 17:09:09 +0000 (UTC) X-HE-Tag: ball92_3a1479427077 X-Filterd-Recvd-Size: 5872 Received: from mail-ot1-f66.google.com (mail-ot1-f66.google.com [209.85.210.66]) by imf04.hostedemail.com (Postfix) with ESMTP for ; Fri, 28 Aug 2020 17:09:08 +0000 (UTC) Received: by mail-ot1-f66.google.com with SMTP id v16so1471590otp.10 for ; Fri, 28 Aug 2020 10:09:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:from:to:cc:subject:in-reply-to:message-id:references :user-agent:mime-version; bh=AlHaItSwyGl2fC9Ow48G8IDOgw9Yy1xYhccrgTX4cvg=; b=neqKKanld1X88jCKMHvtmWYb8PcYWKga/TDGnXR8YTDvCgh3ZmrrMJ/ALRgGHwA9pf gur80p506gpjfYlravsgocKQ/V6sGtBpd56kX1DWAngSzNmFi0Ie87PCbGhevBumraQG L2m+liKW+NP/3r5+J5DFIdnoq2RVHe5FT3eiJyEUMhq7FpMCDyKPeOrv3oU5Ot4sobib LjvC5UZY+obQ1gcEa+LXz4MbNSVrepHZc2WIpqUx6YTVfL7jrHLneGrN/ZFjjmX71spk U3DmxjtTCkyYFUIhj1uGTFlgN9uIxLRTNTbWMqpR6OOVmSiUMyP3E6GrorQ+29FDp8Xx QOgg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:in-reply-to:message-id :references:user-agent:mime-version; bh=AlHaItSwyGl2fC9Ow48G8IDOgw9Yy1xYhccrgTX4cvg=; b=aVt18I9p6Io2aI4uXQ68B7UI57Rfvmr2zyHdGFwnCUbewApme2whVrIlr4DxIlYpGp 4l3O15pYlvfmVPoOBmz7NGRR9cPesAtHYz5x4VORa0PVZqxdzYeQmGgtXrpYn1AEvNKe quMrvzHSRjhY8IIAW/gLLaR7ZJvgUrPFHwJ6xK6lR3u598IPN4ZhKQEju8HX00diF/EC F7zDevaSCTVftwB81JLyc8JnaOTTo830+LmVklr46wlvrwnMrBCaTwGiyvESaaE0Uh9k L8tVn0ZdocmePscdSQF625SPzwYCZH8g44LUI3JsPpuhU24upavtaqSIeS4B3+z8MsUE i3aA== X-Gm-Message-State: AOAM531toUqGXZSVkFZU3EJ0wmvj9/XG64xun8i0+MbB2NI0i/UfHoLw 0ewYYCkaJvYL3WTTHJFGJmalUA== X-Google-Smtp-Source: ABdhPJytkVpK2BZ1KVJ2r44vTBuYZIQ4m6NdhB9zINe0rg9WaWEGoxzy1WAY0R/neODhqPrp5+pYMg== X-Received: by 2002:a9d:6952:: with SMTP id p18mr1971258oto.321.1598634547582; Fri, 28 Aug 2020 10:09:07 -0700 (PDT) Received: from eggly.attlocal.net (172-10-233-147.lightspeed.sntcca.sbcglobal.net. [172.10.233.147]) by smtp.gmail.com with ESMTPSA id q144sm265661oic.16.2020.08.28.10.09.05 (version=TLS1 cipher=ECDHE-ECDSA-AES128-SHA bits=128/128); Fri, 28 Aug 2020 10:09:06 -0700 (PDT) Date: Fri, 28 Aug 2020 10:08:52 -0700 (PDT) From: Hugh Dickins X-X-Sender: hugh@eggly.anvils To: Matthew Wilcox cc: Linux MM , Hugh Dickins , Yang Shi , Yang Shi Subject: Re: Is shmem page accounting wrong on split? In-Reply-To: Message-ID: References: <20200828142546.GN14765@casper.infradead.org> <20200828145528.GO14765@casper.infradead.org> User-Agent: Alpine 2.11 (LSU 23 2013-08-11) MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Rspamd-Queue-Id: 11FD4180AD80F X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam03 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, 28 Aug 2020, Yang Shi wrote: > On Fri, Aug 28, 2020 at 7:55 AM Matthew Wilcox wrote: > > > > 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. It's a good observation of an oddity that I probably didn't think of, but you haven't said which kind of shmem page accounting goes wrong here (vm_enough_memory? df of filesystem? du of filesystem? memcg charge? all of the above? observed in practice?), and what needs solving. If that page has already been deleted from page cache when splitting, truncate_inode_page() sees NULL page->mapping != mapping and returns without doing anything. What's the problem? Hugh > > > > 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? > > I'm fine to have split_huge_page() return 1. > > > > > +++ 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; > > It would be more clear if we could have some comment about what "-1" > means. It took me a little while to understand the magic number, but > once I understood it it looks more straightforward to me. > > > } > > > > /*