From patchwork Wed May 15 05:57:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Gomez X-Patchwork-Id: 13664604 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 03361C25B75 for ; Wed, 15 May 2024 05:57:47 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A976C6B03D2; Wed, 15 May 2024 01:57:38 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9E7016B03D3; Wed, 15 May 2024 01:57:38 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7ED286B03D5; Wed, 15 May 2024 01:57:38 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 583C06B03D2 for ; Wed, 15 May 2024 01:57:38 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id D1B03A1454 for ; Wed, 15 May 2024 05:57:37 +0000 (UTC) X-FDA: 82119573354.19.E7A9226 Received: from mailout1.w1.samsung.com (mailout1.w1.samsung.com [210.118.77.11]) by imf18.hostedemail.com (Postfix) with ESMTP id DF47D1C0006 for ; Wed, 15 May 2024 05:57:34 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=samsung.com header.s=mail20170921 header.b=ZkVfT9z6; spf=pass (imf18.hostedemail.com: domain of da.gomez@samsung.com designates 210.118.77.11 as permitted sender) smtp.mailfrom=da.gomez@samsung.com; dmarc=pass (policy=none) header.from=samsung.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1715752655; a=rsa-sha256; cv=none; b=laFGrHOMKvWJuG/4prr0zzcJF8mpAfQa2NnLFhFo29xRnWXhj5hoG5dG0BNvZwOeW1zPa3 xS8yJ4S9xUfAAnOdJkf8QlguppT9XqH/wrA0QfS4Sa47EHWuFKUpfa3dch245v2Q26OHxE wHAk7kp5kZUMC3X+0dP6Rq9//Ihs460= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=samsung.com header.s=mail20170921 header.b=ZkVfT9z6; spf=pass (imf18.hostedemail.com: domain of da.gomez@samsung.com designates 210.118.77.11 as permitted sender) smtp.mailfrom=da.gomez@samsung.com; dmarc=pass (policy=none) header.from=samsung.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1715752655; 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=ISz7TrEyCDZh2RGvxSi8e/BBnML+fSScyaJx5o0KWiw=; b=ynZKXhhQK/1EIk9j7Jq+ZZcBfzWj7xpSh9mI9wo8VaT2lZjjvGAUuHmawVoO4Um71DTrs5 rJ3asRdmMPjG1Qs3V6nSWh3TamMZsXIW+jHqCIsX/UNnLSu2njtQuxAMrm06okYGeXKhrG fjKd+ndsqXKFrebxUV0xc0sDyXpMKYE= Received: from eucas1p2.samsung.com (unknown [182.198.249.207]) by mailout1.w1.samsung.com (KnoxPortal) with ESMTP id 20240515055733euoutp0175a9966755f1eee06cdfde38ae415848~Pk-KyaDB11504315043euoutp01b for ; Wed, 15 May 2024 05:57:33 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.w1.samsung.com 20240515055733euoutp0175a9966755f1eee06cdfde38ae415848~Pk-KyaDB11504315043euoutp01b DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1715752653; bh=ISz7TrEyCDZh2RGvxSi8e/BBnML+fSScyaJx5o0KWiw=; h=From:To:CC:Subject:Date:In-Reply-To:References:From; b=ZkVfT9z6ael406ECJDYHpyFlabEiCh8WUVcXIkkarczOEAsRGOJCKZL52AYr75W6T uoj03w0wf1/00ChFsPCnXmqb7wvsMWWgvMFpdaaBd+9vwh88jAYGaGo5zdxGfDZvGq n4cOnWbLkoEb2Sax5KhYhWp7GXyMvKEyzmEpNi9A= Received: from eusmges2new.samsung.com (unknown [203.254.199.244]) by eucas1p2.samsung.com (KnoxPortal) with ESMTP id 20240515055733eucas1p2d44dc66c51ebcdde1ad1cb3160016f11~Pk-Kf7b9q1079110791eucas1p2e; Wed, 15 May 2024 05:57:33 +0000 (GMT) Received: from eucas1p1.samsung.com ( [182.198.249.206]) by eusmges2new.samsung.com (EUCPMTA) with SMTP id 35.D8.09875.DCE44466; Wed, 15 May 2024 06:57:33 +0100 (BST) Received: from eusmtrp1.samsung.com (unknown [182.198.249.138]) by eucas1p2.samsung.com (KnoxPortal) with ESMTPA id 20240515055732eucas1p2302bbca4d60e2e811a5c59e34f83628d~Pk-JgremL1114511145eucas1p29; Wed, 15 May 2024 05:57:32 +0000 (GMT) Received: from eusmgms2.samsung.com (unknown [182.198.249.180]) by eusmtrp1.samsung.com (KnoxPortal) with ESMTP id 20240515055732eusmtrp1649bb55890ac4fc12b6b8f6506fb74b2~Pk-JfzHi20390703907eusmtrp1_; Wed, 15 May 2024 05:57:32 +0000 (GMT) X-AuditID: cbfec7f4-11bff70000002693-e9-66444ecdd352 Received: from eusmtip2.samsung.com ( [203.254.199.222]) by eusmgms2.samsung.com (EUCPMTA) with SMTP id DA.F1.09010.CCE44466; Wed, 15 May 2024 06:57:32 +0100 (BST) Received: from CAMSVWEXC01.scsc.local (unknown [106.1.227.71]) by eusmtip2.samsung.com (KnoxPortal) with ESMTPA id 20240515055732eusmtip20173b018d0674b7f27dab1c2ee4741f8~Pk-JRqiWL1596015960eusmtip2O; Wed, 15 May 2024 05:57:32 +0000 (GMT) Received: from CAMSVWEXC02.scsc.local (2002:6a01:e348::6a01:e348) by CAMSVWEXC01.scsc.local (2002:6a01:e347::6a01:e347) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Wed, 15 May 2024 06:57:31 +0100 Received: from CAMSVWEXC02.scsc.local ([::1]) by CAMSVWEXC02.scsc.local ([fe80::3c08:6c51:fa0a:6384%13]) with mapi id 15.00.1497.012; Wed, 15 May 2024 06:57:31 +0100 From: Daniel Gomez To: "hughd@google.com" , "akpm@linux-foundation.org" , "willy@infradead.org" , "jack@suse.cz" , "mcgrof@kernel.org" CC: "linux-mm@kvack.org" , "linux-xfs@vger.kernel.org" , "djwong@kernel.org" , "Pankaj Raghav" , "dagmcr@gmail.com" , "yosryahmed@google.com" , "baolin.wang@linux.alibaba.com" , "ritesh.list@gmail.com" , "lsf-pc@lists.linux-foundation.org" , "david@redhat.com" , "chandan.babu@oracle.com" , "linux-kernel@vger.kernel.org" , "brauner@kernel.org" , Daniel Gomez Subject: [PATCH 07/12] shmem: check if a block is uptodate before splice into pipe Thread-Topic: [PATCH 07/12] shmem: check if a block is uptodate before splice into pipe Thread-Index: AQHapozGTHnkaf4XgkaJL36kMuhxtQ== Date: Wed, 15 May 2024 05:57:31 +0000 Message-ID: <20240515055719.32577-8-da.gomez@samsung.com> In-Reply-To: <20240515055719.32577-1-da.gomez@samsung.com> Accept-Language: en-US, en-GB Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-messagesentrepresentingtype: 1 x-ms-exchange-transport-fromentityheader: Hosted x-originating-ip: [106.210.248.161] MIME-Version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrEKsWRmVeSWpSXmKPExsWy7djPc7pn/VzSDCavFLCYs34Nm8X/vccY LV4f/sRocemonMXZvt9sFl/X/2K2uPyEz+Lppz4Wi9nTm5ksLu+aw2Zxb81/Votdf3awW+x7 vZfZ4saEp4wWB091sFv8/gGU3b4r0kHQY+esu+weCzaVem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ck/PDVOtHHp/ztvfwgvSpkWZWOR/lQwYTJf3IbHHJZetnu4 Fzz4JTd59TYWC0XBRdeXs6guu/3e+DrLAtmLmku9vhxR6/pUNWv7z23K97YE/y/SN2t67v5P M7r3h27eT0aj2IWvlFiKMxINtZiLihMBeBCgoAEEAAA= X-CMS-MailID: 20240515055732eucas1p2302bbca4d60e2e811a5c59e34f83628d X-Msg-Generator: CA X-RootMTR: 20240515055732eucas1p2302bbca4d60e2e811a5c59e34f83628d X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20240515055732eucas1p2302bbca4d60e2e811a5c59e34f83628d References: <20240515055719.32577-1-da.gomez@samsung.com> X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: DF47D1C0006 X-Stat-Signature: i11o85cg5ejpbqji1q3hyqjd6f3mzp85 X-HE-Tag: 1715752654-523783 X-HE-Meta: U2FsdGVkX1+xXRxN+UTjFv2jzHITfSmvxbo5QIj1A0oRiTslyd5oQCGoqpkY99t5sagMv/bUmEF/7X6qxrfw5Zg+I/BMn17BhPVdQc01sKUKqBfF2JvRPEhL8vQZr9GtHevhH+cm0LefVOsBHMnTKnj1dK5RGnYxyN5FvYpXGoA+y9H7AzTI+flCycTfKhn+8CCrO7WhPsWAMqJcuJ+RMm0jHwxreoImHbd/mZwoYxWdthFmuAacAXcox5X2cz6TV4tdHOphIHfPZ6ze0MQg5zyr6JO8wQN8e04EObuVJUsM88uA8GzFpG/hmUtYECCTCKbkAWCj1ty88NP3KgctbS+N5Ou6TuyA7KEdoGtH+3TASCLnbnB8IyX+8wPin97BCdE2nMNrNH4aruHOCY1ZQS535U20bb47lr1vnifs0vIcY0w4UJ+22hgaDECPThhoFyv51zriokCr9udZAg5MA8fWOe8KSae4GNe2qYceRdmXPlr4rj8er8DHCH9lbcQoAwr8IqMmjB4HEJmn2dWN9cz1uOJSa3RNr5GCx57Nt7DJeJU+Eq+MmjhhJI7BV0rRQ39bzt6PPEOs69dg8ysm7LDotel36S1hkeoM5JAbese8W1Chn4CkFPGjVMS+lyyzBheI16vThpoHU7CY+O0E+UbAnIes5nXug3hFruyGTZft1EyBzR5PoOXSuGadgw7SqsTirfBouDTU93jJpH5AkFoMfSEvm6s7exPILEcOPKSojNMyvEHMTu4dOzR9LcaHBehsC6y3YFjLBW/hf3r9ZBhhtr3al6el2RSnlfxsb3MgC/Bl8WvAM6Z1PKes4seVLJoqPi4uD0pnMaRqsbwv3cwcc+01rNHv+lce3Ek2ejfBLZBxCcP5z/KO2wHnjTI+Tf9SUy88GA9A/r9mOaYhs9VU2ygavqmsosAlCJvH/BCLVvVjHGYwfZY6VeV286Rb2I8rGFNuUGBTMw4iZ9b ltPnNuuS w6ztOF5zXXO3Bn1MiIqCWP1RauvIWgS9S5M6bZAvzF+YSOboI8S6FyYPx8IWd78vOdQg1C4wvIazIpGjwlzuJof7eCe66uezX58TCNwG8gbhJ3IjlJH+ZwzsbG6HQBUR/+y4foxan0vfgEHq+EMFbJc/kj3+qB6Zl0BOTr+O5biDcaHgM+C4r36wNMZ2fQm9i/7kS9yuQ0AJm6tAVulXipTQNLwPrgjy6o9Xzu248Ry1dmkQ= 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: The splice_read() path assumes folios are always uptodate. Make sure all blocks in the given range are uptodate or else, splice zeropage into the pipe. Maximize the number of blocks that can be spliced into pipe at once by increasing the 'part' to the latest uptodate block found. Signed-off-by: Daniel Gomez --- mm/shmem.c | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/mm/shmem.c b/mm/shmem.c index 68fe769d91b1..e06cb6438ef8 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -3223,8 +3223,30 @@ static ssize_t shmem_file_splice_read(struct file *in, loff_t *ppos, if (unlikely(*ppos >= isize)) break; part = min_t(loff_t, isize - *ppos, len); + if (folio && folio_test_large(folio) && + folio_test_private(folio)) { + unsigned long from = offset_in_folio(folio, *ppos); + unsigned int bfirst = from >> inode->i_blkbits; + unsigned int blast, blast_upd; + + len = min(folio_size(folio) - from, len); + blast = (from + len - 1) >> inode->i_blkbits; + + blast_upd = sfs_get_last_block_uptodate(folio, bfirst, + blast); + if (blast_upd <= blast) { + unsigned int bsize = 1 << inode->i_blkbits; + unsigned int blks = blast_upd - bfirst + 1; + unsigned int bbytes = blks << inode->i_blkbits; + unsigned int boff = (*ppos % bsize); + + part = min_t(loff_t, bbytes - boff, len); + } + } - if (folio) { + if (folio && shmem_is_block_uptodate( + folio, offset_in_folio(folio, *ppos) >> + inode->i_blkbits)) { /* * If users can be writing to this page using arbitrary * virtual addresses, take care about potential aliasing