From patchwork Wed May 15 05:57:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Gomez X-Patchwork-Id: 13664621 Received: from mailout2.w1.samsung.com (mailout2.w1.samsung.com [210.118.77.12]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 419233A1DC for ; Wed, 15 May 2024 05:57:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=210.118.77.12 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715752650; cv=none; b=dQ5FkigzD+P35rYUQCAELKUEsyaS67/3Jak+gL+xStx9+oUH9DiCv8B4cO4E2wuQDu2b+1chw2hOf0grjKWxNTsU7unVRWydL6Sh/KgG9J0pGODFPhQvwNd8UVhg/Di+BN4G2+2AnxKt1N+ux+LEGLBgp8ij+tX71FF96AE70jI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715752650; c=relaxed/simple; bh=RH5M2Ft1yieIKx+BOHBf4ZaFqhptJPv2A+bAcQFaiHQ=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:Content-Type: MIME-Version:References; b=RXPSOhJDw+9UyhhTYoZjCWn4jn7eFb5gffYW2/zn7mH7uqp3kzPkHCXw1KJBDpCsGdKtOwV8l3q0e7Y6zAF8B4cz6JxZP6J4OWCrVcgpicZePgivC8V7lKHd1Qd4HTV1ahNzQNziyx2bP7r8V5s+6kRnv2KPgrpJPaF+A7gRgpo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=samsung.com; spf=pass smtp.mailfrom=samsung.com; dkim=pass (1024-bit key) header.d=samsung.com header.i=@samsung.com header.b=ngyRgTVK; arc=none smtp.client-ip=210.118.77.12 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=samsung.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=samsung.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=samsung.com header.i=@samsung.com header.b="ngyRgTVK" Received: from eucas1p2.samsung.com (unknown [182.198.249.207]) by mailout2.w1.samsung.com (KnoxPortal) with ESMTP id 20240515055726euoutp021e499958ffdd8c97e79237574b9aeccf~Pk-EUSUOw1334513345euoutp02K for ; Wed, 15 May 2024 05:57:26 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.w1.samsung.com 20240515055726euoutp021e499958ffdd8c97e79237574b9aeccf~Pk-EUSUOw1334513345euoutp02K DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1715752646; bh=dTnZOoNYjEenQBIjBgvJcx5/I/6R08XCA2XZxGoD7mw=; h=From:To:CC:Subject:Date:In-Reply-To:References:From; b=ngyRgTVKgIg06q8/vI0Fid46l37RPLZvHru4oqaGh/1vminFbwPmV86npg8rgwWAv RriHtUBW0RpYX6BP2vGsF19pKZsDEiYTWJ8lgrtshZXCeTRBWlb/vdteRyeGKLRgvs m5ZiVX3BQToI7JU8pA0udsY+xeX3WVGdCT7J97kk= Received: from eusmges1new.samsung.com (unknown [203.254.199.242]) by eucas1p1.samsung.com (KnoxPortal) with ESMTP id 20240515055724eucas1p14abe531cee8b71732d5f48dbf9cc26e6~Pk-CeXLbu2872228722eucas1p1Y; Wed, 15 May 2024 05:57:24 +0000 (GMT) Received: from eucas1p1.samsung.com ( [182.198.249.206]) by eusmges1new.samsung.com (EUCPMTA) with SMTP id 75.BC.09624.4CE44466; Wed, 15 May 2024 06:57:24 +0100 (BST) Received: from eusmtrp1.samsung.com (unknown [182.198.249.138]) by eucas1p1.samsung.com (KnoxPortal) with ESMTPA id 20240515055724eucas1p1c502dbded4dc6ff929c7aff570de80c2~Pk-B985K61859218592eucas1p1C; Wed, 15 May 2024 05:57:24 +0000 (GMT) Received: from eusmgms1.samsung.com (unknown [182.198.249.179]) by eusmtrp1.samsung.com (KnoxPortal) with ESMTP id 20240515055724eusmtrp1eef596575f6b6795be5c3de034b524d3~Pk-B9Q91t0390703907eusmtrp1o; Wed, 15 May 2024 05:57:24 +0000 (GMT) X-AuditID: cbfec7f2-bfbff70000002598-44-66444ec46294 Received: from eusmtip1.samsung.com ( [203.254.199.221]) by eusmgms1.samsung.com (EUCPMTA) with SMTP id E9.16.08810.4CE44466; Wed, 15 May 2024 06:57:24 +0100 (BST) Received: from CAMSVWEXC02.scsc.local (unknown [106.1.227.72]) by eusmtip1.samsung.com (KnoxPortal) with ESMTPA id 20240515055723eusmtip1edc9607f2a5ec529c7552cf4a0766878~Pk-Bw0UHM0235902359eusmtip1Q; Wed, 15 May 2024 05:57:23 +0000 (GMT) Received: from CAMSVWEXC02.scsc.local (2002:6a01:e348::6a01:e348) by CAMSVWEXC02.scsc.local (2002:6a01:e348::6a01:e348) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Wed, 15 May 2024 06:57:23 +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:23 +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 01/12] splice: don't check for uptodate if partially uptodate is impl Thread-Topic: [PATCH 01/12] splice: don't check for uptodate if partially uptodate is impl Thread-Index: AQHapozBbWbHWLdhTE2QsNHTwXO1jw== Date: Wed, 15 May 2024 05:57:23 +0000 Message-ID: <20240515055719.32577-2-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 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAA02SfUxTZxTGfe+9vfdS1nmp3XgDQ0wNfwha1JntRYm6TJObaSYmJsavaCMX JAOUWytM50JkIasiY3VDbZkFKxQKhtiCQIUqDEE+NESmI4AkLO0yymJLEfzoFWZ7ceG/35Pz nPOckxwal7+QRNEZ2Sc5PludqSSlxO2u14/WdH69LW3t8MuVqKy+jkTzbV0ATf7uB+jx/eXo YXGARDP1b3A06PoQuf3FBDJeLsDQoKOMRGN18xLkEJop5Jxsw9FQiRug9t4fKRR49a7a5Ni3 NYJtMTyj2HKblrVXx7M2q45kbX49xT64EiDYlvEk9tKQBbBT7mGC9TqfkGx/eSfFTtuWp3yw X5qcymVmnOL4xM1HpMf6TBXYiaeyvEaDlcgHI9LzIIyGzAZonJigzgMpLWeqAbzYdYUUxQsA C2vnMVFMA3jj70r8fUvA5wViwQKgebQB/99lLnu1MKwfQNMjHyGKGgA9/1aF+klmFXT22EIu BTMCoLu3PyRwpkcCBXsLEXQtY/ZCvfAPFmQFcxCW1tbhIqvgjZtuSZAJJg56Al4qyDImCfqa PCFPGLMRPjPNkEEGTAz8q+ZNyIMzkXDYZcLEKyLgdWPrwkUfwznHOCnyavjwTxcQeS1srHQS Iq+E9c8LMXGOCg79+gspcgKsqpjExR0iYM9VV+hkyLRL4c/FryVi8zb4eGRiIWwZ9HQ3UCJ/ AvsuFRElIMGwaD/DogzDogzDooxyQFhBJKfVZKVzmnXZX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CAucevJfCaIHwQkluw5zwxhi0q8fPwP6jcdibPXnzBC2AYSW5fuY4GwlSXW v2tjgpijJ3Fj6hQ2CFtbYtnC18wQ9whKnJz5hGUCo/QsJOtmIWmZhaRlFpKWBYwsqxhFUkuL c9Nziw31ihNzi0vz0vWS83M3MQIT3rZjPzfvYJz36qPeIUYmDsZDjBIczEoivCJpzmlCvCmJ lVWpRfnxRaU5qcWHGE2BYTSRWUo0OR+YcvNK4g3NDEwNTcwsDUwtzYyVxHk9CzoShQTSE0tS s1NTC1KLYPqYODilGpg2yrb7cwj5fbGbxGB7J6p2gv4kXYPW1xlqJ7769l2PluSbqXrhRdVV 93UlZ1LU9h15sLGWK3B+tW3vncdNCxbuunfjjscP46fZ2i/4FxgeOG+2bPtseQHBV0Ec0v5K bvInslnC9j3IyFzbUC9gkH5zvvgTFvevN+vunJst8NxW3/9Qe9q0Ay0rv+ls+nixePI9h9s3 H1042bX/HPcUwbbbRiUexxbaMO0NO33shYj661K5T1zCPGV3tSqbdL4btf61t/Jf2rfBP/+4 juT8nx8yAhmZCiYIbTn4fvvWZuZVidK5zhsiHdZOmjh50hcH0a2pWTsMUj+9S04pXLHJPbD2 zq6ftQYnjf0Ft0+/fSxNiaU4I9FQi7moOBEAoCBM4wEEAAA= X-CMS-MailID: 20240515055724eucas1p1c502dbded4dc6ff929c7aff570de80c2 X-Msg-Generator: CA X-RootMTR: 20240515055724eucas1p1c502dbded4dc6ff929c7aff570de80c2 X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20240515055724eucas1p1c502dbded4dc6ff929c7aff570de80c2 References: <20240515055719.32577-1-da.gomez@samsung.com> From: Pankaj Raghav When a large folio is alloced, splice will zero out the whole folio even if only a small part of it is written, and it updates the uptodate flag of the folio. Once the per-block uptodate tracking is implemented for tmpfs, pipe_buf_confirm() only needs to check the range it needs to splice to be uptodate and not the whole folio as we don't set uptodate flag for partial writes. Signed-off-by: Pankaj Raghav Signed-off-by: Daniel Gomez --- fs/splice.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/fs/splice.c b/fs/splice.c index 218e24b1ac40..e6ac57795590 100644 --- a/fs/splice.c +++ b/fs/splice.c @@ -120,7 +120,9 @@ static int page_cache_pipe_buf_confirm(struct pipe_inode_info *pipe, struct pipe_buffer *buf) { struct folio *folio = page_folio(buf->page); + const struct address_space_operations *ops; int err; + off_t off = folio_page_idx(folio, buf->page) * PAGE_SIZE + buf->offset; if (!folio_test_uptodate(folio)) { folio_lock(folio); @@ -134,12 +136,21 @@ static int page_cache_pipe_buf_confirm(struct pipe_inode_info *pipe, goto error; } + ops = folio->mapping->a_ops; /* * Uh oh, read-error from disk. */ - if (!folio_test_uptodate(folio)) { - err = -EIO; - goto error; + if (!ops->is_partially_uptodate) { + if (!folio_test_uptodate(folio)) { + err = -EIO; + goto error; + } + } else { + if (!ops->is_partially_uptodate(folio, off, + buf->len)) { + err = -EIO; + goto error; + } } /* Folio is ok after all, we are done */ From patchwork Wed May 15 05:57:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Gomez X-Patchwork-Id: 13664622 Received: from mailout2.w1.samsung.com (mailout2.w1.samsung.com [210.118.77.12]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0DE363987D for ; Wed, 15 May 2024 05:57:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=210.118.77.12 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715752652; cv=none; b=qdeBbOkXvAlC6nlfSEi21/g9557bCiqM/7LbkRc3vVaAaosY4E5C+y5r2LX1WiQ9cZPNu7mZx14iwq2Y40cOtfhl+CHlmC3A5wSHec0fIQEdZr5aznNYZqDE1fJRiof4l1nKOhKXlAO8nMPxqUmj1VkBfvUnOmsUVEh7S919R/s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715752652; c=relaxed/simple; bh=LbHXRH3uynyrF2ZrxbNky16a2MNX8zziwc3x2Ic5eD0=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:Content-Type: MIME-Version:References; b=Y3r9N/9r4gCa4OwIHnPYG0MLmVv5qC/okDtxRIWCtUQk35TmRdZbLxk0TRqDRgUP9ZugLXCMj5TH0OZpEqTcgMdk3GimK++jt8fIOFdDgXxuksypggUKsMyQPv8EcZK1rMwzL5yw9v5jMGvKynHh262kU+nbx8GljLtj3WvKndo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=samsung.com; spf=pass smtp.mailfrom=samsung.com; dkim=pass (1024-bit key) header.d=samsung.com header.i=@samsung.com header.b=sqVMr3yB; arc=none smtp.client-ip=210.118.77.12 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=samsung.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=samsung.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=samsung.com header.i=@samsung.com header.b="sqVMr3yB" Received: from eucas1p1.samsung.com (unknown [182.198.249.206]) by mailout2.w1.samsung.com (KnoxPortal) with ESMTP id 20240515055727euoutp020522c8bf468b2ea1ee913070250f0557~Pk-E5qDkP1334513345euoutp02N for ; Wed, 15 May 2024 05:57:27 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.w1.samsung.com 20240515055727euoutp020522c8bf468b2ea1ee913070250f0557~Pk-E5qDkP1334513345euoutp02N DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1715752647; bh=6AbpwZVsLVgVT3CkKdkc06GB5sYOIf3QpK6XfswU18c=; h=From:To:CC:Subject:Date:In-Reply-To:References:From; b=sqVMr3yBGELFFcJQXx0N/7y7+cX9+En6CeWCTEo1+I3rKtkXEW9MQtk9NRR80EnHe DR9jCayKCg+OHmQNrfe7y5HawvCC2YF4IrFRHU3vz3S+vekavEixFiCcrvEz0abgp8 g1KQMmmn3s7V4rXYxTgsGJ1/gMkcN3GcVX2Ml/UA= Received: from eusmges2new.samsung.com (unknown [203.254.199.244]) by eucas1p2.samsung.com (KnoxPortal) with ESMTP id 20240515055726eucas1p2328d05eecfcf5f4f66f26a0b452caf86~Pk-EhwvNb1215012150eucas1p2R; Wed, 15 May 2024 05:57:26 +0000 (GMT) Received: from eucas1p1.samsung.com ( [182.198.249.206]) by eusmges2new.samsung.com (EUCPMTA) with SMTP id A0.D8.09875.6CE44466; Wed, 15 May 2024 06:57:26 +0100 (BST) Received: from eusmtrp1.samsung.com (unknown [182.198.249.138]) by eucas1p2.samsung.com (KnoxPortal) with ESMTPA id 20240515055726eucas1p2a795fc743373571bfc3349f9e1ef3f9e~Pk-EEVLoG1154511545eucas1p2I; Wed, 15 May 2024 05:57:26 +0000 (GMT) Received: from eusmgms2.samsung.com (unknown [182.198.249.180]) by eusmtrp1.samsung.com (KnoxPortal) with ESMTP id 20240515055726eusmtrp1bf43dd20643a60993f5e52ab44b8af56~Pk-EDnfqX0390703907eusmtrp1u; Wed, 15 May 2024 05:57:26 +0000 (GMT) X-AuditID: cbfec7f4-131ff70000002693-d8-66444ec66dea Received: from eusmtip1.samsung.com ( [203.254.199.221]) by eusmgms2.samsung.com (EUCPMTA) with SMTP id 75.F1.09010.6CE44466; Wed, 15 May 2024 06:57:26 +0100 (BST) Received: from CAMSVWEXC01.scsc.local (unknown [106.1.227.71]) by eusmtip1.samsung.com (KnoxPortal) with ESMTPA id 20240515055726eusmtip1afeac5310d50bc39c07e1816d5c07585~Pk-D02d7J0235902359eusmtip1R; Wed, 15 May 2024 05:57:26 +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:25 +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:25 +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 02/12] shmem: add per-block uptodate tracking for large folios Thread-Topic: [PATCH 02/12] shmem: add per-block uptodate tracking for large folios Thread-Index: AQHapozCeJW3qmZrtEOp+8upfVo2+A== Date: Wed, 15 May 2024 05:57:24 +0000 Message-ID: <20240515055719.32577-3-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 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrIKsWRmVeSWpSXmKPExsWy7djPc7rH/FzSDI4161rMWb+GzeL/3mOM Fq8Pf2K0uHRUzuJs3282i6/rfzFbXH7CZ/H0Ux+LxezpzUwWl3fNYbO4t+Y/q8WuPzvYLfa9 3stscWPCU0aLg6c62C1+/wDKbt8V6SDosXPWXXaPBZtKPTav0PLYtKqTzWPTp0nsHidm/Gbx 2PnQ0mPyjeWMHh+f3m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ey/Lgwdrb3B+3uEt+kTwl/+1639X4t0pK0cqvP6Yu OsC5vnP6acYl/RbvH0StzF++iE/USPPmbabGQoXky8v3bTARTGiJz2yxX/DKS2aBrXTw2qpo bsXgufNu9u7611vvNU2JpTgj0VCLuag4EQBY2qAJAAQAAA== X-CMS-MailID: 20240515055726eucas1p2a795fc743373571bfc3349f9e1ef3f9e X-Msg-Generator: CA X-RootMTR: 20240515055726eucas1p2a795fc743373571bfc3349f9e1ef3f9e X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20240515055726eucas1p2a795fc743373571bfc3349f9e1ef3f9e References: <20240515055719.32577-1-da.gomez@samsung.com> Based on iomap per-block dirty and uptodate state track, add support for shmem_folio_state struct to track the uptodate state per-block for large folios. Signed-off-by: Daniel Gomez --- mm/shmem.c | 195 +++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 189 insertions(+), 6 deletions(-) diff --git a/mm/shmem.c b/mm/shmem.c index 94ab99b6b574..4818f9fbd328 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -131,6 +131,124 @@ struct shmem_options { #define SHMEM_SEEN_QUOTA 32 }; +/* + * Structure allocated for each folio to track per-block uptodate state. + * + * Like buffered-io iomap_folio_state struct but only for uptodate. + */ +struct shmem_folio_state { + spinlock_t state_lock; + unsigned long state[]; +}; + +static inline bool sfs_is_fully_uptodate(struct folio *folio) +{ + struct inode *inode = folio->mapping->host; + struct shmem_folio_state *sfs = folio->private; + + return bitmap_full(sfs->state, i_blocks_per_folio(inode, folio)); +} + +static inline bool sfs_is_block_uptodate(struct shmem_folio_state *sfs, + unsigned int block) +{ + return test_bit(block, sfs->state); +} + +/** + * sfs_get_last_block_uptodate - find the index of the last uptodate block + * within a specified range + * @folio: The folio + * @first: The starting block of the range to search + * @last: The ending block of the range to search + * + * Returns the index of the last uptodate block within the specified range. If + * a non uptodate block is found at the start, it returns UINT_MAX. + */ +static unsigned int sfs_get_last_block_uptodate(struct folio *folio, + unsigned int first, + unsigned int last) +{ + struct inode *inode = folio->mapping->host; + struct shmem_folio_state *sfs = folio->private; + unsigned int nr_blocks = i_blocks_per_folio(inode, folio); + unsigned int aux = find_next_zero_bit(sfs->state, nr_blocks, first); + + /* + * Exceed the range of possible last block and return UINT_MAX if a non + * uptodate block is found at the beginning of the scan. + */ + if (aux == first) + return UINT_MAX; + + return min_t(unsigned int, aux - 1, last); +} + +static void sfs_set_range_uptodate(struct folio *folio, + struct shmem_folio_state *sfs, size_t off, + size_t len) +{ + struct inode *inode = folio->mapping->host; + unsigned int first_blk = off >> inode->i_blkbits; + unsigned int last_blk = (off + len - 1) >> inode->i_blkbits; + unsigned int nr_blks = last_blk - first_blk + 1; + unsigned long flags; + + spin_lock_irqsave(&sfs->state_lock, flags); + bitmap_set(sfs->state, first_blk, nr_blks); + if (sfs_is_fully_uptodate(folio)) + folio_mark_uptodate(folio); + spin_unlock_irqrestore(&sfs->state_lock, flags); +} + +static struct shmem_folio_state *sfs_alloc(struct inode *inode, + struct folio *folio) +{ + struct shmem_folio_state *sfs = folio->private; + unsigned int nr_blocks = i_blocks_per_folio(inode, folio); + gfp_t gfp = GFP_KERNEL; + + if (sfs || nr_blocks <= 1) + return sfs; + + /* + * sfs->state tracks uptodate flag when the block size is smaller + * than the folio size. + */ + sfs = kzalloc(struct_size(sfs, state, BITS_TO_LONGS(nr_blocks)), gfp); + if (!sfs) + return sfs; + + spin_lock_init(&sfs->state_lock); + if (folio_test_uptodate(folio)) + bitmap_set(sfs->state, 0, nr_blocks); + folio_attach_private(folio, sfs); + + return sfs; +} + +static void sfs_free(struct folio *folio, bool force) +{ + if (!folio_test_private(folio)) + return; + + if (!force) + WARN_ON_ONCE(sfs_is_fully_uptodate(folio) != + folio_test_uptodate(folio)); + + kfree(folio_detach_private(folio)); +} + +static void shmem_set_range_uptodate(struct folio *folio, size_t off, + size_t len) +{ + struct shmem_folio_state *sfs = folio->private; + + if (sfs) + sfs_set_range_uptodate(folio, sfs, off, len); + else + folio_mark_uptodate(folio); +} #ifdef CONFIG_TMPFS static unsigned long shmem_default_max_blocks(void) { @@ -1487,7 +1605,7 @@ static int shmem_writepage(struct page *page, struct writeback_control *wbc) } folio_zero_range(folio, 0, folio_size(folio)); flush_dcache_folio(folio); - folio_mark_uptodate(folio); + shmem_set_range_uptodate(folio, 0, folio_size(folio)); } swap = folio_alloc_swap(folio); @@ -1769,13 +1887,16 @@ static int shmem_replace_folio(struct folio **foliop, gfp_t gfp, if (!new) return -ENOMEM; + if (folio_get_private(old)) + folio_attach_private(new, folio_detach_private(old)); + folio_get(new); folio_copy(new, old); flush_dcache_folio(new); __folio_set_locked(new); __folio_set_swapbacked(new); - folio_mark_uptodate(new); + shmem_set_range_uptodate(new, 0, folio_size(new)); new->swap = entry; folio_set_swapcache(new); @@ -2063,6 +2184,12 @@ static int shmem_get_folio_gfp(struct inode *inode, pgoff_t index, alloced: alloced = true; + + if (!sfs_alloc(inode, folio) && folio_test_large(folio)) { + error = -ENOMEM; + goto unlock; + } + if (folio_test_pmd_mappable(folio) && DIV_ROUND_UP(i_size_read(inode), PAGE_SIZE) < folio_next_index(folio) - 1) { @@ -2104,7 +2231,7 @@ static int shmem_get_folio_gfp(struct inode *inode, pgoff_t index, for (i = 0; i < n; i++) clear_highpage(folio_page(folio, i)); flush_dcache_folio(folio); - folio_mark_uptodate(folio); + shmem_set_range_uptodate(folio, 0, folio_size(folio)); } /* Perhaps the file has been truncated since we checked */ @@ -2773,8 +2900,8 @@ shmem_write_end(struct file *file, struct address_space *mapping, folio_zero_segments(folio, 0, from, from + copied, folio_size(folio)); } - folio_mark_uptodate(folio); } + shmem_set_range_uptodate(folio, 0, folio_size(folio)); folio_mark_dirty(folio); folio_unlock(folio); folio_put(folio); @@ -2782,6 +2909,59 @@ shmem_write_end(struct file *file, struct address_space *mapping, return copied; } +static void shmem_invalidate_folio(struct folio *folio, size_t offset, + size_t len) +{ + /* + * If we're invalidating the entire folio, clear the dirty state + * from it and release it to avoid unnecessary buildup of the LRU. + */ + if (offset == 0 && len == folio_size(folio)) { + WARN_ON_ONCE(folio_test_writeback(folio)); + folio_cancel_dirty(folio); + sfs_free(folio, true); + } +} + +static bool shmem_release_folio(struct folio *folio, gfp_t gfp_flags) +{ + if (folio_test_dirty(folio) && !sfs_is_fully_uptodate(folio)) + return false; + + sfs_free(folio, false); + return true; +} + +/* + * shmem_is_partially_uptodate checks whether blocks within a folio are + * uptodate or not. + * + * Returns true if all blocks which correspond to the specified part + * of the folio are uptodate. + */ +static bool shmem_is_partially_uptodate(struct folio *folio, size_t from, + size_t count) +{ + struct shmem_folio_state *sfs = folio->private; + struct inode *inode = folio->mapping->host; + unsigned int first, last; + + if (!sfs) + return false; + + /* Caller's range may extend past the end of this folio */ + count = min(folio_size(folio) - from, count); + + /* First and last blocks in range within folio */ + first = from >> inode->i_blkbits; + last = (from + count - 1) >> inode->i_blkbits; + + if (sfs_get_last_block_uptodate(folio, first, last) != last) + return false; + + return true; +} + static ssize_t shmem_file_read_iter(struct kiocb *iocb, struct iov_iter *to) { struct file *file = iocb->ki_filp; @@ -3533,7 +3713,7 @@ static int shmem_symlink(struct mnt_idmap *idmap, struct inode *dir, goto out_remove_offset; inode->i_op = &shmem_symlink_inode_operations; memcpy(folio_address(folio), symname, len); - folio_mark_uptodate(folio); + shmem_set_range_uptodate(folio, 0, folio_size(folio)); folio_mark_dirty(folio); folio_unlock(folio); folio_put(folio); @@ -4523,7 +4703,10 @@ static const struct address_space_operations shmem_aops = { #ifdef CONFIG_MIGRATION .migrate_folio = migrate_folio, #endif - .error_remove_folio = shmem_error_remove_folio, + .error_remove_folio = shmem_error_remove_folio, + .invalidate_folio = shmem_invalidate_folio, + .release_folio = shmem_release_folio, + .is_partially_uptodate = shmem_is_partially_uptodate, }; static const struct file_operations shmem_file_operations = { From patchwork Wed May 15 05:57:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Gomez X-Patchwork-Id: 13664649 Received: from mailout1.w1.samsung.com (mailout1.w1.samsung.com [210.118.77.11]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E6AD13BBCE for ; Wed, 15 May 2024 06:06:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=210.118.77.11 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715753200; cv=none; b=TzkWr5lhip4/lBWGDshiogDQcRJrrXVI1VFJpSTCavhqw+CFSMsUXRRK61e4t3dsBgxfAKlYb2lwUIxmauwSlGDcWG+66gcb6nJgGlDYGeJB5ZZnxRn9yQwFpOz0+QQSI/9FPSIY4b9LUiYY+jv+7FIdgcQF1BQHoIBnh25w9/s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715753200; c=relaxed/simple; bh=3rCXLWBXfZfMLO9t81QDeCVXjTEwchdPf8WSGMNAQ1E=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:Content-Type: MIME-Version:References; b=PFb1eLgVHPPbh/E+k35HgFnTyRWHETEfdpy9+Lnx64mVmZuEUXz2Q+pLN4kyBE2gOVGi/mKm3PD3gomw4NQv2w2XNtXiMFz07dD/+kTis5WayfCObMs1MQH8M7dI1ZyvxN3eS8i6VBaO84I6bWjToFreV8i+8XCFz/+fv7kuV+4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=samsung.com; spf=pass smtp.mailfrom=samsung.com; dkim=pass (1024-bit key) header.d=samsung.com header.i=@samsung.com header.b=q4A3cBzV; arc=none smtp.client-ip=210.118.77.11 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=samsung.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=samsung.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=samsung.com header.i=@samsung.com header.b="q4A3cBzV" Received: from eucas1p1.samsung.com (unknown [182.198.249.206]) by mailout1.w1.samsung.com (KnoxPortal) with ESMTP id 20240515055728euoutp014556076a5b69424e9d0284e9722b2e4a~Pk-FlY6qe1504315043euoutp01Z for ; Wed, 15 May 2024 05:57:28 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.w1.samsung.com 20240515055728euoutp014556076a5b69424e9d0284e9722b2e4a~Pk-FlY6qe1504315043euoutp01Z DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1715752648; bh=seKa6sjLynK9cdKjqPABBz7tIQiUkhLa6rE9aIXSk0U=; h=From:To:CC:Subject:Date:In-Reply-To:References:From; b=q4A3cBzVn9KE2ydc+PwPCpAz6s/hUrGumb4IqYJW7f4Ed9Y3y7Eg2TL0CNMlxnV+N aV/2w1EHQIxJYkiie0OXg73ruCyKvawmsL0Qa8iNP1M+YkbXf1ybCmfIGNQb360oDW 8fRKS8sJ+PtJ9+0mqjKHY9TJhGyK9/GrYMbiDH1M= Received: from eusmges1new.samsung.com (unknown [203.254.199.242]) by eucas1p1.samsung.com (KnoxPortal) with ESMTP id 20240515055727eucas1p1cce4046f8f5533c6eea17fae56ae77c7~Pk-FRrwRp2649226492eucas1p1m; Wed, 15 May 2024 05:57:27 +0000 (GMT) Received: from eucas1p2.samsung.com ( [182.198.249.207]) by eusmges1new.samsung.com (EUCPMTA) with SMTP id 48.BC.09624.7CE44466; Wed, 15 May 2024 06:57:27 +0100 (BST) Received: from eusmtrp1.samsung.com (unknown [182.198.249.138]) by eucas1p2.samsung.com (KnoxPortal) with ESMTPA id 20240515055727eucas1p2413c65b8b227ac0c6007b4600574abd8~Pk-E2YLc31177811778eucas1p2O; Wed, 15 May 2024 05:57:27 +0000 (GMT) Received: from eusmgms2.samsung.com (unknown [182.198.249.180]) by eusmtrp1.samsung.com (KnoxPortal) with ESMTP id 20240515055727eusmtrp12a11692dcfa90fab16fe695c42ed0ffa~Pk-E1UwJs0390703907eusmtrp1z; Wed, 15 May 2024 05:57:27 +0000 (GMT) X-AuditID: cbfec7f2-c11ff70000002598-4f-66444ec7cb92 Received: from eusmtip2.samsung.com ( [203.254.199.222]) by eusmgms2.samsung.com (EUCPMTA) with SMTP id E6.F1.09010.7CE44466; Wed, 15 May 2024 06:57:27 +0100 (BST) Received: from CAMSVWEXC01.scsc.local (unknown [106.1.227.71]) by eusmtip2.samsung.com (KnoxPortal) with ESMTPA id 20240515055727eusmtip2fc68020aac0eb188bacb160d886bb72a~Pk-EpQJBJ1596015960eusmtip2L; Wed, 15 May 2024 05:57:27 +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:26 +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:26 +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 03/12] shmem: move folio zero operation to write_begin() Thread-Topic: [PATCH 03/12] shmem: move folio zero operation to write_begin() Thread-Index: AQHapozDwSlh4G2vDEmdcsveZO13yA== Date: Wed, 15 May 2024 05:57:25 +0000 Message-ID: <20240515055719.32577-4-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 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrEKsWRmVeSWpSXmKPExsWy7djP87rH/VzSDOZeUrGYs34Nm8X/vccY LV4f/sRocemonMXZvt9sFl/X/2K2uPyEz+Lppz4Wi9nTm5ksLu+aw2Zxb81/Votdf3awW+x7 vZfZ4saEp4wWB091sFv8/gGU3b4r0kHQY+esu+weCzaVemxeoeWxaVUnm8emT5PYPU7M+M3i sfOhpcfkG8sZPT4+vcXi8X7fVTaPMwuOsHt83iQXwBPFZZOSmpNZllqkb5fAlXHrzD+mgueC FZt/LWNsYLzP18XIySEhYCLxYsNC5i5GLg4hgRWMEjPaFrGBJIQEvjBK9J2QhEh8ZpR4N+U0 M0zH8uYLUEXLGSV+n+KCK5r7azMjhHOGUWLOoh9QzkpGiXtvbrCCtLAJaErsO7mJHSQhInCb UeLpqTNgDrPASVaJP5t3soBUCQt4SKz79gKsQ0TAX2LHs1dMELaexJELC8GWswioSkxd9wfs KF4BS4kPi/8zgticAlYSd+d/BathFJCVeLTyFzuIzSwgLnHryXwmiCcEJRbN3gP1kJjEv10P 2SBsHYmz158wQtgGEluX7mOBsJUl1r9rY4KYoydxY+oUNghbW2LZwtdQNwhKnJz5hAXkGQmB nVwS92+3QC1zkdjway3UAmGJV8e3sEPYMhKnJ/ewTGDUnoXkvllIdsxCsmMWkh0LGFlWMYqn lhbnpqcWG+allusVJ+YWl+al6yXn525iBCbL0/+Of9rBOPfVR71DjEwcjIcYJTiYlUR4RdKc 04R4UxIrq1KL8uOLSnNSiw8xSnOwKInzqqbIpwoJpCeWpGanphakFsFkmTg4pRqYmCYlvmqf 2BX/pKsl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kLbOQtMxC0rKAkWUVo0hqaXFuem6x kV5xYm5xaV66XnJ+7iZGYMrbduznlh2MK1991DvEyMTBeIhRgoNZSYRXJM05TYg3JbGyKrUo P76oNCe1+BCjKTCMJjJLiSbnA5NuXkm8oZmBqaGJmaWBqaWZsZI4r2dBR6KQQHpiSWp2ampB ahFMHxMHp1QDU7DFr4ynt03ZQ3pmz/l8xSdR4nEwv8OhrRldjYnsFks9VMR7Hk6Tnrt5kuTy v/wd/51LljyQmLDNyX6lY+KDpPiq3fx/nc9N8bMP4LitsN2qvfzDPF4RVpWaG1P6tzziVI10 eyT/R5DzT8oPXdEj0zZwMR14JndEe6Hw+RcbJrqWzWDyu3TJ6MW0Po3MeI/G2mSNC5FuUhtO NK7lWZ0nnPnwfkco55RkbUau8OKNkRm9mxfafH8SkX0vYAVX/3TuujN3V0Q+f/n1M//Nizlx uw6cqV0sGN8dLJjAMmWxPqdXvAvf77AdzSuVFhn/Tp5xq2JLq1GlQ4iPQvRDnb/VShvXRztM Xy48YU+l0b56JZbijERDLeai4kQAdnZNzAIEAAA= X-CMS-MailID: 20240515055727eucas1p2413c65b8b227ac0c6007b4600574abd8 X-Msg-Generator: CA X-RootMTR: 20240515055727eucas1p2413c65b8b227ac0c6007b4600574abd8 X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20240515055727eucas1p2413c65b8b227ac0c6007b4600574abd8 References: <20240515055719.32577-1-da.gomez@samsung.com> Simplify zero out operation by moving it from write_end() to the write_begin(). If a large folio does not have any block uptodate when we first get it, zero it out entirely. Signed-off-by: Daniel Gomez --- mm/shmem.c | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/mm/shmem.c b/mm/shmem.c index 4818f9fbd328..86ad539b6a0f 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -149,6 +149,14 @@ static inline bool sfs_is_fully_uptodate(struct folio *folio) return bitmap_full(sfs->state, i_blocks_per_folio(inode, folio)); } +static inline bool sfs_is_any_uptodate(struct folio *folio) +{ + struct inode *inode = folio->mapping->host; + struct shmem_folio_state *sfs = folio->private; + + return !bitmap_empty(sfs->state, i_blocks_per_folio(inode, folio)); +} + static inline bool sfs_is_block_uptodate(struct shmem_folio_state *sfs, unsigned int block) { @@ -239,6 +247,15 @@ static void sfs_free(struct folio *folio, bool force) kfree(folio_detach_private(folio)); } +static inline bool shmem_is_any_uptodate(struct folio *folio) +{ + struct shmem_folio_state *sfs = folio->private; + + if (folio_test_large(folio) && sfs) + return sfs_is_any_uptodate(folio); + return folio_test_uptodate(folio); +} + static void shmem_set_range_uptodate(struct folio *folio, size_t off, size_t len) { @@ -2872,6 +2889,9 @@ shmem_write_begin(struct file *file, struct address_space *mapping, if (ret) return ret; + if (!shmem_is_any_uptodate(folio)) + folio_zero_range(folio, 0, folio_size(folio)); + *pagep = folio_file_page(folio, index); if (PageHWPoison(*pagep)) { folio_unlock(folio); @@ -2894,13 +2914,6 @@ shmem_write_end(struct file *file, struct address_space *mapping, if (pos + copied > inode->i_size) i_size_write(inode, pos + copied); - if (!folio_test_uptodate(folio)) { - if (copied < folio_size(folio)) { - size_t from = offset_in_folio(folio, pos); - folio_zero_segments(folio, 0, from, - from + copied, folio_size(folio)); - } - } shmem_set_range_uptodate(folio, 0, folio_size(folio)); folio_mark_dirty(folio); folio_unlock(folio); From patchwork Wed May 15 05:57:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Gomez X-Patchwork-Id: 13664648 Received: from mailout1.w1.samsung.com (mailout1.w1.samsung.com [210.118.77.11]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 160223BBCF for ; Wed, 15 May 2024 06:06:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=210.118.77.11 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715753200; cv=none; b=Byct+i6FfLbtS1OOeOzV/dsvo6p5BppdhBpH1sjlzNKil15V8a1+Bw6MPG2wDHNt6Dq7eL0HGnEjYyxbmuhiJIhn9TrrGJAw1YRW8mrAvKWxGFmtGnAxcKkQlcZhIer8/V4vihZXEsLjVjFIEmAEiZ1H5CL11J2e789x4R0d3Zw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715753200; c=relaxed/simple; bh=KNLDOdcMJHdonJIFbAEgulwCa2Oo/AmJi3h6ziGNLfs=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:Content-Type: MIME-Version:References; b=m0rJeCu4CIUUPnlflDOURsf1nrNrpgyu7DCQh4kKR0QtzZGzfs88R+xVcSf9rEdxN66oMC+8Y9VZYovFocK5U6hien4L3yJA6CvLPfUmO8w7jlNdgF0O3poeu5YKxQ4sEUz8CVPKS3alLoWohh9m/PlSQ9Kg92kOtdoma4YTmrU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=samsung.com; spf=pass smtp.mailfrom=samsung.com; dkim=pass (1024-bit key) header.d=samsung.com header.i=@samsung.com header.b=iF9QYRA2; arc=none smtp.client-ip=210.118.77.11 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=samsung.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=samsung.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=samsung.com header.i=@samsung.com header.b="iF9QYRA2" Received: from eucas1p1.samsung.com (unknown [182.198.249.206]) by mailout1.w1.samsung.com (KnoxPortal) with ESMTP id 20240515055729euoutp01b0f54336d3eb0854bdfe902069230cbd~Pk-HWNCg_1504015040euoutp01R for ; Wed, 15 May 2024 05:57:29 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.w1.samsung.com 20240515055729euoutp01b0f54336d3eb0854bdfe902069230cbd~Pk-HWNCg_1504015040euoutp01R DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1715752649; bh=TvwQ3/t0rLMlRSFpe0qm/SVRP0obWxz9NLqJPflU2UQ=; h=From:To:CC:Subject:Date:In-Reply-To:References:From; b=iF9QYRA2fhupfZkTnrimDqeRi6wjYm0sMeOp0s5h8j692FXl0E3QjwQRodtCpRm64 +G8KcwQ2IAF7D+h2qGkK9eThiOsfeUH3RG8J/ThTzFnEU12i5NpznNNkBZPG70EGIv EaQFp+sLI3WpGCwP9whM6ce+M1zVolcg4HrOvNR4= Received: from eusmges1new.samsung.com (unknown [203.254.199.242]) by eucas1p2.samsung.com (KnoxPortal) with ESMTP id 20240515055729eucas1p25a1ae40ac6143a6c66beda0dcd46d6ac~Pk-GwWyTN0594605946eucas1p2R; Wed, 15 May 2024 05:57:29 +0000 (GMT) Received: from eucas1p1.samsung.com ( [182.198.249.206]) by eusmges1new.samsung.com (EUCPMTA) with SMTP id 99.BC.09624.8CE44466; Wed, 15 May 2024 06:57:28 +0100 (BST) Received: from eusmtrp1.samsung.com (unknown [182.198.249.138]) by eucas1p1.samsung.com (KnoxPortal) with ESMTPA id 20240515055728eucas1p181e0ed81b2663eb0eee6d6134c1c1956~Pk-Fxtmp_2567425674eucas1p1T; Wed, 15 May 2024 05:57:28 +0000 (GMT) Received: from eusmgms2.samsung.com (unknown [182.198.249.180]) by eusmtrp1.samsung.com (KnoxPortal) with ESMTP id 20240515055728eusmtrp126de191b60d8f61e2ba129b4a88ba285~Pk-FxIF7h0390703907eusmtrp11; Wed, 15 May 2024 05:57:28 +0000 (GMT) X-AuditID: cbfec7f2-c11ff70000002598-51-66444ec865cb Received: from eusmtip1.samsung.com ( [203.254.199.221]) by eusmgms2.samsung.com (EUCPMTA) with SMTP id 18.F1.09010.8CE44466; Wed, 15 May 2024 06:57:28 +0100 (BST) Received: from CAMSVWEXC01.scsc.local (unknown [106.1.227.71]) by eusmtip1.samsung.com (KnoxPortal) with ESMTPA id 20240515055728eusmtip1e41b862dcb859f62ee1fd12a0cd79248~Pk-Fir1hx0512305123eusmtip1t; Wed, 15 May 2024 05:57:28 +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:27 +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:27 +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 04/12] shmem: exit shmem_get_folio_gfp() if block is uptodate Thread-Topic: [PATCH 04/12] shmem: exit shmem_get_folio_gfp() if block is uptodate Thread-Index: AQHapozD1A5s10K0O0aGF++xWBxX9g== Date: Wed, 15 May 2024 05:57:27 +0000 Message-ID: <20240515055719.32577-5-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 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrAKsWR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kavR DzXxTzLdAnIOdnw/fsVLCZ55uXLj5j3MzLNFLSQ8rtqI/zWceEWsw3Byb7Gb3yTngqeTJp+d UDizXmX+h9Y4m7gXRw4LGJcuaxPP9wmqOTw3iuGTXv/NiuMLsnbbSq1bl9Mp/2nCz3JZ231e f8pvit7XeVqX9/PSF6HtEZGqQk812G9EnWI9JuXuLGnU7CIoK6/2I2jW1+0PFX/KnSy+5ml+ fppV8HmTzIKln301JypvsPV8JqHF427yx8z3uUJ2X8zsRY61gfOU+9viwrNv3e5Qs7grkPz7 dUlu7i62OY++31ZiKc5INNRiLipOBADETHQjAAQAAA== X-CMS-MailID: 20240515055728eucas1p181e0ed81b2663eb0eee6d6134c1c1956 X-Msg-Generator: CA X-RootMTR: 20240515055728eucas1p181e0ed81b2663eb0eee6d6134c1c1956 X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20240515055728eucas1p181e0ed81b2663eb0eee6d6134c1c1956 References: <20240515055719.32577-1-da.gomez@samsung.com> When we get a folio from the page cache with filemap_get_entry() and is uptodate we exit from shmem_get_folio_gfp(). Replicate the same behaviour if the block is uptodate in the index we are operating on. Signed-off-by: Daniel Gomez --- mm/shmem.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/mm/shmem.c b/mm/shmem.c index 86ad539b6a0f..69f3b98fdf7c 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -256,6 +256,16 @@ static inline bool shmem_is_any_uptodate(struct folio *folio) return folio_test_uptodate(folio); } +static inline bool shmem_is_block_uptodate(struct folio *folio, + unsigned int block) +{ + struct shmem_folio_state *sfs = folio->private; + + if (folio_test_large(folio) && sfs) + return sfs_is_block_uptodate(sfs, block); + return folio_test_uptodate(folio); +} + static void shmem_set_range_uptodate(struct folio *folio, size_t off, size_t len) { @@ -2146,7 +2156,7 @@ static int shmem_get_folio_gfp(struct inode *inode, pgoff_t index, } if (sgp == SGP_WRITE) folio_mark_accessed(folio); - if (folio_test_uptodate(folio)) + if (shmem_is_block_uptodate(folio, index - folio_index(folio))) goto out; /* fallocated folio */ if (sgp != SGP_READ) From patchwork Wed May 15 05:57:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Gomez X-Patchwork-Id: 13664623 Received: from mailout2.w1.samsung.com (mailout2.w1.samsung.com [210.118.77.12]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C7E9A3B79F for ; Wed, 15 May 2024 05:57:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=210.118.77.12 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715752653; cv=none; b=eJKOK22O3cEwuP7y7nLb4U5tBmWK1sbX2VQtWbMxe5H/yYPnpC5kAEnDaxJGvObbrnzcqaUKEFmTuVBfMXL3OHHTR6EBPC8bn+K8oNaAlsPgE1g+cR1qhAnGS4rBKlMaEjpPimy55VpNiTgRSt961b5bY6xZ0aXIzVfkNPwJ2Tk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715752653; c=relaxed/simple; bh=nKWtereSLnu+oADE1O/ufkjOx3uZ4D3VDRJRS1eEsrU=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:Content-Type: MIME-Version:References; b=IXhiq2Z5Y2skmsASMytq0PlTukvYr6pPBTtIF7lGX4jWtpynpUIMEsOTjSkHm5YMGavEY7W2n0b2QO9nhdtG50PFzxdN0Ue/Zhba5MBRFC0hrF7eFLYjQ3hyzgsyp4dzHBw23nlHdQqYwYSUm+v7cxC+t7x3yNeGj6M7VfDA+IE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=samsung.com; spf=pass smtp.mailfrom=samsung.com; dkim=pass (1024-bit key) header.d=samsung.com header.i=@samsung.com header.b=u4gdewf9; arc=none smtp.client-ip=210.118.77.12 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=samsung.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=samsung.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=samsung.com header.i=@samsung.com header.b="u4gdewf9" Received: from eucas1p1.samsung.com (unknown [182.198.249.206]) by mailout2.w1.samsung.com (KnoxPortal) with ESMTP id 20240515055730euoutp022866c13aa86ac67bad51f8caa2d17464~Pk-HoGjk11630116301euoutp024 for ; Wed, 15 May 2024 05:57:30 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.w1.samsung.com 20240515055730euoutp022866c13aa86ac67bad51f8caa2d17464~Pk-HoGjk11630116301euoutp024 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1715752650; bh=LR6zBAqCV5AW0imgsMiCR7+GSDVrb77Uvzm1KnB3t5Q=; h=From:To:CC:Subject:Date:In-Reply-To:References:From; b=u4gdewf9aJ1/hhtGBiE/AmTK+E5NWKJWqtb2PRSlRy83TSAxt4f3BpHcof9oHbueN MzhWqh/cQJSDFsGv8sy8w4ztloQ2ME+6LaNnRwvwsRd6kpdoAxXP4czSSaz95blMV0 +IyiWcyKqbhQsY6Q5tpyQPHYqJ/qj4t9yFEv2zHE= Received: from eusmges1new.samsung.com (unknown [203.254.199.242]) by eucas1p1.samsung.com (KnoxPortal) with ESMTP id 20240515055729eucas1p1783caa60b5809909e5f5f02340a8b5e9~Pk-HRYZK_2872228722eucas1p1g; Wed, 15 May 2024 05:57:29 +0000 (GMT) Received: from eucas1p1.samsung.com ( [182.198.249.206]) by eusmges1new.samsung.com (EUCPMTA) with SMTP id BB.BC.09624.9CE44466; Wed, 15 May 2024 06:57:29 +0100 (BST) Received: from eusmtrp1.samsung.com (unknown [182.198.249.138]) by eucas1p1.samsung.com (KnoxPortal) with ESMTPA id 20240515055729eucas1p14e953424ad39bbb923c64163b1bbd4b3~Pk-Gop9GA2569725697eucas1p19; Wed, 15 May 2024 05:57:29 +0000 (GMT) Received: from eusmgms1.samsung.com (unknown [182.198.249.179]) by eusmtrp1.samsung.com (KnoxPortal) with ESMTP id 20240515055729eusmtrp1fe48c4be7bfa2cd516577c63c5d4fcec~Pk-GoCb900390703907eusmtrp15; Wed, 15 May 2024 05:57:29 +0000 (GMT) X-AuditID: cbfec7f2-bfbff70000002598-56-66444ec9e21e Received: from eusmtip1.samsung.com ( [203.254.199.221]) by eusmgms1.samsung.com (EUCPMTA) with SMTP id 4C.16.08810.9CE44466; Wed, 15 May 2024 06:57:29 +0100 (BST) Received: from CAMSVWEXC02.scsc.local (unknown [106.1.227.72]) by eusmtip1.samsung.com (KnoxPortal) with ESMTPA id 20240515055728eusmtip16c7550411a40722fd434edbb57cdb6d4~Pk-GdPs9a0562305623eusmtip1T; Wed, 15 May 2024 05:57:28 +0000 (GMT) Received: from CAMSVWEXC02.scsc.local (2002:6a01:e348::6a01:e348) by CAMSVWEXC02.scsc.local (2002:6a01:e348::6a01:e348) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Wed, 15 May 2024 06:57:28 +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:28 +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 05/12] shmem: clear_highpage() if block is not uptodate Thread-Topic: [PATCH 05/12] shmem: clear_highpage() if block is not uptodate Thread-Index: AQHapozEyRWHtpwfgE2CvOQjrDJhgA== Date: Wed, 15 May 2024 05:57:28 +0000 Message-ID: <20240515055719.32577-6-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 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrEKsWRmVeSWpSXmKPExsWy7djPc7on/VzSDJrmGlrMWb+GzeL/3mOM Fq8Pf2K0uHRUzuJs3282i6/rfzFbXH7CZ/H0Ux+LxezpzUwWl3fNYbO4t+Y/q8WuPzvYLfa9 3stscWPCU0aLg6c62C1+/wDKbt8V6SDosXPWXXaPBZtKPTav0PLYtKqTzWPTp0nsHidm/Gbx 2PnQ0mPyjeWMHh+f3mLxeL/vKpvHmQVH2D0+b5IL4InisklJzcksSy3St0vgyph04zxbwVa2 ireXO5gaGBewdjFyckgImEjcvjydrYuRi0NIYAWjxJX5x5lBEkICXxglLswKhUh8ZpQ4s2om G0zH6rWPoTqWM0pcunKRFa7qXet+Joj2M0CZkw4QiZWMEk9PLGAESbAJaErsO7mJHSQhInAb KHHqDJjDLHCSVeLP5p0sIFXCAu4STed+soPYIgI+EvdvrmaCsPUkFnS+BYuzCKhKfOleCfYG r4ClRO+2HjCbU8BK4u78r2DHMgrISjxa+QusnllAXOLWk/lMEE8ISiyavYcZwhaT+LfrIdRz OhJnrz9hhLANJLYu3ccCYStLrH/XxgQxR0/ixtQpbBC2tsSyha+ZIW4QlDg58wkLyDMSAju5 JF4e/gq1zEXiU+sFqAXCEq+Ob2GHsGUkTk/uYZnAqD0Ly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5kgbD2JBZ1vweIsAqoSX7pXgh3CK2Ap0butB8wWArIvvdrOCGJzClhJ3J3/lQ3EZhSQlXi0 8hdYL7OAuMStJ/OZIJ4QkFiy5zwzhC0q8fLxP6jndCTOXn/CCGEbSGxduo8FwlaWWP+ujQli jp7EjalT2CBsbYllC18zQ9wjKHFy5hOWCYzSs5Csm4WkZRaSlllIWhYwsqxiFEktLc5Nzy02 1CtOzC0uzUvXS87P3cQITHnbjv3cvINx3quPeocYmTgYDzFKcDArifCKpDmnCfGmJFZWpRbl xxeV5qQWH2I0BYbRRGYp0eR8YNLNK4k3NDMwNTQxszQwtTQzVhLn9SzoSBQSSE8sSc1OTS1I LYLpY+LglGpgypv91ajndmjpQ9E6vgCli63sYQJCl4s6r5hmy5jOPnzn469rEh0HJ5//MD2V /1z3j6vy+zatb9tetmHDwtdyeR/TH/y7FM/LeD7ipUp8tliX1v9dP1ae4CtNe+8/b4Gn0xKV upnWjmVN3xba37+leDcw3rH9VcTv2ZYWNT+TbJIYdyuqdk/bVHb66eKq5c2K9wwCrBn1NSf+ SAi/Ubx757y8O0oOyc7mvtcTUlWVDHjCxPr2u7XbrLQLqok/V+47xX+t+KJNTX3Tz7z4GSCx MJ8z7GnU6bcZrHE9v3/+DJ6nYqmSFrd5Dc+N9erB95w+193devD39GXbeZ7K1E1sfq132CyP g2P/l4jzER/eK7EUZyQaajEXFScCAKuYz08CBAAA X-CMS-MailID: 20240515055729eucas1p14e953424ad39bbb923c64163b1bbd4b3 X-Msg-Generator: CA X-RootMTR: 20240515055729eucas1p14e953424ad39bbb923c64163b1bbd4b3 X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20240515055729eucas1p14e953424ad39bbb923c64163b1bbd4b3 References: <20240515055719.32577-1-da.gomez@samsung.com> clear_highpage() is called for all the subpages (blocks) in a large folio when the folio is not uptodate. Do clear the subpages only when they are not uptodate. Signed-off-by: Daniel Gomez --- mm/shmem.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mm/shmem.c b/mm/shmem.c index 69f3b98fdf7c..04992010225f 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -2256,7 +2256,8 @@ static int shmem_get_folio_gfp(struct inode *inode, pgoff_t index, long i, n = folio_nr_pages(folio); for (i = 0; i < n; i++) - clear_highpage(folio_page(folio, i)); + if (!shmem_is_block_uptodate(folio, i)) + clear_highpage(folio_page(folio, i)); flush_dcache_folio(folio); shmem_set_range_uptodate(folio, 0, folio_size(folio)); } From patchwork Wed May 15 05:57:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Gomez X-Patchwork-Id: 13664626 Received: from mailout2.w1.samsung.com (mailout2.w1.samsung.com [210.118.77.12]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A8CC44A99C for ; Wed, 15 May 2024 05:57:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=210.118.77.12 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715752660; cv=none; b=vGRgvpTdHkRcEV7+RWhsF+qNjkFE6U2gYTTlvfcbIIoHLXuPXDVPHFOfMmpRh4CyUnzlemMesYrKSegiz+K4iL9Iaii5kTwUDzdiEu2OzBqWnIkYc55M9qjhVVXuhMMe360arW7RnfHSEzjz2l+s4IzA+FKwDFievw532FOdM6U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715752660; c=relaxed/simple; bh=lc5Bcuya4k9VDqOmugl/UQAcSKJ85TOXE7/4aly3gXY=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:Content-Type: MIME-Version:References; b=Qdb786G4m3R2r1Rm1+989mQcoMsDapLYBAAOhJ+/tZsEuCLXQntdTzWvzY/CqzfrO5GoPyNe3nTwUu+gZfds6bPNugyv5TueEn4Bg8MjNlCVX55H4eeZxX+ZUIgsmAnKrysb4PQwSYDcZV2cw27VNvAG03zVxHuk4sf1xLHb1As= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=samsung.com; spf=pass smtp.mailfrom=samsung.com; dkim=pass (1024-bit key) header.d=samsung.com header.i=@samsung.com header.b=V6X+pv4+; arc=none smtp.client-ip=210.118.77.12 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=samsung.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=samsung.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=samsung.com header.i=@samsung.com header.b="V6X+pv4+" Received: from eucas1p1.samsung.com (unknown [182.198.249.206]) by mailout2.w1.samsung.com (KnoxPortal) with ESMTP id 20240515055737euoutp02d603b204e5ce7bf4b558875252c827bc~Pk-OSxnNG1630116301euoutp029 for ; Wed, 15 May 2024 05:57:37 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.w1.samsung.com 20240515055737euoutp02d603b204e5ce7bf4b558875252c827bc~Pk-OSxnNG1630116301euoutp029 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1715752657; bh=UpgQNcs3t+vPhgTbp5qaltdkcX9R16oQVfuTuAdyYIA=; h=From:To:CC:Subject:Date:In-Reply-To:References:From; b=V6X+pv4+/cBmEU8T11EPsFfVxs/5YtIbbio/GJliZS3fM7HMZwpBQft9a7HilFsIz /qDLPhHudz7k9wBLqS5fAM3LWbKlq6U0ooUrdtlKAtadGgKh1Xc9wvuCr2XSeVyU3b kNBG7nrP+x1JpjG799YNIHCZI4DtXMyNL35DxE68= Received: from eusmges2new.samsung.com (unknown [203.254.199.244]) by eucas1p2.samsung.com (KnoxPortal) with ESMTP id 20240515055732eucas1p21f818cb2496ee822433ed04389e46e34~Pk-Jf679M0594605946eucas1p2V; Wed, 15 May 2024 05:57:32 +0000 (GMT) Received: from eucas1p1.samsung.com ( [182.198.249.206]) by eusmges2new.samsung.com (EUCPMTA) with SMTP id A3.D8.09875.CCE44466; Wed, 15 May 2024 06:57:32 +0100 (BST) Received: from eusmtrp1.samsung.com (unknown [182.198.249.138]) by eucas1p1.samsung.com (KnoxPortal) with ESMTPA id 20240515055731eucas1p12cbbba88e24a011ef5871f90ff25ae73~Pk-IlqFp62570125701eucas1p1D; Wed, 15 May 2024 05:57:31 +0000 (GMT) Received: from eusmgms2.samsung.com (unknown [182.198.249.180]) by eusmtrp1.samsung.com (KnoxPortal) with ESMTP id 20240515055731eusmtrp1cf7b95a0a73627267d00f9d9cd74d1b4~Pk-IkvrDl0390703907eusmtrp19; Wed, 15 May 2024 05:57:31 +0000 (GMT) X-AuditID: cbfec7f4-11bff70000002693-e5-66444ecc2765 Received: from eusmtip2.samsung.com ( [203.254.199.222]) by eusmgms2.samsung.com (EUCPMTA) with SMTP id B9.F1.09010.BCE44466; Wed, 15 May 2024 06:57:31 +0100 (BST) Received: from CAMSVWEXC02.scsc.local (unknown [106.1.227.72]) by eusmtip2.samsung.com (KnoxPortal) with ESMTPA id 20240515055730eusmtip2f331ce6df1efce75d1c8a5633c334c55~Pk-IU51Z-1596015960eusmtip2N; Wed, 15 May 2024 05:57:30 +0000 (GMT) Received: from CAMSVWEXC02.scsc.local (2002:6a01:e348::6a01:e348) by CAMSVWEXC02.scsc.local (2002:6a01:e348::6a01:e348) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Wed, 15 May 2024 06:57:30 +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:30 +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 06/12] shmem: set folio uptodate when reclaim Thread-Topic: [PATCH 06/12] shmem: set folio uptodate when reclaim Thread-Index: AQHapozFha++cZmim0iVIxwtuJabGw== Date: Wed, 15 May 2024 05:57:29 +0000 Message-ID: <20240515055719.32577-7-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 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrIKsWRmVeSWpSXmKPExsWy7djPc7pn/FzSDBZP4rGYs34Nm8X/vccY LV4f/sRocemonMXZvt9sFl/X/2K2uPyEz+Lppz4Wi9nTm5ksLu+aw2Zxb81/Votdf3awW+x7 vZfZ4saEp4wWB091sFv8/gGU3b4r0kHQY+esu+weCzaVemxeoeWxaVUnm8emT5PYPU7M+M3i sfOhpcfkG8sZPT4+vcXi8X7fVTaPMwuOsHt83iQXwBPFZZOSmpNZllqkb5fAldG0JKVgBlvF 0mMv2RoY+1m7GDk5JARMJJpmPWDpYuTiEBJYwShx49E1KOcLo8TZnd/ZIJzPjBI/fr9khGm5 /2YzK0RiOaPEzgsTWeCquj92MUM4Zxgllq89ww7hrGSU2PjjPNhKNgFNiX0nN4ElRARuM0o8 PQVRxSxwklXiz+adLCBVwgK2EosPH2QHsUUEnCRO7twGFOcAsvUk/qx1AwmzCKhKfOg9wQZi 8wpYSvz6dwq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0mMv2RoY+1m7GDk5JARMJO6/ 2Qxkc3EICSxllOh/vo4dIiEjsfHLVagiYYk/17rYIIo+MkpcPXmTBcI5wyhx6scrqPaVjBJd C7+BtbMJaErsO7mJHSQhInCbUeLpqTNgDrPASVaJA6c/g1UJC9hKLD58EMwWEXCSOLlzG9Bc DiBbT+LPWjeQMIuAqsSH3hNsIDavgKXEr3+nwMqFgOxLr7YzgticAlYSd+d/BathFJCVeLTy F1gNs4C4xK0n85kgfhCQWLLnPDOELSrx8vE/qN90JM5ef8IIYRtIbF26jwXCVpZY/66NCWKO nsSNqVPYIGxtiWULXzND3CMocXLmE5YJjNKzkKybhaRlFpKWWUhaFjCyrGIUSS0tzk3PLTbS K07MLS7NS9dLzs/dxAhMd9uO/dyyg3Hlq496hxiZOBgPMUpwMCuJ8IqkOacJ8aYkVlalFuXH F5XmpBYfYjQFhtFEZinR5Hxgws0riTc0MzA1NDGzNDC1NDNWEuf1LOhIFBJITyxJzU5NLUgt gulj4uCUamAyP5nIsNs+Sk3q4tWcoqmO8rZzeZqnKJiwcKTWXSxTlzHmTdQ5NV99ptWzR90i mTrh10QfNq5kdNijvnb1/Inx2rlSfJMr31bUNpj/rbANFhD4/3hTwBxzh2S9R7+fWv+71a7y j/f6jA7ZbN8pdqsmSUtneD0NFNtutSahUGU257Jut4Z7wXfD3955fp138rKiUKv9Ez9Ld2du D9q0ircu/oxd11FtpdQySxvLr6uPshRyn781e0/e82ksX3N2BCswvj3/erX66y3FZ2fnzHtl L/G0LHvD+YRL2xzaHFr6fX2L1KYwMPhfb4np2llzK4n/1ad74f//H3twu+5oj23M4ps7TnPU rE37waKm06PEUpyRaKjFXFScCACpKEirAAQAAA== X-CMS-MailID: 20240515055731eucas1p12cbbba88e24a011ef5871f90ff25ae73 X-Msg-Generator: CA X-RootMTR: 20240515055731eucas1p12cbbba88e24a011ef5871f90ff25ae73 X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20240515055731eucas1p12cbbba88e24a011ef5871f90ff25ae73 References: <20240515055719.32577-1-da.gomez@samsung.com> When reclaiming some space by splitting a large folio through shmem_unused_huge_shrink(), a large folio is split regardless of its uptodate status. Mark all the blocks as uptodate in the reclaim path so split_folio() can release the folio private struct (shmem_folio_state). Signed-off-by: Daniel Gomez --- mm/shmem.c | 1 + 1 file changed, 1 insertion(+) diff --git a/mm/shmem.c b/mm/shmem.c index 04992010225f..68fe769d91b1 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -842,6 +842,7 @@ static unsigned long shmem_unused_huge_shrink(struct shmem_sb_info *sbinfo, goto move_back; } + shmem_set_range_uptodate(folio, 0, folio_size(folio)); ret = split_folio(folio); folio_unlock(folio); folio_put(folio); 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: 13664624 Received: from mailout2.w1.samsung.com (mailout2.w1.samsung.com [210.118.77.12]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 317B13D38E for ; Wed, 15 May 2024 05:57:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=210.118.77.12 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715752656; cv=none; b=dOh1gnYUsCDMtfM9Hl7BQCiNBrLblDa05J/gnPS9DzvgDmJAND7+ADDzcKeXwfC0CGsdqrB25BWNjX8ZtTULvh3rPYMexipfBMWvJpJLzZVkx8Hwcuf/6uuYqrYwBP+ClUkWo6s0GuXkJARR0uvmrLCB0CXJk2n+ajJPIuV7Iag= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715752656; c=relaxed/simple; bh=89+H9PvAC7hTsgg4Ho2crFN+biV5BGlsEVOQmKZxxZM=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:Content-Type: MIME-Version:References; b=aiYYSeIyEjOcdhlZt34JuSVVtIbOulGsqqu6oXpcAWVSO8qQ9QqIwHvAn6X/VZ8C99lskgEcA6Fsq+s1+xRT0yQYGVt+90CMF0oK1kzFDZ6l7VwkUVhBhG2W1h+onzNep6V7WIFTiDauNVIAQniQoLskR2gmt7vwQ5MvXYydga8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=samsung.com; spf=pass smtp.mailfrom=samsung.com; dkim=pass (1024-bit key) header.d=samsung.com header.i=@samsung.com header.b=ZkVfT9z6; arc=none smtp.client-ip=210.118.77.12 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=samsung.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=samsung.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=samsung.com header.i=@samsung.com header.b="ZkVfT9z6" Received: from eucas1p2.samsung.com (unknown [182.198.249.207]) by mailout2.w1.samsung.com (KnoxPortal) with ESMTP id 20240515055733euoutp025a06fbda482c617ac65a0f5215254713~Pk-K4EcPZ1335213352euoutp02a for ; Wed, 15 May 2024 05:57:33 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.w1.samsung.com 20240515055733euoutp025a06fbda482c617ac65a0f5215254713~Pk-K4EcPZ1335213352euoutp02a 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 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrEKsWRmVeSWpSXmKPExsWy7djPc7pn/VzSDCavFLCYs34Nm8X/vccY LV4f/sRocemonMXZvt9sFl/X/2K2uPyEz+Lppz4Wi9nTm5ksLu+aw2Zxb81/Votdf3awW+x7 vZfZ4saEp4wWB091sFv8/gGU3b4r0kHQY+esu+weCzaVemxeoeWxaVUnm8emT5PYPU7M+M3i sfOhpcfkG8sZPT4+vcXi8X7fVTaPMwuOsHt83iQXwBPFZZOSmpNZllqkb5fAldF74CRbwWPe iklvoxoY73N1MXJySAiYSCz5/puli5GLQ0hgBaPEj1vvmCCcL4wSj/tnQzmfGSUerL/ABNPy 58U9ZojEckaJTZfbGeGq7i49yArhn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811a5c59e34f83628d 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> 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 From patchwork Wed May 15 05:57:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Gomez X-Patchwork-Id: 13664625 Received: from mailout2.w1.samsung.com (mailout2.w1.samsung.com [210.118.77.12]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A00B43D552 for ; Wed, 15 May 2024 05:57:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=210.118.77.12 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715752657; cv=none; b=s9oJdWx54pfcAsGgItCcX0piemRaRh/lrbAgjB7NhGzF0Jx0lT9bDvq+BrTTtNztLbfNfAGOYXo9/IBN6Ho0rlScMYFD0jL6Umf897sEZbYTwHbP4fzGpVkcX235iQI+wt6y5FYoSGIVeIG0ybErp10OFhQDxqllPmPo64SnuCA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715752657; c=relaxed/simple; bh=ctPb7XxM+TWxPhd3Fu6+Fa+0hskhZ7PD8nkromhva34=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:Content-Type: MIME-Version:References; b=LuFdUXFO2z/eyQcGVo6oAXNZtTEQUi78rnzlbz64kqsjU4bG3c/67nQNsSxO3C9LjMmzI6oyL9nbHbI/EJ3Rj1EHAln2oVuXmSmzPxGRLRQAIFsGkzhjr0+Uv9l6Ta3aSvSmL/KEBkoFGYu1nr9p7i1qTt47AL8gSyWjukgD1AE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=samsung.com; spf=pass smtp.mailfrom=samsung.com; dkim=pass (1024-bit key) header.d=samsung.com header.i=@samsung.com header.b=kKiv/K/0; arc=none smtp.client-ip=210.118.77.12 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=samsung.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=samsung.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=samsung.com header.i=@samsung.com header.b="kKiv/K/0" Received: from eucas1p2.samsung.com (unknown [182.198.249.207]) by mailout2.w1.samsung.com (KnoxPortal) with ESMTP id 20240515055734euoutp0278b1c9acf8b08413057fb494843d4bc7~Pk-LLHOWK2018620186euoutp02J for ; Wed, 15 May 2024 05:57:34 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.w1.samsung.com 20240515055734euoutp0278b1c9acf8b08413057fb494843d4bc7~Pk-LLHOWK2018620186euoutp02J DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1715752654; bh=Yzf34yJLjjOZ5L6S/TOvcg7MvQWva+m/QvkKTJ1hVb4=; h=From:To:CC:Subject:Date:In-Reply-To:References:From; b=kKiv/K/0A8lf09vqiaIlDRS+gML5VtHlI2Q7RrAPMGRgI+49KSIhBA+ip3dV2J9Fz zsXZ9z/AXfGOPn/puBP6qb4iY8y+Z7Kir1jke0oh1ezzjLcJqzMhbN4drL/MHLvsUl MxraXULuMzNCaydYXN/bliQ0l4wfGqBZmBlUbQZ8= Received: from eusmges1new.samsung.com (unknown [203.254.199.242]) by eucas1p2.samsung.com (KnoxPortal) with ESMTP id 20240515055733eucas1p2a521a9e0623f0531a8272ecfb655f5b7~Pk-K2bw-B0810008100eucas1p2S; Wed, 15 May 2024 05:57:33 +0000 (GMT) Received: from eucas1p1.samsung.com ( [182.198.249.206]) by eusmges1new.samsung.com (EUCPMTA) with SMTP id FC.BC.09624.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 20240515055733eucas1p2804d2fb5f5bf7d6adb460054f6e9f4d8~Pk-KcM6iH1245212452eucas1p2C; Wed, 15 May 2024 05:57:33 +0000 (GMT) Received: from eusmgms2.samsung.com (unknown [182.198.249.180]) by eusmtrp1.samsung.com (KnoxPortal) with ESMTP id 20240515055733eusmtrp129539bea3fb8883a5d82c38a09701dcf~Pk-Kbl7An0411404114eusmtrp1B; Wed, 15 May 2024 05:57:33 +0000 (GMT) X-AuditID: cbfec7f2-bfbff70000002598-5c-66444ecd6288 Received: from eusmtip1.samsung.com ( [203.254.199.221]) by eusmgms2.samsung.com (EUCPMTA) with SMTP id FB.F1.09010.DCE44466; Wed, 15 May 2024 06:57:33 +0100 (BST) Received: from CAMSVWEXC01.scsc.local (unknown [106.1.227.71]) by eusmtip1.samsung.com (KnoxPortal) with ESMTPA id 20240515055733eusmtip1aa61160f14684c57a464d66ecebdd55b~Pk-KOVfKq0235902359eusmtip1T; Wed, 15 May 2024 05:57:33 +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:32 +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:32 +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 08/12] shmem: clear uptodate blocks after PUNCH_HOLE Thread-Topic: [PATCH 08/12] shmem: clear uptodate blocks after PUNCH_HOLE Thread-Index: AQHapozGSURBX17ZzUyZscS7mtN1hQ== Date: Wed, 15 May 2024 05:57:32 +0000 Message-ID: <20240515055719.32577-9-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 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrEKsWRmVeSWpSXmKPExsWy7djPc7pn/VzSDH6/UbaYs34Nm8X/vccY LV4f/sRocemonMXZvt9sFl/X/2K2uPyEz+Lppz4Wi9nTm5ksLu+aw2Zxb81/Votdf3awW+x7 vZfZ4saEp4wWB091sFv8/gGU3b4r0kHQY+esu+weCzaVemxeoeWxaVUnm8emT5PYPU7M+M3i sfOhpcfkG8sZPT4+vcXi8X7fVTaPMwuOsHt83iQXwBPFZZOSmpNZllqkb5fAldHeuJG14Kh6 xb+jrYwNjB/kuxg5OSQETCRebWtj6WLk4hASWMEoMelDOztIQkjgC6PEtGWGEPZnRomZW7Jg Ghp/zmGCaFjOKLF4YgMjhANU9O36HTYI5wyjxIMzJ1khnJWMEjOOv2AB6WcT0JTYd3ITO0hC ROA2o8TTU2fAHGaBk6wSfzbvBKsSFnCRuL7rFhuILSLgKfFr4V5WCFtPYvraZWBxFgFVicYn 7xlBbF4BS4m3i+eB1XAKWEncnf8VrIZRQFbi0cpfYB8xC4hL3HoynwniC0GJRbP3MEPYYhL/ dj1kg7B1JM5ef8IIYRtIbF26jwXCVpZY/66NCWKOnsSNqVPYIGxtiWULXzND3CAocXLmE3BQ Sgjs5JJYdmot1AIXiaaG2VCLhSVeHd/CDmHLSJye3MMygVF7FpL7ZiHZMQvJjllIdixgZFnF KJ5aWpybnlpsmJdarlecmFtcmpeul5yfu4kRmCxP/zv+aQfj3Fcf9Q4xMnEwHmKU4GBWEuEV SXNOE+JNSaysSi3Kjy8qzUktPsQozcGiJM6rmiKfKiSQnliSmp2aWpBaBJNl4uCUamCyuyT0 g1erRuSxldT9olc6/CcERZSc254s6b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WcUoklpanJueW2yk V5yYW1yal66XnJ+7iRGY8rYd+7llB+PKVx/1DjEycTAeYpTgYFYS4RVJc04T4k1JrKxKLcqP LyrNSS0+xGgKDKOJzFKiyfnApJtXEm9oZmBqaGJmaWBqaWasJM7rWdCRKCSQnliSmp2aWpBa BNPHxMEp1cCUm9kkv/Tirt2rGp0XzUvlNb3EuObMWwe7L/3l2zNkDhT9i7Ge6PHl5Nz8SGX/ W3JP1JMbzn861xzFFlnEX6/24eUj3viQ2LcVAoJ9Sa2fLzCq/55VZXmi8fQOfqFvpveKZ3wR 2DPlDIOvrMyRLJmwuxzaxQujVUsW71eRTXo56ep+pgnGgvsTmp7mNz0JEb6h5i3HMifwxfa7 a5jWC0z/HPt1o5LU2zfpsnL6T+r6/9+ytve5ofq116RCvE7lm/VTec62wAcpV0+W35fO+Pzz 1TbD6W+3Hvj+s1H8LkMXS2bTwkBfXjvjv8smra4992eR1P4Srud3cvSlmlfF1UR4Skh3H/vS ZbH48P1f0iJKLMUZiYZazEXFiQBTKjItAgQAAA== X-CMS-MailID: 20240515055733eucas1p2804d2fb5f5bf7d6adb460054f6e9f4d8 X-Msg-Generator: CA X-RootMTR: 20240515055733eucas1p2804d2fb5f5bf7d6adb460054f6e9f4d8 X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20240515055733eucas1p2804d2fb5f5bf7d6adb460054f6e9f4d8 References: <20240515055719.32577-1-da.gomez@samsung.com> In the fallocate path with PUNCH_HOLE mode flag enabled, clear the uptodate flag for those blocks covered by the punch. Skip all partial blocks as they may still contain data. Signed-off-by: Daniel Gomez --- mm/shmem.c | 78 +++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 72 insertions(+), 6 deletions(-) diff --git a/mm/shmem.c b/mm/shmem.c index e06cb6438ef8..d5e6c8eba983 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -209,6 +209,28 @@ static void sfs_set_range_uptodate(struct folio *folio, spin_unlock_irqrestore(&sfs->state_lock, flags); } +static void sfs_clear_range_uptodate(struct folio *folio, + struct shmem_folio_state *sfs, size_t off, + size_t len) +{ + struct inode *inode = folio->mapping->host; + unsigned int first_blk, last_blk; + unsigned long flags; + + first_blk = DIV_ROUND_UP_ULL(off, 1 << inode->i_blkbits); + last_blk = DIV_ROUND_DOWN_ULL(off + len, 1 << inode->i_blkbits) - 1; + if (last_blk == UINT_MAX) + return; + + if (first_blk > last_blk) + return; + + spin_lock_irqsave(&sfs->state_lock, flags); + bitmap_clear(sfs->state, first_blk, last_blk - first_blk + 1); + folio_clear_uptodate(folio); + spin_unlock_irqrestore(&sfs->state_lock, flags); +} + static struct shmem_folio_state *sfs_alloc(struct inode *inode, struct folio *folio) { @@ -276,6 +298,19 @@ static void shmem_set_range_uptodate(struct folio *folio, size_t off, else folio_mark_uptodate(folio); } + +static void shmem_clear_range_uptodate(struct folio *folio, size_t off, + size_t len) +{ + struct shmem_folio_state *sfs = folio->private; + + if (sfs) + sfs_clear_range_uptodate(folio, sfs, off, len); + else + folio_clear_uptodate(folio); + +} + #ifdef CONFIG_TMPFS static unsigned long shmem_default_max_blocks(void) { @@ -1103,12 +1138,33 @@ static struct folio *shmem_get_partial_folio(struct inode *inode, pgoff_t index) return folio; } +static void shmem_clear(struct folio *folio, loff_t start, loff_t end, int mode) +{ + loff_t pos = folio_pos(folio); + unsigned int offset, length; + + if (!(mode & FALLOC_FL_PUNCH_HOLE) || !(folio_test_large(folio))) + return; + + if (pos < start) + offset = start - pos; + else + offset = 0; + length = folio_size(folio); + if (pos + length <= (u64)end) + length = length - offset; + else + length = end + 1 - pos - offset; + + shmem_clear_range_uptodate(folio, offset, length); +} + /* * Remove range of pages and swap entries from page cache, and free them. * If !unfalloc, truncate or punch hole; if unfalloc, undo failed fallocate. */ static void shmem_undo_range(struct inode *inode, loff_t lstart, loff_t lend, - bool unfalloc) + bool unfalloc, int mode) { struct address_space *mapping = inode->i_mapping; struct shmem_inode_info *info = SHMEM_I(inode); @@ -1166,6 +1222,7 @@ static void shmem_undo_range(struct inode *inode, loff_t lstart, loff_t lend, if (folio) { same_folio = lend < folio_pos(folio) + folio_size(folio); folio_mark_dirty(folio); + shmem_clear(folio, lstart, lend, mode); if (!truncate_inode_partial_folio(folio, lstart, lend)) { start = folio_next_index(folio); if (same_folio) @@ -1255,9 +1312,17 @@ static void shmem_undo_range(struct inode *inode, loff_t lstart, loff_t lend, shmem_recalc_inode(inode, 0, -nr_swaps_freed); } +static void shmem_truncate_range_mode(struct inode *inode, loff_t lstart, + loff_t lend, int mode) +{ + shmem_undo_range(inode, lstart, lend, false, mode); + inode_set_mtime_to_ts(inode, inode_set_ctime_current(inode)); + inode_inc_iversion(inode); +} + void shmem_truncate_range(struct inode *inode, loff_t lstart, loff_t lend) { - shmem_undo_range(inode, lstart, lend, false); + shmem_undo_range(inode, lstart, lend, false, 0); inode_set_mtime_to_ts(inode, inode_set_ctime_current(inode)); inode_inc_iversion(inode); } @@ -3342,7 +3407,7 @@ static long shmem_fallocate(struct file *file, int mode, loff_t offset, if ((u64)unmap_end > (u64)unmap_start) unmap_mapping_range(mapping, unmap_start, 1 + unmap_end - unmap_start, 0); - shmem_truncate_range(inode, offset, offset + len - 1); + shmem_truncate_range_mode(inode, offset, offset + len - 1, mode); /* No need to unmap again: hole-punching leaves COWed pages */ spin_lock(&inode->i_lock); @@ -3408,9 +3473,10 @@ static long shmem_fallocate(struct file *file, int mode, loff_t offset, info->fallocend = undo_fallocend; /* Remove the !uptodate folios we added */ if (index > start) { - shmem_undo_range(inode, - (loff_t)start << PAGE_SHIFT, - ((loff_t)index << PAGE_SHIFT) - 1, true); + shmem_undo_range( + inode, (loff_t)start << PAGE_SHIFT, + ((loff_t)index << PAGE_SHIFT) - 1, true, + 0); } goto undone; } From patchwork Wed May 15 05:57:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Gomez X-Patchwork-Id: 13664628 Received: from mailout2.w1.samsung.com (mailout2.w1.samsung.com [210.118.77.12]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D82504AEE0 for ; Wed, 15 May 2024 05:57:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=210.118.77.12 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715752660; cv=none; b=Tv4A2A8r08wDC67yKVP6iOPxfpC6fNSz4ov+wfo7o4wx6PPY6bWEv/OMeLMJP7USeUIRrM80EfW0KovjiLCP2wMt0ekdh4DnGEKAqiSsza2sIXscDzcmuFHYI/XnfENDo0aBZSjEsOmk470bOgSgJiojvheVeKxJ6yXOXYPpi0I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715752660; c=relaxed/simple; bh=XBBTszZS8nSEUwCRzHqmScQZNOWKWiftnOHPAays+8Y=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:Content-Type: MIME-Version:References; b=NG1JYLpW8PkDg6+5W8RMGIcb8rTJvQ6wRoIpJMbIHivEmVEmC0iQo1i1jwcoV6VHTY1sDi5uPyQc4WuvJWosHPpsDXxbtcjNo9lUR0ko0TqmcBOsynhiVA/Dl1ccqYqqgDhC+m/qgstCwDY8T3eYKBfMSuuXrm/NX42wOQg0ZV0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=samsung.com; spf=pass smtp.mailfrom=samsung.com; dkim=pass (1024-bit key) header.d=samsung.com header.i=@samsung.com header.b=HEognthI; arc=none smtp.client-ip=210.118.77.12 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=samsung.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=samsung.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=samsung.com header.i=@samsung.com header.b="HEognthI" Received: from eucas1p1.samsung.com (unknown [182.198.249.206]) by mailout2.w1.samsung.com (KnoxPortal) with ESMTP id 20240515055737euoutp02d828e3eaa4628fe4d29fc01700d17ba2~Pk-OgZ0Tl2017920179euoutp02O for ; Wed, 15 May 2024 05:57:37 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.w1.samsung.com 20240515055737euoutp02d828e3eaa4628fe4d29fc01700d17ba2~Pk-OgZ0Tl2017920179euoutp02O DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1715752657; bh=t+LtSI8A+WgybP8NqP+rojjUG/bT6woZXyJ+I7vfPH0=; h=From:To:CC:Subject:Date:In-Reply-To:References:From; b=HEognthIkmnPhdriZmRVNdoD04/O3Jx12OyZQOvs8XEUQzLhmTjExcmavKd/QTIJ6 QD+bRgRur7e2X1q8N4G3leH8yfJKGyRPLzQtTWKsY3LrlnINuMIMKA15SFLMg9VqMU HpWo8N22zTYQVCRt7km9m1RtlQ8/cMa9GMrkwhUQ= Received: from eusmges2new.samsung.com (unknown [203.254.199.244]) by eucas1p2.samsung.com (KnoxPortal) with ESMTP id 20240515055736eucas1p2f25fe01f090462c69e1148cea0c1d5a8~Pk-NBWHHN1079110791eucas1p2h; Wed, 15 May 2024 05:57:36 +0000 (GMT) Received: from eucas1p1.samsung.com ( [182.198.249.206]) by eusmges2new.samsung.com (EUCPMTA) with SMTP id 37.D8.09875.FCE44466; Wed, 15 May 2024 06:57:35 +0100 (BST) Received: from eusmtrp2.samsung.com (unknown [182.198.249.139]) by eucas1p2.samsung.com (KnoxPortal) with ESMTPA id 20240515055735eucas1p2a967b4eebc8e059588cd62139f006b0d~Pk-MUqVPC0808808088eucas1p2V; Wed, 15 May 2024 05:57:35 +0000 (GMT) Received: from eusmgms1.samsung.com (unknown [182.198.249.179]) by eusmtrp2.samsung.com (KnoxPortal) with ESMTP id 20240515055735eusmtrp2b5840e2e22c2bff3b8f61569b97ef6b3~Pk-MUA_zl0256302563eusmtrp2P; Wed, 15 May 2024 05:57:35 +0000 (GMT) X-AuditID: cbfec7f4-11bff70000002693-ef-66444ecfdcc6 Received: from eusmtip1.samsung.com ( [203.254.199.221]) by eusmgms1.samsung.com (EUCPMTA) with SMTP id 5F.16.08810.FCE44466; Wed, 15 May 2024 06:57:35 +0100 (BST) Received: from CAMSVWEXC01.scsc.local (unknown [106.1.227.71]) by eusmtip1.samsung.com (KnoxPortal) with ESMTPA id 20240515055735eusmtip17eac0a1eafc6d97691a64a17f60abd3d~Pk-MHq1jo0512205122eusmtip1a; Wed, 15 May 2024 05:57:35 +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:34 +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:34 +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 09/12] shmem: enable per-block uptodate Thread-Topic: [PATCH 09/12] shmem: enable per-block uptodate Thread-Index: AQHapozH2Ew2w2FSxkCziesEgQoVNA== Date: Wed, 15 May 2024 05:57:33 +0000 Message-ID: <20240515055719.32577-10-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 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrAKsWRmVeSWpSXmKPExsWy7djPc7rn/VzSDPbNtrKYs34Nm8X/vccY LV4f/sRocemonMXZvt9sFl/X/2K2uPyEz+Lppz4Wi9nTm5ksLu+aw2Zxb81/Votdf3awW+x7 vZfZ4saEp4wWB091sFv8/gGU3b4r0kHQY+esu+weCzaVemxeoeWxaVUnm8emT5PYPU7M+M3i sfOhpcfkG8sZPT4+vcXi8X7fVTaPMwuOsHt83iQXwBPFZZOSmpNZllqkb5fAlbHpkl7BRdaK /s7TTA2Md1m6GDk5JARMJH5/bWMHsYUEVjBKzL7F1sXIBWR/YZRoef2WEcL5zCjx4soiuI65 Mx6yQiSWM0o83vCJFaIdqOrydhGIxBlGidYHD9kgEisZJS421oHYbAKaEvtObmIHKRIRuM0o 8fTUGTCHWeAkq8SfzTvBdggLmEtcWD4RrFtEwEbi4cYOdghbT+Jj43Uwm0VAVWLhghvMIDav gJXE1k2rGEFsTiD77vyvYL2MArISj1b+AqtnFhCXuPVkPhPED4ISi2bvYYawxST+7YK4VEJA R+Ls9SeMELaBxNal+6B+VpZY/66NCWKOnsSNqVPYIGxtiWULX0PdIChxcuYTFpBnJAR2cknM mLwGaoGLxNcdbawQtrDEq+Nb2CFsGYn/O+czTWDUnoXkvllIdsxCsmMWkh0LGFlWMYqnlhbn pqcWG+WllusVJ+YWl+al6yXn525iBCbK0/+Of9nBuPzVR71DjEwcjIcYJTiYlUR4RdKc04R4 UxIrq1KL8uOLSnNSiw8xSnOwKInzqqbIpwoJpCeWpGanphakFsFkmTg4pRqYItfPnKL13/N9 3Mmj9yZ4LaooeBtY0ipsmMVQdb7qsIvZsWYzo38fKn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n7uJkZgwtt27OfmHYzzXn3UO8TIxMF4iFGCg1lJhFckzTlNiDclsbIqtSg/ vqg0J7X4EKMpMIwmMkuJJucDU25eSbyhmYGpoYmZpYGppZmxkjivZ0FHopBAemJJanZqakFq EUwfEwenVAPTxKx7kpMdTk1gaEwzlotyMuPwMubXuvOr9bfb8lfK98zW6h0yT1/RGp7sZX1U ULTKx8Zo6ZzSZ+8/lRnKRiuclAj9+T+i5M5MI0WTF8mfJmyudbWVbgg22uCvtqYqS63nfGFV lkrQXDsldc5Y/2kvF1qkty7S2bWWP7ZapONfpPaluxHlT36ZbZC7GniT48RR9u2cBT/KhRfx 3Up5KrRzYpAv1wf3qa8zV3EF8B8tf9fpoZipnSTX7rSAZc/dBW+yLNanvxRmnbNo/tSF9eVv DaTP79r1JHjf9Yr/N1Jir5df7pG3l2zWubP6iclxzeWxs9dcnetiVtXqfPFJ9sOUIJfnNqZt AlHiC/UXMSmxFGckGmoxFxUnAgA2YmL4AQQAAA== X-CMS-MailID: 20240515055735eucas1p2a967b4eebc8e059588cd62139f006b0d X-Msg-Generator: CA X-RootMTR: 20240515055735eucas1p2a967b4eebc8e059588cd62139f006b0d X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20240515055735eucas1p2a967b4eebc8e059588cd62139f006b0d References: <20240515055719.32577-1-da.gomez@samsung.com> In the write_end() function, mark only the blocks that are being written as uptodate. Signed-off-by: Daniel Gomez --- mm/shmem.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm/shmem.c b/mm/shmem.c index d5e6c8eba983..7a6ad678e2ff 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -2991,7 +2991,7 @@ shmem_write_end(struct file *file, struct address_space *mapping, if (pos + copied > inode->i_size) i_size_write(inode, pos + copied); - shmem_set_range_uptodate(folio, 0, folio_size(folio)); + shmem_set_range_uptodate(folio, offset_in_folio(folio, pos), len); folio_mark_dirty(folio); folio_unlock(folio); folio_put(folio); From patchwork Wed May 15 05:57:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Gomez X-Patchwork-Id: 13664627 Received: from mailout1.w1.samsung.com (mailout1.w1.samsung.com [210.118.77.11]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C11804AEDD for ; Wed, 15 May 2024 05:57:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=210.118.77.11 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715752660; cv=none; b=CUiAYS8Afq7Us2ytavfABIdlCNs7dopPURiFP8XxjqoNydhgmvUNugKf/RvdhYmoKP0BnOi9adJyniDT7LnbiWjauZFPxb902FvGDqbGB7TOXphvWXh1T9cW5pF+xt98gmuhyqKJp1bETmwu2AX9AGPd8LMuhgKaoHDsV928aTg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715752660; c=relaxed/simple; bh=0RjdBokNWoS+vSi83hgJATS/2MIQWi5fahvmgWZkpmk=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:Content-Type: MIME-Version:References; b=tavBd/wcTkGANEMyYDvywVzOXkW4hP55DPJtKEZY5EL6+bbNgEQPqbI9HGNbG/ix34km8Xm9QZ11AeOee/phoWlZ/xGd88NPIrUvyrSl4hAzvlqVj4yR7CZZXfowkXizsOmDLJRCDDZC2ecbGLZ8q7+/9HFyuoWotTTm5kmoCok= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=samsung.com; spf=pass smtp.mailfrom=samsung.com; dkim=pass (1024-bit key) header.d=samsung.com header.i=@samsung.com header.b=XE0WeUZ4; arc=none smtp.client-ip=210.118.77.11 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=samsung.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=samsung.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=samsung.com header.i=@samsung.com header.b="XE0WeUZ4" Received: from eucas1p2.samsung.com (unknown [182.198.249.207]) by mailout1.w1.samsung.com (KnoxPortal) with ESMTP id 20240515055737euoutp01bb0dd00b00eb3dfee23706a812c60540~Pk-OZp7k91508115081euoutp01L for ; Wed, 15 May 2024 05:57:37 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.w1.samsung.com 20240515055737euoutp01bb0dd00b00eb3dfee23706a812c60540~Pk-OZp7k91508115081euoutp01L DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1715752657; bh=KSFa/00drIrpTPTVaHKTJFLNN4vEYokk0j2qhn9ASTY=; h=From:To:CC:Subject:Date:In-Reply-To:References:From; b=XE0WeUZ4/fxHAxJkG/mIY/WGU0C4ZHUEw5qzBkuqT9YA+ux6u/VMvXpPQ5QfXZsCN RAdqw8x6EFSJ3Uy0xmtAXcHqL9FipFkZbQdC03MkUvzvsQe44ht0ez97k3oK7S9HbB ZKW8iyeunnHh5sOncAza29RBBZxrEoJLw6eIoNhE= Received: from eusmges2new.samsung.com (unknown [203.254.199.244]) by eucas1p2.samsung.com (KnoxPortal) with ESMTP id 20240515055737eucas1p2687839099f1491893036e9edf50d6776~Pk-N8z2ap0810008100eucas1p2W; Wed, 15 May 2024 05:57:37 +0000 (GMT) Received: from eucas1p2.samsung.com ( [182.198.249.207]) by eusmges2new.samsung.com (EUCPMTA) with SMTP id 58.D8.09875.0DE44466; Wed, 15 May 2024 06:57:36 +0100 (BST) Received: from eusmtrp1.samsung.com (unknown [182.198.249.138]) by eucas1p1.samsung.com (KnoxPortal) with ESMTPA id 20240515055736eucas1p1bfa9549398e766532d143ba9314bee18~Pk-NPUDB_1859218592eucas1p1L; Wed, 15 May 2024 05:57:36 +0000 (GMT) Received: from eusmgms2.samsung.com (unknown [182.198.249.180]) by eusmtrp1.samsung.com (KnoxPortal) with ESMTP id 20240515055736eusmtrp1cd38f7c68e33115cb0f700536a34b1e1~Pk-NOpRJH0411404114eusmtrp1C; Wed, 15 May 2024 05:57:36 +0000 (GMT) X-AuditID: cbfec7f4-11bff70000002693-f1-66444ed03f5f Received: from eusmtip1.samsung.com ( [203.254.199.221]) by eusmgms2.samsung.com (EUCPMTA) with SMTP id 6D.F1.09010.0DE44466; Wed, 15 May 2024 06:57:36 +0100 (BST) Received: from CAMSVWEXC01.scsc.local (unknown [106.1.227.71]) by eusmtip1.samsung.com (KnoxPortal) with ESMTPA id 20240515055736eusmtip10c080390bd41a09baa29d247f828f893~Pk-NCedQq0562705627eusmtip1T; Wed, 15 May 2024 05:57:36 +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:35 +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:35 +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 10/12] shmem: add order arg to shmem_alloc_folio() Thread-Topic: [PATCH 10/12] shmem: add order arg to shmem_alloc_folio() Thread-Index: AQHapozIzXRp8FIrX0Ow3XgDmWV32Q== Date: Wed, 15 May 2024 05:57:35 +0000 Message-ID: <20240515055719.32577-11-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 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrIKsWRmVeSWpSXmKPExsWy7djP87oX/FzSDHZ9srSYs34Nm8X/vccY LV4f/sRocemonMXZvt9sFl/X/2K2uPyEz+Lppz4Wi9nTm5ksLu+aw2Zxb81/Votdf3awW+x7 vZfZ4saEp4wWB091sFv8/gGU3b4r0kHQY+esu+weCzaVemxeoeWxaVUnm8emT5PYPU7M+M3i sfOhpcfkG8sZPT4+vcXi8X7fVTaPMwuOsHt83iQXwBPFZZOSmpNZllqkb5fAlTHv32L2gg3i Ff9/bmJpYOwU7mLk5JAQMJHYOuUDaxcjF4eQwApGid2LZ7ODJIQEvjBKvH2cDJH4zCjx9f1W dpiOWXcus0AkljNKzOxfyA5XtXDBaWYI5wyjxKO7kxghZq1klDjzUATEZhPQlNh3chNYh4jA bUaJp6fOgDnMAidZJf5s3skCUiUs4CSx93wLM4gtIuAucfTWLBYIW0/i9MsZYFNZBFQlJqz7 AFbDK2AlsfTrObA4J5B9d/5XNhCbUUBW4tHKX2CHMwuIS9x6Mp8J4glBiUWz9zBD2GIS/3Y9 ZIOwdSTOXn/CCGEbSGxduo8FwlaWWP+ujQlijp7EjalT2CBsbYllC19D3SAocXLmE6j6nVwS zTfrIGwXicPPzkADT1ji1fEtULaMxOnJPSwTGLVnITlvFpIVs5CsmIVkxQJGllWM4qmlxbnp qcVGeanlesWJucWleel6yfm5mxiBqfL0v+NfdjAuf/VR7xAjEwfjIUYJDmYlEV6RNOc0Id6U xMq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0q8fPwP6jcdibPXnzBC2AYSW5fuY4GwlSXWv2tj gpijJ3Fj6hQ2CFtbYtnC11D3CEqcnPmEZQKj9Cwk62YhaZmFpGUWkpYFjCyrGEVSS4tz03OL jfSKE3OLS/PS9ZLzczcxAhPetmM/t+xgXPnqo94hRiYOxkOMEhzMSiK8ImnOaUK8KYmVValF +fFFpTmpxYcYTYFhNJFZSjQ5H5hy80riDc0MTA1NzCwNTC3NjJXEeT0LOhKFBNITS1KzU1ML Uotg+pg4OKUamFgN7O6vOHnc/+p+pr9Ptq9pbzyg0zx7rvZNdukX8xz+sGyS/yXUdlXCLUG4 RkrP3k0sIeRWWpYbp7W6+swXmryvFv1ct23Rokmt35dM1/51cvc13v/SKidS/eqTelQ6bjI+ URAuN2Hnz2cKvxJ3SS3k8rTZgXsMYh8fPV67x6F5mtyMxX1dQW6nZq/iz/BW7C8NUJbcUZCm cd5f3z2ornxusa1H1MfPUpG3J5qfbeUTO/vqgdPit1Wf+n2VN683NlI+lXLmFzPfA2uuM3Wb RN26T/LqZJQ7Xdsp75R5I+DXvy2Kf9V/LLRl9HQS6FkyYVOQ/5cEt8SoGYFT1nilvJnKs9FW P/vf0+B+vnM8SizFGYmGWsxFxYkAp8+SoAEEAAA= X-CMS-MailID: 20240515055736eucas1p1bfa9549398e766532d143ba9314bee18 X-Msg-Generator: CA X-RootMTR: 20240515055736eucas1p1bfa9549398e766532d143ba9314bee18 X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20240515055736eucas1p1bfa9549398e766532d143ba9314bee18 References: <20240515055719.32577-1-da.gomez@samsung.com> Add folio order argument to the shmem_alloc_folio(). Return will make use of the new page_rmappable_folio() where order-0 and high order folios are both supported. As the order requested may not match the order returned when allocating high order folios, make sure pages are calculated after getting the folio. Signed-off-by: Daniel Gomez --- mm/shmem.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/mm/shmem.c b/mm/shmem.c index 7a6ad678e2ff..d531018ffece 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -1828,18 +1828,18 @@ static struct folio *shmem_alloc_hugefolio(gfp_t gfp, return page_rmappable_folio(page); } -static struct folio *shmem_alloc_folio(gfp_t gfp, - struct shmem_inode_info *info, pgoff_t index) +static struct folio *shmem_alloc_folio(gfp_t gfp, struct shmem_inode_info *info, + pgoff_t index, unsigned int order) { struct mempolicy *mpol; pgoff_t ilx; struct page *page; - mpol = shmem_get_pgoff_policy(info, index, 0, &ilx); - page = alloc_pages_mpol(gfp, 0, mpol, ilx, numa_node_id()); + mpol = shmem_get_pgoff_policy(info, index, order, &ilx); + page = alloc_pages_mpol(gfp, order, mpol, ilx, numa_node_id()); mpol_cond_put(mpol); - return (struct folio *)page; + return page_rmappable_folio(page); } static struct folio *shmem_alloc_and_add_folio(gfp_t gfp, @@ -1848,6 +1848,7 @@ static struct folio *shmem_alloc_and_add_folio(gfp_t gfp, { struct address_space *mapping = inode->i_mapping; struct shmem_inode_info *info = SHMEM_I(inode); + unsigned int order = 0; struct folio *folio; long pages; int error; @@ -1856,7 +1857,6 @@ static struct folio *shmem_alloc_and_add_folio(gfp_t gfp, huge = false; if (huge) { - pages = HPAGE_PMD_NR; index = round_down(index, HPAGE_PMD_NR); /* @@ -1875,12 +1875,13 @@ static struct folio *shmem_alloc_and_add_folio(gfp_t gfp, if (!folio) count_vm_event(THP_FILE_FALLBACK); } else { - pages = 1; - folio = shmem_alloc_folio(gfp, info, index); + folio = shmem_alloc_folio(gfp, info, index, order); } if (!folio) return ERR_PTR(-ENOMEM); + pages = folio_nr_pages(folio); + __folio_set_locked(folio); __folio_set_swapbacked(folio); @@ -1976,7 +1977,7 @@ static int shmem_replace_folio(struct folio **foliop, gfp_t gfp, */ gfp &= ~GFP_CONSTRAINT_MASK; VM_BUG_ON_FOLIO(folio_test_large(old), old); - new = shmem_alloc_folio(gfp, info, index); + new = shmem_alloc_folio(gfp, info, index, folio_order(old)); if (!new) return -ENOMEM; @@ -2855,7 +2856,7 @@ int shmem_mfill_atomic_pte(pmd_t *dst_pmd, if (!*foliop) { ret = -ENOMEM; - folio = shmem_alloc_folio(gfp, info, pgoff); + folio = shmem_alloc_folio(gfp, info, pgoff, 0); if (!folio) goto out_unacct_blocks; From patchwork Wed May 15 05:57:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Gomez X-Patchwork-Id: 13664629 Received: from mailout2.w1.samsung.com (mailout2.w1.samsung.com [210.118.77.12]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9B1BF4EB3C for ; Wed, 15 May 2024 05:57:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=210.118.77.12 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715752662; cv=none; b=qHLpDn8WQU/YvbB/na5BDY19memc0ElCJoIn0anPLzvjVeYVKZY0923Uzy2rfi+KsqPffvzbcPiRA1VW9dpp3fs0YC8cE0u2sefcUJ6zRzei9ihFx8+Eicm5V5CupLO/EaFCD7KkSxBE6nvU0YztH8a6H5gKNpx2f6tqqTIZFZ0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715752662; c=relaxed/simple; bh=ysNTQu2FZmxm2DeMyyYooKIt081V6zV0r+ddDudM9pQ=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:Content-Type: MIME-Version:References; b=Oy+1d1R/h9RwyzqvaVvmYC9pyIMt66B6K/xlD2C8Q7jeB1ZhuQOTF/IngGsta5tbKaBE5WnhC599Lx7QUAnYbRkK12c0mmLwEQrgXJGoyX9u0spts07fC0I3vnDdeJhkyPijZ4gC3VtlxvvHS790abM7B7HiDWlVUj4WyQbqD5U= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=samsung.com; spf=pass smtp.mailfrom=samsung.com; dkim=pass (1024-bit key) header.d=samsung.com header.i=@samsung.com header.b=U9Enp2W+; arc=none smtp.client-ip=210.118.77.12 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=samsung.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=samsung.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=samsung.com header.i=@samsung.com header.b="U9Enp2W+" Received: from eucas1p2.samsung.com (unknown [182.198.249.207]) by mailout2.w1.samsung.com (KnoxPortal) with ESMTP id 20240515055739euoutp0283df8f5c448a2808fb2aeb7fdf6826b7~Pk-P6Xhp11566715667euoutp02A for ; Wed, 15 May 2024 05:57:39 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.w1.samsung.com 20240515055739euoutp0283df8f5c448a2808fb2aeb7fdf6826b7~Pk-P6Xhp11566715667euoutp02A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1715752659; bh=YnJglILKqFkdTEiFzR72jsMog/cpgSZTzUSnpJww0Pw=; h=From:To:CC:Subject:Date:In-Reply-To:References:From; b=U9Enp2W+Lk709O62hv/eifsGkq8F1T0sf+tU1Dy4hamOZKVWmPbcclBPJ+kNHSU0N 2O5HlteJ/HiOo9ctcvkG9N5/pZXo9EH7pTbAZAN5SdB+2gXHGu7Yz2xNahommkyvfu uUR15N41Ab7XFV4FDD9ghctG+FI6p7gfoQCz81cI= Received: from eusmges3new.samsung.com (unknown [203.254.199.245]) by eucas1p2.samsung.com (KnoxPortal) with ESMTP id 20240515055738eucas1p2ee046cb2cbd220fc7d567cbe8c42157c~Pk-PmR0te1241412414eucas1p2E; Wed, 15 May 2024 05:57:38 +0000 (GMT) Received: from eucas1p2.samsung.com ( [182.198.249.207]) by eusmges3new.samsung.com (EUCPMTA) with SMTP id B3.97.09620.2DE44466; Wed, 15 May 2024 06:57:38 +0100 (BST) Received: from eusmtrp2.samsung.com (unknown [182.198.249.139]) by eucas1p1.samsung.com (KnoxPortal) with ESMTPA id 20240515055738eucas1p15335a32c790b731aa5857193bbddf92d~Pk-POZAf12872228722eucas1p1l; Wed, 15 May 2024 05:57:38 +0000 (GMT) Received: from eusmgms1.samsung.com (unknown [182.198.249.179]) by eusmtrp2.samsung.com (KnoxPortal) with ESMTP id 20240515055738eusmtrp2b09bc45b45a944e66f031ac0931385d5~Pk-PNwuEc0256302563eusmtrp2U; Wed, 15 May 2024 05:57:38 +0000 (GMT) X-AuditID: cbfec7f5-d31ff70000002594-cf-66444ed2cdbd Received: from eusmtip1.samsung.com ( [203.254.199.221]) by eusmgms1.samsung.com (EUCPMTA) with SMTP id C4.26.08810.2DE44466; Wed, 15 May 2024 06:57:38 +0100 (BST) Received: from CAMSVWEXC02.scsc.local (unknown [106.1.227.72]) by eusmtip1.samsung.com (KnoxPortal) with ESMTPA id 20240515055738eusmtip13dda217c4b57766f5e88e5a9ca71a2c7~Pk-O_ejJe0562305623eusmtip1V; Wed, 15 May 2024 05:57:38 +0000 (GMT) Received: from CAMSVWEXC02.scsc.local (2002:6a01:e348::6a01:e348) by CAMSVWEXC02.scsc.local (2002:6a01:e348::6a01:e348) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Wed, 15 May 2024 06:57:37 +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:37 +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 11/12] shmem: add file length arg in shmem_get_folio() path Thread-Topic: [PATCH 11/12] shmem: add file length arg in shmem_get_folio() path Thread-Index: AQHapozJF6Lbb0RRX0KKO162vQDDlA== Date: Wed, 15 May 2024 05:57:36 +0000 Message-ID: <20240515055719.32577-12-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 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrEKsWRmVeSWpSXmKPExsWy7djP87qX/FzSDKbM0raYs34Nm8X/vccY LV4f/sRocemonMXZvt9sFl/X/2K2uPyEz+Lppz4Wi9nTm5ksLu+aw2Zxb81/Votdf3awW+x7 vZfZ4saEp4wWB091sFv8/gGU3b4r0kHQY+esu+weCzaVemxeoeWxaVUnm8emT5PYPU7M+M3i sfOhpcfkG8sZPT4+vcXi8X7fVTaPMwuOsHt83iQXwBPFZZOSmpNZllqkb5fAlTH5YQd7QaNH xY6POxkbGM9YdjFyckgImEj0nO5nArGFBFYwSvyaodrFyAVkf2GUeNt+jxHC+cwocfDlYUaY jnPNn1kgEssZJT7N/M8MV9XxciMThHOGUaLxxy6ozEpGiVO/14H1swloSuw7uYkdJCEicJtR 4umpM2AOs8BJVok/m3eygFQJC3hLHD+3ixXEFhEIkrh84yRQNweQrSfxcrIsSJhFQFXizZ0z zCA2r4CVxIfPX8FaOYHsu/O/soHYjAKyEo9W/mIHsZkFxCVuPZnPBPGEoMSi2XuYIWwxiX+7 HrJB2DoSZ68/gXrUQGLr0n0sELayxPp3bUwQc/QkbkydwgZha0ssW/ga6gZBiZ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pM2AOs8BJVokDpz+zg1QJC3hLHD+3C2gJB1BVkMSb ZVwQpp7Ey8myIBUsAqoSb+6cYQaxeQWsJD58/soCYgsJWEpcerWdEcTmBIrfnf8VbC+jgKzE o5W/wKYzC4hL3HoynwniBQGJJXvOM0PYohIvH/+Dek1H4uz1J4wQtoHE1qX7WCBsZYn179qY IOboSdyYOoUNwtaWWLbwNdQ9ghInZz5hmcAoPQvJullIWmYhaZmFpGUBI8sqRpHU0uLc9Nxi Q73ixNzi0rx0veT83E2MwHS37djPzTsY5736qHeIkYmD8RCjBAezkgivSJpzmhBvSmJlVWpR fnxRaU5q8SFGU2AYTWSWEk3OBybcvJJ4QzMDU0MTM0sDU0szYyVxXs+CjkQhgfTEktTs1NSC 1CKYPiYOTqkGJm3xhav3XuXjOtuTN9NX5kfootTNXQks34OZbrbM/y6zfd+FoM0OE2t2LZdo 2DlppdhB9oPXZpp1C78vuOOqql2TdkP52CmrOx1HRV1n7+Rc9TVDSkvjqELZ4RPONmueKQb1 i8ZtPtz/6ufRfxxZHe7N+7JSn1Uc3tqa7m6iEvpYcd4+/dCGtb9iq/g9lhkeWT97/3yHv+yv Nk5lLLs1b9KzRTGHd2qdTrqx+oXxvZQf/7ZtP75n4kdvhe99Uwv2LTvZtHryu+uGy+Q/+79+ +f6s30/b+4rn1OuUHXRE7+oLcrvKf9VkvfuW44EF80UtXfNLPbskZgrZnstMe3VlY86cf99P 6v26GbnStP9iqguHEktxRqKhFnNRcSIAJzOFFgAEAAA= X-CMS-MailID: 20240515055738eucas1p15335a32c790b731aa5857193bbddf92d X-Msg-Generator: CA X-RootMTR: 20240515055738eucas1p15335a32c790b731aa5857193bbddf92d X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20240515055738eucas1p15335a32c790b731aa5857193bbddf92d References: <20240515055719.32577-1-da.gomez@samsung.com> In preparation for large folio in the write and fallocate paths, add file length argument in shmem_get_folio() path to be able to calculate the folio order based on the file size. Use of order-0 (PAGE_SIZE) for read, page cache read, and vm fault. This enables high order folios in the write and fallocate path once the folio order is calculated based on the length. Signed-off-by: Daniel Gomez --- fs/xfs/scrub/xfile.c | 6 +++--- fs/xfs/xfs_buf_mem.c | 3 ++- include/linux/shmem_fs.h | 2 +- mm/khugepaged.c | 3 ++- mm/shmem.c | 35 ++++++++++++++++++++--------------- mm/userfaultfd.c | 2 +- 6 files changed, 29 insertions(+), 22 deletions(-) diff --git a/fs/xfs/scrub/xfile.c b/fs/xfs/scrub/xfile.c index 8cdd863db585..4905f5e4cb5d 100644 --- a/fs/xfs/scrub/xfile.c +++ b/fs/xfs/scrub/xfile.c @@ -127,7 +127,7 @@ xfile_load( unsigned int offset; if (shmem_get_folio(inode, pos >> PAGE_SHIFT, &folio, - SGP_READ) < 0) + SGP_READ, PAGE_SIZE) < 0) break; if (!folio) { /* @@ -197,7 +197,7 @@ xfile_store( unsigned int offset; if (shmem_get_folio(inode, pos >> PAGE_SHIFT, &folio, - SGP_CACHE) < 0) + SGP_CACHE, PAGE_SIZE) < 0) break; if (filemap_check_wb_err(inode->i_mapping, 0)) { folio_unlock(folio); @@ -268,7 +268,7 @@ xfile_get_folio( pflags = memalloc_nofs_save(); error = shmem_get_folio(inode, pos >> PAGE_SHIFT, &folio, - (flags & XFILE_ALLOC) ? SGP_CACHE : SGP_READ); + (flags & XFILE_ALLOC) ? SGP_CACHE : SGP_READ, PAGE_SIZE); memalloc_nofs_restore(pflags); if (error) return ERR_PTR(error); diff --git a/fs/xfs/xfs_buf_mem.c b/fs/xfs/xfs_buf_mem.c index 9bb2d24de709..784c81d35a1f 100644 --- a/fs/xfs/xfs_buf_mem.c +++ b/fs/xfs/xfs_buf_mem.c @@ -149,7 +149,8 @@ xmbuf_map_page( return -ENOMEM; } - error = shmem_get_folio(inode, pos >> PAGE_SHIFT, &folio, SGP_CACHE); + error = shmem_get_folio(inode, pos >> PAGE_SHIFT, &folio, SGP_CACHE, + PAGE_SIZE); if (error) return error; diff --git a/include/linux/shmem_fs.h b/include/linux/shmem_fs.h index 3fb18f7eb73e..bc59b4a00228 100644 --- a/include/linux/shmem_fs.h +++ b/include/linux/shmem_fs.h @@ -142,7 +142,7 @@ enum sgp_type { }; int shmem_get_folio(struct inode *inode, pgoff_t index, struct folio **foliop, - enum sgp_type sgp); + enum sgp_type sgp, size_t len); struct folio *shmem_read_folio_gfp(struct address_space *mapping, pgoff_t index, gfp_t gfp); diff --git a/mm/khugepaged.c b/mm/khugepaged.c index 38830174608f..947770ded68c 100644 --- a/mm/khugepaged.c +++ b/mm/khugepaged.c @@ -1863,7 +1863,8 @@ static int collapse_file(struct mm_struct *mm, unsigned long addr, xas_unlock_irq(&xas); /* swap in or instantiate fallocated page */ if (shmem_get_folio(mapping->host, index, - &folio, SGP_NOALLOC)) { + &folio, SGP_NOALLOC, + PAGE_SIZE)) { result = SCAN_FAIL; goto xa_unlocked; } diff --git a/mm/shmem.c b/mm/shmem.c index d531018ffece..fcd2c9befe19 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -1134,7 +1134,7 @@ static struct folio *shmem_get_partial_folio(struct inode *inode, pgoff_t index) * (although in some cases this is just a waste of time). */ folio = NULL; - shmem_get_folio(inode, index, &folio, SGP_READ); + shmem_get_folio(inode, index, &folio, SGP_READ, PAGE_SIZE); return folio; } @@ -1844,7 +1844,7 @@ static struct folio *shmem_alloc_folio(gfp_t gfp, struct shmem_inode_info *info, static struct folio *shmem_alloc_and_add_folio(gfp_t gfp, struct inode *inode, pgoff_t index, - struct mm_struct *fault_mm, bool huge) + struct mm_struct *fault_mm, bool huge, size_t len) { struct address_space *mapping = inode->i_mapping; struct shmem_inode_info *info = SHMEM_I(inode); @@ -2173,7 +2173,7 @@ static int shmem_swapin_folio(struct inode *inode, pgoff_t index, */ static int shmem_get_folio_gfp(struct inode *inode, pgoff_t index, struct folio **foliop, enum sgp_type sgp, gfp_t gfp, - struct vm_fault *vmf, vm_fault_t *fault_type) + struct vm_fault *vmf, vm_fault_t *fault_type, size_t len) { struct vm_area_struct *vma = vmf ? vmf->vma : NULL; struct mm_struct *fault_mm; @@ -2258,7 +2258,7 @@ static int shmem_get_folio_gfp(struct inode *inode, pgoff_t index, huge_gfp = vma_thp_gfp_mask(vma); huge_gfp = limit_gfp_mask(huge_gfp, gfp); folio = shmem_alloc_and_add_folio(huge_gfp, - inode, index, fault_mm, true); + inode, index, fault_mm, true, len); if (!IS_ERR(folio)) { count_vm_event(THP_FILE_ALLOC); goto alloced; @@ -2267,7 +2267,8 @@ static int shmem_get_folio_gfp(struct inode *inode, pgoff_t index, goto repeat; } - folio = shmem_alloc_and_add_folio(gfp, inode, index, fault_mm, false); + folio = shmem_alloc_and_add_folio(gfp, inode, index, fault_mm, false, + len); if (IS_ERR(folio)) { error = PTR_ERR(folio); if (error == -EEXIST) @@ -2377,10 +2378,10 @@ static int shmem_get_folio_gfp(struct inode *inode, pgoff_t index, * Return: 0 if successful, else a negative error code. */ int shmem_get_folio(struct inode *inode, pgoff_t index, struct folio **foliop, - enum sgp_type sgp) + enum sgp_type sgp, size_t len) { return shmem_get_folio_gfp(inode, index, foliop, sgp, - mapping_gfp_mask(inode->i_mapping), NULL, NULL); + mapping_gfp_mask(inode->i_mapping), NULL, NULL, len); } EXPORT_SYMBOL_GPL(shmem_get_folio); @@ -2475,7 +2476,7 @@ static vm_fault_t shmem_fault(struct vm_fault *vmf) WARN_ON_ONCE(vmf->page != NULL); err = shmem_get_folio_gfp(inode, vmf->pgoff, &folio, SGP_CACHE, - gfp, vmf, &ret); + gfp, vmf, &ret, PAGE_SIZE); if (err) return vmf_error(err); if (folio) { @@ -2954,6 +2955,9 @@ shmem_write_begin(struct file *file, struct address_space *mapping, struct folio *folio; int ret = 0; + if (!mapping_large_folio_support(mapping)) + len = min_t(size_t, len, PAGE_SIZE - offset_in_page(pos)); + /* i_rwsem is held by caller */ if (unlikely(info->seals & (F_SEAL_GROW | F_SEAL_WRITE | F_SEAL_FUTURE_WRITE))) { @@ -2963,7 +2967,7 @@ shmem_write_begin(struct file *file, struct address_space *mapping, return -EPERM; } - ret = shmem_get_folio(inode, index, &folio, SGP_WRITE); + ret = shmem_get_folio(inode, index, &folio, SGP_WRITE, len); if (ret) return ret; @@ -3083,7 +3087,7 @@ static ssize_t shmem_file_read_iter(struct kiocb *iocb, struct iov_iter *to) break; } - error = shmem_get_folio(inode, index, &folio, SGP_READ); + error = shmem_get_folio(inode, index, &folio, SGP_READ, PAGE_SIZE); if (error) { if (error == -EINVAL) error = 0; @@ -3260,7 +3264,7 @@ static ssize_t shmem_file_splice_read(struct file *in, loff_t *ppos, break; error = shmem_get_folio(inode, *ppos / PAGE_SIZE, &folio, - SGP_READ); + SGP_READ, PAGE_SIZE); if (error) { if (error == -EINVAL) error = 0; @@ -3469,7 +3473,8 @@ static long shmem_fallocate(struct file *file, int mode, loff_t offset, error = -ENOMEM; else error = shmem_get_folio(inode, index, &folio, - SGP_FALLOC); + SGP_FALLOC, + (end - index) << PAGE_SHIFT); if (error) { info->fallocend = undo_fallocend; /* Remove the !uptodate folios we added */ @@ -3822,7 +3827,7 @@ static int shmem_symlink(struct mnt_idmap *idmap, struct inode *dir, } else { inode_nohighmem(inode); inode->i_mapping->a_ops = &shmem_aops; - error = shmem_get_folio(inode, 0, &folio, SGP_WRITE); + error = shmem_get_folio(inode, 0, &folio, SGP_WRITE, PAGE_SIZE); if (error) goto out_remove_offset; inode->i_op = &shmem_symlink_inode_operations; @@ -3868,7 +3873,7 @@ static const char *shmem_get_link(struct dentry *dentry, struct inode *inode, return ERR_PTR(-ECHILD); } } else { - error = shmem_get_folio(inode, 0, &folio, SGP_READ); + error = shmem_get_folio(inode, 0, &folio, SGP_READ, PAGE_SIZE); if (error) return ERR_PTR(error); if (!folio) @@ -5255,7 +5260,7 @@ struct folio *shmem_read_folio_gfp(struct address_space *mapping, int error; error = shmem_get_folio_gfp(inode, index, &folio, SGP_CACHE, - gfp, NULL, NULL); + gfp, NULL, NULL, PAGE_SIZE); if (error) return ERR_PTR(error); diff --git a/mm/userfaultfd.c b/mm/userfaultfd.c index 3c3539c573e7..540a0c2d4325 100644 --- a/mm/userfaultfd.c +++ b/mm/userfaultfd.c @@ -359,7 +359,7 @@ static int mfill_atomic_pte_continue(pmd_t *dst_pmd, struct page *page; int ret; - ret = shmem_get_folio(inode, pgoff, &folio, SGP_NOALLOC); + ret = shmem_get_folio(inode, pgoff, &folio, SGP_NOALLOC, PAGE_SIZE); /* Our caller expects us to return -EFAULT if we failed to find folio */ if (ret == -ENOENT) ret = -EFAULT; From patchwork Wed May 15 05:57:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Gomez X-Patchwork-Id: 13664630 Received: from mailout1.w1.samsung.com (mailout1.w1.samsung.com [210.118.77.11]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7D0A83D38E for ; Wed, 15 May 2024 05:57:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=210.118.77.11 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715752664; cv=none; b=sSct22jEGZlmx4taS2jsFGHa2gECNJhkOWn1p8ApMSGDUJ4o9tXa7wHQ6HHRdWxTo+tLD0JLFbpfj1IUf8X4Uo3u01InGc+TV58kct5WxgIMR4fJ3aafJNmn8bZZbiRO800kyG4DOWrhUjx+CNObMlx+TgyH4yuui1lm6+owpxk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715752664; c=relaxed/simple; bh=GTJH/8ICMJ+xrFPIDY3SHirDZMutD6vtJowQ3Y1pmXY=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:Content-Type: MIME-Version:References; b=FeYZ4CTRHNcx9czVAIrwTYOf60wu5FeuKUnNj+k6DX4OKgpff+dCQFB+0ZGLnlAf31qrzyg0z1qKPgDKYjG/1K7nVc5CidwPlv74lBMuMr9pLlmX0aWsxEHTdfSjdaKTL7Ra0PItOdXOfhABfeSMQYeTXiVd1N0tTghfGo+SW3k= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=samsung.com; spf=pass smtp.mailfrom=samsung.com; dkim=pass (1024-bit key) header.d=samsung.com header.i=@samsung.com header.b=SONL4RGQ; arc=none smtp.client-ip=210.118.77.11 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=samsung.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=samsung.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=samsung.com header.i=@samsung.com header.b="SONL4RGQ" Received: from eucas1p2.samsung.com (unknown [182.198.249.207]) by mailout1.w1.samsung.com (KnoxPortal) with ESMTP id 20240515055741euoutp01e7e0daf9b1444275275b08d3fb916e88~Pk-R4ev372237822378euoutp01G for ; Wed, 15 May 2024 05:57:41 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.w1.samsung.com 20240515055741euoutp01e7e0daf9b1444275275b08d3fb916e88~Pk-R4ev372237822378euoutp01G DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1715752661; bh=SA7vsxMb4nPPaawAJ345Tbdd6TJyw9vmKosmLEJCqb4=; h=From:To:CC:Subject:Date:In-Reply-To:References:From; b=SONL4RGQ+3aW3BkT0h8/QH6hsaAX39vkj1HmfbOJsXx4+FG0cBs7IWKZDx2H4DvD9 D+BoEZCaxUDJODjN/sJEd/u6Scd+J7FkcMoGZKyY2WYTjlU9aFRg3TraxXWA70yTqz c+bkaCxk3K/DrjoJGBNQ+uai9RzZsu82Mle5zQQs= Received: from eusmges1new.samsung.com (unknown [203.254.199.242]) by eucas1p2.samsung.com (KnoxPortal) with ESMTP id 20240515055740eucas1p25652a13d9ff1daf6170721db7d20973d~Pk-RhccWA1242112421eucas1p2K; Wed, 15 May 2024 05:57:40 +0000 (GMT) Received: from eucas1p1.samsung.com ( [182.198.249.206]) by eusmges1new.samsung.com (EUCPMTA) with SMTP id 62.CC.09624.4DE44466; Wed, 15 May 2024 06:57:40 +0100 (BST) Received: from eusmtrp1.samsung.com (unknown [182.198.249.138]) by eucas1p1.samsung.com (KnoxPortal) with ESMTPA id 20240515055740eucas1p1bf112e73a7009a0f9b2bbf09c989a51b~Pk-RFZpih2872228722eucas1p1q; Wed, 15 May 2024 05:57:40 +0000 (GMT) Received: from eusmgms2.samsung.com (unknown [182.198.249.180]) by eusmtrp1.samsung.com (KnoxPortal) with ESMTP id 20240515055740eusmtrp1f762462ac90672e4ece458eafc17f138~Pk-RDcVyU0411404114eusmtrp1E; Wed, 15 May 2024 05:57:40 +0000 (GMT) X-AuditID: cbfec7f2-bfbff70000002598-6c-66444ed47f04 Received: from eusmtip1.samsung.com ( [203.254.199.221]) by eusmgms2.samsung.com (EUCPMTA) with SMTP id EF.F1.09010.4DE44466; Wed, 15 May 2024 06:57:40 +0100 (BST) Received: from CAMSVWEXC01.scsc.local (unknown [106.1.227.71]) by eusmtip1.samsung.com (KnoxPortal) with ESMTPA id 20240515055740eusmtip1c1c5c7fdc67df03cf35207303023806f~Pk-Q1q2AV0512205122eusmtip1d; Wed, 15 May 2024 05:57:40 +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:39 +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:39 +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 12/12] shmem: add large folio support to the write and fallocate paths Thread-Topic: [PATCH 12/12] shmem: add large folio support to the write and fallocate paths Thread-Index: AQHapozKay8vuuiPlUac1QtltK7AQQ== Date: Wed, 15 May 2024 05:57:38 +0000 Message-ID: <20240515055719.32577-13-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 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAA02Se0xTZxjG851zenporB5KtV/qxIBhQ9Ai0cUPZpRkGI9x2WayZRMv0K0H RKFAD53oNMGRzdkwws2pBSayMC4SScq9Qo2AKBQwchNELi6tl3YBKZJVIFTawxb++z3v877f 877JR+GSWYGcilenshq1MsGfFBH1He96tw98Hhm748pwMCqsriKRq6UDIHubA6C++76oJ2uB RHPV8zjqt6xFVkcWgQquZmCo31hIovEqlwAZFxuFyGRvwdFwthWge12/CtGCc9ltMB6J8Gaa 9GNCptigZWrKgxhD5WWSMThyhczDawsE0/Q8jMkbLgPMjPUpwUybBkmmu7hdyMwafL9cEyXa o2IT4n9gNSF7Y0Qn63MnBcmP5WnNjT1YOqhdrwNeFKR3wYmMS5gOiCgJXQ5gR1Mlzou3AJbm 9wNezAJYZpggdIDyjDx6IefrZQA6x55g/zf99q5bwItuAF+PTxG8qABw4KqRdCeS9FZo6jQI 3YaUHgX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pNZllqkb5egl7Ft0gPWgotSFXt2nGVqYNwi2sXIwSEhYCJx /plUFyMXh5DAUkaJroOtbF2MnEBxGYmNX66yQtjCEn+udbFBFH1klHj/8wwjhHOGUeL8+eXM EM5KRon9u74wg7SwCWhK7Du5iR0kISJwm1Hi6akzYA6zwElWiQOnP7ODVAkLREicnruVEcQW EYiVWD7jKwuErSdx6sFlsDiLgKrEu/+/wabyClhJzN5xhAnEFhKwlLj0ajtYDSdQ/O78r2CH MwrISjxa+QtsPrOAuMStJ/OZIJ4QkFiy5zwzhC0q8fLxP6jndCTOXn/CCGEbSGxduo8FwlaW WP+ujQlijp7EjalT2CBsbYllC19D3SMocXLmE5YJjNKzkKybhaRlFpKWWUhaFjCyrGIUSS0t zk3PLTbSK07MLS7NS9dLzs/dxAhMeNuO/dyyg3Hlq496hxiZOBgPMUpwMCuJ8IqkOacJ8aYk VlalFuXHF5XmpBYfYjQFhtFEZinR5Hxgys0riTc0MzA1NDGzNDC1NDNWEuf1LOhIFBJITyxJ zU5NLUgtgulj4uCUamCSV+c1TItZX7ko/miyb2O816/A+Id7bhksrta6mrb+2KPexS46SZWP 5qhvLFgbdeGZ6LSrFbFRnrvmWrf+f7UrSeBFzsGjuo+lajJLeFMmPPqupudslZI1rTPyQtnq mKpji8QmLRNtmeRdfVuBaaO4Y53uIZ+Q7NQtc2oYZp05fnW/2vPMlbufHZp53pp1x4FNqtkb DZfkvzubtKTnS4ffxyNfPvqGrpj3WrHl6L7JNifXc9SdcT7zRTgkW8n5TnioxpaVtfcWTs9f +Z5xz9ZZU6xf5v31ObTrrpzcuocMQv/3rorfHbd4maFL228+jQC+F099nFZ01hZqLfNf9qLQ s7fpZJxNTcHaONfnj2/9VmIpzkg01GIuKk4EAM2Wut0BBAAA X-CMS-MailID: 20240515055740eucas1p1bf112e73a7009a0f9b2bbf09c989a51b X-Msg-Generator: CA X-RootMTR: 20240515055740eucas1p1bf112e73a7009a0f9b2bbf09c989a51b X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20240515055740eucas1p1bf112e73a7009a0f9b2bbf09c989a51b References: <20240515055719.32577-1-da.gomez@samsung.com> Add large folio support for shmem write and fallocate paths matching the same high order preference mechanism used in the iomap buffered IO path as used in __filemap_get_folio(). Add shmem_mapping_size_order() to get a hint for the order of the folio based on the file size which takes care of the mapping requirements. Swap does not support high order folios for now, so make it order-0 in case swap is enabled. Skip high order folio allocation loop when reclaim path returns with no space left (ENOSPC). Add __GFP_COMP flag for high order folios allocation path to fix a memory leak. Signed-off-by: Daniel Gomez --- mm/shmem.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 47 insertions(+), 2 deletions(-) diff --git a/mm/shmem.c b/mm/shmem.c index fcd2c9befe19..9308a334a940 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -1836,23 +1836,63 @@ static struct folio *shmem_alloc_folio(gfp_t gfp, struct shmem_inode_info *info, struct page *page; mpol = shmem_get_pgoff_policy(info, index, order, &ilx); - page = alloc_pages_mpol(gfp, order, mpol, ilx, numa_node_id()); + page = alloc_pages_mpol(gfp | __GFP_COMP, order, mpol, ilx, + numa_node_id()); mpol_cond_put(mpol); return page_rmappable_folio(page); } +/** + * shmem_mapping_size_order - Get maximum folio order for the given file size. + * @mapping: Target address_space. + * @index: The page index. + * @size: The suggested size of the folio to create. + * + * This returns a high order for folios (when supported) based on the file size + * which the mapping currently allows at the given index. The index is relevant + * due to alignment considerations the mapping might have. The returned order + * may be less than the size passed. + * + * Like __filemap_get_folio order calculation. + * + * Return: The order. + */ +static inline unsigned int +shmem_mapping_size_order(struct address_space *mapping, pgoff_t index, + size_t size, struct shmem_sb_info *sbinfo) +{ + unsigned int order = ilog2(size); + + if ((order <= PAGE_SHIFT) || + (!mapping_large_folio_support(mapping) || !sbinfo->noswap)) + return 0; + + order -= PAGE_SHIFT; + + /* If we're not aligned, allocate a smaller folio */ + if (index & ((1UL << order) - 1)) + order = __ffs(index); + + order = min_t(size_t, order, MAX_PAGECACHE_ORDER); + + /* Order-1 not supported due to THP dependency */ + return (order == 1) ? 0 : order; +} + static struct folio *shmem_alloc_and_add_folio(gfp_t gfp, struct inode *inode, pgoff_t index, struct mm_struct *fault_mm, bool huge, size_t len) { struct address_space *mapping = inode->i_mapping; struct shmem_inode_info *info = SHMEM_I(inode); - unsigned int order = 0; + unsigned int order = shmem_mapping_size_order(mapping, index, len, + SHMEM_SB(inode->i_sb)); struct folio *folio; long pages; int error; +neworder: if (!IS_ENABLED(CONFIG_TRANSPARENT_HUGEPAGE)) huge = false; @@ -1937,6 +1977,11 @@ static struct folio *shmem_alloc_and_add_folio(gfp_t gfp, unlock: folio_unlock(folio); folio_put(folio); + if ((error != -ENOSPC) && (order > 0)) { + if (--order == 1) + order = 0; + goto neworder; + } return ERR_PTR(error); }