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: 13664600 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id A45A9C25B75 for ; Wed, 15 May 2024 05:57:35 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C0C6F6B03CB; Wed, 15 May 2024 01:57:32 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B94DB6B03CE; Wed, 15 May 2024 01:57:32 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8D8576B03CB; Wed, 15 May 2024 01:57:32 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 5CE2F6B03CB for ; Wed, 15 May 2024 01:57:32 -0400 (EDT) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id D6761A202F for ; Wed, 15 May 2024 05:57:31 +0000 (UTC) X-FDA: 82119573102.22.CE2DA8F Received: from mailout1.w1.samsung.com (mailout1.w1.samsung.com [210.118.77.11]) by imf24.hostedemail.com (Postfix) with ESMTP id DFDB1180002 for ; Wed, 15 May 2024 05:57:28 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=samsung.com header.s=mail20170921 header.b=ngyRgTVK; spf=pass (imf24.hostedemail.com: domain of da.gomez@samsung.com designates 210.118.77.11 as permitted sender) smtp.mailfrom=da.gomez@samsung.com; dmarc=pass (policy=none) header.from=samsung.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1715752649; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=dTnZOoNYjEenQBIjBgvJcx5/I/6R08XCA2XZxGoD7mw=; b=aHAHg6rAjEfbedC5lI2pogWRIxLZhvTqh7yt2+xv32O41iniUbxTzCrhAWX26OvneofRrz J2HpYA7RkfkL9MSdOPiP1QUUdbotrzG7KEhgFFdefYYmPAXOoiO+Eo1BDyjnzw1YMWGpdA sx6dopnpfnmGiwhTQRKkg4bxvHJ6sT0= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1715752649; a=rsa-sha256; cv=none; b=IghCcvHX7zem+OW1Xs3+KcurDgTRObbKZnjFVc9dqltlepfTZURAlWJRegMGX4+q+3Skic 5t9ctlfVk1i1b0/szT8EqczeQ+rRCYtmUjcYHQJWTTRR4kMUfJaUY3q5OtAE24pgKQy8cr VBe+KIQpWc+2ZLqCd7zxqSpNfgqHWkE= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=samsung.com header.s=mail20170921 header.b=ngyRgTVK; spf=pass (imf24.hostedemail.com: domain of da.gomez@samsung.com designates 210.118.77.11 as permitted sender) smtp.mailfrom=da.gomez@samsung.com; dmarc=pass (policy=none) header.from=samsung.com Received: from eucas1p2.samsung.com (unknown [182.198.249.207]) by mailout1.w1.samsung.com (KnoxPortal) with ESMTP id 20240515055726euoutp010402091f47e2b6d6342eec8569f22e93~Pk-EMkdTM1504015040euoutp01L for ; Wed, 15 May 2024 05:57:26 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.w1.samsung.com 20240515055726euoutp010402091f47e2b6d6342eec8569f22e93~Pk-EMkdTM1504015040euoutp01L 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 x-originating-ip: [106.210.248.161] MIME-Version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAA02SfUxTZxTGfe+9vfdS1nmp3XgDQ0wNfwha1JntRYm6TJObaSYmJsavaCMX JAOUWytM50JkIasiY3VDbZkFKxQKhtiCQIUqDEE+NESmI4AkLO0yymJLEfzoFWZ7ceG/35Pz nPOckxwal7+QRNEZ2Sc5PludqSSlxO2u14/WdH69LW3t8MuVqKy+jkT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cUwbbbRiUexxbaMO0NO33shYj661K5T1zCPGV3tSqbdL4btf61t/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> X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: DFDB1180002 X-Rspam-User: X-Stat-Signature: b4azqrdy8o6fxr8q7rndubun31e9wuto X-HE-Tag: 1715752648-157836 X-HE-Meta: U2FsdGVkX181U5wDBwWOV9YIi4OS1rLfhNdSHRS9k+uLmL/B7KolYOVVFmS+7f9l6IHC6pcwoMLHOL7HKlVOBHLAWDo9R1U+t/Zs8M8XMBtUSuDqEbLmMFxyMg2JMDCxgq8xBEKma6TjXKKXJl3gfHLIlHaB7ryd+YjJacTPv+fswPlKIwSnKykLaurzCNFZ1qaqF0Kt4OSP+cXDmAPWDEASu7niPOsTtJvIA0f9u6PdpXru+FAOeYV/JPsjESwdCj5vmXSG+0XfA8pYSBGMbAJlhngPA4a9HEId04AilfWZO0br7r327LAV1/EV9el7VweA0I9v8/gjhmfCEjUHV6DoI3NREJ9X7lwfAovveSivfmgEirwIzVWAgvMdOs2ZyfjMWo7EpMqVLCtISVv9a/t2yE4mn/vkmK9gc2o/71craOXAAshi7WxfSi2gnRe3UbqmxjS4gh8CNBgynexL+D4Q8lFi7JTv72Gwdey1aIIeZGuipZamc4+ujYYY8xwygvmX03OCTGccidSUqShmaah4WUdhVBMAzIg6R4rkKyQkCTLeUBL+6Qweeo23RiGPyCROzvTMSRtFfaKM3hNOouUlrrTzQZiPHxk07H/z9sACdzR81836M2LXAi/rbYR/yK3zMSv+YzVDoMovyYj02NR+mryXCcbTbD2iERFbBC42o0CwWGU3E81296np0gYEgJK+P5MuBaUaDcEFPTxPoI2R0VDQI3rOdPHily6691EK9/cPBQyMeZk6odrVzR8jSpb9ezNf+mTrAEZ3ET27pKiz58QKJAHECo0a5e5Ns/TLv7qJJhPRfkLyjYlU+kAvQQvhLljId1aIiiIyJYfe+et+vYfShp6U9BiDUpdZou7qFyMsluC0JUHXe7qwHdN2ksRjaxGbBGFrPU7YAVEQvlo+Svn0TfutWFFXRPZjyhit8xnc0RcG/F3KavOwAgDJlf8diPJHJDGBOq0wjPe bc6uvZFH 2UsKVN16eh2TUPRgfJNvRQyZL0kJ0tgLpgiLkCiEowEWvgsLV5iyis7Y6Rb3w2B0BojgdcboZJY39vVxscJYnRsfBC2gI1eyPHthRFBxVtBU++2D0eDSKPnqqmbYxbKc3ve40zthBupbQb1meXF8Ze2vdnEXsVfC5ovBZJb+V0T499UXtqGhzFSbrI5z99hn4iGnwiazlvadDNCre/haj6JanUTFSQw6ccB0f41vunuQ1gUU= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: 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: 13664599 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 14B1DC25B7A for ; Wed, 15 May 2024 05:57:32 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7577D6B03CC; Wed, 15 May 2024 01:57:32 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6E7E66B03CE; Wed, 15 May 2024 01:57:32 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4B81E6B03CD; Wed, 15 May 2024 01:57:32 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 2761B6B03CB for ; Wed, 15 May 2024 01:57:32 -0400 (EDT) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id E0F2A403F2 for ; Wed, 15 May 2024 05:57:31 +0000 (UTC) X-FDA: 82119573102.17.4301FB4 Received: from mailout1.w1.samsung.com (mailout1.w1.samsung.com [210.118.77.11]) by imf09.hostedemail.com (Postfix) with ESMTP id E38C5140006 for ; Wed, 15 May 2024 05:57:28 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=samsung.com header.s=mail20170921 header.b=sqVMr3yB; spf=pass (imf09.hostedemail.com: domain of da.gomez@samsung.com designates 210.118.77.11 as permitted sender) smtp.mailfrom=da.gomez@samsung.com; dmarc=pass (policy=none) header.from=samsung.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1715752649; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=6AbpwZVsLVgVT3CkKdkc06GB5sYOIf3QpK6XfswU18c=; b=n2ttg7Ou7c+4Lyb9dppHnT4Ju267QaxDEVbfw9Se3CAvFFflLnDV+OJpibcCHkvKFcsRzK 0U8bYmUvyy07tQCUUQrmiDQxk2FkZKrqafltRKoMQpdUXc/jTQz8bxCG4OuylffcsRtAzN adqvQwh5U69OAEdj9b/M66Ip475POaM= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1715752649; a=rsa-sha256; cv=none; b=iGl3401R0/L8nOvpZJxORuwOx8JpACavc7xh7O0TJswdZ80GGueA1nacGYw+DK5cc35Ykb KH2F6baAbdkDjGZULcq4cdK9uui2IDAH5qZ3sOFKENTx0Jgp4Ru9tXgfQdm2y1irdKDfD3 xxHpXpFWuVV4c8Q6X3Uj310KrfWpmzs= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=samsung.com header.s=mail20170921 header.b=sqVMr3yB; spf=pass (imf09.hostedemail.com: domain of da.gomez@samsung.com designates 210.118.77.11 as permitted sender) smtp.mailfrom=da.gomez@samsung.com; dmarc=pass (policy=none) header.from=samsung.com Received: from eucas1p1.samsung.com (unknown [182.198.249.206]) by mailout1.w1.samsung.com (KnoxPortal) with ESMTP id 20240515055727euoutp019652cb37ea0f3e89fce16584437ea93b~Pk-Ez9Kfs1504315043euoutp01X for ; Wed, 15 May 2024 05:57:27 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.w1.samsung.com 20240515055727euoutp019652cb37ea0f3e89fce16584437ea93b~Pk-Ez9Kfs1504315043euoutp01X 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 x-originating-ip: [106.210.248.161] MIME-Version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrIKsWRmVeSWpSXmKPExsWy7djPc7rH/FzSDI4161rMWb+GzeL/3mOM Fq8Pf2K0uHRUzuJs3282i6/rfzFbXH7CZ/H0Ux+LxezpzUwWl3fNYbO4t+Y/q8WuPzvYLfa9 3stscWPCU0aLg6c62C1+/wDKbt8V6SDosXPWXXaPBZtKPTav0PLYtKqTzWPTp0nsHidm/Gbx 2PnQ0mPyjeWMHh+f3mLxeL/vKpvHmQVH2D0+b5IL4InisklJzcksSy3St0vgymhpm8hY0OBS 0fe9g6mB8aB5FyMnh4SAicT5ef/Zuxi5OIQEVjBKrDz5gA3C+cIocbq/jwnC+cwosXvTfTaY ltudhxkhEssZJU5cO8ACV7Xo+B1mCOcMo8TyNUtYIZyVjBILdj1kB+lnE9CU2HdyE9hKEYHb jBJPT50Bc5gFTrJK/Nm8E2gYB4ewQIBEzz5DEFNEIFTi6p8gkF4RAT2JFet3MYOEWQRUJa41 BoKEeQUsJdb2b2UBsTkFrCTuzv8KdiqjgKzEo5W/wNYyC4hL3HoynwniBUGJRbP3MEPYYhL/ dj2Eek1H4uz1J4wQtoHE1qX7WCBsZYn179qYIOboSdyYOoUNwtaWWLbwNTPEDYISJ2c+AYeE hMBBLon/z7azQjS7SEzYtw9qqLDEq+Nb2CFsGYnTk3tYJjBqz0Jy3ywkO2Yh2TELyY4FjCyr GMVTS4tz01OLjfJSy/WKE3OLS/PS9ZLzczcxAlPl6X/Hv+xgXP7qo94hRiYOxkOMEhzMSiK8 ImnOaUK8KYmVValF+fFFpTmpxYcYpTlYlMR5VVPkU4UE0hNLUrNTUwtSi2CyTBycUg1M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Fv4mhniHkGJkzOfsExglJ6FZN0sJC2zkLTMQtKygJFlFaNIamlx bnpusZFecWJucWleul5yfu4mRmC623bs55YdjCtffdQ7xMjEwXiIUYKDWUmEVyTNOU2INyWx siq1KD++qDQntfgQoykwiCYyS4km5wMTbl5JvKGZgamhiZmlgamlmbGSOK9nQUeikEB6Yklq dmpqQWoRTB8TB6dUA1PwQyvn3HrXnjO/RQR3blKfHnY5+IaEic41pxMJqy9v/rGTa+/iiG9c /MuiSjeuCXuRyKHbeLFmx6y3kW5fFz6/qnYuae9npvAVGj6y1rsdNlZ/vT3BxKvmmE7r+XDZ C1NtNJV0Fr3a2lU4RegB03o5qzcTBJvnm8YstzP/Ulb/8HyB24tc0wLFfTOstLo/38xX+Oug fEb+j7WHHu+ttfJxd3xqL1+yX+xjLfpey/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> X-Rspam-User: X-Stat-Signature: 4xn47pg7tb1ptxrgmidoucrb3k9u93n4 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: E38C5140006 X-HE-Tag: 1715752648-867763 X-HE-Meta: U2FsdGVkX18FbcPn4DaqgMjTt1SvQBWRLYfnTnCBn0g6x+V6o+9JlQuo06Iy7PhpHg+4W46sU7uFLI0PhRrPdcK30lIwhR6iOpX5AEsjWmQs0kJI6l+3jjsO9cmGheaZspV/fTqtIGImHS1lNcbH5GPd/KHAjSeOwo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: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: 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: 13664601 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3D045C25B75 for ; Wed, 15 May 2024 05:57:39 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 384206B010B; Wed, 15 May 2024 01:57:34 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 331526B010D; Wed, 15 May 2024 01:57:34 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 013566B03D0; Wed, 15 May 2024 01:57:33 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id DA30C6B03CE for ; Wed, 15 May 2024 01:57:33 -0400 (EDT) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 7E891403F2 for ; Wed, 15 May 2024 05:57:33 +0000 (UTC) X-FDA: 82119573186.20.4BC76CC Received: from mailout2.w1.samsung.com (mailout2.w1.samsung.com [210.118.77.12]) by imf15.hostedemail.com (Postfix) with ESMTP id 2A459A000A for ; Wed, 15 May 2024 05:57:29 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=samsung.com header.s=mail20170921 header.b=q4A3cBzV; spf=pass (imf15.hostedemail.com: domain of da.gomez@samsung.com designates 210.118.77.12 as permitted sender) smtp.mailfrom=da.gomez@samsung.com; dmarc=pass (policy=none) header.from=samsung.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1715752650; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=seKa6sjLynK9cdKjqPABBz7tIQiUkhLa6rE9aIXSk0U=; b=wVa7zW0FvM7pG2PAozIHfI9TQAerGxZ73Vd+8zki7l+HlpceGyY1MlgtplOEFFSX8FxLQ3 f1bKXl0hGXa9XUZud1CwM237+Z7SJ7E3W4bRm1zvaHnRXrdYZTtmawKmunmYyZHxq9KZvU XVx2QoRV1UsI2zZex5ChY4o2Ns0Pu0k= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=samsung.com header.s=mail20170921 header.b=q4A3cBzV; spf=pass (imf15.hostedemail.com: domain of da.gomez@samsung.com designates 210.118.77.12 as permitted sender) smtp.mailfrom=da.gomez@samsung.com; dmarc=pass (policy=none) header.from=samsung.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1715752650; a=rsa-sha256; cv=none; b=KVCB2A6cvKm+ITtufHfdXBVu/eKo7nPZFSmBV/Ze9aPTfIzTcAwLMflsC8UaELEVznmXPI SftCuTQJ26XCNACX/3SFX9YpHhsQ+GquO5YUshWs2Nk0aGRuhfxmc93g5eyOcDvRfMgFEg okKRCtVjEnkVYRh0OlTLD2kSXnWlJUQ= Received: from eucas1p1.samsung.com (unknown [182.198.249.206]) by mailout2.w1.samsung.com (KnoxPortal) with ESMTP id 20240515055727euoutp02e89172cfb60de710a73d3930cc909aff~Pk-FiJmEr1334513345euoutp02O for ; Wed, 15 May 2024 05:57:27 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.w1.samsung.com 20240515055727euoutp02e89172cfb60de710a73d3930cc909aff~Pk-FiJmEr1334513345euoutp02O 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 x-originating-ip: [106.210.248.161] 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/BathFJCVeLTyFzuIzSwgLnHryXwm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72uUwQCRmJjV+uskLYwhJ/rnVBFX1klHj1eyIzhHOGUeLPpkZWCGcl o8Tpno9sIC1sApoS+05uYgdJiAjcZpR4euoMmMMscJJV4sDpz+wgVcICHhLrvr0AWyIi4Cux cstfFghbT+LIhYVgk1gEVCWmrvvDDGLzClhKfFj8nxHEFgKyL73aDmZzClhJ3J3/FayeUUBW 4tHKX2DzmQXEJW49mQ/1kIDEkj3nmSFsUYmXj/9BPacjcfb6E0YI20Bi69J9LBC2ssT6d21M EHP0JG5MncIGYWtLLFv4GuoeQYmTM5+wTGCUnoVk3SwkLbOQtMxC0rKAkWUVo0hqaXFuem6x 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> X-Rspam-User: X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 2A459A000A X-Stat-Signature: w4f4e1kewax8zax5wsy1ngsgp17j8x5s X-HE-Tag: 1715752649-956496 X-HE-Meta: U2FsdGVkX185laAY7AYoXPYy8Lj0GGuMZ89src9pSN056ZZMuK72t4F3UZ007UKz/j7P58F/zcjXJBvtjzSMuRNj+A90EVDnlzoIDm5nAOI1crbUCAu2kswBRU/ImMakTts7KqHcq9XKb6Zqa+t+4s1rtHqL6VY+o5xM/Ni8X1z4jTbfVzqwjG6GusUbwC1MRC6gJCSJk2NaWnq/lDdkBtuTcKQkMOGCv41B9X7AiWKHbVJArMkS4Kosgeh/NS8tSilwbnF0yKjYv5i1CPQHNUyDjHAJNUSJ82EsrrTusaAv6Ibu4Xha5m1ADR44Oqyieb6Np0MEkVpFDI5y9fY5f1ieXarqvRhTg6XLhiPWrtewAvV4PC8lRDKfUm72b7+3oeC2eiRUhzh7UDBuxcmtdmy3kTZXdxGK8Z8OieGqDD0HNvw+DkLOLf8g1lQUlIK99UmUAnMTA5yT6UQ28+ZCRacl66agnyeLixVXsdf3AXKSwr+8Ha/O6m9WdFehRQj1y3guN5t2LPJCb443K4tWCgJdxivhoCPRgmEMtHts7mjLqWprZcnqDjQ3WPBT+td9Esz0e1trCPmXvSklgmlBTC2iWM9Q+kaD1ThMI8CDXpw4R9EBnn28tOfrv/PGJiOfNoA0rwB8IORqFnm15jg3UFogSSAhfbmaoF7F1NS8PvfLtP3JkG7/XwfAbGZp5DxaE25Sw0OtLlUYsJZEhh0u0CXtSvAr9FxEWBsobFG8Jy2WlTAdMxRNaSloHnze9SbBriI/XOuWucc1rqESsxXXh+HgkGPq6sfG6iwCFoVoTMVuPmsVIOunk++ECEOtkg0jLXRX8Cli1IbN3Acxq4dqJI1g/xen7CD8SfkecqhJxn3K6max7O9+z3XGxjM7jBcOVNwprENRwZG5MyQtyIanyy7jGwJhs47mCf5/alO6o2HMWIzLc2lsDeoedh34T9Auv4M2KjLp4lM2Am9Wyte xjdXQfyx SIBpG2IK0kUixxmPy6faKeZHEt4Gzo6mhe08kju6j2jGwGW3FROX2lkqfjQMAOGIYaUkI6GOC5Hmfa4mgsvkSDsGdJ2uo0RDBFvYrvg//fbrp9SLvw4KryiSX7RxUgNsqduOPRVtULxoWLemIdZbe2rNwhv8/ox+Ij6xPgMFH2OuLsH7NBrL7KHC4ifWuFjWM1AKclNtYt+ZIip0h/dPg1O8uCsvLQrhJDFDIcrng7NxJUzAJJD701xsEZ1cPmVp0dZ/BQlPgA/8scg/2zlRm5OJ004RFj/GQxKwz X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: 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: 13664602 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1EB6DC25B75 for ; Wed, 15 May 2024 05:57:42 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9E8AA6B010D; Wed, 15 May 2024 01:57:34 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 972078D004F; Wed, 15 May 2024 01:57:34 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7C3A76B0113; Wed, 15 May 2024 01:57:34 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 5DF806B010F for ; Wed, 15 May 2024 01:57:34 -0400 (EDT) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 119E2121454 for ; Wed, 15 May 2024 05:57:34 +0000 (UTC) X-FDA: 82119573228.08.810AD58 Received: from mailout2.w1.samsung.com (mailout2.w1.samsung.com [210.118.77.12]) by imf13.hostedemail.com (Postfix) with ESMTP id 295C92000B for ; Wed, 15 May 2024 05:57:30 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=samsung.com header.s=mail20170921 header.b=iF9QYRA2; spf=pass (imf13.hostedemail.com: domain of da.gomez@samsung.com designates 210.118.77.12 as permitted sender) smtp.mailfrom=da.gomez@samsung.com; dmarc=pass (policy=none) header.from=samsung.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1715752651; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=TvwQ3/t0rLMlRSFpe0qm/SVRP0obWxz9NLqJPflU2UQ=; b=evS5+5nl0zLuFQEm7Jh3ILEmcWnPiHVg+ZUS/ZPSAkH+aaFkxtD9PoI02i0y93VWTz2aEF MDqCxt8wEY5k/FdpbZ0QHouXY/vMxBtGbsByN9XxpxfCIMLH08Cqoh1bAX+w23H92gVeoN TucUMjVHWjMsL/Jakmroa0MVsI2VVdo= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=pass header.d=samsung.com header.s=mail20170921 header.b=iF9QYRA2; spf=pass (imf13.hostedemail.com: domain of da.gomez@samsung.com designates 210.118.77.12 as permitted sender) smtp.mailfrom=da.gomez@samsung.com; dmarc=pass (policy=none) header.from=samsung.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1715752651; a=rsa-sha256; cv=none; b=ZSP65doYw9cH++9I08fTtY0hsXxKTa9D7npE5aPcbpoMUoJ/je2dwJXRg22c1KVJ4Kjltc DOeqK13v5cHXQTPqqGcueCX161CYXLXZd3X/1LZufqTZjge3cu2TU72wmr+yjiU6btbxcF sVPXSkKTpj9gajjt0xL/A5+d8lHGN5U= Received: from eucas1p1.samsung.com (unknown [182.198.249.206]) by mailout2.w1.samsung.com (KnoxPortal) with ESMTP id 20240515055729euoutp02690184600c0b2a7baeaa1e92f2735bcf~Pk-HQwITs1334813348euoutp02a for ; Wed, 15 May 2024 05:57:29 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.w1.samsung.com 20240515055729euoutp02690184600c0b2a7baeaa1e92f2735bcf~Pk-HQwITs1334813348euoutp02a 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 x-originating-ip: [106.210.248.161] MIME-Version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrAKsWRmVeSWpSXmKPExsWy7djPc7on/FzSDB58t7SYs34Nm8X/vccY LV4f/sRocemonMXZvt9sFl/X/2K2uPyEz+Lppz4Wi9nTm5ksLu+aw2Zxb81/Votdf3awW+x7 vZfZ4saEp4wWB091sFv8/gGU3b4r0kHQY+esu+weCzaVemxeoeWxaVUnm8emT5PYPU7M+M3i sfOhpcfkG8sZPT4+vcXi8X7fVTaPMwuOsHt83iQXwBPFZZOSmpNZllqkb5fAlbHi+hXmgm1c FXuuLGRvYNzL0cXIySEhYCLx+2YjWxcjF4eQwApGiffT7rJDOF8YJX7vnMcM4XxmlJh3uYsJ puVQ43tWiMRyRonW3j4muKo3D3ZAOWeAMv8fsIK0CAmsZJT480wUxGYT0JTYd3IT2BIRgduM Ek9PnQFzmAVOskr82byTpYuRg0NYwF/i3XoREFNEIETibo8xSK+IgJ7EjM8N7CBhFgFVibc7 E0DCvAKWEtNXvGIHsTkFrCTuzv/KBmIzCshKPFr5CyzOLCAucevJfKgPBCUWzd7DDGGLSfzb 9ZANwtaROHv9CSOEbSCxdek+FghbWWL9uzYmiDl6EjemTmGDsLUlli18zQxxg6DEyZlPWEA+ kRDYyyXRtmADVLOLxIln36AWCEu8Or6FHcKWkTg9uYdlAqP2LCT3zUKyYxaSHbOQ7FjAyLKK UTy1tDg3PbXYMC+1XK84Mbe4NC9dLzk/dxMjMFGe/nf80w7Gua8+6h1iZOJgPMQowcGsJMIr kuacJsSbklhZlVqUH19UmpNafIhRmoNFSZxXNUU+VUggPbEkNTs1tSC1CCbLxMEp1cCkxW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zn7BMYJSehWTdLCQts5C0zELSsoCRZRWjSGppcW56 brGRXnFibnFpXrpecn7uJkZgutt27OeWHYwrX33UO8TIxMF4iFGCg1lJhFckzTlNiDclsbIq tSg/vqg0J7X4EKMpMIgmMkuJJucDE25eSbyhmYGpoYmZpYGppZmxkjivZ0FHopBAemJJanZq akFqEUwfEwenVAPTikBz2+mSLnf+JpU2bIt7NfuxpcPCF8zP63gTuuSk17e6fN17Pn12kavR 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> X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 295C92000B X-Stat-Signature: ws8xuyxxsb45bk94grrkc8171tc46ifp X-Rspam-User: X-HE-Tag: 1715752650-710889 X-HE-Meta: U2FsdGVkX1+hrXAY+RKD3Sh4gXlOf1EDGdJRcalyxWH9FEd/x2cbA1mmp7bi3dHpdzrc1ySk/BzMZ7uMThVL9MIL/AdZtyKpNy7/3TwJp1XPhHqLgC64fNqxlESJ7xLa2ZwycFyGu3TLCu9gIScBmj4We3Hwoa90oSK9NStvGyCDgsXo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ytctNet+gK7OFB9wQ== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: 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: 13664603 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 22DD0C25B75 for ; Wed, 15 May 2024 05:57:45 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 46B576B011C; Wed, 15 May 2024 01:57:35 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3F44B6B0125; Wed, 15 May 2024 01:57:35 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 15DF86B0121; Wed, 15 May 2024 01:57:35 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id DFF4F6B0115 for ; Wed, 15 May 2024 01:57:34 -0400 (EDT) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 8E195804E3 for ; Wed, 15 May 2024 05:57:34 +0000 (UTC) X-FDA: 82119573228.06.17F8D4F Received: from mailout2.w1.samsung.com (mailout2.w1.samsung.com [210.118.77.12]) by imf12.hostedemail.com (Postfix) with ESMTP id 9CBD04001B for ; Wed, 15 May 2024 05:57:31 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=samsung.com header.s=mail20170921 header.b=u4gdewf9; dmarc=pass (policy=none) header.from=samsung.com; spf=pass (imf12.hostedemail.com: domain of da.gomez@samsung.com designates 210.118.77.12 as permitted sender) smtp.mailfrom=da.gomez@samsung.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1715752651; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=LR6zBAqCV5AW0imgsMiCR7+GSDVrb77Uvzm1KnB3t5Q=; b=k140ryhbT4iiUXRRKMLul7ufsErUp65ya2qmmIlr14d0mfL1QLTeEmHcmloeS2rHbJxquj 4eA20+5aJNUqk/6SBvLAYkffO04NJQsKE7wB8RwONhxxRQPMc1z66F9AJpxvHVxuvEMQb5 vR4d2d96MpE5SE2WppjeaBFUGTOTx/E= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1715752651; a=rsa-sha256; cv=none; b=ay1GauDK8S+OjFe+xHF1F+7uHtymeNmlVTWrf6YHIQVnza3O9f0pxQ1QrIC6YZWN4i5wLi dWsaSqfgBDIOIquTJiFW7Z68nPhU87JzO5//n0y6Sjk2PWBcpiIK0njOBaaQbMtn+kVjSK Qkp3sh36XQiXopazSZSi/4uWQcgbcpI= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=samsung.com header.s=mail20170921 header.b=u4gdewf9; dmarc=pass (policy=none) header.from=samsung.com; spf=pass (imf12.hostedemail.com: domain of da.gomez@samsung.com designates 210.118.77.12 as permitted sender) smtp.mailfrom=da.gomez@samsung.com Received: from eucas1p1.samsung.com (unknown [182.198.249.206]) by mailout2.w1.samsung.com (KnoxPortal) with ESMTP id 20240515055730euoutp0251516c73db872ad34c91c4ef02fa27a3~Pk-HjDUMX1334513345euoutp02S for ; Wed, 15 May 2024 05:57:30 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.w1.samsung.com 20240515055730euoutp0251516c73db872ad34c91c4ef02fa27a3~Pk-HjDUMX1334513345euoutp02S 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 x-originating-ip: [106.210.248.161] 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+Qus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Lk5JAQMJFY vfYxWxcjF4eQwFJGiSf7prJDJGQkNn65ClUkLPHnWhdU0UdGiRnTr7BAOGcYJVad62WEcFYy SvyZ84kJpIVNQFNi38lN7CAJEYHbjBJPT50Bc5gFTrJKHDj9GWyJsIC7RNO5n2C2iICPxP2b q5kgbD2JBZ1vweIsAqoSX7pXgh3CK2Ap0butB8wWArIvvdrOCGJzClhJ3J3/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> X-Stat-Signature: sy9qapurrbxnrn87ssyf9gxhhnjk6equ X-Rspamd-Queue-Id: 9CBD04001B X-Rspam-User: X-Rspamd-Server: rspam01 X-HE-Tag: 1715752651-49628 X-HE-Meta: U2FsdGVkX18Av2fbXyYvlQh+5/1jyVonOUBiTqPu3fml3F8Nap1hdXuFQYut9L7f3DkibrjkmD1X5NSLT4IqabqXryxcBlTlKgIvaELM075iuzLsc81PY/RoOAbCCYfBoWvt0QvLfsH8Z0noqFjRWinHJweFqpsQKmAcGCiAEKmhJPb6p6L6ieZMDmAiGkeTyoZ55zieY0O3zqt0sejn71X8e9DCYtgp0fsyfat1pTfgJ2FxbziSoK+XqgCGHd+ftJPvR5wwFcXoIekfCqfpdVNjIdkPvBmORO5pyOzJeESKUVk6W8l+96fvmaa/19VuIaYWGU5xHXB19D2tp3GzBD9NkVJCFr8/PXdi0kStZW2VQS8lOHN4sQSjL/TXVL/HJY1kRJ2oQmv3z0HN7nlwuTB1na4W5ahB3COaWCWJtazHZE6HLyUS8eXf+kNVBSt7suucl3FnzsHVsz0FezUugf7LEQIuCfaLiDQYJuRkY90kHckez0re/3G+DfjHfQXD8XtubdxBhGS1fD/P90Z5tO2ty7yFf0D8kL1HPB6K4hjRvF2E6+3SSjFMmjxHo9BQCEum+T7T8b8jjtQ5/AcRk2WDFkpjlZrrE2OiB7fxj0oo49pDjzrmZpyrDEnadg8ibJwbFkP3UKGDQg8CJESDwZ2FV9+fit1VkOIaRGxNTGn5GfYT1DvgWnfVfvPTHFCgEwjSI+6hf1DBjOxxFmhnbu/GSHjtM8jyuCNK3ufpnBxUuPNepOIb9AQyxt907MOVuO5ElsL1Nvfo/EA1BFkZd8YM8SwAp6+YKZtwpxNoVqse/MQdhS4F0dYEBCHftg1QeYeYV7knT9tinGuGiZteaLYO+mYNpbDinXZv9y3Q4k8z252jBNxLGciqatjnWGBFletvP3d4/COMR9IxhHL4huPUc6tK7SYyswVTDvALAuP6QJT2/idxdd/tPqs6+K2prxo3+z5mOX3U80ka0lX 7s+vkP3G nQssHxmy04JHpPPndQoo0Ax7tTiaQBBncExyJQM/8prPKr5ZeAzTMvIILs4xeloABILbnq/W/IMvjrxS3DKB4ESYSu8pMG/pW1l6z0LroI35bVMDCbmYZ7h3qAn1NCHUQw7KClxDBJU/GEdjgeV3U+yxOL+KZCatiLMCa59VupFPf2QhiD5mhnbD9Gi4VvA72o2cH3Neo1WCaC6ovHOhrfjSZeeQy5EdsyQwlHSjZt+w+kigLFumvSKDDBKXGQGaMYQNtK15tFwo3o07MBY4vopWAtA== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: 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: 13664607 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id DF344C25B75 for ; Wed, 15 May 2024 05:57:57 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8B6906B03D8; Wed, 15 May 2024 01:57:42 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 83C606B03DA; Wed, 15 May 2024 01:57:42 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 618496B03D9; Wed, 15 May 2024 01:57:42 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 3B2086B0165 for ; Wed, 15 May 2024 01:57:42 -0400 (EDT) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id E199B121103 for ; Wed, 15 May 2024 05:57:41 +0000 (UTC) X-FDA: 82119573522.10.E26D04C Received: from mailout2.w1.samsung.com (mailout2.w1.samsung.com [210.118.77.12]) by imf18.hostedemail.com (Postfix) with ESMTP id 077B41C000A for ; Wed, 15 May 2024 05:57:38 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=samsung.com header.s=mail20170921 header.b=V6X+pv4+; spf=pass (imf18.hostedemail.com: domain of da.gomez@samsung.com designates 210.118.77.12 as permitted sender) smtp.mailfrom=da.gomez@samsung.com; dmarc=pass (policy=none) header.from=samsung.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1715752659; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=UpgQNcs3t+vPhgTbp5qaltdkcX9R16oQVfuTuAdyYIA=; b=EO05bfufOLgaGzPuR1A3U36AzH8mlYx6Pef+PCwvCjKlOPzm/Ml1SsXAF68TRHIWTV1kTm 1PKGpB92WFy0qCQc+ZqtO7YnRaGXvhMLR27SPkUaKC54MtGHkb4gS1hDuMSSiEsPzVbDhh SNf16s8d9OZhdcFB11B2mWdrRLs1T3o= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1715752659; a=rsa-sha256; cv=none; b=IloTXAZVW9Jd4uoJ3+6B8Ew3m5LlXk0CGzQX6pUrwoWyajQ9eO1se4hPKt6Zmzqj1u+e0p d533WCed3KrJvi2YhAIZ5mBGb9CnR5jiE1BNrKFhAzRYyBMUbB2wQawL4lG0iwfW0VxMJX DL7TfPwry4AUvLKD9pVULqMngu1RPXk= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=samsung.com header.s=mail20170921 header.b=V6X+pv4+; spf=pass (imf18.hostedemail.com: domain of da.gomez@samsung.com designates 210.118.77.12 as permitted sender) smtp.mailfrom=da.gomez@samsung.com; dmarc=pass (policy=none) header.from=samsung.com Received: from eucas1p1.samsung.com (unknown [182.198.249.206]) by mailout2.w1.samsung.com (KnoxPortal) with ESMTP id 20240515055737euoutp02cca71963f94f72bb9b31d00f5ac5e23c~Pk-OK7nIP2018420184euoutp02J for ; Wed, 15 May 2024 05:57:37 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.w1.samsung.com 20240515055737euoutp02cca71963f94f72bb9b31d00f5ac5e23c~Pk-OK7nIP2018420184euoutp02J 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 x-originating-ip: [106.210.248.161] 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 PQVRxS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1OUX1qSqpCRX1xiqxRtaGGkZ2hp oWdkYqlnaGwea2VkqqRvZ5OSmpNZllqkb5egl9G0JKVgBlvF0mMv2RoY+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> X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 077B41C000A X-Rspam-User: X-Stat-Signature: yb5r7i4kmngxkqgqwzytbfr6gkt7biod X-HE-Tag: 1715752658-754451 X-HE-Meta: U2FsdGVkX1+qDDKEjscXC/lRYC4LY8BtvgRGXITHOe+XP6kyUqGQ3svnjNXeEoXfbPGYU567FhsCgA2j+7dAPvpkaLptsgZbEwHfVJo65SGA7s4TeRNLfKey3O2FKKUn23NNT+nESao5KinHOd2CxmAo6oxcDzyRAAjp3N1w0p4Zu55LhwaAk0sMceCYtqRIkDFOodwdqDLO8/bmg4/51YWH9P9tCQWi87IZHQ42Vdw0TuddhvrBf/j+3Jd/gKxfVTntldK+sSZZYPOj9l580iBu1fLZDgnVc8K3GkdfzzmRFnaleNzb9d7GLjr3yGC6tWhJTNQnqR7jj3iSmmLiRqb+Z62UuOZAKTybnxi1Aa80wXAc3sWjJauD0JHHTPjq2pPL1/Zm58vVMLp/R+aDTU8JgZ9siE4/Ol9zO7147eCMzJ2Dy9cbayiIgbq1mwX3wZt5myuGiDQ71Cu5YQtmLyN51zHKz3HMLQiYk3fBRgwWzCNSEbVoLGYnGxjkoZlLdJFlzCj8mI444yNdf43Vj52cOO7t31K/5MdTnYDr1XL+N/aaaRZAGFBrJht7Ne2qZUWrT9hzVbbWtsgv44bxj7jBDdiexAzfQTNnO4HY69aF4M9aK6U0ig3y6GnIIc7Q6ftHeqR+HN2KTs55yw79xxpYejSL5k8M1S/Zn39Uk+XtAZC8HQ7SwyRw1GOnKU87vGZdpSLgg9JkDhmuaUtTMUqkEFP+5fsO6/QSuPiGl60qDSTVho3NOnBDlcIz3YOaP/yXDV0qA6PFsh2jYLd/zmTxBsAKupVMRfPnp0qDGcIl5g6sT4NzVDfSLEknGrO586w1HHq8x9/dTRPKYtxql+Pgg2fuYB2y3BB0pFOFz7k2O0XsOkO+dVYXfiS0X4YZ5Kl+dKxenDhU5fF5Qdw7qwqEzMpqT2YC40J3FNVPhcQRddrTlM5pk7FWlfXwkJNcGkkSuEOKPjsVgLOdj5N V8eY/pTH 3//RJoMf5YfdKvK9rZ6D/Bx4SFAlPA7EoU+mbNf6cKbjad4wVSGV+mfDP7g12pmQA/dUgIm6LKsXuLPYAqCLAw5uqtk1kAj7zZL0myVxLLYs4Y+c/u2UnOJ1MDvMJeN7fCFOQwFz4oRhUSROKlQcCIvSqHWKUy94E0SVyDW1xhSGw2uUCbKwm+A7HtpGG7A2bDEjoMd2mTlwKja55iqCE6CgyoERE314p6VayXq6/UO5F+7Q= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: 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: 13664604 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 03361C25B75 for ; Wed, 15 May 2024 05:57:47 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A976C6B03D2; Wed, 15 May 2024 01:57:38 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9E7016B03D3; Wed, 15 May 2024 01:57:38 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7ED286B03D5; Wed, 15 May 2024 01:57:38 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 583C06B03D2 for ; Wed, 15 May 2024 01:57:38 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id D1B03A1454 for ; Wed, 15 May 2024 05:57:37 +0000 (UTC) X-FDA: 82119573354.19.E7A9226 Received: from mailout1.w1.samsung.com (mailout1.w1.samsung.com [210.118.77.11]) by imf18.hostedemail.com (Postfix) with ESMTP id DF47D1C0006 for ; Wed, 15 May 2024 05:57:34 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=samsung.com header.s=mail20170921 header.b=ZkVfT9z6; spf=pass (imf18.hostedemail.com: domain of da.gomez@samsung.com designates 210.118.77.11 as permitted sender) smtp.mailfrom=da.gomez@samsung.com; dmarc=pass (policy=none) header.from=samsung.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1715752655; a=rsa-sha256; cv=none; b=laFGrHOMKvWJuG/4prr0zzcJF8mpAfQa2NnLFhFo29xRnWXhj5hoG5dG0BNvZwOeW1zPa3 xS8yJ4S9xUfAAnOdJkf8QlguppT9XqH/wrA0QfS4Sa47EHWuFKUpfa3dch245v2Q26OHxE wHAk7kp5kZUMC3X+0dP6Rq9//Ihs460= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=samsung.com header.s=mail20170921 header.b=ZkVfT9z6; spf=pass (imf18.hostedemail.com: domain of da.gomez@samsung.com designates 210.118.77.11 as permitted sender) smtp.mailfrom=da.gomez@samsung.com; dmarc=pass (policy=none) header.from=samsung.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1715752655; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=ISz7TrEyCDZh2RGvxSi8e/BBnML+fSScyaJx5o0KWiw=; b=ynZKXhhQK/1EIk9j7Jq+ZZcBfzWj7xpSh9mI9wo8VaT2lZjjvGAUuHmawVoO4Um71DTrs5 rJ3asRdmMPjG1Qs3V6nSWh3TamMZsXIW+jHqCIsX/UNnLSu2njtQuxAMrm06okYGeXKhrG fjKd+ndsqXKFrebxUV0xc0sDyXpMKYE= Received: from eucas1p2.samsung.com (unknown [182.198.249.207]) by mailout1.w1.samsung.com (KnoxPortal) with ESMTP id 20240515055733euoutp0175a9966755f1eee06cdfde38ae415848~Pk-KyaDB11504315043euoutp01b for ; Wed, 15 May 2024 05:57:33 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.w1.samsung.com 20240515055733euoutp0175a9966755f1eee06cdfde38ae415848~Pk-KyaDB11504315043euoutp01b DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1715752653; bh=ISz7TrEyCDZh2RGvxSi8e/BBnML+fSScyaJx5o0KWiw=; h=From:To:CC:Subject:Date:In-Reply-To:References:From; b=ZkVfT9z6ael406ECJDYHpyFlabEiCh8WUVcXIkkarczOEAsRGOJCKZL52AYr75W6T uoj03w0wf1/00ChFsPCnXmqb7wvsMWWgvMFpdaaBd+9vwh88jAYGaGo5zdxGfDZvGq n4cOnWbLkoEb2Sax5KhYhWp7GXyMvKEyzmEpNi9A= Received: from eusmges2new.samsung.com (unknown [203.254.199.244]) by eucas1p2.samsung.com (KnoxPortal) with ESMTP id 20240515055733eucas1p2d44dc66c51ebcdde1ad1cb3160016f11~Pk-Kf7b9q1079110791eucas1p2e; Wed, 15 May 2024 05:57:33 +0000 (GMT) Received: from eucas1p1.samsung.com ( [182.198.249.206]) by eusmges2new.samsung.com (EUCPMTA) with SMTP id 35.D8.09875.DCE44466; Wed, 15 May 2024 06:57:33 +0100 (BST) Received: from eusmtrp1.samsung.com (unknown [182.198.249.138]) by eucas1p2.samsung.com (KnoxPortal) with ESMTPA id 20240515055732eucas1p2302bbca4d60e2e811a5c59e34f83628d~Pk-JgremL1114511145eucas1p29; Wed, 15 May 2024 05:57:32 +0000 (GMT) Received: from eusmgms2.samsung.com (unknown [182.198.249.180]) by eusmtrp1.samsung.com (KnoxPortal) with ESMTP id 20240515055732eusmtrp1649bb55890ac4fc12b6b8f6506fb74b2~Pk-JfzHi20390703907eusmtrp1_; Wed, 15 May 2024 05:57:32 +0000 (GMT) X-AuditID: cbfec7f4-11bff70000002693-e9-66444ecdd352 Received: from eusmtip2.samsung.com ( [203.254.199.222]) by eusmgms2.samsung.com (EUCPMTA) with SMTP id DA.F1.09010.CCE44466; Wed, 15 May 2024 06:57:32 +0100 (BST) Received: from CAMSVWEXC01.scsc.local (unknown [106.1.227.71]) by eusmtip2.samsung.com (KnoxPortal) with ESMTPA id 20240515055732eusmtip20173b018d0674b7f27dab1c2ee4741f8~Pk-JRqiWL1596015960eusmtip2O; Wed, 15 May 2024 05:57:32 +0000 (GMT) Received: from CAMSVWEXC02.scsc.local (2002:6a01:e348::6a01:e348) by CAMSVWEXC01.scsc.local (2002:6a01:e347::6a01:e347) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Wed, 15 May 2024 06:57:31 +0100 Received: from CAMSVWEXC02.scsc.local ([::1]) by CAMSVWEXC02.scsc.local ([fe80::3c08:6c51:fa0a:6384%13]) with mapi id 15.00.1497.012; Wed, 15 May 2024 06:57:31 +0100 From: Daniel Gomez To: "hughd@google.com" , "akpm@linux-foundation.org" , "willy@infradead.org" , "jack@suse.cz" , "mcgrof@kernel.org" CC: "linux-mm@kvack.org" , "linux-xfs@vger.kernel.org" , "djwong@kernel.org" , "Pankaj Raghav" , "dagmcr@gmail.com" , "yosryahmed@google.com" , "baolin.wang@linux.alibaba.com" , "ritesh.list@gmail.com" , "lsf-pc@lists.linux-foundation.org" , "david@redhat.com" , "chandan.babu@oracle.com" , "linux-kernel@vger.kernel.org" , "brauner@kernel.org" , Daniel Gomez Subject: [PATCH 07/12] shmem: check if a block is uptodate before splice into pipe Thread-Topic: [PATCH 07/12] shmem: check if a block is uptodate before splice into pipe Thread-Index: AQHapozGTHnkaf4XgkaJL36kMuhxtQ== Date: Wed, 15 May 2024 05:57:31 +0000 Message-ID: <20240515055719.32577-8-da.gomez@samsung.com> In-Reply-To: <20240515055719.32577-1-da.gomez@samsung.com> Accept-Language: en-US, en-GB Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-messagesentrepresentingtype: 1 x-ms-exchange-transport-fromentityheader: Hosted x-originating-ip: [106.210.248.161] MIME-Version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrEKsWRmVeSWpSXmKPExsWy7djPc7pn/VzSDCavFLCYs34Nm8X/vccY LV4f/sRocemonMXZvt9sFl/X/2K2uPyEz+Lppz4Wi9nTm5ksLu+aw2Zxb81/Votdf3awW+x7 vZfZ4saEp4wWB091sFv8/gGU3b4r0kHQY+esu+weCzaVemxeoeWxaVUnm8emT5PYPU7M+M3i sfOhpcfkG8sZPT4+vcXi8X7fVTaPMwuOsHt83iQXwBPFZZOSmpNZllqkb5fAldF74CRbwWPe iklvoxoY73N1MXJySAiYSCz5/puli5GLQ0hgBaPEj1vvmCCcL4wSj/tnQzmfGSUerL/ABNPy 58U9ZojEckaJTZfbGeGq7i49yArhnGGUeN7wix3CWcko8ff5Y3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VTaPMwuOsHt83iQXwBOlZ1OUX1qSqpCRX1xiqxRtaGGkZ2hp oWdkYqlnaGwea2VkqqRvZ5OSmpNZllqkb5egl9F74CRbwWPeiklvoxoY73N1MXJySAiYSPx5 cY+5i5GLQ0hgKaPEvq477BAJGYmNX66yQtjCEn+udbFBFH1klDj2+gQThHOGUeJJ1wR2CGcl o8TtmW0sIC1sApoS+05uAkuICNxmlHh66gyYwyxwklXiwOnPYEuEBUIketZOBesQEYiUaGmb zQZh60ncv7yWGcRmEVCV6FneDFbDK2Ap8bhxLhOILQRkX3q1nRHE5hSwkrg7/ytYL6OArMSj lb/A5jMLiEvcejKfCeIJAYkle84zQ9iiEi8f/4N6Tkfi7PUnjBC2gcTWpftYIGxlifXv2pgg 5uhJ3Jg6hQ3C1pZYtvA1M8Q9ghInZz5hmcAoPQvJullIWmYhaZmFpGUBI8sqRpHU0uLc9Nxi I73ixNzi0rx0veT83E2MwIS37djPLTsYV776qHeIkYmD8RCjBAezkgivSJpzmhBvSmJlVWpR fnxRaU5q8SFGU2AYTWSWEk3OB6bcvJJ4QzMDU0MTM0sDU0szYyVxXs+CjkQhgfTEktTs1NSC 1CKYPiYOTqkGplU//CuSpmf5LipLiN28uVB/f/v0l1nNC/OPrb9txbRuyt6vK1auYJr3sNRt y5/WHzW982bNyDl5eum8Hk3DzB97O16XTrU9+mEzQ4/erR333e7mOTz6ki353ifS5X4P2zqR mMyF7yIfSMS9fPD+zp8z26dvfrE52/hF/zWDdJ2k6U/+Lm+y32fPf7dlee92nk+rC5eu/D+H 0UPXqK064afl7WLTHU9EbB6wXck/PDVOtHHp/ztvfwgvSpkWZWOR/lQwYTJf3IbHHJZetnu4 Fzz4JTd59TYWC0XBRdeXs6guu/3e+DrLAtmLmku9vhxR6/pUNWv7z23K97YE/y/SN2t67v5P M7r3h27eT0aj2IWvlFiKMxINtZiLihMBeBCgoAEEAAA= X-CMS-MailID: 20240515055732eucas1p2302bbca4d60e2e811a5c59e34f83628d X-Msg-Generator: CA X-RootMTR: 20240515055732eucas1p2302bbca4d60e2e811a5c59e34f83628d X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20240515055732eucas1p2302bbca4d60e2e811a5c59e34f83628d References: <20240515055719.32577-1-da.gomez@samsung.com> X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: DF47D1C0006 X-Stat-Signature: i11o85cg5ejpbqji1q3hyqjd6f3mzp85 X-HE-Tag: 1715752654-523783 X-HE-Meta: U2FsdGVkX1+xXRxN+UTjFv2jzHITfSmvxbo5QIj1A0oRiTslyd5oQCGoqpkY99t5sagMv/bUmEF/7X6qxrfw5Zg+I/BMn17BhPVdQc01sKUKqBfF2JvRPEhL8vQZr9GtHevhH+cm0LefVOsBHMnTKnj1dK5RGnYxyN5FvYpXGoA+y9H7AzTI+flCycTfKhn+8CCrO7WhPsWAMqJcuJ+RMm0jHwxreoImHbd/mZwoYxWdthFmuAacAXcox5X2cz6TV4tdHOphIHfPZ6ze0MQg5zyr6JO8wQN8e04EObuVJUsM88uA8GzFpG/hmUtYECCTCKbkAWCj1ty88NP3KgctbS+N5Ou6TuyA7KEdoGtH+3TASCLnbnB8IyX+8wPin97BCdE2nMNrNH4aruHOCY1ZQS535U20bb47lr1vnifs0vIcY0w4UJ+22hgaDECPThhoFyv51zriokCr9udZAg5MA8fWOe8KSae4GNe2qYceRdmXPlr4rj8er8DHCH9lbcQoAwr8IqMmjB4HEJmn2dWN9cz1uOJSa3RNr5GCx57Nt7DJeJU+Eq+MmjhhJI7BV0rRQ39bzt6PPEOs69dg8ysm7LDotel36S1hkeoM5JAbese8W1Chn4CkFPGjVMS+lyyzBheI16vThpoHU7CY+O0E+UbAnIes5nXug3hFruyGTZft1EyBzR5PoOXSuGadgw7SqsTirfBouDTU93jJpH5AkFoMfSEvm6s7exPILEcOPKSojNMyvEHMTu4dOzR9LcaHBehsC6y3YFjLBW/hf3r9ZBhhtr3al6el2RSnlfxsb3MgC/Bl8WvAM6Z1PKes4seVLJoqPi4uD0pnMaRqsbwv3cwcc+01rNHv+lce3Ek2ejfBLZBxCcP5z/KO2wHnjTI+Tf9SUy88GA9A/r9mOaYhs9VU2ygavqmsosAlCJvH/BCLVvVjHGYwfZY6VeV286Rb2I8rGFNuUGBTMw4iZ9b ltPnNuuS w6ztOF5zXXO3Bn1MiIqCWP1RauvIWgS9S5M6bZAvzF+YSOboI8S6FyYPx8IWd78vOdQg1C4wvIazIpGjwlzuJof7eCe66uezX58TCNwG8gbhJ3IjlJH+ZwzsbG6HQBUR/+y4foxan0vfgEHq+EMFbJc/kj3+qB6Zl0BOTr+O5biDcaHgM+C4r36wNMZ2fQm9i/7kS9yuQ0AJm6tAVulXipTQNLwPrgjy6o9Xzu248Ry1dmkQ= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: The splice_read() path assumes folios are always uptodate. Make sure all blocks in the given range are uptodate or else, splice zeropage into the pipe. Maximize the number of blocks that can be spliced into pipe at once by increasing the 'part' to the latest uptodate block found. Signed-off-by: Daniel Gomez --- mm/shmem.c | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/mm/shmem.c b/mm/shmem.c index 68fe769d91b1..e06cb6438ef8 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -3223,8 +3223,30 @@ static ssize_t shmem_file_splice_read(struct file *in, loff_t *ppos, if (unlikely(*ppos >= isize)) break; part = min_t(loff_t, isize - *ppos, len); + if (folio && folio_test_large(folio) && + folio_test_private(folio)) { + unsigned long from = offset_in_folio(folio, *ppos); + unsigned int bfirst = from >> inode->i_blkbits; + unsigned int blast, blast_upd; + + len = min(folio_size(folio) - from, len); + blast = (from + len - 1) >> inode->i_blkbits; + + blast_upd = sfs_get_last_block_uptodate(folio, bfirst, + blast); + if (blast_upd <= blast) { + unsigned int bsize = 1 << inode->i_blkbits; + unsigned int blks = blast_upd - bfirst + 1; + unsigned int bbytes = blks << inode->i_blkbits; + unsigned int boff = (*ppos % bsize); + + part = min_t(loff_t, bbytes - boff, len); + } + } - if (folio) { + if (folio && shmem_is_block_uptodate( + folio, offset_in_folio(folio, *ppos) >> + inode->i_blkbits)) { /* * If users can be writing to this page using arbitrary * virtual addresses, take care about potential aliasing 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: 13664605 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 38559C25B75 for ; Wed, 15 May 2024 05:57:51 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CFA396B03D3; Wed, 15 May 2024 01:57:38 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C60A16B03D6; Wed, 15 May 2024 01:57:38 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8AE946B03D4; Wed, 15 May 2024 01:57:38 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 5EDD16B03D3 for ; Wed, 15 May 2024 01:57:38 -0400 (EDT) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 16AA0A1455 for ; Wed, 15 May 2024 05:57:38 +0000 (UTC) X-FDA: 82119573396.10.6C3FC7C Received: from mailout2.w1.samsung.com (mailout2.w1.samsung.com [210.118.77.12]) by imf07.hostedemail.com (Postfix) with ESMTP id 2C2964000D for ; Wed, 15 May 2024 05:57:34 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=samsung.com header.s=mail20170921 header.b=bXJqDcB0; dmarc=pass (policy=none) header.from=samsung.com; spf=pass (imf07.hostedemail.com: domain of da.gomez@samsung.com designates 210.118.77.12 as permitted sender) smtp.mailfrom=da.gomez@samsung.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1715752655; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=Yzf34yJLjjOZ5L6S/TOvcg7MvQWva+m/QvkKTJ1hVb4=; b=acIJMoWYHFbKJZAGIlqQdq7A2PakUERWvmXcqKvGHVF+Xm4yuHqR7GEP1PqcYJrlP6uo0n 64VLdZJkVJnuW0FbrCZhfPTnjBHI0pXey78JTpZUIjdH8KYc/Vb/uaIB02AUgJrKkHAGRU 9f1qrLT2n5X8vJNRDJ7rCtCT8RcR8Bo= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1715752655; a=rsa-sha256; cv=none; b=nL4QhqDoGaelWm/fX3IK/upvT/6i17gckqatA7in/A+VxVlawLGIX0ItIA/A8LFdAl+zm7 Og48IanXkoqsVBAttFnWBY/Ola6EkBb+O+ZDPdKnkR1R6PMjPc58b7gKPAk0Ry+Za9dZm9 3VV6uEEi4ZdpqlV5To6JrH8sGmmRZC0= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=samsung.com header.s=mail20170921 header.b=bXJqDcB0; dmarc=pass (policy=none) header.from=samsung.com; spf=pass (imf07.hostedemail.com: domain of da.gomez@samsung.com designates 210.118.77.12 as permitted sender) smtp.mailfrom=da.gomez@samsung.com Received: from eucas1p2.samsung.com (unknown [182.198.249.207]) by mailout2.w1.samsung.com (KnoxPortal) with ESMTP id 20240515055733euoutp021ee63bbf6046f2155f5bc72aa0d8edc7~Pk-LFXIPk1630416304euoutp026 for ; Wed, 15 May 2024 05:57:33 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.w1.samsung.com 20240515055733euoutp021ee63bbf6046f2155f5bc72aa0d8edc7~Pk-LFXIPk1630416304euoutp026 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1715752653; bh=Yzf34yJLjjOZ5L6S/TOvcg7MvQWva+m/QvkKTJ1hVb4=; h=From:To:CC:Subject:Date:In-Reply-To:References:From; b=bXJqDcB0N9aUk1MGm91N6M1lKG8EaMISYNP47SSH3mR0BWBor5or/6AkM/1sz755Y IJZrTE9iiB/9h7xctUC2I7XihsHAOiTUvnMYUVLGyUiM9XUCT2kHWcvdGwXXeSZ7sM jsouEsfBa5ZUmuBW14uWD05hp9m1WcsjQ4L1/DgA= 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 x-originating-ip: [106.210.248.161] 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/CcERZSc254s6bvLJMm5LqF/haLB88tpG2O02pgMVlRt941L/Hb6jyrL s2cpuo69/CfNom5PadrxqiMgV2utzi4f2cuzWNOC7l9+ekbhdnTwyYXPEv2lgoVOPRC7u+2A Q/2dQ62fu+q21irfi138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qaWasJM7rWdCRKCSQnliSmp2aWpBa 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> X-Stat-Signature: 5c4846hieihawphbunpnou4w34hrkjo4 X-Rspamd-Queue-Id: 2C2964000D X-Rspam-User: X-Rspamd-Server: rspam01 X-HE-Tag: 1715752654-343610 X-HE-Meta: U2FsdGVkX1/LLs67RHXkfgMkKx/WI6tAugHDfJbSjNRfjj7PjcBjXjrnEZM2kKiXzaFTmYGtrzK/0rkexosj/x+Yyo585H0I6+6kjuz+oonlUmOUyS7Jaxa7/y+E/hGY2yOAHAqrUuP2Iifv4QVZed82AcEYV6pihqHG+HUD/OLaUBOiigvjsniGF4AIslppF5zIZFOTmbOGaHMKdwoWaUSBUGGn6Mk/4w16gX9BWiCsmhx8GHkuCOlzmt1c8u7SAe1hcN1GJDCxLD5e8K5RG8BPIGtWR600FZsNOw7QxBTn3musQpApnywy4C5uFg9viPxtG1F4n+Xc4E2mfOb3F8UfdWjvKEZ9z/7xn3NtDBm3Es/U/lt53uNOd6sCMmQjmbm9SYJaStq4aLDLhKgjlB7kpPvsZu780fvdQQITTWmSBknYPOU0DWsDuJwWDmQQdMJcop1/bY/7sTdZFpdVeiyugBqny5cvsxxSbg+orAEAirJ42eQ6JD7qxQds/1aFxEDMKq0FBvYAeNeVewLy5lFztDutSYgvqPA71TExJoJJG1liZxF3Gfs07ZEQ0/Xnn/c9OCGA5W3ncM5BkDt8QyJ4Vlsckhxni0t0LoN9wxHcnr/zfo2jmQYAj0Pfnh3OptXeWr8JulaAsHm2/T/v1onsU83TdMAv98IA9g75+WoMpy1LDjX1eU9u/4XUDi0BAQZ9fFfZVYG4MXWakhqJCNCdtQiWnIampHGGm4d9OqAd5F13QpZOKRaOBMOEPMFZCjNp35/2CFOXrbDGqvoLZnrEdHjIFo6spQDfw7mZ2p9b2i8k7s4rNKynjZs1qrm21ZE2wXxPFVL8k/PiGi4LCHbazUOAEdAmjovBrH/mwfhFdQ08NLXbv2fox4Kz4QPtQWJa0+GmzTTU2hH3fP7E3Zt5It+G8Ca2M4BFNGI+df2V89fnqcNVL8jBZU9Mm49xGO0O6axNeeBVHsb2vO+ E7lngCJV pG+ovyic0GE/xVCh4rCwUAF24zvqO2uUojudST0/YIWX0Q+ROcmt/S/79IyBE/vl+ukATrhDSMBNGO5yCyt3m+YRXZwkSpbK1fovxObe8FtK0XrnteeunOorXCvDl7vVsebS8BiNEbmR7MDvV70OW2NdUgURpVTK6V5hrLtYmLHe+hEyeTwgPu8ahTJDsDFWSOGmP4zzFlqCo0j4uR/2SPz5TT9CdjQC6lFOcoFQ2p3ShY1OLqZU4aTUV318QXkl77pmXqsRlzW2nur0R/FfJAJx7x3ORiq3OIzco X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: 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: 13664608 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id DB1A8C25B75 for ; Wed, 15 May 2024 05:58:01 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CAA966B0165; Wed, 15 May 2024 01:57:42 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C33BF6B03D9; Wed, 15 May 2024 01:57:42 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8AF296B03D5; Wed, 15 May 2024 01:57:42 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 3DBFD6B03D5 for ; Wed, 15 May 2024 01:57:42 -0400 (EDT) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id F15C21C1881 for ; Wed, 15 May 2024 05:57:41 +0000 (UTC) X-FDA: 82119573522.07.CE343E3 Received: from mailout1.w1.samsung.com (mailout1.w1.samsung.com [210.118.77.11]) by imf11.hostedemail.com (Postfix) with ESMTP id 185644000A for ; Wed, 15 May 2024 05:57:38 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=samsung.com header.s=mail20170921 header.b=HEognthI; dmarc=pass (policy=none) header.from=samsung.com; spf=pass (imf11.hostedemail.com: domain of da.gomez@samsung.com designates 210.118.77.11 as permitted sender) smtp.mailfrom=da.gomez@samsung.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1715752659; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=t+LtSI8A+WgybP8NqP+rojjUG/bT6woZXyJ+I7vfPH0=; b=hrvNdLwzEVx3KoAqTRXS/7080Zxn7A1RvGAY0uY14JerfPr2nJXczXkm+obuINYc8AJoSj aR9/AXRP4doc1zSxeH3d77rIAaji/szDlGf9sRUq2RmEXq7iTn+EuwU7rtxwuTvV8CZ6LJ DaNjZZOd9xV2UImgGPG62kkGh3bW4fc= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=samsung.com header.s=mail20170921 header.b=HEognthI; dmarc=pass (policy=none) header.from=samsung.com; spf=pass (imf11.hostedemail.com: domain of da.gomez@samsung.com designates 210.118.77.11 as permitted sender) smtp.mailfrom=da.gomez@samsung.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1715752659; a=rsa-sha256; cv=none; b=vsIcJXJ0m9Ujz+0ru6tuHQSdAE2nDJ1xD2e3wcxmKrAZoFVot982jzx4ocTnv8abeFgvZd 06qazuOfchOw7TJq8P7AMtmTqPyc6lgBmCCt1vxJOf2F00GubwLpXYPoJEXPaFCcRtVXv/ 7Qh7fbOqnpfvHuaRwzwEOQz6xl50fKw= Received: from eucas1p1.samsung.com (unknown [182.198.249.206]) by mailout1.w1.samsung.com (KnoxPortal) with ESMTP id 20240515055737euoutp01e0e6a78fd205d8d7250df814f88fe342~Pk-OcTLTZ2238622386euoutp01B for ; Wed, 15 May 2024 05:57:37 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.w1.samsung.com 20240515055737euoutp01e0e6a78fd205d8d7250df814f88fe342~Pk-OcTLTZ2238622386euoutp01B 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 x-originating-ip: [106.210.248.161] MIME-Version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrAKsWRmVeSW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8Zo6ZzSZ+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> X-Rspamd-Queue-Id: 185644000A X-Stat-Signature: e9a5p7pqedw9xapjnmcpqsekyw3tzfaa X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1715752658-210091 X-HE-Meta: U2FsdGVkX1+kxK71kDinZCrAicqDsZvepAJKNcDNdAzoZY08n94riypMH3oFHW63Lq3jveb2/wZH4ggiX+uYDtD50rPsbFM4RyOJRNEqyXyfu/NdCPRWnyf3hTQgHS591SUFFLo8vHDopBG/6Qb0jWTbwnfv6eKfJAVMUx9INhQlub3jMXlW9a2E/Fk2YY3P3nhX8L6zHsuFtJn3EmooNPB3ZSI9aISUMHwQNmA+83qbXCM8SFUwVssKl9jpkcfp860rAvqjfTwXa1C4uIdbW7xAq6fBiTc7R+BVxHcvvsbHMccVRqWmxbmCJqw7jwOD7yP/HZ7LcWYRgsZLV1cSQhp23t6yhGy/Lb1Nm2wDQlzY0Gsx8rMyhJKPWKQborWVHW/TzBrrg8c4tr3Jb1U4FhLLl/agDvH4DlV6bIerpGe6/wunlRy7aJsWlwBM9cS/uzAEZrEaI8dSXs5FNL/k4tY77PyrQxkzG7Zisrw8H0i+zF3yqPVJQHnoirM1BEIQGTLdsC57FNRBpWy8j4GKwCmw5ylPWc9fvqy0HLPnD27JIiL1qtXPT8L6E4XySyM3MVMMCDKT1YHSfuMC8QMT+8iY6Oc7KAYpzSK7HPf31c1rZ5nmqTyiSWJCSoLjspBpkreBjo4UZjWEJh70fpTlPmFr6gK5DV9+Dn32lKW0PYwu8Ay8Br1wANZhVG8MJoavxAXXe+rqXcbtJ1o39S91uCr7jBbEfi8dmWoEFVxLtFYVTEkG5a1h5geCxUb9xEm2XZO3ugpetakHED6zFHfN6GzzWZ/bJ6fn31wl4DMep3MmGYFlqcOAwckQc2WV1oDWSpUySPmx0HuQQnV8clPeN5R6P5tOZzsZiHme0Qh0KBe+rtZjIAijz8V/8HWi86B4NWaZ8ikIjBWEkW9quc8/fielTN6Sk/NJprn+hobVeqYwJe+eYFbf6d5IYnw4GJATiI6IISb+F4DdTCStpSO LiALgb37 EbxrOVaC2L8QJKiaIDmqxRkTOdcNIeoGgTu80X8eCgZgmpBnNLf/qFTevjai662WltyKGAicJ97TlQ1y2EOvpBwTjGUClKdT8cft2g1qj330xnGSuLJs8ZZhh5Sd5hQ0IIneTxfd+ZLsVwM0warvvU1nI1vsBQ7SA7lbOAkz8J+L7LqjyhIw2kR5IWSze4p1JJ7kRR8ZaMKr3pTAGOpEbOmv9Yk0nAwDMAmjq+dLcdj0V5xk= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: 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: 13664606 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 975D4C25B75 for ; Wed, 15 May 2024 05:57:54 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0C27A6B015D; Wed, 15 May 2024 01:57:42 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 025286B0165; Wed, 15 May 2024 01:57:41 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D1F656B015D; Wed, 15 May 2024 01:57:41 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id ACF5D6B0153 for ; Wed, 15 May 2024 01:57:41 -0400 (EDT) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 6D3F3121103 for ; Wed, 15 May 2024 05:57:41 +0000 (UTC) X-FDA: 82119573522.02.8DEF214 Received: from mailout1.w1.samsung.com (mailout1.w1.samsung.com [210.118.77.11]) by imf29.hostedemail.com (Postfix) with ESMTP id 897CC120016 for ; Wed, 15 May 2024 05:57:38 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=samsung.com header.s=mail20170921 header.b=XE0WeUZ4; dmarc=pass (policy=none) header.from=samsung.com; spf=pass (imf29.hostedemail.com: domain of da.gomez@samsung.com designates 210.118.77.11 as permitted sender) smtp.mailfrom=da.gomez@samsung.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1715752658; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=KSFa/00drIrpTPTVaHKTJFLNN4vEYokk0j2qhn9ASTY=; b=WX5FtPAqgIlzDU4CZ5174Us6/0xwqg+HjT8lbOL42hCUOs685DbEXe7+l2Iw0T3w6dF1+f LaIa3jIEqaxl//2XjWlJJbIRWE9Jq4xr2VEjrtRSEB5oXliVZ/l4dFyt2ODCia5pnSw33Z mGhZHiza0+d8EIY8PUM90yBlq2lwHGg= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=samsung.com header.s=mail20170921 header.b=XE0WeUZ4; dmarc=pass (policy=none) header.from=samsung.com; spf=pass (imf29.hostedemail.com: domain of da.gomez@samsung.com designates 210.118.77.11 as permitted sender) smtp.mailfrom=da.gomez@samsung.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1715752658; a=rsa-sha256; cv=none; b=r+Tg1zrGO+T5c8+4YCIuQookVQEfZV/KaQSvbPw2n7+uBueRiHN1feaXUvGrxdWeoPCz/p y34F5PiiibkFMqAES5n0L2N/8qQa00JAusLCxTCAOVWJTDaHNHvLUAONeyJj9qPtxNu95H jcqa3VHj00akxjaCLQkUB7bp0oZWG/0= Received: from eucas1p2.samsung.com (unknown [182.198.249.207]) by mailout1.w1.samsung.com (KnoxPortal) with ESMTP id 20240515055737euoutp01f6edc2da26c5a067c4ba60b50b5518aa~Pk-OQj1uv2237822378euoutp01B for ; Wed, 15 May 2024 05:57:37 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.w1.samsung.com 20240515055737euoutp01f6edc2da26c5a067c4ba60b50b5518aa~Pk-OQj1uv2237822378euoutp01B 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 x-originating-ip: [106.210.248.161] MIME-Version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvr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g0zx7rvZNdukX8xz+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> X-Rspamd-Queue-Id: 897CC120016 X-Stat-Signature: 9ejzosuzewoa4kgwfd85nxomznfeo491 X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1715752658-620013 X-HE-Meta: U2FsdGVkX183rHv59NXp25EAe776fJ1fAWr6Rt47R6cUsuq3//BipNIGv88QAZ6rbJKgIVjVRM8L1zKYF0yVtOrxyX88ZA2syb/MQz6bwQchR87UA6mSM1anMgkvo/JSyuIm7L2eIemXSf8ff8txJ6nDMgq2nl+/3b1cIWvl978nonhvVgZPIkxXjOQK+DmYo0lFMxEZ41W6UeNaPR2a8iOUKLm7BxfyCdnLCqxj1anF+K+jhWCbekhjv2W7yn3FRthz5hJnIKWMspd1uW7IYly/Rk6ox3aXeCX3tLo5isKqtJ7EX+/RoBz+fLSVfJ+Tx0FUel2fUHFuvs+xgE0xKSCFyXOML/JJAurfQR6nE012E/xWEYPLIsN0Zjiv+6ZozMpv3324Ijx/DyhYbQ87wVw2RQ/3HpZFUqXs3oQUScH8oyAxcFbP5IpGtfvIXx8aSj2uOSWAY9Hp6BNxpa69Z7XYfj7TdKnTa8wA1WWKBOVC7SWpGo3cdMaX9bR/Z+KAHugRkCfZ0vadPZU0upk9J1vc5/OKljCSTVFeutEf74EZQ2kpXwdTD1KwssMVqOEbkUGjDV8Wgw5e2Kst1PXzgB/8qXTMu1ZH/1A5/nsyowNYKGH2QDpQ2igP2befms6SZQArh7R19yxf5Wd/Meig//m+zKNku1zEKcBBA9OdnIj0k4qSxICkgbqm+Mein0lHDOT0ElefQBUks82c7So4PzEhFK/taGeNGuxe4S7HA7c5tjEEfI5W80A+B5ml7IMteS9qPIPHRq5/I0f+e6EZ53tS4yIfqaL1SKCnDkUAO9jZ+G7KtSdBezHKMijadB1WVPlFVUqMzBaQCcsfh9KvgaOIWZQL6K9TF/LnEdbbm4iEfPGSsuUDM+33UW7GkdYfprVRuM/pmFA8hdV5i4wAkd8pscd2wrkLX+zcp76XuBqFAwiqKDs+MpgGVOVV2oaI99POM7r8Y6t2S5IUXEc 1fL/DB6x eON7CTqhGktf8EnALX2jjvdsfcK/qOOZ+1pHK2sYqM0U5f0Twf4+njuWOmZvFrYbOyDRiO0HU0O4xY+TElFNLGmzIW7TCjgRqOIxT4a71HjgeTEeMdmWJ1ySXm4rOw8TgDbTagRumThesIumK15R4qt9Hjqtpf9vbdO/ANJtyEk+pl9TGxd9lPfK/oDuE4OzSCfnIbeOnXP5WK6J3LKt+73M5qaGmXSSlRN0PogRc6jbCLEakibOkaB90GCzQ+0OkD+pOTKtFAoifkDCCMOszaS+rWA== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: 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: 13664609 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id A46B3C25B75 for ; Wed, 15 May 2024 05:58:05 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E32166B03D5; Wed, 15 May 2024 01:57:43 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id DB7916B03D9; Wed, 15 May 2024 01:57:43 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BBC636B03DA; Wed, 15 May 2024 01:57:43 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 930456B03D5 for ; Wed, 15 May 2024 01:57:43 -0400 (EDT) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 4A16F1C1881 for ; Wed, 15 May 2024 05:57:43 +0000 (UTC) X-FDA: 82119573606.06.2B4F03E Received: from mailout1.w1.samsung.com (mailout1.w1.samsung.com [210.118.77.11]) by imf16.hostedemail.com (Postfix) with ESMTP id 5215A18001D for ; Wed, 15 May 2024 05:57:40 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=samsung.com header.s=mail20170921 header.b=U9Enp2W+; spf=pass (imf16.hostedemail.com: domain of da.gomez@samsung.com designates 210.118.77.11 as permitted sender) smtp.mailfrom=da.gomez@samsung.com; dmarc=pass (policy=none) header.from=samsung.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1715752660; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=YnJglILKqFkdTEiFzR72jsMog/cpgSZTzUSnpJww0Pw=; b=3/huN9kvYdwtNbLGZrawjTPKxV6uxQdBS5fvI7+dXuVUn7gKbgAJFCpV5OAFJjK2AUOYQe eHoZnGV30PZG8SjGL0t9JJxBVzxTNtHxOTH9IJqulo+0IKQ9oQ6+u73Q4AyoVUqc0N8vuM rnxiGJvVPPZ9DyU6aYEtcRVlRpaDATM= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=samsung.com header.s=mail20170921 header.b=U9Enp2W+; spf=pass (imf16.hostedemail.com: domain of da.gomez@samsung.com designates 210.118.77.11 as permitted sender) smtp.mailfrom=da.gomez@samsung.com; dmarc=pass (policy=none) header.from=samsung.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1715752660; a=rsa-sha256; cv=none; b=fLKUyxkCIgW8OK7r8Pm54lAxJIbQS3QB+v9VHUzUMxPIbWrEEpDdOlcyKaz48/Aw/RACLW I44Xid2e8H00w5sDGTsPhi56XpFVteyJfw7Bdt5Scap5KeIfFbAVQkVaBfta5yUKn/JYqh afDZ0zrL3M4/O3f9VIiPD/OlnwNXLrw= Received: from eucas1p2.samsung.com (unknown [182.198.249.207]) by mailout1.w1.samsung.com (KnoxPortal) with ESMTP id 20240515055739euoutp011ed1c7156d5d174fda8f78f4c87bae4b~Pk-P1dj_V2238622386euoutp01D for ; Wed, 15 May 2024 05:57:39 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.w1.samsung.com 20240515055739euoutp011ed1c7156d5d174fda8f78f4c87bae4b~Pk-P1dj_V2238622386euoutp01D 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 x-originating-ip: [106.210.248.161] 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/ga6gZBiZMzn4ADRkJg L5fElvZJUM0uEueOTIUaKizx6vgWdghbRuL/zvlMExi1ZyG5bxaSHbOQ7JiFZMcCRpZVjOKp pcW56anFxnmp5XrFibnFpXnpesn5uZsYgcny9L/jX3cwrnj1Ue8QIxMH4yFGCQ5mJRFekTTn NCHelMTKqtSi/Pii0pzU4kOM0hwsSuK8qinyqUIC6YklqdmpqQWpRTBZJg5OqQYmacYDHDlq ymanV8UdnnfZaqNc7+vHk47LTdW8/VNf1urzx6W/o/fVTzYXWi+zRLYpTVsv3f3c7bpjolsv p6wznvTSxrtOI37Zt117IpRLDTRZef6onleod1dwPSr41Js3qDpY+uuvT7czsw1uKn3j0m38 491x6Pwk1hxXPn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yVxXs+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> X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 5215A18001D X-Stat-Signature: cqhzn835h3gyz18jjrbs9f73kczhi13k X-Rspam-User: X-HE-Tag: 1715752660-312915 X-HE-Meta: U2FsdGVkX18EDgYloQnT5HMkqoJPhV01KaEkLCVqWgfpksm+6c5WJGhNrUyWYav4C+pZuuhVUFj05vudCFD3M/8Bm5auSh2QTWNhKaPLtI8lBIZ/1A7R1WDUiChmkCANwx6Ue8x9DDOGZepEsuebMEAkgLIrRqNQ9QWlVG8n5u5W6KvvOYEjuoC+wzWeaHt+Vw4Y3murO2/319xnBmMKHJMjPO7weIlvncYk40JZqUQs6xY/JnjITTiW2mp4mcmJl7pR7SatPYwZPi997g9SxnqEyF5r/ne9x8+ahTtQGf8HRmWGUuFR7B7I4lcd6HR3JP3/QKnphhAeHcm5gclZJKSEK6Q1BonJAp24GCarWIqL9vhtZBl5KqzE+7zeWPAtBkPi/WOSaHMyDmiUTFoWDadqtaCiJ2zfO0dKG6pTvzjQ1B8szog+6QonI2Z9SewtlVDVYV8HJnKAfYld9ctQ5MsChDrOr5Rhas8FeZ2wyK/Pac6+d3d8Xi45ODr2vQTWatwjv0ttB7SNFoXfti9HTPZu4OBcrJ9Ne7Jdug/UF6iZLhZU05XnNtvRZDffNR31gFPeHHWrdXnxsiNSLDhWFCgSsfIXMGLUrFJDYdpr6BRJX0f8TFdOIzWl7a/Sk2kBlTCjqI0/fH+yQtf3ISk9/sT6MXTFqtZTRRPW2eDsInXLAZYbgem6/J3MDfArf72aI+ia2U4Bkudo+lCWD7SJl0pw7K9Eize934cZLWIDwgjKfPkIqn/TKXD/NgxwT3OrUxJKVYGgpj+3NsRoznWVHn2aRysdLxafNdIZS8/tGnSfEEkO25OE0CvXPg4U6uVBzVE8KeqPvzVcLv4lQ2MicJcm5yL3vq5lZM8/vVfpCXguM+4mR52vttL0O1a2vBii0jaO0PqJo7UaVN799i5V+SXIk/aBl20JBo8+5Vd42rtjaR/QVlviQKzZsf5P/I/xOenPxCpWI3odS7kYMeY srOYVTFM 8+U2G7mVnDQAMJZrj89sVjaknz4p9E0A6vqkgrI+SgVhhrttfNiyUJUTVrg3rxTxrdTCwdYkZeYJtxWpDdXaRMNwjkK0bRn9a6qz7xpCpfArMTGiorHoadRp+YkJNwpq11/6O/+99E4L30rbL0AKkfLBv0sFPK7fTUwRARmd7ZFCkiflJDoe8G4J+eC7FKTu6dcz0Hxop+wdIcwU+VMMK8aBerXlJA3e/FUSb2cxhgGaUlaytUlI+t7jzhFaVzitwdL0K/qq+2GVzi7ScTkrvS4UwIw== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: 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: 13664610 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id A44C0C25B75 for ; Wed, 15 May 2024 05:58:09 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 41DC86B03DB; Wed, 15 May 2024 01:57:46 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3CF446B03DD; Wed, 15 May 2024 01:57:46 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 21FFC6B03DC; Wed, 15 May 2024 01:57:46 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id E73786B03DA for ; Wed, 15 May 2024 01:57:45 -0400 (EDT) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id A9D9F1C1881 for ; Wed, 15 May 2024 05:57:45 +0000 (UTC) X-FDA: 82119573690.12.299E843 Received: from mailout1.w1.samsung.com (mailout1.w1.samsung.com [210.118.77.11]) by imf01.hostedemail.com (Postfix) with ESMTP id 7096D40007 for ; Wed, 15 May 2024 05:57:42 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=samsung.com header.s=mail20170921 header.b=SONL4RGQ; dmarc=pass (policy=none) header.from=samsung.com; spf=pass (imf01.hostedemail.com: domain of da.gomez@samsung.com designates 210.118.77.11 as permitted sender) smtp.mailfrom=da.gomez@samsung.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1715752662; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=SA7vsxMb4nPPaawAJ345Tbdd6TJyw9vmKosmLEJCqb4=; b=Y+HYhtu3SdNVy0tsm7OCH9OVP9MFDH55w7YtALYwIWS/2v1UQB359OHhfeAIoptYS1yNAt CRYR2GkiBTeTrWlPALFsTNAahgF5//7hP55wZ25BOqM4Eki3zpWX24iHkC/t1YBNIFKfdV t56W77/ULCwiN6sWWP9aHFyZNYC8kjM= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=samsung.com header.s=mail20170921 header.b=SONL4RGQ; dmarc=pass (policy=none) header.from=samsung.com; spf=pass (imf01.hostedemail.com: domain of da.gomez@samsung.com designates 210.118.77.11 as permitted sender) smtp.mailfrom=da.gomez@samsung.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1715752662; a=rsa-sha256; cv=none; b=sOUAdH8YxFE0TMYKhY5xjHt0oZScp4dMPJ2pnPMFDwSDpnSiFlFYrLzTuMQNvu1YNMtP4r v2IS/oXzxU2QQ/cKssyEYax4VnWwaJ7+5ZJ7awq4yGQwO4+jcsNdvDdIBEDKYQyr/9w+u1 nV1Ttv7c/7+IxQYq46+YIqeF1UUF6Xw= Received: from eucas1p2.samsung.com (unknown [182.198.249.207]) by mailout1.w1.samsung.com (KnoxPortal) with ESMTP id 20240515055741euoutp01e0140bc2a10abd443dfc4e8de0f0eeb5~Pk-RzVCif1508115081euoutp01O for ; Wed, 15 May 2024 05:57:41 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.w1.samsung.com 20240515055741euoutp01e0140bc2a10abd443dfc4e8de0f0eeb5~Pk-RzVCif1508115081euoutp01O 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 x-originating-ip: [106.210.248.161] MIME-Version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAA02Se0xTZxjG851zenporB5KtV/qxIBhQ9Ai0cUPZpRkGI9x2WayZRMv0K0H RKFAD53oNMGRzdkwws2pBSayMC4SScq9Qo2AKBQwchNELi6tl3YBKZJVIFTawxb++z3v877f 877JR+GSWYGcilenshq1MsGfFBH1He96tw98Hhm748pwMCqsriKRq6UDIHubA6C++76oJ2uB RHPV8zjqt6xFVkcWgQquZmCo31hIovEqlwAZFxuFyGRvwdFwthWge12/CtGCc9ltMB6J8Gaa 9GNCptigZWrKgxhD5WWSMThyhczDawsE0/Q8jMkbLgPMjPUpwUybBkmmu7hdyMwafL9cEyXa o2IT4n9gNSF7Y0Qn63MnBcmP5WnNjT1YOqhdrwNeFKR3wYmMS5gOiCgJXQ5gR1Mlzou3AJbm 9wNezAJYZpggdIDyjDx6IefrZQA6x55g/zf99q5bwItuAF+PTxG8qABw4KqRdCeS9FZo6jQI 3YaUHgXQ2tXtETjdKYCLNU2Eu8uH/haai+qAm6X0cag3DQl4VsCuyX5PnaAD4JRrAXezmA6H BY3tmJu9lnnsxpwnDdCb4N8V80I347QMPrXcwPi7vWFJQTPO8wa4ZHxO8rwN9jyxAJ53wLpS E8HzFlg99QvGv6OAw1fySZ6D4V837Ss7eMPO6xbPyZC+J4LNHeaV4UjY1/dsJcwH2h7UCnn+ AJrzMolsEKxftZ9+VYZ+VYZ+VUYxICqBjNVyiXEsF6pmzyg4ZSKnVccpvk9KNIDlf2leeuBo BEW2GUUrwCjQCiCF+0vF0thPYyVilfLsOVaTFK3RJrBcK9hIEf4ycYBqMyuh45Sp7GmWTWY1 /7kY5SVPx2LCjL+/yRk93ndpX3zGhgPrsgc3inPnBMz+ybMlsn2Z2vlP7AH1623abYsRL0cq NJE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yg3Hlq496hxiZOBgPMUpwMCuJ8IqkOacJ8aYk 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> X-Rspamd-Queue-Id: 7096D40007 X-Stat-Signature: fwxcimbbsmjron9cj94yyxdxqhnf6zke X-Rspam-User: X-Rspamd-Server: rspam04 X-HE-Tag: 1715752662-550447 X-HE-Meta: U2FsdGVkX1+GEeLGakuxXm03DM8PNZwmuu3PXPf8TZLPymKyHSOj18ONyuUwCh8cRygACL0L+RR7D0h7/99O00UPkkpLhHJ1TqxF47Y8PSbK//P+y2CGJ/am0N4AdMukWBXUv0KkYxl1KofASUbTQsBu4RCrj9Cfwy4wIAsMDIc7Hcy7A5Oglz4GxCQXMcDEWZ929MNVAANWEXHa+9Yu2FWcVxkrt0oqHuRYUhDCAigT5f5QYYdMTrRSknRCsrG1zouEU5wVVDZxua5p0RVVWarB5FGdeqjPDD0AJklI7NxouVbEb1JdXwXjjT/6C7VDtzt1oHwiOt4UQDWRCo4bNMU2zpZw2fYTA8BR7HseADji2Th8tg02uKQNV0gfpJQmIPZraUlNBynhBlzsdDMbTGspRXiNcRsM/wQ0FZPsjKyKz3BZTmxF0wse/bqSu74V+CIZCWODIn2E/GdpzIdzDqE7bwdFqQs9vTfSBawq8v/vts0SyLPDTNb7J0b5ofv20ZvmdE2IHIgIoqC0ljPFUNFwL4A8I2tKRB/yd2dJ3hAPo/D7tjh8ZjV1AtBky3cEZNkD3U8xoKy8jl1Ao1xObVX2/to7+ONSOgIh8X/HUUSKs2zIdg8y/0MndwCWIMVPxCgoIbnVjhVs3ANZLk9j0U6PfDq7ddpeFRMe6WEKoWio433rGJmeDvAqIoPsI5zsiQiQidAnalJEQkGJ1JVBrKt25xUqaN5xi1i2AQhNbnzN4d4Q/uM6jKdOYQN+/EezyMdWz4G9RU/URjP96E7uw9TOArDxqER4EhinXDljbOm+SYSPNvE+hR4ww0+WOUdfl3GZiLrTrtvMt3uoDX4FO8qqBc5XygwAnOlmw9YJ595UdLfYXjQwNb/NyOe4wkY1b8mQVPford5hZMlaMyaZpKM7Mr5gQmU8korVG5bcpBJSkqLJyXaow46it+FA4V1/usC6BlFDf4X5pqW8Qqm S2Vl6D2p v0iYNX6xOyTJJFG71hdShD6RnpZux5sJB3dQ/gynG+pXVrUghP4frLntIYfHLB6t4u6Xd7K9GPICsDnq2PYn1rA+2RNS55K8SUYrd/9+UH59XeKDJVgCn3Y3IIeOCJYjIJyFjLrijgHls/qAshHt/2hyYtvoRVH77LLFojUo3SVgUl+DkJqbhFKVvw6TBhJUdayPme6eP46xPfSLGWNPIUoxwVL6tv1p7iuS1fgKYe38Q3UM= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: 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); }