This patch extends the nilfs_segment_usage structure with two extra
fields. This changes the on-disk format of the SUFILE, but the nilfs2
metadata files are flexible enough, so that there are no compatibility
issues. The extension is fully backwards compatible. Nevertheless a
feature compatibility flag was added to indicate the on-disk format
change.
The new field su_nlive_blks is used to track the number of live blocks
in the corresponding segment. Its value should always be smaller than
su_nblocks, which contains the total number of blocks in the segment.
The field su_nlive_lastmod is necessary because of the protection period
used by the GC. It is a timestamp, which contains the last time
su_nlive_blks was modified. For example if a file is deleted, its
blocks are subtracted from su_nlive_blks and are therefore considered to
be reclaimable by the kernel. But the GC additionally protects them with
the protection period. So while su_nilve_blks contains the number of
potentially reclaimable blocks, the actual number depends on the
protection period. To enable GC policies to effectively choose or prefer
segments with unprotected blocks, the timestamp in su_nlive_lastmod is
necessary.
Signed-off-by: Andreas Rohner
---
fs/nilfs2/ioctl.c | 4 ++--
fs/nilfs2/sufile.c| 38 +--
fs/nilfs2/sufile.h| 5
include/linux/nilfs2_fs.h | 58 ---
4 files changed, 93 insertions(+), 12 deletions(-)
diff --git a/fs/nilfs2/ioctl.c b/fs/nilfs2/ioctl.c
index 9a20e51..f6ee54e 100644
--- a/fs/nilfs2/ioctl.c
+++ b/fs/nilfs2/ioctl.c
@@ -1250,7 +1250,7 @@ static int nilfs_ioctl_set_suinfo(struct inode *inode,
struct file *filp,
goto out;
ret = -EINVAL;
- if (argv.v_size < sizeof(struct nilfs_suinfo_update))
+ if (argv.v_size < NILFS_MIN_SUINFO_UPDATE_SIZE)
goto out;
if (argv.v_nmembs > nilfs->ns_nsegments)
@@ -1316,7 +1316,7 @@ long nilfs_ioctl(struct file *filp, unsigned int cmd,
unsigned long arg)
return nilfs_ioctl_get_cpstat(inode, filp, cmd, argp);
case NILFS_IOCTL_GET_SUINFO:
return nilfs_ioctl_get_info(inode, filp, cmd, argp,
- sizeof(struct nilfs_suinfo),
+ NILFS_MIN_SEGMENT_USAGE_SIZE,
nilfs_ioctl_do_get_suinfo);
case NILFS_IOCTL_SET_SUINFO:
return nilfs_ioctl_set_suinfo(inode, filp, cmd, argp);
diff --git a/fs/nilfs2/sufile.c b/fs/nilfs2/sufile.c
index a369c30..ae08050 100644
--- a/fs/nilfs2/sufile.c
+++ b/fs/nilfs2/sufile.c
@@ -466,6 +466,11 @@ void nilfs_sufile_do_scrap(struct inode *sufile, __u64
*data,
su->su_lastmod = cpu_to_le64(0);
su->su_nblocks = cpu_to_le32(0);
su->su_flags = cpu_to_le32(1UL << NILFS_SEGMENT_USAGE_DIRTY);
+ if (nilfs_sufile_ext_supported(sufile)) {
+ su->su_nlive_blks = cpu_to_le32(0);
+ su->su_pad = cpu_to_le32(0);
+ su->su_nlive_lastmod = cpu_to_le64(0);
+ }
kunmap_atomic(kaddr);
nilfs_sufile_mod_counter(header_bh, clean ? (u64)-1 : 0, dirty ? 0 : 1);
@@ -496,7 +501,7 @@ void nilfs_sufile_do_free(struct inode *sufile, __u64 *data,
WARN_ON(!nilfs_segment_usage_dirty(su));
sudirty = nilfs_segment_usage_dirty(su);
- nilfs_segment_usage_set_clean(su);
+ nilfs_segment_usage_set_clean(su, NILFS_MDT(sufile)->mi_entry_size);
kunmap_atomic(kaddr);
mark_buffer_dirty(su_bh);
@@ -551,6 +556,9 @@ int nilfs_sufile_set_segment_usage(struct inode *sufile,
__u64 segnum,
if (modtime)
su->su_lastmod = cpu_to_le64(modtime);
su->su_nblocks = cpu_to_le32(nblocks);
+ if (nilfs_sufile_ext_supported(sufile) &&
+ nblocks < le32_to_cpu(su->su_nlive_blks))
+ su->su_nlive_blks = su->su_nblocks;
kunmap_atomic(kaddr);
mark_buffer_dirty(bh);
@@ -713,7 +721,7 @@ static int nilfs_sufile_truncate_range(struct inode *sufile,
nc = 0;
for (su = su2, j = 0; j < n; j++, su = (void *)su + susz) {
if (nilfs_segment_usage_error(su)) {
- nilfs_segment_usage_set_clean(su);
+ nilfs_segment_usage_set_clean(su, susz);
nc++;
}
}
@@ -836,6 +844,8 @@ ssize_t nilfs_sufile_get_suinfo(struct inode *sufile, __u64
segnum, void *buf,
struct the_nilfs *nilfs = sufile->i_sb->s_fs_info;
void *kaddr;
unsigned long nsegs, segusages_per_block;
+ __u64 lm = 0;
+ __u32 nlb = 0;
ssize_t n;
int ret, i, j;
@@ -873,6 +883,17 @@ ssize_t nilfs_sufile_get_suinfo(struct inode *sufile,
__u64 segnum, void *buf,
if (nilfs_segm