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 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 87548C433F5 for ; Wed, 12 Jan 2022 17:19:41 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BF38D6B01A8; Wed, 12 Jan 2022 12:19:40 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id B7CD36B01A9; Wed, 12 Jan 2022 12:19:40 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9F5116B01AA; Wed, 12 Jan 2022 12:19:40 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0175.hostedemail.com [216.40.44.175]) by kanga.kvack.org (Postfix) with ESMTP id 704E16B01A8 for ; Wed, 12 Jan 2022 12:19:40 -0500 (EST) Received: from smtpin26.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id EF7DA181C9650 for ; Wed, 12 Jan 2022 17:19:39 +0000 (UTC) X-FDA: 79022296920.26.37EC2B6 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf05.hostedemail.com (Postfix) with ESMTP id 6C166100012 for ; Wed, 12 Jan 2022 17:19:39 +0000 (UTC) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 6B4D4616C1; Wed, 12 Jan 2022 17:19:38 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C80A8C36AEA; Wed, 12 Jan 2022 17:19:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1642007977; bh=o4t9U0eYLfqHTIBmy++CHkJ+gEPvd4uI1Gekf+xhCng=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=P83jDWg9wPnwg99E7rOT8E5xfPyQK2mStynhV57nj3IMZQwgaHQw0Ea0Q0EGetGIK pC4J6e+oG57m928hhTCTAUbEVzwjFnlAQM4j+BVymLHRPzg+K0wLTjY6VAUJ+abEjs sFlo0sgbPnZOYw9nu9DfIXmS7kcU3bzjVLcx6gTVZKlEfl2bXSISzTAVQsrN6Q981W 0GcsvPdnykc697cOu5VIwVNEFKINNgcj0YHiYmvHkiQJHODsLITaRYjV472fviVmk+ Hs5kTNyoKAmiwfGsMO3dF63b79Wyp2yrNQWdw/4/JIWwDtHJ4Y7CpomiICUuNSczsv pW7q+dViBJGHQ== Date: Wed, 12 Jan 2022 09:19:37 -0800 From: "Darrick J. Wong" To: Hugh Dickins Cc: Lukas Czerner , Mikulas Patocka , Zdenek Kabelac , linux-mm@kvack.org, linux-fsdevel@vger.kernel.org Subject: Re: unusual behavior of loop dev with backing file in tmpfs Message-ID: <20220112171937.GA19154@magnolia> References: <20211126075100.gd64odg2bcptiqeb@work> <5e66a9-4739-80d9-5bb5-cbe2c8fef36@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <5e66a9-4739-80d9-5bb5-cbe2c8fef36@google.com> X-Rspamd-Queue-Id: 6C166100012 X-Stat-Signature: bys6ifmma4wrnfe6mzc79arbjas5y5pz Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=P83jDWg9; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf05.hostedemail.com: domain of djwong@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=djwong@kernel.org X-Rspamd-Server: rspam08 X-HE-Tag: 1642007979-529858 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 Tue, Jan 11, 2022 at 08:28:02PM -0800, Hugh Dickins wrote: > On Fri, 26 Nov 2021, Lukas Czerner wrote: > > > > I've noticed unusual test failure in e2fsprogs testsuite > > (m_assume_storage_prezeroed) where we use mke2fs to create a file system > > on loop device backed in file on tmpfs. For some reason sometimes the > > resulting file number of allocated blocks (stat -c '%b' /tmp/file) differs, > > but it really should not. > > > > I was trying to create a simplified reproducer and noticed the following > > behavior on mainline kernel (v5.16-rc2-54-g5d9f4cf36721) > > > > # truncate -s16M /tmp/file > > # stat -c '%b' /tmp/file > > 0 > > > > # losetup -f /tmp/file > > # stat -c '%b' /tmp/file > > 672 > > > > That alone is a little unexpected since the file is really supposed to > > be empty and when copied out of the tmpfs, it really is empty. But the > > following is even more weird. > > > > We have a loop setup from above, so let's assume it's /dev/loop0. The > > following should be executed in quick succession, like in a script. > > > > # dd if=/dev/zero of=/dev/loop0 bs=4k > > # blkdiscard -f /dev/loop0 > > # stat -c '%b' /tmp/file > > 0 > > # sleep 1 > > # stat -c '%b' /tmp/file > > 672 > > > > Is that expected behavior ? From what I've seen when I use mkfs instead > > of this simplified example the number of blocks allocated as reported by > > stat can vary a quite a lot given more complex operations. The file itself > > does not seem to be corrupted in any way, so it is likely just an > > accounting problem. > > > > Any idea what is going on there ? > > I have half an answer; but maybe you worked it all out meanwhile anyway. > > Yes, it happens like that for me too: 672 (but 216 on an old installation). > > Half the answer is that funny code at the head of shmem_file_read_iter(): > /* > * Might this read be for a stacking filesystem? Then when reading > * holes of a sparse file, we actually need to allocate those pages, > * and even mark them dirty, so it cannot exceed the max_blocks limit. > */ > if (!iter_is_iovec(to)) > sgp = SGP_CACHE; > which allocates pages to the tmpfs for reads from /dev/loop0; whereas > normally a read of a sparse tmpfs file would just give zeroes without > allocating. > > [Do we still need that code? Mikulas asked 18 months ago, and I never > responded (sorry) because I failed to arrive at an informed answer. > It comes from a time while unionfs on tmpfs was actively developing, > and solved a real problem then; but by the time it went into tmpfs, > unionfs had already been persuaded to proceed differently, and no > longer needed it. I kept it in for indeterminate other stacking FSs, > but it's probably just culted cargo, doing more harm than good. I > suspect the best thing to do is, after the 5.17 merge window closes, > revive Mikulas's patch to delete it and see if anyone complains.] I for one wouldn't mind if tmpfs no longer instantiated cache pages for a read from a hole -- it's a little strange, since most disk filesystems (well ok xfs and ext4, haven't checked the others) don't do that. Anyone who really wants a preallocated page should probably be using fallocate or something... --D > But what is asynchronously reading /dev/loop0 (instantiating pages > initially, and reinstantiating them after blkdiscard)? I assume it's > some block device tracker, trying to read capacity and/or partition > table; whether from inside or outside the kernel, I expect you'll > guess much better than I can. > > Hugh