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 6E1D9C5321E for ; Mon, 19 Aug 2024 11:47:17 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id F41836B007B; Mon, 19 Aug 2024 07:47:16 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id EF2076B0089; Mon, 19 Aug 2024 07:47:16 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DEA956B008A; Mon, 19 Aug 2024 07:47:16 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id BF6D76B007B for ; Mon, 19 Aug 2024 07:47:16 -0400 (EDT) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 7186EA84A9 for ; Mon, 19 Aug 2024 11:47:16 +0000 (UTC) X-FDA: 82468819272.30.3FCC900 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf26.hostedemail.com (Postfix) with ESMTP id 88A3414001A for ; Mon, 19 Aug 2024 11:47:14 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=KhinJIbK; spf=pass (imf26.hostedemail.com: domain of dhowells@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1724067931; 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=/BXnkxNev4eqM9SF7QxyJDhAGvzkKQgET2zOAAZoUuI=; b=QytY8hMdGp97k/UUgvk2ND5mo3Z0mWXz5R8gcs2dHfCfHaFsmTa9TW7Yid4pc1amsJd88f 8s1rlM09V0OdSZvtDpHj99Om60H2LQ23aiKr83XasU+Z0mPKT6xM9C3CHfj0j2qRo+1sXp iHQv2UzCD1w3Tn3pXUeG452RuBdfoHM= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=KhinJIbK; spf=pass (imf26.hostedemail.com: domain of dhowells@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1724067931; a=rsa-sha256; cv=none; b=cOzIHNJB+EVJxgTXWtfOENoTbbyN+7FOSDIv/aqeJFj043Q4qq1mB7GD9FlH1ujusW/R8e 1W7tvx+hcRaid2vWaNW2X2ERPwj/RFIV7EKuetgr7qdzhZo5S8GV2zaHVCPgXL7Jf/Ffwo Kirk0keVWBZfXiZyMojntmcr7oPmyz0= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1724068033; h=from:from: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; bh=/BXnkxNev4eqM9SF7QxyJDhAGvzkKQgET2zOAAZoUuI=; b=KhinJIbK2JcCoWUYO2lVWyRtIT3BicXlJkKLFkM7XuXiKUpbHzq7fGXN+81gK++oBuDExN 9xsOP0Bth9hIiNSzZvPay6fwX5/iDUJy3WHCHgehCiMpl+yLBg9CfbuIr+zB7hTHLaQ1HS N7K8WvYGtZiP22pcZ7izdTAc8QMhDiU= Received: from mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-85--2BxB3vTOoaoqk81-59JpA-1; Mon, 19 Aug 2024 07:47:06 -0400 X-MC-Unique: -2BxB3vTOoaoqk81-59JpA-1 Received: from mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.15]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id DAA5F1955BEE; Mon, 19 Aug 2024 11:47:02 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.42.28.30]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 75E1F19773E0; Mon, 19 Aug 2024 11:46:56 +0000 (UTC) Organization: Red Hat UK Ltd. Registered Address: Red Hat UK Ltd, Amberley Place, 107-111 Peascod Street, Windsor, Berkshire, SI4 1TE, United Kingdom. Registered in England and Wales under Company Registration No. 3798903 From: David Howells In-Reply-To: <20240818165124.7jrop5sgtv5pjd3g@quentin> References: <20240818165124.7jrop5sgtv5pjd3g@quentin> <20240815090849.972355-1-kernel@pankajraghav.com> <2924797.1723836663@warthog.procyon.org.uk> To: "Pankaj Raghav (Samsung)" Cc: dhowells@redhat.com, brauner@kernel.org, akpm@linux-foundation.org, chandan.babu@oracle.com, linux-fsdevel@vger.kernel.org, djwong@kernel.org, hare@suse.de, 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 Subject: Re: [PATCH v12 00/10] enable bs > ps in XFS MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <3402932.1724068015.1@warthog.procyon.org.uk> Content-Transfer-Encoding: quoted-printable Date: Mon, 19 Aug 2024 12:46:55 +0100 Message-ID: <3402933.1724068015@warthog.procyon.org.uk> X-Scanned-By: MIMEDefang 3.0 on 10.30.177.15 X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 88A3414001A X-Stat-Signature: 7ion9diannjozfuzfehabq8etxibaocq X-Rspam-User: X-HE-Tag: 1724068034-71286 X-HE-Meta: U2FsdGVkX1+n9FYORkEhUQirgBNUnal/OVscxfRCkGhGz2yiEoTpECuhY5/2pTHHZe8rrE/TyJ6u6TMpORfDCcnlX0EQV3nIGSPqLG7LJkxcYZRsJ0tw0WR05+miU/dDTBtq7yMjS38PfJaQ6ZWjfJN78UP4iyIUgYjOjVon/mXKaQcWAiLXlwwKbSyexxPZr5X8ymn/+hIdIv+7mO/+VoZulJeV3tIkdmTtBwsfjK/zeeuGLoZEyg7f8R1wprKQP4OUgOYraXDGhRXOFTHC9i1x72pgP6izC0Yx+ZdNOV5iPiK1SNKBUdE9FqOunrCekTd+8Z/pMtCJbpsSXdjgNw70o0wPBz2yu+c1bvxu8uG2WyPKLBSDe1wMaFOQj6+rIv6fB0tdVaymeOfvx4ZTgt7EMKXPTTSVhy918BEy6kZ9slDuG5RyTuG3Uh0V0agMnB8gR3+EXOZPLkEapHPQtPVknG/Y8gwj2KmDESA0zGIzJYZc/TZIdAGQnBw4GiCRyKpxDZxRQbozkTpKfxJ+8dDMyb6tw9cXPof+c3Li4f+g3/e9XgUlwLSiN0LPtMaCKVNLTpc0Warx+erw2/87kJNfcU9GUGECQshy5DCWqpkJG9Z6n5Z7lNR3ewDqXXTdSf1U6bD3pi9X550zt9XHKijjB9mzkEllOaEEP1LltOoVZ2YPEG5CBHxqlCIc48XIJVXIK68KlZV7x+XHUsfhjx8fNjy5fXQ+YAs2F5WgTeF4WnL6tFy+MCy3oP1TtNaVb8HcRqaeLuAO0GrOVpnjpUekSoro7bEofIi/+VXUlo6FdAgsRMXeoMYcfSEAOGnb0DQkbUm473oI/8rcMDYzwQCqVaiHWhTuCGu/lHeJQRZJ6kwaCfRj3SmmWJ1Ygc5/T9bXuv5XDBxrXumKOtq0N+uzh4UPu7BPRoUZIDZqxKaqSzp45U2rTUQ/MhL+qI7rGnztMV+7nbhdLERplcv Aqr3LHTb wbyqtP3T6wPPdWA486dmcwakXuwPxcIPLRpvHLCdn57J/d4rBUTgtPaiVOEDa1VLdZ0aH540vq8QE0mPLjLA3MJ5UEQ27WtmRChGKUOOPuxPQW2OXzFCnTKmDU4P/eIeiNoR54+2B4QhAamRX5qG8fnCzdcPBlNWfFcQtwt4YA07GoEijiOnVKgE+c2KmhmB5zKNv32qqA3z90ICX2jfdFispv4CMAi2oK9xtI9BDkrk0LieFR+CmMFPPwj4Z9zt4lQTJxDe4dPlh7wPke5aF+QQVwcUSKnOjBpLa 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: Hi Pankaj, I can reproduce the problem with: xfs_io -t -f -c "pwrite -S 0x58 0 40" -c "fsync" -c "truncate 4" -c "trunc= ate 4096" /xfstest.test/wubble; od -x /xfstest.test/wubble borrowed from generic/393. I've distilled it down to the attached C progr= am. 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=3D9e s=3D0 l=3D28 f=3D0 pankaj-5833: netfs_folio: pfn=3D116fec i=3D0009e ix=3D00000-00001 mod-str= eamw Then first ftruncate() is called to reduce the file size to 4: pankaj-5833: netfs_truncate: ni=3D9e isz=3D2028 rsz=3D2028 zp=3D4000 to=3D= 4 pankaj-5833: netfs_inval_folio: pfn=3D116fec i=3D0009e ix=3D00000-00001 o= =3D4 l=3D1ffc d=3D78787878 pankaj-5833: netfs_folio: pfn=3D116fec i=3D0009e ix=3D00000-00001 inval-p= art pankaj-5833: netfs_set_size: ni=3D9e resize-file isz=3D4 rsz=3D4 zp=3D4 You can see the invalidate_folio call, with the offset at 0x4 an the lengt= h 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=3D9e isz=3D4 rsz=3D4 zp=3D4 to=3D1000 pankaj-5833: netfs_inval_folio: pfn=3D116fec i=3D0009e ix=3D00000-00001 o= =3D1000 l=3D1000 d=3D78787878 pankaj-5833: netfs_folio: pfn=3D116fec i=3D0009e ix=3D00000-00001 inval-p= art pankaj-5833: netfs_set_size: ni=3D9e resize-file isz=3D1000 rsz=3D1000 zp= =3D4 And here's the problem: in the invalidate_folio() call, the offset is 0x10= 00 and the length is 0x1000 (o=3D and l=3D). But that's the wrong half of th= e 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) =3D=3D -1) { perror(y); exit(1); } } = while(0) static const char xxx[40] =3D "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"; static const char yyy[40] =3D "yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy"; static const char dropfile[] =3D "/proc/sys/vm/drop_caches"; static const char droptype[] =3D "3"; static const char file[] =3D "/xfstest.test/wubble"; int main(int argc, char *argv[]) { int fd, drop; /* Fill in the second 8K block of the file... */ fd =3D 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 =3D open(dropfile, O_WRONLY); ERR(drop, dropfile); ERR(write(drop, droptype, sizeof(droptype) - 1), "write-drop"); ERR(close(drop), "close-drop"); fd =3D 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); }