Skip to contentSkip to conversation

xfs: improve xfs_iext_destroy() by freeing extent indirection array directly

PATCH Superseded Jeff Liu 2 participants 5 messages Sep 20, 2013 – Sep 24, 2013 XFS filesystem

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Jeff Liu

author
#0 lore raw

PATCH 1/1 xfs: improve xfs_iext_destroy() by freeing extent indirection array directly

From: Jie Liu <[email protected]>

To free the incore file extents stores at the indirection array, we call the common routine xfs_iext_irec_remove() to remove a record from the array one at a time in reverse order, which will resize an extent indirection array repeatedly according to the array size.

This is not often the case to make a file with thousands extent records stores at an indirection array, but above operation is inefficient and could result in memory fragments.

This patch refine xfs_iext_destroy() by freeing the extent records from the indirection array directly in this case.

---
 fs/xfs/xfs_inode_fork.c |    7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
fs/xfs/xfs_inode_fork.c +5 -2
index 02f1083..ba70f98 100644
@@ -1525,9 +1525,12 @@ xfs_iext_destroy(
 		int	nlists;
 
 		nlists = ifp->if_real_bytes / XFS_IEXT_BUFSZ;
-		for (erp_idx = nlists - 1; erp_idx >= 0 ; erp_idx--) {
-			xfs_iext_irec_remove(ifp, erp_idx);
+		for (erp_idx = 0; erp_idx < nlists; erp_idx++) {
+			xfs_ext_irec_t	*erp = &ifp->if_u1.if_ext_irec[erp_idx];
+			if (erp->er_extbuf)
+				kmem_free(erp->er_extbuf);
 		}
+		kmem_free(ifp->if_u1.if_ext_irec);
 		ifp->if_flags &= ~XFS_IFEXTIREC;
 	} else if (ifp->if_real_bytes) {
 		kmem_free(ifp->if_u1.if_extents);

-- 1.7.9.5

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

#1 lore raw
Quoted 10 lines · Jeff Liu

From: Jie Liu <[email protected]>

To free the incore file extents stores at the indirection array, we call the common routine xfs_iext_irec_remove() to remove a record from the array one at a time in reverse order, which will resize an extent indirection array repeatedly according to the array size.

This is not often the case to make a file with thousands extent records stores at an indirection array, but above operation is inefficient and could result in memory fragments.

Yes, it may be inefficient, but I don't see that it's a contributor to memory fragmentation as the reallocated buffer is freed shortly after it has been allocated as the array shrinks. Do you have any evidence to suggest that such behaviour is actually fragmenting memory? If so, is the any test case that reproduces this problem?

How did you test the change?

Quoted 5 lines

This patch refine xfs_iext_destroy() by freeing the extent records from the indirection array directly in this case.

---

FWIW, it is best to title a resend as [PATCH x/y, V2], and here tell us what changed between posts such as:

V2:
- fixed typo in original posting

Quoted 9 lines
 fs/xfs/xfs_inode_fork.c |    7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
fs/xfs/xfs_inode_fork.c +0 -0
index 02f1083..ba70f98 100644
@@ -1525,9 +1525,12 @@ xfs_iext_destroy(
 		int	nlists;

fs/xfs/xfs_inode_fork.c xfs_iext_destroy( · line 1533

Quoted 10 lines
fs/xfs/xfs_inode_fork.c +5 -2
 
 		nlists = ifp->if_real_bytes / XFS_IEXT_BUFSZ;
-		for (erp_idx = nlists - 1; erp_idx >= 0 ; erp_idx--) {
-			xfs_iext_irec_remove(ifp, erp_idx);
+		for (erp_idx = 0; erp_idx < nlists; erp_idx++) {
+			xfs_ext_irec_t	*erp = &ifp->if_u1.if_ext_irec[erp_idx];
+			if (erp->er_extbuf)
+				kmem_free(erp->er_extbuf);
 		}
+		kmem_free(ifp->if_u1.if_ext_irec);

The code looks correct...

Cheers,

Dave.

Signature · 7 lines
Dave Chinner
[email protected]

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
author
#2 lore raw
Quoted 12 lines · Dave Chinner
Quoted 10 lines · Jeff Liu

From: Jie Liu <[email protected]>

To free the incore file extents stores at the indirection array, we call the common routine xfs_iext_irec_remove() to remove a record from the array one at a time in reverse order, which will resize an extent indirection array repeatedly according to the array size.

This is not often the case to make a file with thousands extent records stores at an indirection array, but above operation is inefficient and could result in memory fragments.

Quoted 5 lines

Yes, it may be inefficient, but I don't see that it's a contributor to memory fragmentation as the reallocated buffer is freed shortly after it has been allocated as the array shrinks. Do you have any evidence to suggest that such behaviour is actually fragmenting memory? If so, is the any test case that reproduces this problem?

Ah, yes, it should not cause memory fragmentation.

The benefits is that this change could save alloc/free buffers depending on the number of extents records are stored at indirection array.

Quoted 2 lines

How did you test the change?

I only test this change with a simple case for creating a sparse file with 8192 extents, which was shown as following,

xfs_io -f -c "truncate 10g" /xfs/testme

for i in $(seq 0 1 8191); do

	offset=$(($i * $((1 << 20))))
	xfs_io -c "pwrite $offset 1k" /xfs/testme

done

Quoted 4 lines
Quoted 4 lines

This patch refine xfs_iext_destroy() by freeing the extent records from the indirection array directly in this case.

Quoted 8 lines
Quoted 2 lines

---

FWIW, it is best to title a resend as [PATCH x/y, V2], and here tell us what changed between posts such as:

V2:
- fixed typo in original posting

Ok. :)

Thanks,
-Jeff

Quoted 24 lines
Quoted 10 lines
 fs/xfs/xfs_inode_fork.c |    7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
fs/xfs/xfs_inode_fork.c +0 -0
index 02f1083..ba70f98 100644
@@ -1525,9 +1525,12 @@ xfs_iext_destroy(
 		int	nlists;

fs/xfs/xfs_inode_fork.c xfs_iext_destroy( · line 1533

Quoted 10 lines
fs/xfs/xfs_inode_fork.c +5 -2
 
 		nlists = ifp->if_real_bytes / XFS_IEXT_BUFSZ;
-		for (erp_idx = nlists - 1; erp_idx >= 0 ; erp_idx--) {
-			xfs_iext_irec_remove(ifp, erp_idx);
+		for (erp_idx = 0; erp_idx < nlists; erp_idx++) {
+			xfs_ext_irec_t	*erp = &ifp->if_u1.if_ext_irec[erp_idx];
+			if (erp->er_extbuf)
+				kmem_free(erp->er_extbuf);
 		}
+		kmem_free(ifp->if_u1.if_ext_irec);

The code looks correct...

Quoted 3 lines

Cheers,

Dave.

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

#3 lore raw
Quoted 20 lines · Jeff Liu
Quoted 12 lines · Dave Chinner
Quoted 10 lines · Jeff Liu

From: Jie Liu <[email protected]>

To free the incore file extents stores at the indirection array, we call the common routine xfs_iext_irec_remove() to remove a record from the array one at a time in reverse order, which will resize an extent indirection array repeatedly according to the array size.

This is not often the case to make a file with thousands extent records stores at an indirection array, but above operation is inefficient and could result in memory fragments.

Quoted 5 lines

Yes, it may be inefficient, but I don't see that it's a contributor to memory fragmentation as the reallocated buffer is freed shortly after it has been allocated as the array shrinks. Do you have any evidence to suggest that such behaviour is actually fragmenting memory? If so, is the any test case that reproduces this problem?

Quoted 4 lines

Ah, yes, it should not cause memory fragmentation.

The benefits is that this change could save alloc/free buffers depending on the number of extents records are stored at indirection array.

OK, can you send a new version with an updated commit message?

Cheers,

Dave.

Signature · 7 lines
Dave Chinner
[email protected]

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
author
#4 lore raw
Quoted 21 lines · Dave Chinner
Quoted 20 lines · Jeff Liu
Quoted 17 lines · Dave Chinner
Quoted 10 lines · Jeff Liu

From: Jie Liu <[email protected]>

To free the incore file extents stores at the indirection array, we call the common routine xfs_iext_irec_remove() to remove a record from the array one at a time in reverse order, which will resize an extent indirection array repeatedly according to the array size.

This is not often the case to make a file with thousands extent records stores at an indirection array, but above operation is inefficient and could result in memory fragments.

Yes, it may be inefficient, but I don't see that it's a contributor to memory fragmentation as the reallocated buffer is freed shortly after it has been allocated as the array shrinks. Do you have any evidence to suggest that such behaviour is actually fragmenting memory? If so, is the any test case that reproduces this problem?

Quoted 6 lines
Quoted 4 lines

Ah, yes, it should not cause memory fragmentation.

The benefits is that this change could save alloc/free buffers depending on the number of extents records are stored at indirection array.

OK, can you send a new version with an updated commit message?

Sure, will post it soon.

Thanks,
-Jeff

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