null_blk: Fix: memory release when memory_backed=1

Message ID 20230605062354.24785-1-nj.shetty@samsung.com
State New
Headers
Series null_blk: Fix: memory release when memory_backed=1 |

Commit Message

Nitesh Shetty June 5, 2023, 6:23 a.m. UTC
  Memory/pages are not freed, when unloading nullblk driver.

Steps to reproduce issue
  1.free -h
        total        used        free      shared  buff/cache   available
Mem:    7.8Gi       260Mi       7.1Gi       3.0Mi       395Mi       7.3Gi
Swap:      0B          0B          0B
  2.modprobe null_blk memory_backed=1
  3.dd if=/dev/urandom of=/dev/nullb0 oflag=direct bs=1M count=1000
  4.modprobe -r null_blk
  5.free -h
        total        used        free      shared  buff/cache   available
Mem:    7.8Gi       1.2Gi       6.1Gi       3.0Mi       398Mi       6.3Gi
Swap:      0B          0B          0B

Signed-off-by: Anuj Gupta <anuj20.g@samsung.com>
Signed-off-by: Nitesh Shetty <nj.shetty@samsung.com>
---

Added a blktest[1] block/034 to test the same issue.
We will raise a PR, if issue is acked and fix is pulled in kernel.

[1] https://github.com/nitesh-shetty/blktests/tree/fix/block/mem_leak
---
 drivers/block/null_blk/main.c | 1 +
 1 file changed, 1 insertion(+)


base-commit: bc708bbd8260ee4eb3428b0109f5f3be661fae46
  

Comments

Jens Axboe June 5, 2023, 10:15 p.m. UTC | #1
On Mon, 05 Jun 2023 11:53:53 +0530, Nitesh Shetty wrote:
> Memory/pages are not freed, when unloading nullblk driver.
> 
> Steps to reproduce issue
>   1.free -h
>         total        used        free      shared  buff/cache   available
> Mem:    7.8Gi       260Mi       7.1Gi       3.0Mi       395Mi       7.3Gi
> Swap:      0B          0B          0B
>   2.modprobe null_blk memory_backed=1
>   3.dd if=/dev/urandom of=/dev/nullb0 oflag=direct bs=1M count=1000
>   4.modprobe -r null_blk
>   5.free -h
>         total        used        free      shared  buff/cache   available
> Mem:    7.8Gi       1.2Gi       6.1Gi       3.0Mi       398Mi       6.3Gi
> Swap:      0B          0B          0B
> 
> [...]

Applied, thanks!

[1/1] null_blk: Fix: memory release when memory_backed=1
      commit: 8cfb98196cceec35416041c6b91212d2b99392e4

Best regards,
  

Patch

diff --git a/drivers/block/null_blk/main.c b/drivers/block/null_blk/main.c
index b3fedafe301e..864013019d6b 100644
--- a/drivers/block/null_blk/main.c
+++ b/drivers/block/null_blk/main.c
@@ -2244,6 +2244,7 @@  static void null_destroy_dev(struct nullb *nullb)
 	struct nullb_device *dev = nullb->dev;
 
 	null_del_dev(nullb);
+	null_free_device_storage(dev, false);
 	null_free_dev(dev);
 }