Linux-Block Archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 blktests] block/034: Test memory is released by null-blk driver with memory_backed=1
       [not found] <CGME20230614170954epcas5p33d4ddecf3bf2ff178068b073ff2e2a06@epcas5p3.samsung.com>
@ 2023-06-14 17:06 ` Nitesh Shetty
  2023-06-15  9:25   ` Shinichiro Kawasaki
  0 siblings, 1 reply; 2+ messages in thread
From: Nitesh Shetty @ 2023-06-14 17:06 UTC (permalink / raw
  To: shinichiro.kawasaki, gost.dev; +Cc: linux-block, Nitesh Shetty

This tests memory leak, by loading/unloading nullblk driver.
Steps:
	1. Load nullblk driver with memory_backed=1
	2. "dd" of 50M
	3. Unload null-blk driver
We do it for 5 iterations to avoid any noise.

Commit 8cfb98196cceec35416041c6b91212d2b99392e4 fixes issue in kernel

Signed-off-by: Nitesh Shetty <nj.shetty@samsung.com>
---
 tests/block/034     | 60 +++++++++++++++++++++++++++++++++++++++++++++
 tests/block/034.out |  2 ++
 2 files changed, 62 insertions(+)
 create mode 100644 tests/block/034
 create mode 100644 tests/block/034.out

diff --git a/tests/block/034 b/tests/block/034
new file mode 100644
index 0000000..9a3bec4
--- /dev/null
+++ b/tests/block/034
@@ -0,0 +1,60 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-3.0+
+# Copyright (C) 2023 Nitesh Shetty
+#
+# Check memory leak when null_blk driver is loaded with memory_backed=1
+
+. tests/block/rc
+. common/null_blk
+
+DESCRIPTION="load/unload null_blk memory_backed=1 to check memleak"
+QUICK=1
+
+requires() {
+	_have_module null_blk
+	_have_module_param null_blk memory_backed
+	_have_program dd
+}
+
+run_nullblk_dd() {
+	if ! _init_null_blk memory_backed=1; then
+		echo "Loading null_blk failed"
+		return 1
+	fi
+	dd if=/dev/urandom of=/dev/nullb0 oflag=direct bs=1M count="$1" > \
+		/dev/null 2>&1
+	_exit_null_blk
+}
+
+free_memory() {
+	sed -n -e 's/^MemFree:[[:blank:]]*\([0-9]*\)[[:blank:]]*kB$/\1/p' \
+		/proc/meminfo
+}
+
+test() {
+	echo "Running ${TEST_NAME}"
+
+	local mem_leak=0 size=50
+	local i mem_start mem_end mem_used
+
+	for ((i = 0; i < 5; i++)); do
+		mem_start=$(free_memory)
+		run_nullblk_dd $size
+		mem_end=$(free_memory)
+
+		mem_used=$(((mem_start - mem_end) / 1024))
+		# -10MB to account for some randomness in freeing by some
+		# simultaneous process
+		if ((mem_used >= size - 10)); then
+			mem_leak=$((mem_leak + 1))
+		fi
+	done
+
+	# There might be possibilty of some random process freeing up memory at
+	# same time nullblk is unloaded.
+	# we consider 3/5 times to be positive.
+	if ((mem_leak > 3)); then
+		echo "Memleak: Memory is not freed by null-blk driver"
+	fi
+	echo "Test complete"
+}
diff --git a/tests/block/034.out b/tests/block/034.out
new file mode 100644
index 0000000..a916dd8
--- /dev/null
+++ b/tests/block/034.out
@@ -0,0 +1,2 @@
+Running block/034
+Test complete
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH v2 blktests] block/034: Test memory is released by null-blk driver with memory_backed=1
  2023-06-14 17:06 ` [PATCH v2 blktests] block/034: Test memory is released by null-blk driver with memory_backed=1 Nitesh Shetty
@ 2023-06-15  9:25   ` Shinichiro Kawasaki
  0 siblings, 0 replies; 2+ messages in thread
From: Shinichiro Kawasaki @ 2023-06-15  9:25 UTC (permalink / raw
  To: Nitesh Shetty; +Cc: gost.dev@samsung.com, linux-block@vger.kernel.org

On Jun 14, 2023 / 22:36, Nitesh Shetty wrote:
> This tests memory leak, by loading/unloading nullblk driver.
> Steps:
> 	1. Load nullblk driver with memory_backed=1
> 	2. "dd" of 50M
> 	3. Unload null-blk driver
> We do it for 5 iterations to avoid any noise.
> 
> Commit 8cfb98196cceec35416041c6b91212d2b99392e4 fixes issue in kernel

Applied, thanks!

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-06-15  9:25 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <CGME20230614170954epcas5p33d4ddecf3bf2ff178068b073ff2e2a06@epcas5p3.samsung.com>
2023-06-14 17:06 ` [PATCH v2 blktests] block/034: Test memory is released by null-blk driver with memory_backed=1 Nitesh Shetty
2023-06-15  9:25   ` Shinichiro Kawasaki

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).