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.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable 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 21779C4320A for ; Fri, 30 Jul 2021 21:36:45 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 9C57960F3A for ; Fri, 30 Jul 2021 21:36:43 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 9C57960F3A Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id D51036B0033; Fri, 30 Jul 2021 17:36:42 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D01CE6B0036; Fri, 30 Jul 2021 17:36:42 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BEF5D8D0001; Fri, 30 Jul 2021 17:36:42 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0190.hostedemail.com [216.40.44.190]) by kanga.kvack.org (Postfix) with ESMTP id A21ED6B0033 for ; Fri, 30 Jul 2021 17:36:42 -0400 (EDT) Received: from smtpin07.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 2F49C16B08 for ; Fri, 30 Jul 2021 21:36:42 +0000 (UTC) X-FDA: 78420563844.07.7D5FDA3 Received: from mail-ej1-f50.google.com (mail-ej1-f50.google.com [209.85.218.50]) by imf12.hostedemail.com (Postfix) with ESMTP id 8C95D1006378 for ; Fri, 30 Jul 2021 21:36:41 +0000 (UTC) Received: by mail-ej1-f50.google.com with SMTP id x11so18298996ejj.8 for ; Fri, 30 Jul 2021 14:36:41 -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=BHRdpHzssosN281+yG++IdMiDGzijOSqxARWz3dit88=; b=aui1RaBDIevJde/b4U2A9KW2i7OSym58Ljf37Yt407gYsdr3UjgRvhVyxXb49AHR0s xvaH5NuuZufzFD/u3Gu/jceTu4lKxySYb9rUqS/XcaP8+HyfRg5Vzkxi4V4Zmm3uec48 sIZDw+1sSU/dg/+T5CPNsEk6dBZgZDsw6iiyeNCYPI6XLlRiNM1fhqENpY2FN7Tjq2od /E+HHKVELqMJ5eI3JxZFsaLxtQMbu/ScZcVeBBxLwV1Z9pVDDX/5fR+lExNNOTTwAv8B QT08FB6ZVSIlJS30Gx/G5P3maeOX/MIEBBkPbqbpsKxDz+oUhxn0qTAeF2vJ6qM1kdT2 4n9A== 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=BHRdpHzssosN281+yG++IdMiDGzijOSqxARWz3dit88=; b=k8Yh5vp1tBmqOFZS9iyHmhDKqSKIcTX6/1Ou3E1SfVVx81lm3pRKcrI8VqlfBVdQNN 6gV+1QeC2Y19SheuVYWgci+abeu48rXT9pZmPBnX8GZ8XXqLEbsZJ4EXXlb7OXw/OQJm FGQ2HgxU++XWJJHdIQe7u09LafDeyB+CKzNTBn8Nz3DI3X86If242uRZQPs6ifsAF1An HY2u6JjrrKNw5A5mmO2kL2dZ8c9bnLRNurRY0mgttoEiQbc/e/ugkKIgNMUlSJJDFP8s Qv9U1iQdFYnEvSaU4tpt1x2d0ZyIP2EbydFH3+FbYlFkwzDx/Yp2Pr1Ds9VHmNrebtao k60A== X-Gm-Message-State: AOAM533g7ed9NW6Q71cH+0KD+jg+pwHWenkGR9rAyjIrO7nXGCUcXVBO 1AqC3ctXPT69ACfeyO5roWinkSc+ghwhRTsiHSs= X-Google-Smtp-Source: ABdhPJy9R4i42eTcls1i9Y/2WZAQ0xCIG6g3TtP09aeUVBKpq+6WOSbADUykf66Emajn0U1oncUepgaehqmCD4oyJsg= X-Received: by 2002:a17:906:1919:: with SMTP id a25mr4722791eje.161.1627681000237; Fri, 30 Jul 2021 14:36:40 -0700 (PDT) MIME-Version: 1.0 References: <2862852d-badd-7486-3a8e-c5ea9666d6fb@google.com> In-Reply-To: From: Yang Shi Date: Fri, 30 Jul 2021 14:36:28 -0700 Message-ID: Subject: Re: [PATCH 01/16] huge tmpfs: fix fallocate(vanilla) advance over huge pages To: Hugh Dickins Cc: Andrew Morton , Shakeel Butt , "Kirill A. Shutemov" , Miaohe Lin , Mike Kravetz , Michal Hocko , Rik van Riel , Christoph Hellwig , Matthew Wilcox , "Eric W. Biederman" , Alexey Gladkov , Chris Wilson , Matthew Auld , Linux FS-devel Mailing List , Linux Kernel Mailing List , linux-api@vger.kernel.org, Linux MM Content-Type: text/plain; charset="UTF-8" Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=gmail.com header.s=20161025 header.b=aui1RaBD; spf=pass (imf12.hostedemail.com: domain of shy828301@gmail.com designates 209.85.218.50 as permitted sender) smtp.mailfrom=shy828301@gmail.com; dmarc=pass (policy=none) header.from=gmail.com X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 8C95D1006378 X-Stat-Signature: wds7fk8ut9nfzak8ihgxea7pkbjdho3o X-HE-Tag: 1627681001-576005 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, Jul 30, 2021 at 12:25 AM Hugh Dickins wrote: > > shmem_fallocate() goes to a lot of trouble to leave its newly allocated > pages !Uptodate, partly to identify and undo them on failure, partly to > leave the overhead of clearing them until later. But the huge page case > did not skip to the end of the extent, walked through the tail pages one > by one, and appeared to work just fine: but in doing so, cleared and > Uptodated the huge page, so there was no way to undo it on failure. > > Now advance immediately to the end of the huge extent, with a comment on > why this is more than just an optimization. But although this speeds up > huge tmpfs fallocation, it does leave the clearing until first use, and > some users may have come to appreciate slow fallocate but fast first use: > if they complain, then we can consider adding a pass to clear at the end. > > Fixes: 800d8c63b2e9 ("shmem: add huge pages support") > Signed-off-by: Hugh Dickins Reviewed-by: Yang Shi A nit below: > --- > mm/shmem.c | 19 ++++++++++++++++--- > 1 file changed, 16 insertions(+), 3 deletions(-) > > diff --git a/mm/shmem.c b/mm/shmem.c > index 70d9ce294bb4..0cd5c9156457 100644 > --- a/mm/shmem.c > +++ b/mm/shmem.c > @@ -2736,7 +2736,7 @@ static long shmem_fallocate(struct file *file, int mode, loff_t offset, > inode->i_private = &shmem_falloc; > spin_unlock(&inode->i_lock); > > - for (index = start; index < end; index++) { > + for (index = start; index < end; ) { > struct page *page; > > /* > @@ -2759,13 +2759,26 @@ static long shmem_fallocate(struct file *file, int mode, loff_t offset, > goto undone; > } > > + index++; > + /* > + * Here is a more important optimization than it appears: > + * a second SGP_FALLOC on the same huge page will clear it, > + * making it PageUptodate and un-undoable if we fail later. > + */ > + if (PageTransCompound(page)) { > + index = round_up(index, HPAGE_PMD_NR); > + /* Beware 32-bit wraparound */ > + if (!index) > + index--; > + } > + > /* > * Inform shmem_writepage() how far we have reached. > * No need for lock or barrier: we have the page lock. > */ > - shmem_falloc.next++; > if (!PageUptodate(page)) > - shmem_falloc.nr_falloced++; > + shmem_falloc.nr_falloced += index - shmem_falloc.next; > + shmem_falloc.next = index; This also fixed the wrong accounting of nr_falloced, so it should be able to avoid returning -ENOMEM prematurely IIUC. Is it worth mentioning in the commit log? > > /* > * If !PageUptodate, leave it that way so that freeable pages > -- > 2.26.2 >