Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp7281009pxv; Fri, 30 Jul 2021 14:43:48 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxieDTutcMvEUlerNpaztlRd8xVpFXRwV5KvA4JaIrH0l48cP5DmU2Vm7NzLj0lpoeW+pHq X-Received: by 2002:aa7:cace:: with SMTP id l14mr5632093edt.14.1627681428188; Fri, 30 Jul 2021 14:43:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627681428; cv=none; d=google.com; s=arc-20160816; b=c8FsTX+eEX3L+AmMBPSLPd/1Bc53aX82yr9M1lx6H8GVeq6hRj2G6HvM5jX6pzUy6F VNMGDJUUezksS0zUuw72GR9mH6q3cEUN7g/dhJZ3Kp4oGdJ82IZeOEjUFXEzkMzN8sLE DFD+kCcOnZV53xwoUxgtOWurHVRCo99txVVbo0EDEWbsyQXnag2bWQHLqwKtfRNTn/M1 cuYNe6q9S4yX46D/jDL6TYI5JGvNPkGNbqIbDxmClAuLxctNxy/Z61f7ME0eloi0XBoY dgLsjO7g+LcJfi7gyUb9S2uZAN0gWroSqU1wZKYI1smszHuv7BS0bDFo0ZL57v+/3odz 874Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=BHRdpHzssosN281+yG++IdMiDGzijOSqxARWz3dit88=; b=t2YNxi2TJtgHVoTioFi8vq/71TKSZVyxmG8ev04e3SimBVdkXeP0bLyEtHk4/0wZ3p j5zHMWcuwgZ/aI9jEfytnsvuIdun0cksEz1A1GeES1g48K9lwOaDGRtyB2xEA1BOBpv5 h+zL04C/uVfyt0Uxd9sVbNP2fyrAnI64BQeR4roZoO9bABnP4EBrnOUt0HGBH6moI4U1 snynyka1+aHfieLfPxJx+hGA6yzm4WmGFwSAd3fE9sAEDRipQGyM7HClPXnEu6yFPiB2 TtN3mVVPQvu62yLXGEsAfWFAKmYbU/4fyXxLaNV01LZ6gY9f1HkMnuvUzThBCU39JXKZ hX+A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=aui1RaBD; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h15si2537441ejj.98.2021.07.30.14.43.25; Fri, 30 Jul 2021 14:43:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=aui1RaBD; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230284AbhG3Vgs (ORCPT + 99 others); Fri, 30 Jul 2021 17:36:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37470 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229997AbhG3Vgs (ORCPT ); Fri, 30 Jul 2021 17:36:48 -0400 Received: from mail-ej1-x633.google.com (mail-ej1-x633.google.com [IPv6:2a00:1450:4864:20::633]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 965C9C061765; Fri, 30 Jul 2021 14:36:41 -0700 (PDT) Received: by mail-ej1-x633.google.com with SMTP id x11so18298984ejj.8; 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=IhQfwlUsE3ZOLjdaLCLwVsq/IXwk2ORzm2DVQgDjhmdfq7R1m9KqzwQiBqaXpBFUBH HOYVQQPJ7gVp72clS3FmM8dMWrp0jz35bmuBcYnEvNToVxL/LjK5cxCObVH1qk9HaOWH brZeqd+tnz4IYGk9bH2BpV1HZKOmvCJLwtwiT+6saIltq316zEKU+wq5Ovuyqpm7+p3g cNyjEhgD1wW4grj8g7Q+BEoijejHUd+OZA3dOS6sqBLPYNtpenc60vW8HjM8/2jfzk6d ZyjRePF5X+gagrjBQGtOQhrcjdBP1kFtRTg3CkO0fV77SZk2Tv08k9mtTsiNn6vZdq2c qzqQ== X-Gm-Message-State: AOAM531PFHyRVnU5kxkP8nbG3pfV9IYTnUfSZOs5GstsRtEWAmSUqaSk WcBzSszwBRfMc0pakFr1ojCcwCzmajZnP8uXIPU= 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" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 >