mm: kvfree the swap cluster info if the swap file is unsatisfactory
Subsystems (2)
PATCH 1/1 mm: kvfree the swap cluster info if the swap file is unsatisfactory
If initializing a small swap file fails because the swap file has a problem (holes, etc.) then we need to free the cluster info as part of cleanup. Unfortunately a previous patch changed the code to use kvzalloc but did not change all the vfree calls to use kvfree.
Found by running generic/357 from xfstests.
--- mm/swapfile.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
mm/swapfile.c +1 -1
@@ -3052,7 +3052,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags) p->flags =0 ;spin_unlock (&swap_lock);vfree (swap_map); -vfree (cluster_info); +kvfree (cluster_info);if (swap_file) {if (inode &&S_ISREG (inode->i_mode)) {inode_unlock (inode);
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
[email protected] liked your message with Boxer for Android.
On Aug 31, 2017 7:36 PM, "Darrick J. Wong" <[email protected]> wrote:
If initializing a small swap file fails because the swap file has a problem (holes, etc.) then we need to free the cluster info as part of cleanup. Unfortunately a previous patch changed the code to use kvzalloc but did not change all the vfree calls to use kvfree.
Found by running generic/357 from xfstests.
---mm/swapfile.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
mm/swapfile.c +0 -0
@@ -3052,7 +3052,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
p->flags = 0;spin_unlock(&swap_lock);vfree(swap_map);
-vfree(cluster_info);
+kvfree(cluster_info);
if (swap_file) {
if (inode && S_ISREG(inode->i_mode)) {inode_unlock(inode);
Quoted 8 lines · Darrick J. Wong
If initializing a small swap file fails because the swap file has a problem (holes, etc.) then we need to free the cluster info as part of cleanup. Unfortunately a previous patch changed the code to use kvzalloc but did not change all the vfree calls to use kvfree.
Found by running generic/357 from xfstests.
Signed-off-by Darrick J. Wong <[email protected]>
Thanks for fixing!
Best Regards,
Huang, Ying
Quoted 9 lines
--- mm/swapfile.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)mm/swapfile.c +0
-0
mm/swapfile.c SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags) · line 3058
Quoted 8 lines
mm/swapfile.c +1
-1@@ -3052,7 +3052,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags) p->flags =0 ;spin_unlock (&swap_lock);vfree (swap_map); -vfree (cluster_info); +kvfree (cluster_info);if (swap_file) {if (inode &&S_ISREG (inode->i_mode)) {inode_unlock (inode);
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 5 lines · Darrick J. Wong
If initializing a small swap file fails because the swap file has a problem (holes, etc.) then we need to free the cluster info as part of cleanup. Unfortunately a previous patch changed the code to use kvzalloc but did not change all the vfree calls to use kvfree.
Hopefully this can make it into 4.13.
Quoted 3 lines
Found by running generic/357 from xfstests.
Signed-off-by Darrick J. Wong <[email protected]>
But I think there's also a memory leak and we need this on top of your fix:
mm, swapfile: fix swapon frontswap_map memory leak on error
Free frontswap_map if an error is encountered before enable_swap_info().
--- mm/swapfile.c | 1 + 1 file changed, 1 insertion(+)
mm/swapfile.c +1 -0
@@ -3053,6 +3053,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)spin_unlock (&swap_lock);vfree (swap_map);kvfree (cluster_info); +kvfree (frontswap_map);if (swap_file) {if (inode &&S_ISREG (inode->i_mode)) {inode_unlock (inode);
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Huang, Ying
Reviewed-byQuoted 36 lines · David Rientjes
Quoted 5 lines · Darrick J. Wong
If initializing a small swap file fails because the swap file has a problem (holes, etc.) then we need to free the cluster info as part of cleanup. Unfortunately a previous patch changed the code to use kvzalloc but did not change all the vfree calls to use kvfree.
Hopefully this can make it into 4.13.
Fixes 54f180d3c181 ("mm, swap: use kvzalloc to allocate some swap data structures")Cc [email protected] [4.12]Quoted 3 lines
Found by running generic/357 from xfstests.
Signed-off-by Darrick J. Wong <[email protected]>Acked-by David Rientjes <[email protected]>But I think there's also a memory leak and we need this on top of your fix:
mm, swapfile: fix swapon
frontswap_mapmemory leak on errorFree
frontswap_mapif an error is encountered beforeenable_swap_info().Signed-off-by David Rientjes <[email protected]>--- mm/swapfile.c | 1 + 1 file changed, 1 insertion(+)
mm/swapfile.c SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags) · line 3059
Quoted 7 lines
mm/swapfile.c +1
-0@@ -3053,6 +3053,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)spin_unlock (&swap_lock);vfree (swap_map);kvfree (cluster_info); +kvfree (frontswap_map);if (swap_file) {if (inode &&S_ISREG (inode->i_mode)) {inode_unlock (inode);
Yes. There is a memory leak.
Best Regards,
Huang, Ying
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>