From patchwork Fri Feb 9 14:29:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Gomez X-Patchwork-Id: 13551418 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 611E8C48297 for ; Fri, 9 Feb 2024 14:29:30 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3BA1A6B0095; Fri, 9 Feb 2024 09:29:13 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 266636B009B; Fri, 9 Feb 2024 09:29:13 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AC74C6B0088; Fri, 9 Feb 2024 09:29:12 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 66C5E6B0088 for ; Fri, 9 Feb 2024 09:29:12 -0500 (EST) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 3FB5F141067 for ; Fri, 9 Feb 2024 14:29:12 +0000 (UTC) X-FDA: 81772497744.26.A99A221 Received: from mailout1.w1.samsung.com (mailout1.w1.samsung.com [210.118.77.11]) by imf14.hostedemail.com (Postfix) with ESMTP id 4B59D100009 for ; Fri, 9 Feb 2024 14:29:09 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=samsung.com header.s=mail20170921 header.b=RBme5bg9; spf=pass (imf14.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=1707488949; 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=2ukBs3XODipZcH9UMRwa+Bu+eJvhDnac4gizoogX/Is=; b=meISIpNjkVpLB/2tgKnc6uJkEgInHcwFDX12dBo3ZDiLhcCe+zONNoMxCyWjmkS6f1fGKw OECGEU66cxWrsLj2g8MmPGb5hdDGL3IK2uWZ2B8aSIuCW0H1SArKuoDu+X1FuuGnRdI9uI 9epXnx+7lEUwhg3P/5dMpNfo565gPtQ= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=samsung.com header.s=mail20170921 header.b=RBme5bg9; spf=pass (imf14.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=1707488949; a=rsa-sha256; cv=none; b=TOpp+Lhkv9R+pFmEPLs6Vkm8RRCXJxl0up28KUZS7R4w7eqWCuaoyUGif70dYF4TtkZxSC KHxJS9mEmDWzBYHMUg6MmmcMwvCGs6nuouX9v3HMS1T5K1yPqe/lI4sBhLlHfU3wnBooGf qMP9Xgcx10P4RpPNF5Cnv5wh42TYn1Y= Received: from eucas1p1.samsung.com (unknown [182.198.249.206]) by mailout1.w1.samsung.com (KnoxPortal) with ESMTP id 20240209142907euoutp0108a05b6566327b5c13de939de64974e4~yOCa8cBI72778527785euoutp01g for ; Fri, 9 Feb 2024 14:29:07 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.w1.samsung.com 20240209142907euoutp0108a05b6566327b5c13de939de64974e4~yOCa8cBI72778527785euoutp01g DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1707488947; bh=2ukBs3XODipZcH9UMRwa+Bu+eJvhDnac4gizoogX/Is=; h=From:To:CC:Subject:Date:In-Reply-To:References:From; b=RBme5bg9CdOVU1oMxV4Ybb5Xo1Nj93LPn/TZtYuGuDM8JoXqabMx1IU3QdKo7ub71 br84AeHS1lrt3ijAYBC6HuMLYGxyp0VVNLhcqZ+bvQl9HOZFq7OxWRJ+FKG5t7UoD+ ozfa6KR1lEkjdqiPt4HA+LzBQOIeV3uqHiwc+BsA= Received: from eusmges3new.samsung.com (unknown [203.254.199.245]) by eucas1p2.samsung.com (KnoxPortal) with ESMTP id 20240209142907eucas1p22dc004862a93d76c2817fc28c5432e48~yOCapm-8m0060200602eucas1p2G; Fri, 9 Feb 2024 14:29:07 +0000 (GMT) Received: from eucas1p1.samsung.com ( [182.198.249.206]) by eusmges3new.samsung.com (EUCPMTA) with SMTP id 9D.2E.09552.3B636C56; Fri, 9 Feb 2024 14:29:07 +0000 (GMT) Received: from eusmtrp1.samsung.com (unknown [182.198.249.138]) by eucas1p2.samsung.com (KnoxPortal) with ESMTPA id 20240209142907eucas1p2024d2809a150c6e58082de0937596290~yOCaQYIdi0486804868eucas1p2E; Fri, 9 Feb 2024 14:29:07 +0000 (GMT) Received: from eusmgms2.samsung.com (unknown [182.198.249.180]) by eusmtrp1.samsung.com (KnoxPortal) with ESMTP id 20240209142906eusmtrp1ee69ff838c2b80b9dc3c11119a3a418b~yOCaPfpUX0528405284eusmtrp1C; Fri, 9 Feb 2024 14:29:06 +0000 (GMT) X-AuditID: cbfec7f5-0bd9da8000002550-a1-65c636b3a878 Received: from eusmtip2.samsung.com ( [203.254.199.222]) by eusmgms2.samsung.com (EUCPMTA) with SMTP id 04.B3.10702.2B636C56; Fri, 9 Feb 2024 14:29:06 +0000 (GMT) Received: from CAMSVWEXC01.scsc.local (unknown [106.1.227.71]) by eusmtip2.samsung.com (KnoxPortal) with ESMTPA id 20240209142906eusmtip2e2024a73a312042137f498874cbdbfe6~yOCaHDNtj0196001960eusmtip2P; Fri, 9 Feb 2024 14:29:06 +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; Fri, 9 Feb 2024 14:29:06 +0000 Received: from CAMSVWEXC02.scsc.local ([::1]) by CAMSVWEXC02.scsc.local ([fe80::3c08:6c51:fa0a:6384%13]) with mapi id 15.00.1497.012; Fri, 9 Feb 2024 14:29:06 +0000 From: Daniel Gomez To: "viro@zeniv.linux.org.uk" , "brauner@kernel.org" , "jack@suse.cz" , "hughd@google.com" , "akpm@linux-foundation.org" CC: "dagmcr@gmail.com" , "linux-fsdevel@vger.kernel.org" , "linux-kernel@vger.kernel.org" , "linux-mm@kvack.org" , "willy@infradead.org" , "hch@infradead.org" , "mcgrof@kernel.org" , Pankaj Raghav , "gost.dev@samsung.com" , "Daniel Gomez" Subject: [RFC PATCH 7/9] shmem: check if a block is uptodate before splice into pipe Thread-Topic: [RFC PATCH 7/9] shmem: check if a block is uptodate before splice into pipe Thread-Index: AQHaW2RVHDRO8t3PIUKSo0ZMZU2cLg== Date: Fri, 9 Feb 2024 14:29:04 +0000 Message-ID: <20240209142901.126894-8-da.gomez@samsung.com> In-Reply-To: <20240209142901.126894-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.110.32.67] MIME-Version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFjrHKsWRmVeSWpSXmKPExsWy7djPc7qbzY6lGhzsEbeYs34Nm8Xrw58Y Lc72/WazOD1hEZPF0099LBazpzczWezZe5LF4vKuOWwW99b8Z7W4MeEpo8X5v8dZLX7/mMPm wOOxc9Zddo8Fm0o9Nq/Q8ti0qpPNY9OnSeweJ2b8ZvE4s+AIu8fnTXIem568ZQrgjOKySU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7ei8s5YjdIu1b ZDsxXHvJjXU3CounL41h5OsTfW7yu7htIpMSS3FGoqEWc1FxIgA4VgMl3gMAAA== X-CMS-MailID: 20240209142907eucas1p2024d2809a150c6e58082de0937596290 X-Msg-Generator: CA X-RootMTR: 20240209142907eucas1p2024d2809a150c6e58082de0937596290 X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20240209142907eucas1p2024d2809a150c6e58082de0937596290 References: <20240209142901.126894-1-da.gomez@samsung.com> X-Rspamd-Queue-Id: 4B59D100009 X-Rspam-User: X-Stat-Signature: xqnmdero9quaaxjn9sfbxxwtahqc16b9 X-Rspamd-Server: rspam01 X-HE-Tag: 1707488949-172804 X-HE-Meta: U2FsdGVkX1+7PKL5XvDMqIDbyZnlatE8n+dQr/O2Eiuo6CJLLM+ykgx4P5vqdJ46Gj7vcBkz597VdksRpbrrvqebmjU8A7psHHBdX7kdK5P5XvCpBvYhcvdRsbow4AjXN3X8GZcUaCpr4ntf19I71EwUIePsYk29+MTzl/OZ82jDPWYApDrI9WgGph9ZZTVoL9iGnjyKgwa0JklZQWaJrsWeegGcBZhqMr7qbA5H6cIClEYldMYR5ymh/YadyGodDutTb/ScmQyEJO/Q3IiJNOnFIN9UPaM34rAM2zzqai2FfK+4hQMm+Tu4Ya9HJ34Uam5qiPfBvBLI56pd+60arbqBIKvdh/S3ZWw3HUkRxTuB3Bkldwfj+GaZ8wioHf29myVV0URopjyTe3Q76UaF5twl4HubvIIvX/dPqKsEO9mHQbCeMMNSoPv3tz2gf5KUzxKjgkolpkFMrAcYnBLumNYecxqaRdJ489Vru2XGrEXMfYl9Pk2FgQ5AWj2Tqm8OkKwOHiCJv2N4y8uFJyQJiJy8fMooaQsLEWhD/qwnBe2F3eLiDSI+2ME3rmnLMnTYofMluSSJ+KpyDl3su41RaxO9BCJeHX6/8FcKPmy+cSLqFepU/RNDtpYztJ0XdZI/XI75HJWsWUqKbHnRPX0eQlRWWeLQs59S2ST2S39YmqbWaz47mf/tpbz4QrxjTOZhBM/fzEgJtpd1eXSLTPC4TavKqhcVKfF7lpDP2JciJ4ShV2DhYuysl2P1MljvmIWO2KzdovjQuzKUWAldxLu+uAgIQQLaYPB0eie48zi6aRZEeRFFblOT8nIY7NfmIlvCUrJsNRwlfv2hQM5Fwle/fR2Txhb2lXw2yrAF4IihIRIOD8dgE2wDwacsEaIYoBmyJ9TnfbOEKdQp2i68XPrdgAvzuXlQ4EFYwy84ui2CSa6AVoqqBq+AsTGIZKHYcXdoOlOcYk1A/2njljat2Yk SzWABNba hgrGSDEtD6u6V+bzF7IJjpjpzVZLAhbLlWXPhjfWdg7dPpKYH3y406n0Kwu3MH4RZhdKRVcNPNSBkflentRUx6nuYpTjdubQDpJMQV2h4fsHJYS2NbV3Lg1mAycqapWtWE+FEG1qRd2iz6ephGv85nuAhHHYM+UG9eVJr 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 9fa86cb82da9..2d2eeb40f19b 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -3196,8 +3196,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