ocfs2: add trimfs dlm lock
PATCH 1/1 ocfs2: add trimfs dlm lock
As you know, ocfs2 has support trim the underlying disk via fstrim command. But there is a problem, ocfs2 is a shared storage cluster file system, if the user configures a scheduled fstrim job on each file system node, this will trigger multiple nodes trim a shared disk simultaneously, it is very wasteful for CPU and IO consumption.
Then, we introduce a trimfs dlm lock, which will make only one fstrim command is running on the shared disk among the cluster, the other fstrim command should be returned with -EBUSY errno.
--- fs/ocfs2/alloc.c | 18 +++++++++++++++++- fs/ocfs2/dlmglue.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ fs/ocfs2/dlmglue.h | 2 ++ fs/ocfs2/ocfs2.h | 1 + fs/ocfs2/ocfs2_lockid.h | 5 +++++ 5 files changed, 73 insertions(+), 1 deletion(-)
fs/ocfs2/alloc.c +17 -1
@@ -7401,10 +7401,24 @@ int ocfs2_trim_fs(struct super_block *sb, struct fstrim_range *range)inode_lock (main_bm_inode); + ret =ocfs2_trim_fs_lock (osb); +if (ret <0 ) { +if (ret != -EAGAIN ) +mlog_errno (ret); +else { + ret = -EBUSY ; +mlog (ML_NOTICE , +"Cannot trim disk %s since a trim operation is " +"running on it from another node.\n" , + sb->s_id); + } + goto out_mutex; + } + ret =ocfs2_inode_lock (main_bm_inode, &main_bm_bh,0 );if (ret <0 ) {mlog_errno (ret); - goto out_mutex; + goto out_fsunlock; } main_bm = (struct ocfs2_dinode *)main_bm_bh->b_data;
@@ -7466,6 +7480,8 @@ int ocfs2_trim_fs(struct super_block *sb, struct fstrim_range *range) out_unlock:ocfs2_inode_unlock (main_bm_inode,0 );brelse (main_bm_bh); +out_fsunlock: +ocfs2_trim_fs_unlock (osb); out_mutex:inode_unlock (main_bm_inode);iput (main_bm_inode);
fs/ocfs2/dlmglue.c +48 -0
66 lines not on this page · raw message
fs/ocfs2/dlmglue.h +2 -0
@@ -153,6 +153,8 @@ void ocfs2_super_unlock(struct ocfs2_super *osb,void ocfs2_rename_unlock (struct ocfs2_super *osb);int ocfs2_nfs_sync_lock (struct ocfs2_super *osb,int ex);void ocfs2_nfs_sync_unlock (struct ocfs2_super *osb,int ex); +int ocfs2_trim_fs_lock (struct ocfs2_super *osb); +void ocfs2_trim_fs_unlock (struct ocfs2_super *osb);int ocfs2_dentry_lock (struct dentry *dentry,int ex);void ocfs2_dentry_unlock (struct dentry *dentry,int ex);int ocfs2_file_lock (struct file *file,int ex,int trylock);
fs/ocfs2/ocfs2.h +1 -0
@@ -404,6 +404,7 @@ struct ocfs2_superstruct ocfs2_lock_res osb_super_lockres;struct ocfs2_lock_res osb_rename_lockres;struct ocfs2_lock_res osb_nfs_sync_lockres; +struct ocfs2_lock_res osb_trim_fs_lockres;struct ocfs2_dlm_debug *osb_dlm_debug;struct dentry *osb_debug_root;
fs/ocfs2/ocfs2_lockid.h +5 -0
@@ -50,6 +50,7 @@ enum ocfs2_lock_type {OCFS2_LOCK_TYPE_NFS_SYNC ,OCFS2_LOCK_TYPE_ORPHAN_SCAN ,OCFS2_LOCK_TYPE_REFCOUNT , +OCFS2_LOCK_TYPE_TRIM_FS , OCFS2_NUM_LOCK_TYPES };
@@ -93,6 +94,9 @@ static inline char ocfs2_lock_type_char(enum ocfs2_lock_type type)case OCFS2_LOCK_TYPE_REFCOUNT : c ='T' ;break ; +case OCFS2_LOCK_TYPE_TRIM_FS : + c ='I' ; +break ;default : c ='\0' ; }
@@ -115,6 +119,7 @@ static inline char ocfs2_lock_type_char(enum ocfs2_lock_type type) [OCFS2_LOCK_TYPE_NFS_SYNC] = "NFSSync", [OCFS2_LOCK_TYPE_ORPHAN_SCAN] = "OrphanScan", [OCFS2_LOCK_TYPE_REFCOUNT] = "Refcount", + [OCFS2_LOCK_TYPE_TRIM_FS] = "TrimFs", };static inline const char *ocfs2_lock_type_string (enum ocfs2_lock_type type)
Signature · 1 line
1.8.5.6
PATCH 1/1 ocfs2: add trimfs dlm lock
Quoted 9 lines · On Thu, 7 Dec 2017 21:21:58 +0800 Gang He <[email protected]> wrote:
As you know, ocfs2 has support trim the underlying disk via fstrim command. But there is a problem, ocfs2 is a shared storage cluster file system, if the user configures a scheduled fstrim job on each file system node, this will trigger multiple nodes trim a shared disk simultaneously, it is very wasteful for CPU and IO consumption.
Then, we introduce a trimfs dlm lock, which will make only one fstrim command is running on the shared disk among the cluster, the other fstrim command should be returned with-EBUSYerrno.
Newly returning -EBUSY sounds a bit rude. And non-backward-compatible. Would it be better for the other fstrim callers to wait until the operation has completed then return success?
PATCH 1/1 ocfs2: add trimfs dlm lock
Hello Andrew and All,
Quoted 1 line
Quoted 1 line
Quoted 1 line
Andrew Morton <[email protected]> 12/08/17 7:34 AM >>>
Quoted 9 lines · On Thu, 7 Dec 2017 21:21:58 +0800 Gang He <[email protected]> wrote:
As you know, ocfs2 has support trim the underlying disk via fstrim command. But there is a problem, ocfs2 is a shared storage cluster file system, if the user configures a scheduled fstrim job on each file system node, this will trigger multiple nodes trim a shared disk simultaneously, it is very wasteful for CPU and IO consumption.
Then, we introduce a trimfs dlm lock, which will make only one fstrim command is running on the shared disk among the cluster, the other fstrim command should be returned with-EBUSYerrno.
Newly returning -EBUSY sounds a bit rude. And non-backward-compatible. Would it be better for the other fstrim callers to wait until the operation has completed then return success?
Gang: OK, that means, if multiple nodes trim a shared disk simultaneously, only one node (get the lock first) do the real trimming operation, the other nodes will wait until that node finishes trimming, then return zero. Does anyone has more comments? If not, I will do this change in v2.
Thanks
Gang
PATCH 1/1 ocfs2: add trimfs dlm lock
Hi Gang,
Quoted 15 lines · Gang He
Hello Andrew and All,
Quoted 1 line
Quoted 1 line
Quoted 1 line
Andrew Morton <[email protected]> 12/08/17 7:34 AM >>>
Quoted 9 lines · On Thu, 7 Dec 2017 21:21:58 +0800 Gang He <[email protected]> wrote:
As you know, ocfs2 has support trim the underlying disk via fstrim command. But there is a problem, ocfs2 is a shared storage cluster file system, if the user configures a scheduled fstrim job on each file system node, this will trigger multiple nodes trim a shared disk simultaneously, it is very wasteful for CPU and IO consumption.
Then, we introduce a trimfs dlm lock, which will make only one fstrim command is running on the shared disk among the cluster, the other fstrim command should be returned with-EBUSYerrno.
Quoted 8 lines
Newly returning
-EBUSYsounds a bit rude. And non-backward-compatible. Would it be better for the other fstrim callers to wait until the operation has completed then return success?
Gang: OK, that means, if multiple nodes trim a shared disk simultaneously, only one node (get the lock first) do the real trimming operation, the other nodes will wait until that node finishes trimming, then return zero. Does anyone has more comments? If not, I will do this change in v2.
IMO, it is better for the other fstrim callers to wait until this node finishes trimming.
Thanks,
Alex
Quoted 13 lines
Thanks
Gang_______________________________________________
Ocfs2-devel mailing list
Ocfs2-devel at oss.oracle.com
https://oss.oracle.com/mailman/listinfo/ocfs2-devel