From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from m16.mail.163.com (m16.mail.163.com [220.197.31.2]) (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 7D2F12AD35 for ; Sat, 3 Oct 2026 03:31:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=220.197.31.2 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790998304; cv=none; b=sL5Q0eo/q+wKgSfp110OWIMXD3ZvXl2Ox2sx66mA00XZiyuh7oQ4mF26Ce+edmfUTJSx1PrTryYHvAJFZyriNs7okZrDY/EsnZ8QJgzY+umDtn0AhFlcFCKh0JUNWD8WS7cp5eGhEFT4ueOW9tAXWVJ2arRomf1y7bjIn4wWErQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790998304; c=relaxed/simple; bh=yjbvQK4M9Z18bxvid7s05ayJKtf5pyrP3hsdZPtkmEA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=KeZD6RVFRz7clfzcya8nXGsPeb4wYetHIhD+ktpKFYytbb+Pfq/DwkrhWz+rJHDdpZNYfTCZdgoER+QoKQzLhThB582ZXLwK7bNVpjYKnDiob7kS8BEAwJAXg84eaAsgmeAGukAHJdF/zCFFY3aGeqcstFHrIHUQk+NBgduZJQ0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com; spf=pass smtp.mailfrom=163.com; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.b=F6CvxnSl; arc=none smtp.client-ip=220.197.31.2 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=163.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.b="F6CvxnSl" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:To:Subject:Date:Message-ID:MIME-Version; bh=4Y IOblJGYPNlFi0ZklAwvanYD54ri9Dcoj7DD599+0Q=; b=F6CvxnSliUeO2HDnSR 3rxOsme3FZ+UjlApAK3t+tuzDppL9xtmALTd8DrKpB6N73zLqOdy8u7Cm/mKCxb5 N4RLc59Ac+4Ty6RRSPwgUChF3eeRxsgzrrortWkhc1Fo2rxM/7x+CQoQPBsE9YDv DZnBis4hhbpA4HMLRen82UYBk= Received: from czl-pc (unknown []) by gzga-smtp-mtada-g0-1 (Coremail) with SMTP id _____wCXTnLfdsBqOdNwCA--.32914S5; Sat, 03 Oct 2026 11:30:43 +0800 (CST) From: Chi Zhiling To: exfat@lists.linux.dev, linux-kernel@vger.kernel.org Cc: Yuezhang.Mo@sony.com, chenxiaosong@chenxiaosong.com, dxdt@dev.snart.me, hyc.lee@gmail.com, linkinjeon@kernel.org, liubaolin12138@163.com, sj1557.seo@samsung.com, Chi Zhiling Subject: [PATCH v2 3/7] exfat: dirty all new pages when extending valid_size Date: Sat, 3 Oct 2026 11:30:28 +0800 Message-ID: <20261003033032.1775311-4-chizhiling@163.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20261003033032.1775311-1-chizhiling@163.com> References: <20261003033032.1775311-1-chizhiling@163.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID:_____wCXTnLfdsBqOdNwCA--.32914S5 X-Coremail-Antispam: 1Uf129KBjvJXoWxur43CF47KF18Cw1fWr45ZFb_yoW5try5pr W3Kr9xGrWDX34DuF1fXr18Zr1F93s3Wa18AFyxXwn3ZFn8Ar1DKr17K3W0vFy5trW7AFy0 gF1Yyry8uF1UXFJanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07jgcTPUUUUU= X-CM-SenderInfo: hfkl6xxlol0wi6rwjhhfrp/xtbC+AOgPmrAduNfFAAA3R From: Chi Zhiling In the current code, exfat_zero_new_range() does not mark non-uptodate pages as dirty, which may cause some blocks within a page to not be written back. This commit no longer checks each block in a non-uptodate page individually. Instead, it reads the entire page back into the cache and then writes it back as a whole. This allows concurrent writes and zeroing operations to be synchronized using the folio lock. Signed-off-by: Chi Zhiling --- fs/exfat/file.c | 89 ++++++++----------------------------------------- 1 file changed, 13 insertions(+), 76 deletions(-) diff --git a/fs/exfat/file.c b/fs/exfat/file.c index 81eeb76ef94b..e1394c5b016a 100644 --- a/fs/exfat/file.c +++ b/fs/exfat/file.c @@ -664,90 +664,27 @@ int exfat_file_fsync(struct file *filp, loff_t start, loff_t end, int datasync) static int exfat_zero_new_range(struct inode *inode, loff_t start, loff_t end) { struct address_space *mapping = inode->i_mapping; - unsigned int blocksize = i_blocksize(inode); - loff_t pos = start; - int err; + loff_t next, pos = start; + struct folio *folio; + pgoff_t index; while (pos < end) { - loff_t next = min_t(loff_t, - round_down(pos, PAGE_SIZE) + PAGE_SIZE, end); - struct folio *folio; - loff_t bpos; - - folio = filemap_get_folio(mapping, pos >> PAGE_SHIFT); - if (IS_ERR(folio)) { - err = iomap_zero_range(inode, pos, next - pos, NULL, - &exfat_iomap_ops, NULL, NULL); - if (err < 0) - return err; - pos = next; - continue; - } + index = pos >> PAGE_SHIFT; + next = min_t(loff_t, (index + 1) << PAGE_SHIFT, end); - if (folio_test_uptodate(folio)) { - folio_lock(folio); - if (folio->mapping == mapping) - folio_mark_dirty(folio); - folio_unlock(folio); - folio_put(folio); - pos = next; - continue; - } + balance_dirty_pages_ratelimited(mapping); - /* - * Zero not-uptodate block runs. iomap_zero_range() requires an - * unlocked folio, so recheck ->mapping after each call. - */ - folio_lock(folio); - bpos = pos; - while (bpos < next) { - loff_t rstart, rend; - - if (folio->mapping != mapping) { - folio_unlock(folio); - err = iomap_zero_range(inode, bpos, next - bpos, - NULL, &exfat_iomap_ops, NULL, NULL); - if (err < 0) { - folio_put(folio); - return err; - } - folio_lock(folio); - break; - } - - if (iomap_is_partially_uptodate(folio, - offset_in_folio(folio, bpos), blocksize)) { - bpos += blocksize; - continue; - } + folio = read_mapping_folio(mapping, index, NULL); + if (IS_ERR(folio)) + return PTR_ERR(folio); - rstart = bpos; - rend = min_t(loff_t, bpos + blocksize, next); - while (rend < next && - !iomap_is_partially_uptodate(folio, - offset_in_folio(folio, rend), blocksize)) - rend = min_t(loff_t, rend + blocksize, next); - - folio_unlock(folio); - err = iomap_zero_range(inode, rstart, rend - rstart, - NULL, &exfat_iomap_ops, NULL, NULL); - if (err < 0) { - folio_put(folio); - return err; - } - folio_lock(folio); - bpos = rend; - } - - /* - * Dirty only a fully uptodate folio. Dirtying a partial folio could - * write uninitialised cache contents over valid on-disk blocks. - */ - if (folio->mapping == mapping && folio_test_uptodate(folio)) + folio_lock(folio); + if (folio->mapping == mapping) { folio_mark_dirty(folio); + pos = next; + } folio_unlock(folio); folio_put(folio); - pos = next; } return 0; -- 2.53.0