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.6 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, 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 6EF37C433E6 for ; Fri, 28 Aug 2020 15:43:22 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 248DD20872 for ; Fri, 28 Aug 2020 15:43:22 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="VFR8f6Hk" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 248DD20872 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id AB4456B0003; Fri, 28 Aug 2020 11:43:21 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A8BB96B0005; Fri, 28 Aug 2020 11:43:21 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9C84B6B0006; Fri, 28 Aug 2020 11:43:21 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0072.hostedemail.com [216.40.44.72]) by kanga.kvack.org (Postfix) with ESMTP id 8766D6B0003 for ; Fri, 28 Aug 2020 11:43:21 -0400 (EDT) Received: from smtpin25.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 3E4238248047 for ; Fri, 28 Aug 2020 15:43:21 +0000 (UTC) X-FDA: 77200396602.25.tree73_4e13d8b27076 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin25.hostedemail.com (Postfix) with ESMTP id 078561804E3A9 for ; Fri, 28 Aug 2020 15:43:21 +0000 (UTC) X-HE-Tag: tree73_4e13d8b27076 X-Filterd-Recvd-Size: 4726 Received: from mail-ed1-f66.google.com (mail-ed1-f66.google.com [209.85.208.66]) by imf20.hostedemail.com (Postfix) with ESMTP for ; Fri, 28 Aug 2020 15:43:20 +0000 (UTC) Received: by mail-ed1-f66.google.com with SMTP id w14so1567391eds.0 for ; Fri, 28 Aug 2020 08:43:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=fb1vazws15mlRsEbhKXSAVoYjhZWpYh3l0I0AMhRe60=; b=VFR8f6HkJJMN8SF65veCoS7IyuLnaHRW6L49NPt7nCGkWLPPOu15p6AazC6EwXtiqq Z9nbKp/0ycMGYHnrIOrk90N2xuSiUhIquxL+WfQJMdwy7msrinTAnMOvS7TpE31lqz1T GUqi5mzP7BxhlXKu2emLyUOJgn26YgPi6V11mMxXG1N1e4KB+ycpCuQhIi5+JnkVZee5 X8uOP2iPxkwcpqGO+PVhbwbcTVBmylUnzSGAODNCZ4sCIYsgfceYXQo0/1edJ6UMEVxT ksqvkR2p69+apdUjwRLRf0NF8AgWAFjN/XLs0iWDGnBkfH9dNT6bRzE3q1QCtiK4jJYY ciUw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=fb1vazws15mlRsEbhKXSAVoYjhZWpYh3l0I0AMhRe60=; b=HxqURP2OHdFPb3T0bAHm1/a+D+KfoVtqAUOQuoy59ncuEkreZ98zrLiPajRErvYgOr 7WheYzgKZ5guutMRuic+WrcNA41heT/k/1lxitMBIIWHWj+LMUHbJ8UbX6EoUXk+Nov0 ofcGo/muxYi+R8FuyYnVQU/NAvaLL1iR0JkZIpYTka8kO7d6y+dXBhHNDDm7pqDX+LPF 9iJsKRgBJq8H6Q/nx+byjW87UBpmDAR6YSLO10VjFEHT4qEDnOTSPNwkFqDB4wX4sJYx SE2LzS8Nj+qW2YcwVzVRh295er9qZH2ZXibfY6bo0wnNlvssDEUXtd1DHi33l39Ng9Je peSw== X-Gm-Message-State: AOAM531vIJfu/KDT30VF5KbT6/o1xEqiXgwxPAqp484kIz9OuT2+W5kD k5U9x73wI4x/q5cNmmIp5puVD6svrhYENLOZn2k= X-Google-Smtp-Source: ABdhPJzD70qQZrCYkhZKmEIr9twaWZ1iLgh12KvCfz/WDTbzooZtb3ZCi4ImgohcKlS4XAQUbRwlpih/px8K9LpfGrI= X-Received: by 2002:a05:6402:1c95:: with SMTP id cy21mr2436442edb.151.1598629399416; Fri, 28 Aug 2020 08:43:19 -0700 (PDT) MIME-Version: 1.0 References: <20200828142546.GN14765@casper.infradead.org> <20200828145528.GO14765@casper.infradead.org> In-Reply-To: <20200828145528.GO14765@casper.infradead.org> From: Yang Shi Date: Fri, 28 Aug 2020 08:43:07 -0700 Message-ID: Subject: Re: Is shmem page accounting wrong on split? To: Matthew Wilcox Cc: Linux MM , Hugh Dickins , Yang Shi Content-Type: text/plain; charset="UTF-8" X-Rspamd-Queue-Id: 078561804E3A9 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam05 X-Bogosity: Ham, tests=bogofilter, spamicity=0.081641, 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 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. > > 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. > } > > /* > >