Received: by 2002:a05:7412:3b8b:b0:fc:a2b0:25d7 with SMTP id nd11csp963702rdb; Fri, 9 Feb 2024 06:32:59 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVf7OxqDEpgdNdLLoi6RDkSDlzBqu6WAzy5w7BlSmTM8zey2Pu+yoZD1+pJjQjDyw2qlyRMEKTUAuIhHl5Ul90/YRTAYOWr1H8jXDXYjg== X-Google-Smtp-Source: AGHT+IFj5Ez3pZ1i5RLIFvyyaZHVdFvLAGfJqGEfomA5DxlJZw2l917q2DudoWm5Pg5e869ngPBV X-Received: by 2002:a17:902:dac1:b0:1da:1827:d6cf with SMTP id q1-20020a170902dac100b001da1827d6cfmr746295plx.51.1707489179585; Fri, 09 Feb 2024 06:32:59 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707489179; cv=pass; d=google.com; s=arc-20160816; b=DAtFt3U/hry6s3bZRkcKp3BLbCA5SyxP2pgWaaeHhknzDPMn3JHGtjMlmjOxbtxHO4 CwDuWcjcd23/DShIQWbhAYgRhnFukTVNzYsV5yG2AHPru4lxDyz3uhyC34yTT6DondR6 xhZAKuoKi9bDyQQHKsg6K7RsQ8mHPf55SDc1aoDqY+y9McZtsnZD6unsXxTgrou+DkNU gksP62IpaYlFQ/JIOdKYr4vpkRc3u8Mi/gO8KPvEFjp5H0obTgvCoGBrmruY2g+pnjzt 5+lON22jJEdaxpwfG9fTYae43ie2yGnyvZjvboy6iJnzpkFigQnrZStg3R4/jCJnemBG Z+fw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:cms-type:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:content-transfer-encoding:content-language :accept-language:in-reply-to:message-id:date:thread-index :thread-topic:subject:cc:to:from:dkim-signature:dkim-filter; bh=5EX9mww1Yf0rOpRLklIYKmjmJtYHS5jxFy+jU2z9Pew=; fh=EADmVmE87qRFv/MXdT4K+OODJB94mFLYtvw/HN265Pk=; b=pO0hhinU+cVNkegCChKXsRuFYSCJRdts9RiPESNbqmXo8VxG36mIEjXwdn+4+3GhVi WQCAAJhHG6E0XyrWq56ycChn/0NxXg4aDTEd1to1s8tDTQ2XG4F+1+TNoCkuZ1cWqnVr 2nEeU6KL92LNPt1diulvBzpwmZ9oklAMV/1BTSQaaMWiUH4YdLt1Lgl9oErnUS+IOXge gRdJz4Llqkhu7al6Y23Nquol6AQ1mgAlXtHsSGrxG9N+N9P8BTavnUoWs9JTDTwNGPud TzUgY0LiUdnPOsGswVBW72BV84iEXB5n1U0N/A5/wPVrxf1CxP8jmfv7LFZmLogqCckO QGUw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=iNLm28Q5; arc=pass (i=1 spf=pass spfdomain=samsung.com dkim=pass dkdomain=samsung.com dmarc=pass fromdomain=samsung.com); spf=pass (google.com: domain of linux-kernel+bounces-59452-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-59452-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=samsung.com X-Forwarded-Encrypted: i=2; AJvYcCW9QST+wJOpb0S+XXvmn7w3MylaBJ8B8xaLFw7jVPfC2+2jNBKVRUFfKX3nFbT9hFWhmn0cvEUnKuDR3fkNXnCOjMiODkpBcbmvqPOo1g== Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id h12-20020a170902680c00b001d791ce5b52si1703163plk.209.2024.02.09.06.32.59 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 09 Feb 2024 06:32:59 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-59452-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=iNLm28Q5; arc=pass (i=1 spf=pass spfdomain=samsung.com dkim=pass dkdomain=samsung.com dmarc=pass fromdomain=samsung.com); spf=pass (google.com: domain of linux-kernel+bounces-59452-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-59452-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=samsung.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id A6F26288096 for ; Fri, 9 Feb 2024 14:29:56 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 390A069DEF; Fri, 9 Feb 2024 14:29:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=samsung.com header.i=@samsung.com header.b="iNLm28Q5" Received: from mailout1.w1.samsung.com (mailout1.w1.samsung.com [210.118.77.11]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D852569960 for ; Fri, 9 Feb 2024 14:29:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=210.118.77.11 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707488949; cv=none; b=ePVMZbDUm84eto0QBG9xp1m/81XpWENyO28jibgQDXZP0Do7h3YYwCgC4lOkG1o6j0wjZZfGAG2l4tYcSIix5H4nHtSE7YcmdBecMQqb/Px5oi1CeBbF/WXlf4AduHTT7a9FdP3hP50QWDkp5zuv01+WwH4AyMHoXY68OdnDSgg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707488949; c=relaxed/simple; bh=upFi55BRB2EZorGwFdgX6LBZWv46QR8JKnPuxrtnafY=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:Content-Type: MIME-Version:References; b=IrzPDep6G4Gy/ijiVODQ36SjwmSpH/3SEAovR3mgCwrn8qii5C7D0+mBgVmrKVeY7bf6hipd8LQgy9NWiztjESAPx+YvEJBPPDX0aUMuEL2sGbSI9vDOAMUaYLi9/YmFgEnG9lyvgyvDcK5JGkWBWPhcEhu0P2rP6hitpNReRNk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=samsung.com; spf=pass smtp.mailfrom=samsung.com; dkim=pass (1024-bit key) header.d=samsung.com header.i=@samsung.com header.b=iNLm28Q5; arc=none smtp.client-ip=210.118.77.11 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=samsung.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=samsung.com Received: from eucas1p2.samsung.com (unknown [182.198.249.207]) by mailout1.w1.samsung.com (KnoxPortal) with ESMTP id 20240209142906euoutp016f3adbfaf2da6399a5800c0bf40af16d~yOCZW2xLw2752227522euoutp01i for ; Fri, 9 Feb 2024 14:29:06 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.w1.samsung.com 20240209142906euoutp016f3adbfaf2da6399a5800c0bf40af16d~yOCZW2xLw2752227522euoutp01i DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1707488946; bh=5EX9mww1Yf0rOpRLklIYKmjmJtYHS5jxFy+jU2z9Pew=; h=From:To:CC:Subject:Date:In-Reply-To:References:From; b=iNLm28Q52eLnCOfv8G9K1mU0dX3bnVJ7nTJpdf1iOu6zrWSahXzu798GPGN2uutw3 dH9S2x4Fe0vbb3SYya8z7xMMwS4Tf9T4HQ5lzJx9Z0blo8q3MI7YDC/s9JKhNpAGMI ea1TZ65+ON5c7yQwpys2kl8OdcvYvuKc4Kq8T3Io= Received: from eusmges2new.samsung.com (unknown [203.254.199.244]) by eucas1p2.samsung.com (KnoxPortal) with ESMTP id 20240209142905eucas1p2901cf7d34b6c0b8739cc8cd9c806d0b4~yOCY8xfYl2314723147eucas1p2o; Fri, 9 Feb 2024 14:29:05 +0000 (GMT) Received: from eucas1p2.samsung.com ( [182.198.249.207]) by eusmges2new.samsung.com (EUCPMTA) with SMTP id DA.F5.09814.1B636C56; Fri, 9 Feb 2024 14:29:05 +0000 (GMT) Received: from eusmtrp2.samsung.com (unknown [182.198.249.139]) by eucas1p2.samsung.com (KnoxPortal) with ESMTPA id 20240209142905eucas1p2df56a08287a84a5fa004142100926bb4~yOCYgKpDC0208802088eucas1p2M; Fri, 9 Feb 2024 14:29:05 +0000 (GMT) Received: from eusmgms1.samsung.com (unknown [182.198.249.179]) by eusmtrp2.samsung.com (KnoxPortal) with ESMTP id 20240209142905eusmtrp2d681160c1113aac64263cd808d288845~yOCYfYvDM2110121101eusmtrp2a; Fri, 9 Feb 2024 14:29:05 +0000 (GMT) X-AuditID: cbfec7f4-711ff70000002656-39-65c636b16a2a Received: from eusmtip2.samsung.com ( [203.254.199.222]) by eusmgms1.samsung.com (EUCPMTA) with SMTP id 48.6F.09146.0B636C56; Fri, 9 Feb 2024 14:29:05 +0000 (GMT) Received: from CAMSVWEXC01.scsc.local (unknown [106.1.227.71]) by eusmtip2.samsung.com (KnoxPortal) with ESMTPA id 20240209142904eusmtip2518107333d642b9a564504242782a9dc~yOCYU-zq50196001960eusmtip2M; Fri, 9 Feb 2024 14:29:04 +0000 (GMT) Received: from CAMSVWEXC02.scsc.local (2002:6a01:e348::6a01:e348) by CAMSVWEXC01.scsc.local (2002:6a01:e347::6a01:e347) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Fri, 9 Feb 2024 14:29:04 +0000 Received: from CAMSVWEXC02.scsc.local ([::1]) by CAMSVWEXC02.scsc.local ([fe80::3c08:6c51:fa0a:6384%13]) with mapi id 15.00.1497.012; Fri, 9 Feb 2024 14:29:04 +0000 From: Daniel Gomez To: "viro@zeniv.linux.org.uk" , "brauner@kernel.org" , "jack@suse.cz" , "hughd@google.com" , "akpm@linux-foundation.org" CC: "dagmcr@gmail.com" , "linux-fsdevel@vger.kernel.org" , "linux-kernel@vger.kernel.org" , "linux-mm@kvack.org" , "willy@infradead.org" , "hch@infradead.org" , "mcgrof@kernel.org" , Pankaj Raghav , "gost.dev@samsung.com" , "Daniel Gomez" Subject: [RFC PATCH 3/9] shmem: move folio zero operation to write_begin() Thread-Topic: [RFC PATCH 3/9] shmem: move folio zero operation to write_begin() Thread-Index: AQHaW2RUQo5uE9Fs4EG+AkzmtoGKGQ== Date: Fri, 9 Feb 2024 14:29:02 +0000 Message-ID: <20240209142901.126894-4-da.gomez@samsung.com> In-Reply-To: <20240209142901.126894-1-da.gomez@samsung.com> Accept-Language: en-US, en-GB Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-messagesentrepresentingtype: 1 x-ms-exchange-transport-fromentityheader: Hosted Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFjrPKsWRmVeSWpSXmKPExsWy7djP87obzY6lGly5o2gxZ/0aNovXhz8x Wpzt+81mcXrCIiaLp5/6WCxmT29mstiz9ySLxeVdc9gs7q35z2pxY8JTRovzf4+zWvz+MYfN gcdj56y77B4LNpV6bF6h5bFpVSebx6ZPk9g9Tsz4zeJxZsERdo/Pm+Q8Nj15yxTAGcVlk5Ka k1mWWqRvl8CVsfSyVcFzwYrPJ76yNDDe5+ti5OSQEDCRePJ1I3MXIxeHkMAKRomZP5YzQjhf GCWadt5jhXA+M0q8PzSRGaalZ9UzFojEckaJj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MTR: 20240209142905eucas1p2df56a08287a84a5fa004142100926bb4 X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20240209142905eucas1p2df56a08287a84a5fa004142100926bb4 References: <20240209142901.126894-1-da.gomez@samsung.com> Simplify zero out operation by moving it from write_end() to the write_begin(). If a large folio does not have any block uptodate when we first get it, zero it out entirely. Signed-off-by: Daniel Gomez --- mm/shmem.c | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/mm/shmem.c b/mm/shmem.c index 5980d7b94f65..3bddf7a89c18 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)); } =20 +static inline bool sfs_is_any_uptodate(struct folio *folio) +{ + struct inode *inode =3D folio->mapping->host; + struct shmem_folio_state *sfs =3D 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)); } =20 +static inline bool shmem_is_any_uptodate(struct folio *folio) +{ + struct shmem_folio_state *sfs =3D 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) { @@ -2845,6 +2862,9 @@ shmem_write_begin(struct file *file, struct address_s= pace *mapping, if (ret) return ret; =20 + if (!shmem_is_any_uptodate(folio)) + folio_zero_range(folio, 0, folio_size(folio)); + *pagep =3D folio_file_page(folio, index); if (PageHWPoison(*pagep)) { folio_unlock(folio); @@ -2867,13 +2887,6 @@ shmem_write_end(struct file *file, struct address_sp= ace *mapping, if (pos + copied > inode->i_size) i_size_write(inode, pos + copied); =20 - if (!folio_test_uptodate(folio)) { - if (copied < folio_size(folio)) { - size_t from =3D 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); --=20 2.43.0