* [PATCH] xfs: improve xfs_iext_destroy() by freeing extent indirection array directly
@ 2013-09-20 14:41 Jeff Liu
2013-09-23 0:36 ` Dave Chinner
0 siblings, 1 reply; 7+ messages in thread
From: Jeff Liu @ 2013-09-20 14:41 UTC (permalink / raw)
To: xfs@oss.sgi.com
From: Jie Liu <jeff.liu@oracle.com>
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.
Signed-off-by: Jie Liu <jeff.liu@oracle.com>
---
fs/xfs/xfs_inode_fork.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/fs/xfs/xfs_inode_fork.c b/fs/xfs/xfs_inode_fork.c
index 02f1083..ba70f98 100644
--- a/fs/xfs/xfs_inode_fork.c
+++ b/fs/xfs/xfs_inode_fork.c
@@ -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
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs
^ permalink raw reply related [flat|nested] 7+ messages in thread* Re: [PATCH] xfs: improve xfs_iext_destroy() by freeing extent indirection array directly
2013-09-20 14:41 [PATCH] xfs: improve xfs_iext_destroy() by freeing extent indirection array directly Jeff Liu
@ 2013-09-23 0:36 ` Dave Chinner
2013-09-23 4:56 ` Jeff Liu
0 siblings, 1 reply; 7+ messages in thread
From: Dave Chinner @ 2013-09-23 0:36 UTC (permalink / raw)
To: Jeff Liu; +Cc: xfs@oss.sgi.com
On Fri, Sep 20, 2013 at 10:41:22PM +0800, Jeff Liu wrote:
> From: Jie Liu <jeff.liu@oracle.com>
>
> 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?
> This patch refine xfs_iext_destroy() by freeing the extent records from
> the indirection array directly in this case.
>
> Signed-off-by: Jie Liu <jeff.liu@oracle.com>
> ---
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
> fs/xfs/xfs_inode_fork.c | 7 +++++--
> 1 file changed, 5 insertions(+), 2 deletions(-)
>
> diff --git a/fs/xfs/xfs_inode_fork.c b/fs/xfs/xfs_inode_fork.c
> index 02f1083..ba70f98 100644
> --- a/fs/xfs/xfs_inode_fork.c
> +++ b/fs/xfs/xfs_inode_fork.c
> @@ -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);
The code looks correct...
Cheers,
Dave.
--
Dave Chinner
david@fromorbit.com
_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: [PATCH] xfs: improve xfs_iext_destroy() by freeing extent indirection array directly
2013-09-23 0:36 ` Dave Chinner
@ 2013-09-23 4:56 ` Jeff Liu
2013-09-23 23:50 ` Dave Chinner
0 siblings, 1 reply; 7+ messages in thread
From: Jeff Liu @ 2013-09-23 4:56 UTC (permalink / raw)
To: Dave Chinner; +Cc: xfs@oss.sgi.com
On 09/23/2013 08:36 AM, Dave Chinner wrote:
> On Fri, Sep 20, 2013 at 10:41:22PM +0800, Jeff Liu wrote:
>> From: Jie Liu <jeff.liu@oracle.com>
>>
>> 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?
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.
>
> 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
>
>> This patch refine xfs_iext_destroy() by freeing the extent records from
>> the indirection array directly in this case.
>>
>> Signed-off-by: Jie Liu <jeff.liu@oracle.com>
>> ---
>
> 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
>
>> fs/xfs/xfs_inode_fork.c | 7 +++++--
>> 1 file changed, 5 insertions(+), 2 deletions(-)
>>
>> diff --git a/fs/xfs/xfs_inode_fork.c b/fs/xfs/xfs_inode_fork.c
>> index 02f1083..ba70f98 100644
>> --- a/fs/xfs/xfs_inode_fork.c
>> +++ b/fs/xfs/xfs_inode_fork.c
>> @@ -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);
>
>
> The code looks correct...
>
> Cheers,
>
> Dave.
_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: [PATCH] xfs: improve xfs_iext_destroy() by freeing extent indirection array directly
2013-09-23 4:56 ` Jeff Liu
@ 2013-09-23 23:50 ` Dave Chinner
2013-09-24 14:05 ` Jeff Liu
0 siblings, 1 reply; 7+ messages in thread
From: Dave Chinner @ 2013-09-23 23:50 UTC (permalink / raw)
To: Jeff Liu; +Cc: xfs@oss.sgi.com
On Mon, Sep 23, 2013 at 12:56:56PM +0800, Jeff Liu wrote:
> On 09/23/2013 08:36 AM, Dave Chinner wrote:
>
> > On Fri, Sep 20, 2013 at 10:41:22PM +0800, Jeff Liu wrote:
> >> From: Jie Liu <jeff.liu@oracle.com>
> >>
> >> 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?
>
> 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.
--
Dave Chinner
david@fromorbit.com
_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] xfs: improve xfs_iext_destroy() by freeing extent indirection array directly
2013-09-23 23:50 ` Dave Chinner
@ 2013-09-24 14:05 ` Jeff Liu
0 siblings, 0 replies; 7+ messages in thread
From: Jeff Liu @ 2013-09-24 14:05 UTC (permalink / raw)
To: Dave Chinner; +Cc: xfs@oss.sgi.com
On 09/24/2013 07:50 AM, Dave Chinner wrote:
> On Mon, Sep 23, 2013 at 12:56:56PM +0800, Jeff Liu wrote:
>> On 09/23/2013 08:36 AM, Dave Chinner wrote:
>>
>>> On Fri, Sep 20, 2013 at 10:41:22PM +0800, Jeff Liu wrote:
>>>> From: Jie Liu <jeff.liu@oracle.com>
>>>>
>>>> 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?
>>
>> 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
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH] xfs: improve xfs_iext_destroy() by freeing extent indirection array directly
@ 2013-09-20 13:21 Jeff Liu
2013-09-20 14:39 ` Jeff Liu
0 siblings, 1 reply; 7+ messages in thread
From: Jeff Liu @ 2013-09-20 13:21 UTC (permalink / raw)
To: xfs@oss.sgi.com
From: Jie Liu <jeff.liu@oracle.com>
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.
Signed-off-by: Jie Liu <jeff.liu@oracle.com>
---
fs/xfs/xfs_inode_fork.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/fs/xfs/xfs_inode_fork.c b/fs/xfs/xfs_inode_fork.c
index 02f1083..ba70f98 100644
--- a/fs/xfs/xfs_inode_fork.c
+++ b/fs/xfs/xfs_inode_fork.c
@@ -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_idex = 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
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs
^ permalink raw reply related [flat|nested] 7+ messages in thread* Re: [PATCH] xfs: improve xfs_iext_destroy() by freeing extent indirection array directly
2013-09-20 13:21 Jeff Liu
@ 2013-09-20 14:39 ` Jeff Liu
0 siblings, 0 replies; 7+ messages in thread
From: Jeff Liu @ 2013-09-20 14:39 UTC (permalink / raw)
To: xfs@oss.sgi.com
On 09/20/2013 09:21 PM, Jeff Liu wrote:
> From: Jie Liu <jeff.liu@oracle.com>
>
> 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.
>
> Signed-off-by: Jie Liu <jeff.liu@oracle.com>
> ---
> fs/xfs/xfs_inode_fork.c | 7 +++++--
> 1 file changed, 5 insertions(+), 2 deletions(-)
>
> diff --git a/fs/xfs/xfs_inode_fork.c b/fs/xfs/xfs_inode_fork.c
> index 02f1083..ba70f98 100644
> --- a/fs/xfs/xfs_inode_fork.c
> +++ b/fs/xfs/xfs_inode_fork.c
> @@ -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_idex = 0; erp_idx < nlists; erp_idx++) {
Sorry, here is a typo, s/erp_idex/erp_idx/, will resend it.
> + 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);
_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2013-09-24 14:04 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-09-20 14:41 [PATCH] xfs: improve xfs_iext_destroy() by freeing extent indirection array directly Jeff Liu
2013-09-23 0:36 ` Dave Chinner
2013-09-23 4:56 ` Jeff Liu
2013-09-23 23:50 ` Dave Chinner
2013-09-24 14:05 ` Jeff Liu
-- strict thread matches above, loose matches on Subject: below --
2013-09-20 13:21 Jeff Liu
2013-09-20 14:39 ` Jeff Liu
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox