From patchwork Fri Feb 9 14:29:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Gomez X-Patchwork-Id: 198913 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp891678dyd; Fri, 9 Feb 2024 06:31:20 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCV3AlzJ5WH34m04YmoA1QNPVgh0p0qJZyPgfrmVu0SEX3Pa4bxwzxLeE+3H9yG/u7m8GTWiVPL4YHuEBr5MCzB5ad56cA== X-Google-Smtp-Source: AGHT+IEt6F6BNcJ4HO3mj7t1lBed9ejTJsCcWynp85IMuIxwcz5RaInXC87+qfaK11Zqt9LxAcjS X-Received: by 2002:a05:6358:6f1a:b0:176:4135:fa3b with SMTP id r26-20020a0563586f1a00b001764135fa3bmr1478514rwn.31.1707489079623; Fri, 09 Feb 2024 06:31:19 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707489079; cv=pass; d=google.com; s=arc-20160816; b=CP4SFJIE5FnBLLROGYq8bfRpE4nqbfQeZ3/i/f/nBFm0GXTcmOQd8B1ucChcv8jg7d biEb4UGG5j/QfU7rAC5leNEFjLzvx4Xd4dnWFzgWtF/zcJXplnsilcXxURHpO0igeNX6 EvBcVkR9TtIASB48EOCHk5VAHPela5DGTv2AZyHd0mrwslx3ckkVN1E0Gf3nQGvIo0hd 7zL16e1JIimMIX7VaOBE+doJ4qjN+KK4GmlrGCTNfkg8HRVNEqL+mbwG8s2PsVeIPUjY YYlxPJKIIDHErC6s8hL6N4ThWPUTmpD5nNupA3H+MU5lhf0rWDQTr2C6dECfuqPpz/95 qmbw== 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=LvyP7ys0AUVy6lZOQUIPKKHPfLmvYS3cHucwJcftXsY=; b=aOCftoVP1QMRKwvkykS/vZlopUp6+yEFgmwuFZx8srhliZryblNcRQMgTvkeUwIAOV vvq7LYPye7liqBOmACaFeGMHfZjbJpKYTEp9aCv2r8ZQF3VgjUPCs+FrGiQdrdg2Yqo9 BVUzkZHC/FNAEnlR6S7TzAi35Xl+CXWHoC18KTFMufkVkYfwob8eqQyAnW5o9Xm+iUWp DHoWzDMPQtm9TfirvEdrQTbDoFINuvQQhZtPMrQ4TbpZcqOkzSkocAtv47uiVNKjpNIA qxlrCJ/jkRRwmuVFA3HdDH1WwLYf122GtZr5O81ehMc0gLQcSw/oMfsZaWejMoD5t/gF KzKg==; 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-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-59452-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=samsung.com X-Forwarded-Encrypted: i=2; AJvYcCX6T2OhH1hEPlucPS0vCkJOhsnVnajU7LWM23tv1ZBGt4dHHc5yq5YfVq+o0xpv0Fiai9X5OM8PjCQ1xogYEOWbd1CjOA== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id a12-20020a0562140c2c00b0068c8519a28esi2067806qvd.398.2024.02.09.06.31.19 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 09 Feb 2024 06:31:19 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-59452-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::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-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-59452-ouuuleilei=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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 3EC171C229B7 for ; Fri, 9 Feb 2024 14:31:07 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 497376D1D4; Fri, 9 Feb 2024 14:29:14 +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 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 k1mWWqRvl8CVsfSyVcFzwYrPJ76yN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c1FxIgDA8rDp3QMAAA== X-CMS-MailID: 20240209142905eucas1p2df56a08287a84a5fa004142100926bb4 X-Msg-Generator: CA X-RootMTR: 20240209142905eucas1p2df56a08287a84a5fa004142100926bb4 X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20240209142905eucas1p2df56a08287a84a5fa004142100926bb4 References: <20240209142901.126894-1-da.gomez@samsung.com> X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790432069268553750 X-GMAIL-MSGID: 1790432069268553750 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)); } +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) { @@ -2845,6 +2862,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); @@ -2867,13 +2887,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);