Received: by 2002:a05:6a10:c7c6:0:0:0:0 with SMTP id h6csp644288pxy; Sat, 31 Jul 2021 20:40:42 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw7g9pR487b/IqC2W9mQuJw0/AXlZYxvdQKT17p9krCE85U5vsNk0PO3379dyfvZLbkgf48 X-Received: by 2002:a05:6402:d67:: with SMTP id ec39mr11824603edb.117.1627789241983; Sat, 31 Jul 2021 20:40:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627789241; cv=none; d=google.com; s=arc-20160816; b=mzOGKBabtCwUrSN78PugwcTNtMw1y+We8K+n2HDub94f5oF2tM6I3RdLh3WKoRK0ia qcjkHuN2S2wHoeWsALDhlBFDeeTG2RBCOYXs+wLu2UX+FxjHWHOobQnjqJ7QVKoq83Xr GAl9ytg5t6a/CmCFj9SVryFashsw5HAIO1gb+aQjNovVu3cvE9u4av7IZraqBk1tg3PY elZJZ7IdpwrfTi1VcfMceXDGV6/z9ie0psv4vxFuQEEjJxSgxNnRLIC7YVce8SG5i85i MR+Am60kzNifPTAz19puuhufjPINp7rK0oiNKjSIFYWr+pCEDzHqhZF7ROJjdIdcMF5z wrhQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:message-id:in-reply-to :subject:cc:to:from:date:dkim-signature; bh=5WRI9ovrYarzT6P+AQzyPA+zqmSi1roZ3PpwFTiVvsU=; b=VmOc/3JAnLq/xEHw3NyF0RKqklBaIxrM92OGGghjZGc2FVB7MCzDnz4sI4syjTBgqN Nhw1TqOgtPvLM+FpiDAZX9oJnji53yNMv7y1gXdjOy2uWYWZdVwmBgPkHJ3t0sfD+Cux MS8Oau0U/CoIC6VwG25TiuCM3nfqIu5Uo7aLtLPzdYtSLuLM/ugG8h3sPOH92njlEzkA 8kJiqbTP4HSiX2Znj0dBwRQnm9PQJ3gbb01HJ0J4s/JrOMTiqRxieIyYevClzvIhnuzf 7pYwKnCaSsSYCnzoygV7Idy691y+Wk/qdu3tlKlgx8z302k/3Pab40yxqe28I39iolzN b+AA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b="VP/8wrr+"; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id i18si5995088ejv.388.2021.07.31.20.40.18; Sat, 31 Jul 2021 20:40:41 -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=@google.com header.s=20161025 header.b="VP/8wrr+"; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232021AbhHADiW (ORCPT + 99 others); Sat, 31 Jul 2021 23:38:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57398 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231452AbhHADiV (ORCPT ); Sat, 31 Jul 2021 23:38:21 -0400 Received: from mail-qk1-x736.google.com (mail-qk1-x736.google.com [IPv6:2607:f8b0:4864:20::736]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B1DABC06175F for ; Sat, 31 Jul 2021 20:38:12 -0700 (PDT) Received: by mail-qk1-x736.google.com with SMTP id 190so13477515qkk.12 for ; Sat, 31 Jul 2021 20:38:12 -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 :mime-version; bh=5WRI9ovrYarzT6P+AQzyPA+zqmSi1roZ3PpwFTiVvsU=; b=VP/8wrr+L9Dht4u0MJMeSSOm1ThNwDEsQqkwdL+2BxCgXIuJ+MtclIzdrzF/wfhwMO yQ9miYXYFYxmzqvE8QDOodcfyok+5jByfAzw8wF3wNFWeBLMx99WiZucz5wBgngYUAG0 PNEfZyKutEQKhv6MNwosmIeiGLkol1lcMX9jMIOIlPL4LfC6ZJwo9ofOYjIlfyoo8elj Tk9j9lZLUVZfMBgp0+Zy/9aL+ydhZQxCzLimxef0eqhpgDaVFsu9AwrBGWIR+hiMR2JA DBAHTy92duQwewQ5ydWLQ4g3BiHgN7LOF2EDS7FnLkBJTpjECrqrXzcX7XbflLAbrVlY xtfA== 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:mime-version; bh=5WRI9ovrYarzT6P+AQzyPA+zqmSi1roZ3PpwFTiVvsU=; b=bqV3UIB9MuaiTApwXLZnnC1TlFDvNJMmDb+VQyop5BcNzKBpMcyjoO2lxdGxVaF64w UtFv1QUWEM6JwRlmSYukdqpAcn5qDCBJBI34SP31GPN8eZGDJ7PWDdE1H8MCeypXA/ed 6Bf3kTYNegPq0N9+gJuKZsiOXslCN8W9NuFgrURAc3F+AknVZ5JDU8cE3jJBMGVq0DMl Vb0TwKeSigld6VDfHwFcTp6LGkghv7a1CpLexeYO8RfEdEtbMVwMctSSyUwuwwW/2bS6 O5oSe9a2Uzs0aQAeG7MTx4aizznOiAhIOzQOerkCcbQ4cDa+l5zvwv117LbmkZtVs5Iq PR/w== X-Gm-Message-State: AOAM531IpGbv7wUrA/GSo/gxfNVRmwv18GN3JPj2K76idtphZpY+Dxu+ Fy/08+TsKL/evtjVvHBop1YLKA== X-Received: by 2002:a05:620a:31a1:: with SMTP id bi33mr9497896qkb.146.1627789091715; Sat, 31 Jul 2021 20:38:11 -0700 (PDT) Received: from ripple.attlocal.net (172-10-233-147.lightspeed.sntcca.sbcglobal.net. [172.10.233.147]) by smtp.gmail.com with ESMTPSA id d200sm3505724qke.95.2021.07.31.20.38.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 31 Jul 2021 20:38:11 -0700 (PDT) Date: Sat, 31 Jul 2021 20:38:00 -0700 (PDT) From: Hugh Dickins X-X-Sender: hugh@ripple.anvils To: Yang Shi cc: Hugh Dickins , 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 Subject: Re: [PATCH 01/16] huge tmpfs: fix fallocate(vanilla) advance over huge pages In-Reply-To: Message-ID: <422db5c4-2490-749c-964b-dd2b93286ed5@google.com> References: <2862852d-badd-7486-3a8e-c5ea9666d6fb@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, 30 Jul 2021, Yang Shi wrote: > 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 Many thanks for reviewing so many of these. > > 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? It took me a long time to see your point there: ah yes, because it made the whole huge page Uptodate when it reached the first tail, there would have been only one nr_falloced++ for the whole of the huge page: well spotted, thanks, I hadn't realized that. Though I'm not so sure about your premature -ENOMEM: because once it has made the huge page Uptodate, the other end (shmem_writepage()) will not be incrementing nr_unswapped at all: so -ENOMEM would have been deferred rather than premature, wouldn't it? Add a comment on this in the commit log: yes, I guess so, but I haven't worked out what to write yet. Hugh > > > > > /* > > * If !PageUptodate, leave it that way so that freeable pages > > -- > > 2.26.2