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 B820FC3DA4A for ; Mon, 19 Aug 2024 12:48:06 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2DE966B007B; Mon, 19 Aug 2024 08:48:06 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 28E6F6B0082; Mon, 19 Aug 2024 08:48:06 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 12FCF6B0083; Mon, 19 Aug 2024 08:48:06 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id E80AE6B007B for ; Mon, 19 Aug 2024 08:48:05 -0400 (EDT) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 80923C1231 for ; Mon, 19 Aug 2024 12:48:05 +0000 (UTC) X-FDA: 82468972530.20.16279A6 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) by imf30.hostedemail.com (Postfix) with ESMTP id 3D7638002C for ; Mon, 19 Aug 2024 12:48:02 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=RXtoiguI; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=We9J5E7k; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=RXtoiguI; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=We9J5E7k; dmarc=pass (policy=none) header.from=suse.de; spf=pass (imf30.hostedemail.com: domain of hare@suse.de designates 195.135.223.130 as permitted sender) smtp.mailfrom=hare@suse.de ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1724071668; a=rsa-sha256; cv=none; b=2zpWudapTh/Z2VOu1vvUKOtugL2XVXl0w00+WmDLk0MQrwqXhV79hEw934zgwtamJAHiU3 iArmVA5/g2Gn4SaiBz7WZGvu+MSdU8sExkrSy3uS5zA6QQHF0S5dZDJWLjFHH7RM0zVlbg YqlSTUt6CQYMbumf2h6Awm2ivfNQ/zA= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=RXtoiguI; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=We9J5E7k; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=RXtoiguI; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=We9J5E7k; dmarc=pass (policy=none) header.from=suse.de; spf=pass (imf30.hostedemail.com: domain of hare@suse.de designates 195.135.223.130 as permitted sender) smtp.mailfrom=hare@suse.de ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1724071668; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=VFCFhO6hZl457IRzJhBFYas41P7AtvK65yfv9OH7YqA=; b=wa8vNHmglo08IDUL0d1fBP70vwatkqOIwHLxQS7d0ibdJgAegCiRvKwi9OMcpFRuqwyIIL wP8NtPBvIm5zVv4g60LnIOvEChegUffO5yZYgfccWyejb8TcjS5Y4mJKZmMQXLFPVQaw5X OS57QxYthWfrY65qxUsAUaG2iNfQ9yA= Received: from imap1.dmz-prg2.suse.org (unknown [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 89E6B2117A; Mon, 19 Aug 2024 12:48:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1724071681; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=VFCFhO6hZl457IRzJhBFYas41P7AtvK65yfv9OH7YqA=; b=RXtoiguI5s78ePFTXA+h+Cd5vs0DWIs8ilCGivIQ6fcrOKDB4WCbzpZPjKMcXKU/xsKw+I 3lB+eNZyjkf8bXKONnKptjyDs39ZsxOehYjM8qhmy5zfiJtVXFdZ81nbPE9XJkfP4rcskM +0Zup79oCaOXMrNTQea/w1nEmOnS+S8= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1724071681; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=VFCFhO6hZl457IRzJhBFYas41P7AtvK65yfv9OH7YqA=; b=We9J5E7kt2BQCD3uo3xHiT0zA+7SUDRNmLi2TlbLRFrcSVvxrUaWe8yVHe/phG94FeOJ+u Z/Us8laZaGP0gjCQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1724071681; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=VFCFhO6hZl457IRzJhBFYas41P7AtvK65yfv9OH7YqA=; b=RXtoiguI5s78ePFTXA+h+Cd5vs0DWIs8ilCGivIQ6fcrOKDB4WCbzpZPjKMcXKU/xsKw+I 3lB+eNZyjkf8bXKONnKptjyDs39ZsxOehYjM8qhmy5zfiJtVXFdZ81nbPE9XJkfP4rcskM +0Zup79oCaOXMrNTQea/w1nEmOnS+S8= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1724071681; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=VFCFhO6hZl457IRzJhBFYas41P7AtvK65yfv9OH7YqA=; b=We9J5E7kt2BQCD3uo3xHiT0zA+7SUDRNmLi2TlbLRFrcSVvxrUaWe8yVHe/phG94FeOJ+u Z/Us8laZaGP0gjCQ== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 383AD1397F; Mon, 19 Aug 2024 12:48:01 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id 8SK7BQE/w2YcZwAAD6G6ig (envelope-from ); Mon, 19 Aug 2024 12:48:01 +0000 Message-ID: <03ae65df-a369-436d-b31c-b3cec6ca3bc1@suse.de> Date: Mon, 19 Aug 2024 14:48:00 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v12 00/10] enable bs > ps in XFS To: David Howells , "Pankaj Raghav (Samsung)" Cc: brauner@kernel.org, akpm@linux-foundation.org, chandan.babu@oracle.com, linux-fsdevel@vger.kernel.org, djwong@kernel.org, gost.dev@samsung.com, linux-xfs@vger.kernel.org, hch@lst.de, david@fromorbit.com, Zi Yan , yang@os.amperecomputing.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, willy@infradead.org, john.g.garry@oracle.com, cl@os.amperecomputing.com, p.raghav@samsung.com, mcgrof@kernel.org, ryan.roberts@arm.com References: <20240818165124.7jrop5sgtv5pjd3g@quentin> <20240815090849.972355-1-kernel@pankajraghav.com> <2924797.1723836663@warthog.procyon.org.uk> <3402933.1724068015@warthog.procyon.org.uk> Content-Language: en-US From: Hannes Reinecke In-Reply-To: <3402933.1724068015@warthog.procyon.org.uk> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Rspam-User: X-Rspamd-Queue-Id: 3D7638002C X-Rspamd-Server: rspam01 X-Stat-Signature: itgnkp7bsz6kpzofkz571n91x67igrjg X-HE-Tag: 1724071682-285889 X-HE-Meta: U2FsdGVkX1+9/qspEcnoh5urwqYWWJklm9AENUq7Ds8ujg5XzINfzVsXsuNQaev1El0QekapbbUWGNcCl8uzbGtDWYE2WsurSFKdDFD3X3R2hWoCam3fTdqbbh7ExWlPBQvztgKBkoF+59gbkfxMybUcQ43uQK0h0mvZmJLupDQ2MxASsaoIyZZwlI12GreUh9xQ2MnJCaJtcBe4qXKY1OUDqEgnzZH9ocNbNt58NDrSApwIYZ6z/hug60oQHbbGc349ZHXY2wkXjx9xW3E8O2JiaG5N6NXrNmZXZp7vIOzsVyOuhGbcVMfh+0pRo3Kv2HiWOaVvtaICyUmiKdycghffDe1sPa1KcNvKTO0vAUaq/m6aySlWbttKDX9vPE/NsDnXtyBQnpGfkGIGuNsJcPhWWDmCp3T/JYrh6E3glKURV7mDlj6QpzMJBlDuVNOBb0UOtCLdBW1GC3K/avPLVoglgZ/mqQV3KPs9McsvuUqOpsHwVf976D/EwWJuughSm3TOi/XUDNeRqKtnDOWPPYegruycMK4I2cD62qXTBpfeFVdf+VvagAFfTOuOKXEER3hVFHMIgW38ZGkHsq9olw9Ufos0cO9eri6yTICYWEyX91YWyaM2Hl+JghKmkz2bjNagnl8DJ80l3wXnwKZ6I7W3tYIcyTwgS++sWzUt5N00/METfJ2LMJ8F08zthO20kru41U3/cNQvcnhzZ3IlQCAKARqgjwyUew40/It/4HvfrTphL26aU5SMGAlABM63u4uQV74TDFAaPzOvNjprMPO3bxCD3dyYTSYdgNITEdUDXWqTb+fqIppBGa5KgbpV0NLkZi3UfNUeUfVPENXR3nRu4ChWprSCpYvZhWkTeU99JjxEVyfQXYdnb6skgz5LKGj3GEJBCEi3kn8y3YyQVMIE9tEsrD2RJZL1Rq8bGIk8Uj1QpMxLXUN41AqoNgAucKzxNtrpVguY6k2kc6K nhoOKR7u o8NXOLdb9YZwbA3t7tIDe1eedyHRyZwlvNCoHQCibTb0dyWTut7kBjnvBNZwMogx05d+xQSaGGechu3AzNkt4kSv2akT4vrsfvX+bf4tg8yTsaW6sjZsq5eYCG3EBPBvOYJ1P30EOTilci49RpuSCqcbT39nPUa4UMj5MHqv2KQCMpqwd/FRJRO38M7+D2ouSDVubmIdx96EB943YU17rrE4cMakwnboUXYwgFueKa9iVnNEYGL5/foPJHNqWSwI2jVkDLyfk8jtMLH18/g9o7Ihwx/m4ZQLW3plAToACVCHlAI2enXbITAXHzg== 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: List-Subscribe: List-Unsubscribe: On 8/19/24 13:46, David Howells wrote: > Hi Pankaj, > > I can reproduce the problem with: > > xfs_io -t -f -c "pwrite -S 0x58 0 40" -c "fsync" -c "truncate 4" -c "truncate 4096" /xfstest.test/wubble; od -x /xfstest.test/wubble > > borrowed from generic/393. I've distilled it down to the attached C program. > > Turning on tracing and adding a bit more, I can see the problem happening. > Here's an excerpt of the tracing (I've added some non-upstream tracepoints). > Firstly, you can see the second pwrite at fpos 0, 40 bytes (ie. 0x28): > > pankaj-5833: netfs_write_iter: WRITE-ITER i=9e s=0 l=28 f=0 > pankaj-5833: netfs_folio: pfn=116fec i=0009e ix=00000-00001 mod-streamw > > Then first ftruncate() is called to reduce the file size to 4: > > pankaj-5833: netfs_truncate: ni=9e isz=2028 rsz=2028 zp=4000 to=4 > pankaj-5833: netfs_inval_folio: pfn=116fec i=0009e ix=00000-00001 o=4 l=1ffc d=78787878 > pankaj-5833: netfs_folio: pfn=116fec i=0009e ix=00000-00001 inval-part > pankaj-5833: netfs_set_size: ni=9e resize-file isz=4 rsz=4 zp=4 > > You can see the invalidate_folio call, with the offset at 0x4 an the length as > 0x1ffc. The data at the beginning of the page is 0x78787878. This looks > correct. > > Then second ftruncate() is called to increase the file size to 4096 > (ie. 0x1000): > > pankaj-5833: netfs_truncate: ni=9e isz=4 rsz=4 zp=4 to=1000 > pankaj-5833: netfs_inval_folio: pfn=116fec i=0009e ix=00000-00001 o=1000 l=1000 d=78787878 > pankaj-5833: netfs_folio: pfn=116fec i=0009e ix=00000-00001 inval-part > pankaj-5833: netfs_set_size: ni=9e resize-file isz=1000 rsz=1000 zp=4 > > And here's the problem: in the invalidate_folio() call, the offset is 0x1000 > and the length is 0x1000 (o= and l=). But that's the wrong half of the folio! > I'm guessing that the caller thereafter clears the other half of the folio - > the bit that should be kept. > > David > --- > /* Distillation of the generic/393 xfstest */ > #include > #include > #include > #include > > #define ERR(x, y) do { if ((long)(x) == -1) { perror(y); exit(1); } } while(0) > > static const char xxx[40] = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"; > static const char yyy[40] = "yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy"; > static const char dropfile[] = "/proc/sys/vm/drop_caches"; > static const char droptype[] = "3"; > static const char file[] = "/xfstest.test/wubble"; > > int main(int argc, char *argv[]) > { > int fd, drop; > > /* Fill in the second 8K block of the file... */ > fd = open(file, O_CREAT|O_TRUNC|O_WRONLY, 0666); > ERR(fd, "open"); > ERR(ftruncate(fd, 0), "pre-trunc $file"); > ERR(pwrite(fd, yyy, sizeof(yyy), 0x2000), "write-2000"); > ERR(close(fd), "close"); > > /* ... and drop the pagecache so that we get a streaming > * write, attaching some private data to the folio. > */ > drop = open(dropfile, O_WRONLY); > ERR(drop, dropfile); > ERR(write(drop, droptype, sizeof(droptype) - 1), "write-drop"); > ERR(close(drop), "close-drop"); > > fd = open(file, O_WRONLY, 0666); > ERR(fd, "reopen"); > /* Make a streaming write on the first 8K block (needs O_WRONLY). */ > ERR(pwrite(fd, xxx, sizeof(xxx), 0), "write-0"); > /* Now use truncate to shrink and reexpand. */ > ERR(ftruncate(fd, 4), "trunc-4"); > ERR(ftruncate(fd, 4096), "trunc-4096"); > ERR(close(fd), "close-2"); > exit(0); > } > Wouldn't the second truncate end up with a 4k file, and not an 8k? IE the resulting file will be: After step 1: 8k After step 2: 4 After step 3: 4k Hmm? Cheers, Hannes -- Dr. Hannes Reinecke Kernel Storage Architect hare@suse.de +49 911 74053 688 SUSE Software Solutions GmbH, Frankenstr. 146, 90461 Nürnberg HRB 36809 (AG Nürnberg), GF: I. Totev, A. McDonald, W. Knoblich