Skip to contentSkip to conversation

xfs: add FITRIM support

PATCH Superseded Christoph Hellwig 3 participants 4 messages Jan 2, 2011 – Jan 6, 2011 XFS filesystem

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xfs: add FITRIM support

Allow manual discards from userspace using the FITRIM ioctl. This is not intended to be run during normal workloads, as the freepsace btree walks can cause large performance degradation.

---

V1 -> V2

- added __user annotations as noted by Alex
- removed non-blocking agf read as noted by Alex
- update range->len as noted by Alex

This does not implement the by-bno search or lock break suggestions from Dave. Given that the 2.6.38 window is about to close those seem a bit risky to me. I'll look into these later.

fs/xfs/xfs_alloc.c +3 -7
Index: xfs/fs/xfs/xfs_alloc.c
===================================================================
@@ -41,10 +41,6 @@
 #define	XFSA_FIXUP_BNO_OK	1
 #define	XFSA_FIXUP_CNT_OK	2
 
-static int
-xfs_alloc_busy_search(struct xfs_mount *mp, xfs_agnumber_t agno,
-		    xfs_agblock_t bno, xfs_extlen_t len);
-
 /*
  * Prototypes for per-ag allocation routines
  */
@@ -94,7 +90,7 @@ xfs_alloc_lookup_ge(
  * Lookup the first record less than or equal to [bno, len]
  * in the btree given by cur.
  */
-STATIC int				/* error */
+int					/* error */
 xfs_alloc_lookup_le(
 	struct xfs_btree_cur	*cur,	/* btree cursor */
 	xfs_agblock_t		bno,	/* starting block of extent */
@@ -127,7 +123,7 @@ xfs_alloc_update(
 /*
  * Get the data from the pointed-to record.
  */
-STATIC int				/* error */
+int					/* error */
 xfs_alloc_get_rec(
 	struct xfs_btree_cur	*cur,	/* btree cursor */
 	xfs_agblock_t		*bno,	/* output: starting block of extent */
@@ -2615,7 +2611,7 @@ restart:
  * will require a synchronous transaction, but it can still be
  * used to distinguish between a partial or exact match.
  */
-static int
+int
 xfs_alloc_busy_search(
 	struct xfs_mount	*mp,
 	xfs_agnumber_t		agno,
fs/xfs/xfs_alloc.h +20 -5
Index: xfs/fs/xfs/xfs_alloc.h
===================================================================
@@ -19,6 +19,7 @@
 #define	__XFS_ALLOC_H__
 
 struct xfs_buf;
+struct xfs_btree_cur;
 struct xfs_mount;
 struct xfs_perag;
 struct xfs_trans;
@@ -118,16 +119,16 @@ xfs_alloc_longest_free_extent(struct xfs
 		struct xfs_perag *pag);
 
 #ifdef __KERNEL__
-
 void
-xfs_alloc_busy_insert(xfs_trans_t *tp,
-		xfs_agnumber_t agno,
-		xfs_agblock_t bno,
-		xfs_extlen_t len);
+xfs_alloc_busy_insert(struct xfs_trans *tp, xfs_agnumber_t agno,
+	xfs_agblock_t bno, xfs_extlen_t len);
 
 void
 xfs_alloc_busy_clear(struct xfs_mount *mp, struct xfs_busy_extent *busyp);
 
+int
+xfs_alloc_busy_search(struct xfs_mount *mp, xfs_agnumber_t agno,
+	xfs_agblock_t bno, xfs_extlen_t len);
 #endif	/* __KERNEL__ */
 
 /*
@@ -205,4 +206,18 @@ xfs_free_extent(
 	xfs_fsblock_t	bno,	/* starting block number of extent */
 	xfs_extlen_t	len);	/* length of extent */
 
+int					/* error */
+xfs_alloc_lookup_le(
+	struct xfs_btree_cur	*cur,	/* btree cursor */
+	xfs_agblock_t		bno,	/* starting block of extent */
+	xfs_extlen_t		len,	/* length of extent */
+	int			*stat);	/* success/failure */
+
+int					/* error */
+xfs_alloc_get_rec(
+	struct xfs_btree_cur	*cur,	/* btree cursor */
+	xfs_agblock_t		*bno,	/* output: starting block of extent */
+	xfs_extlen_t		*len,	/* output: length of extent */
+	int			*stat);	/* output: success/failure */
+
 #endif	/* __XFS_ALLOC_H__ */
fs/xfs/Makefile +1 -0
Index: xfs/fs/xfs/Makefile
===================================================================
@@ -98,6 +98,7 @@ xfs-y				+= $(addprefix $(XFS_LINUX)/, \
 				   kmem.o \
 				   xfs_aops.o \
 				   xfs_buf.o \
+				   xfs_discard.o \
 				   xfs_export.o \
 				   xfs_file.o \
 				   xfs_fs_subr.o \
fs/xfs/linux-2.6/xfs_discard.c new file +191 -0

191 lines not on this page · raw message

fs/xfs/linux-2.6/xfs_discard.h new file +8 -0
Index: xfs/fs/xfs/linux-2.6/xfs_discard.h
===================================================================
@@ -0,0 +1,8 @@
+#ifndef XFS_DISCARD_H
+#define XFS_DISCARD_H 1
+
+struct fstrim_range;
+
+extern int	xfs_ioc_trim(struct xfs_mount *, struct fstrim_range __user *);
+
+#endif /* XFS_DISCARD_H */
fs/xfs/linux-2.6/xfs_trace.h +33 -0
Index: xfs/fs/xfs/linux-2.6/xfs_trace.h
===================================================================
@@ -1759,6 +1759,39 @@ DEFINE_LOG_RECOVER_INO_ITEM(xfs_log_reco
 DEFINE_LOG_RECOVER_INO_ITEM(xfs_log_recover_inode_cancel);
 DEFINE_LOG_RECOVER_INO_ITEM(xfs_log_recover_inode_skip);
 
+DECLARE_EVENT_CLASS(xfs_discard_class,
+	TP_PROTO(struct xfs_mount *mp, xfs_agnumber_t agno,
+		 xfs_agblock_t agbno, xfs_extlen_t len),
+	TP_ARGS(mp, agno, agbno, len),
+	TP_STRUCT__entry(
+		__field(dev_t, dev)
+		__field(xfs_agnumber_t, agno)
+		__field(xfs_agblock_t, agbno)
+		__field(xfs_extlen_t, len)
+	),
+	TP_fast_assign(
+		__entry->dev = mp->m_super->s_dev;
+		__entry->agno = agno;
+		__entry->agbno = agbno;
+		__entry->len = len;
+	),
+	TP_printk("dev %d:%d agno %u agbno %u len %u\n",
+		  MAJOR(__entry->dev), MINOR(__entry->dev),
+		  __entry->agno,
+		  __entry->agbno,
+		  __entry->len)
+)
+
+#define DEFINE_DISCARD_EVENT(name) \
+DEFINE_EVENT(xfs_discard_class, name, \
+	TP_PROTO(struct xfs_mount *mp, xfs_agnumber_t agno, \
+		 xfs_agblock_t agbno, xfs_extlen_t len), \
+	TP_ARGS(mp, agno, agbno, len))
+DEFINE_DISCARD_EVENT(xfs_discard_extent);
+DEFINE_DISCARD_EVENT(xfs_discard_toosmall);
+DEFINE_DISCARD_EVENT(xfs_discard_exclude);
+DEFINE_DISCARD_EVENT(xfs_discard_busy);
+
 #endif /* _TRACE_XFS_H */
 
 #undef TRACE_INCLUDE_PATH
fs/xfs/linux-2.6/xfs_ioctl.c +3 -0
Index: xfs/fs/xfs/linux-2.6/xfs_ioctl.c
===================================================================
@@ -39,6 +39,7 @@
 #include "xfs_dfrag.h"
 #include "xfs_fsops.h"
 #include "xfs_vnodeops.h"
+#include "xfs_discard.h"
 #include "xfs_quota.h"
 #include "xfs_inode_item.h"
 #include "xfs_export.h"
@@ -1294,6 +1295,8 @@ xfs_file_ioctl(
 	trace_xfs_file_ioctl(ip);
 
 	switch (cmd) {
+	case FITRIM:
+		return xfs_ioc_trim(mp, arg);
 	case XFS_IOC_ALLOCSP:
 	case XFS_IOC_FREESP:
 	case XFS_IOC_RESVSP:

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs

Reviewed-by on v1 1/1
#1 lore raw
Quoted 10 lines · Christoph Hellwig

Allow manual discards from userspace using the FITRIM ioctl. This is not intended to be run during normal workloads, as the freepsace btree walks can cause large performance degradation.

---

V1 -> V2

Quoted 7 lines

- added __user annotations as noted by Alex
- removed non-blocking agf read as noted by Alex
- update range->len as noted by Alex

This does not implement the by-bno search or lock break suggestions from Dave. Given that the 2.6.38 window is about to close those seem a bit risky to me. I'll look into these later.

Ok, seemms like a good way to proceed.

Cheers,

Dave.

Signature · 7 lines
Dave Chinner
[email protected]

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
Reviewed-by on v1 1/1
#2 lore raw
In reply to Christoph Hellwig
Quoted 5 lines · Christoph Hellwig

Allow manual discards from userspace using the FITRIM ioctl. This is not intended to be run during normal workloads, as the freepsace btree walks can cause large performance degradation.

This looks good, but I mention three things below. Correct them as you see fit, either way:

Quoted 11 lines

---

V1 -> V2

- added __user annotations as noted by Alex
- removed non-blocking agf read as noted by Alex
- update range->len as noted by Alex

This does not implement the by-bno search or lock break suggestions from Dave. Given that the 2.6.38 window is about to close those seem a bit risky to me. I'll look into these later.

. . .

fs/xfs/linux-2.6/xfs_discard.c line 2

Quoted 8 lines
				   xfs_fs_subr.o \

Index: xfs/fs/xfs/linux-2.6/xfs_discard.c
===================================================================

fs/xfs/linux-2.6/xfs_discard.c new file +2 -0
@@ -0,0 +1,191 @@
+/*
+ * Copyright (C) 2010 Red Hat, Inc.

Maybe 2011 now...

Quoted 6 lines
fs/xfs/linux-2.6/xfs_discard.c new file +6 -0
+ * All Rights Reserved.
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it would be useful,

fs/xfs/linux-2.6/xfs_discard.c line 19

Quoted 10 lines
fs/xfs/linux-2.6/xfs_discard.c new file +10 -0
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write the Free Software Foundation,
+ * Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+#include "xfs.h"
+#include "xfs_sb.h"

. . .

fs/xfs/linux-2.6/xfs_discard.c line 38

Quoted 4 lines
fs/xfs/linux-2.6/xfs_discard.c new file +4 -0
+
+STATIC int
+xfs_trim_extents(
+	struct xfs_mount	*mp,

. . .

fs/xfs/linux-2.6/xfs_discard.c line 103

Quoted 8 lines
fs/xfs/linux-2.6/xfs_discard.c new file +8 -0
+
+		/*
+		 * If the extent is entirely outside of the range we are
+		 * supposed to discard skip it.  Do not bother to trim
+		 * down partially overlapping ranges for now.
+		 */
+		if (XFS_AGB_TO_FSB(mp, agno, fbno) + flen < start ||
+		    XFS_AGB_TO_FSB(mp, agno, fbno) > start + len) {

^
I think this should be >=

fs/xfs/linux-2.6/xfs_discard.c line 106

Quoted 3 lines
fs/xfs/linux-2.6/xfs_discard.c new file +3 -0
+			trace_xfs_discard_exclude(mp, agno, fbno, flen);
+			goto next_extent;
+		}

. . .

fs/xfs/linux-2.6/xfs_discard.h

Quoted 4 lines

Index: xfs/fs/xfs/linux-2.6/xfs_discard.h
===================================================================

fs/xfs/linux-2.6/xfs_discard.h new file +0 -0

Do you want to add a boilerplate copyright header here?

fs/xfs/linux-2.6/xfs_discard.h line 8

Quoted 9 lines
fs/xfs/linux-2.6/xfs_discard.h new file +8 -0
@@ -0,0 +1,8 @@
+#ifndef XFS_DISCARD_H
+#define XFS_DISCARD_H 1
+
+struct fstrim_range;
+
+extern int	xfs_ioc_trim(struct xfs_mount *, struct fstrim_range __user *);
+
+#endif /* XFS_DISCARD_H */

. . .

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs

#3 lore raw
Quoted 3 lines
Quoted 1 line

+ * Copyright (C) 2010 Red Hat, Inc.

Maybe 2011 now...

Nothing major changes in 2011, so no.

Quoted 9 lines

fs/xfs/linux-2.6/xfs_discard.c line 103

Quoted 6 lines
fs/xfs/linux-2.6/xfs_discard.c new file +6 -0
+		 * If the extent is entirely outside of the range we are
+		 * supposed to discard skip it.  Do not bother to trim
+		 * down partially overlapping ranges for now.
+		 */
+		if (XFS_AGB_TO_FSB(mp, agno, fbno) + flen < start ||
+		    XFS_AGB_TO_FSB(mp, agno, fbno) > start + len) {

^
I think this should be >=

Yes.

Quoted 1 line

Do you want to add a boilerplate copyright header here?

Kinda hard to claim copyright on a single prototype.

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs