Re: [PATCH 3/9] nilfs2: extend SUFILE on-disk format to enable counting of live blocks

2015-03-13 Thread Ryusuke Konishi
On Tue, 24 Feb 2015 20:01:38 +0100, Andreas Rohner wrote:
> *buf,
>   int cleansi, cleansu, dirtysi, dirtysu;
>   long ncleaned = 0, ndirtied = 0;
>   int ret = 0;
> + bool sup_ext = (supsz >= NILFS_EXT_SUINFO_UPDATE_SIZE);
> + bool su_ext = nilfs_sufile_ext_supported(sufile);
>  
>   if (unlikely(nsup == 0))
>   return ret;
> @@ -926,6 +949,9 @@ ssize_t nilfs_sufile_set_suinfo(struct inode *sufile, 
> void *buf,
>   (~0UL << __NR_NILFS_SUINFO_UPDATE_FIELDS))
>   || (nilfs_suinfo_update_nblocks(sup) &&
>   sup->sup_sui.sui_nblocks >
> + nilfs->ns_blocks_per_segment)
> + || (nilfs_suinfo_update_nlive_blks(sup) && sup_ext &&
> + sup->sup_sui.sui_nlive_blks >
>   nilfs->ns_blocks_per_segment))
>   return -EINVAL;
>   }
> @@ -953,6 +979,14 @@ ssize_t nilfs_sufile_set_suinfo(struct inode *sufile, 
> void *buf,
>   if (nilfs_suinfo_update_nblocks(sup))
>   su->su_nblocks = cpu_to_le32(sup->sup_sui.sui_nblocks);
>  
> + if (nilfs_suinfo_update_nlive_blks(sup) && sup_ext && su_ext)
> + su->su_nlive_blks =
> + cpu_to_le32(sup->sup_sui.sui_nlive_blks);
> +
> + if (nilfs_suinfo_update_nlive_lastmod(sup) && sup_ext && su_ext)
> + su->su_nlive_lastmod =
> + cpu_to_le64(sup->sup_sui.sui_nlive_lastmod);
> +
>   if (nilfs_suinfo_update_flags(sup)) {
>   /*
>* Active flag is a virtual flag projected by running
> diff --git a/fs/nilfs2/sufile.h b/fs/nilfs2/sufile.h
> index c446325..d56498b 100644
> --- a/fs/nilfs2/sufile.h
> +++ b/fs/nilfs2/sufile.h
> @@ -28,6 +28,11 @@
>  #include 
>  #include "mdt.h"
>  
> +static inline int
> +nilfs_sufile_ext_supported(const struct inode *sufile)
> +{
> + return NILFS_MDT(sufile)->mi_entry_size >= NILFS_EXT_SEGMENT_USAGE_SIZE;
> +}
>  
>  static inline unsigned long nilfs_sufile_get_nsegments(struct inode *sufile)
>  {
> diff --git a/include/linux/nilfs2_fs.h b/include/linux/nilfs2_fs.h
> index ff3fea3..5d83c55 100644
> --- a/include/linux/nilfs2_fs.h
> +++ b/include/linux/nilfs2_fs.h
> @@ -220,9 +220,11 @@ struct nilfs_super_block {
>   * If there is a bit set in the incompatible feature set that the kernel
>   * doesn't know about, it should refuse to mount the filesystem.
>   */
> -#define NILFS_FEATURE_COMPAT_RO_BLOCK_COUNT  0x0001ULL
> +#define NILFS_FEATURE_COMPAT_SUFILE_EXTENSION(1ULL << 0)

This feature name is not good.  sufile can be extended more in a future.
You should name it based on the meaning of the extension of this time.

As I mentioned in another patch, I think this could be unified to the
TRACK_LIVE_BLKS feature that a later patch adds since the live block
counting of this patchset is inherently depending on the extention of
sufile.

>  
> -#define NILFS_FEATURE_COMPAT_SUPP0ULL
> +#define NILFS_FEATURE_COMPAT_RO_BLOCK_COUNT  (1ULL << 0)
> +

Regards,
Ryusuke Konishi
--
To unsubscribe from this list: send the line "unsubscribe linux-nilfs" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 3/9] nilfs2: extend SUFILE on-disk format to enable counting of live blocks

2015-02-24 Thread Andreas Rohner
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