diff options
| author | Konstantin Komarov <almaz.alexandrovich@paragon-software.com> | 2024-06-28 18:27:46 +0300 |
|---|---|---|
| committer | Konstantin Komarov <almaz.alexandrovich@paragon-software.com> | 2024-09-03 16:58:39 +0300 |
| commit | acdbd67bf939577d6f9e3cf796a005c31cec52d8 (patch) | |
| tree | 16a0dc2129bdb8d814a53dffdfdd74311122d448 /fs/ntfs3 | |
| parent | 2db86f7995fe6b62a4d6fee9f3cdeba3c6d27606 (diff) | |
| download | linux-acdbd67bf939577d6f9e3cf796a005c31cec52d8.tar.gz linux-acdbd67bf939577d6f9e3cf796a005c31cec52d8.tar.bz2 linux-acdbd67bf939577d6f9e3cf796a005c31cec52d8.zip | |
fs/ntfs3: Optimize large writes into sparse file
Optimized cluster allocation by allocating a large chunk in advance
before writing, instead of allocating during the writing process
by clusters.
Essentially replicates the logic of fallocate.
Fixes: 4342306f0f0d ("fs/ntfs3: Add file operations and implementation")
Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
Diffstat (limited to 'fs/ntfs3')
| -rw-r--r-- | fs/ntfs3/file.c | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/fs/ntfs3/file.c b/fs/ntfs3/file.c index cddc51f9a93b..d31eae611fe0 100644 --- a/fs/ntfs3/file.c +++ b/fs/ntfs3/file.c @@ -408,6 +408,42 @@ static int ntfs_extend(struct inode *inode, loff_t pos, size_t count, err = 0; } + if (file && is_sparsed(ni)) { + /* + * This code optimizes large writes to sparse file. + * TODO: merge this fragment with fallocate fragment. + */ + struct ntfs_sb_info *sbi = ni->mi.sbi; + CLST vcn = pos >> sbi->cluster_bits; + CLST cend = bytes_to_cluster(sbi, end); + CLST cend_v = bytes_to_cluster(sbi, ni->i_valid); + CLST lcn, clen; + bool new; + + if (cend_v > cend) + cend_v = cend; + + /* + * Allocate and zero new clusters. + * Zeroing these clusters may be too long. + */ + for (; vcn < cend_v; vcn += clen) { + err = attr_data_get_block(ni, vcn, cend_v - vcn, &lcn, + &clen, &new, true); + if (err) + goto out; + } + /* + * Allocate but not zero new clusters. + */ + for (; vcn < cend; vcn += clen) { + err = attr_data_get_block(ni, vcn, cend - vcn, &lcn, + &clen, &new, false); + if (err) + goto out; + } + } + inode_set_mtime_to_ts(inode, inode_set_ctime_current(inode)); mark_inode_dirty(inode); |
