Skip to contentSkip to conversation

common/rc: cleanup old .kmemleak files

PATCH Superseded Luís Henriques 2 participants 6 messages Jul 12, 2023 – Jul 13, 2023

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 common/rc: cleanup old .kmemleak files

I've spent a non-negligible amount of time looking into a kmemleak that didn't exist in the code I was testing because there was an old .kmemleak file in the results directory. I don't think this is an intended behaviour, so I'm proposing to remove these files everytime we capture the result of a new scan.

---
 common/rc | 2 ++
 1 file changed, 2 insertions(+)
common/rc +2 -0
index 741579af82d2..6aa6be704e51 100644
@@ -4433,6 +4433,8 @@ _capture_kmemleak()
 	local kern_knob="$DEBUGFS_MNT/kmemleak"
 	local leak_file="$1"
 
+	rm -f "$leak_file"
+
 	# Tell the kernel to scan for memory leaks.  Apparently the write
 	# returns before the scan is complete, so do it twice in the hopes
 	# that twice is enough to capture all the leaks.
#1 lore raw
Quoted 16 lines · Luís Henriques

I've spent a non-negligible amount of time looking into a kmemleak that didn't exist in the code I was testing because there was an old .kmemleak file in the results directory. I don't think this is an intended behaviour, so I'm proposing to remove these files everytime we capture the result of a new scan.

---
 common/rc | 2 ++
 1 file changed, 2 insertions(+)
common/rc +0 -0
index 741579af82d2..6aa6be704e51 100644

common/rc _capture_kmemleak() · line 4436

Quoted 4 lines
common/rc +1 -0
@@ -4433,6 +4433,8 @@ _capture_kmemleak()
 	local kern_knob="$DEBUGFS_MNT/kmemleak"
 	local leak_file="$1"
 
+	rm -f "$leak_file"

Some callers of this helper specify a device file when all they want to do is clear the old kmemleak report data:

$ git grep -w _capture_kmemleak
common/rc:4490:_capture_kmemleak()
common/rc:4535:         _capture_kmemleak /dev/null
common/rc:4555:         _capture_kmemleak /dev/null
common/rc:4560: _capture_kmemleak "$leak_file"

The simplest fix here I think would be:

# Some callers pass in /dev/null when they want to clear the # kernel's leak report file and do not care what was in that. test -f "$leak_file" && rm -f "$leak_file"

--D

Quoted 4 lines
common/rc +1 -0
+
 	# Tell the kernel to scan for memory leaks.  Apparently the write
 	# returns before the scan is complete, so do it twice in the hopes
 	# that twice is enough to capture all the leaks.
#2 lore raw

PATCH v2 1/1 common/rc: cleanup old .kmemleak files

In reply to Luís Henriques

I've spent a non-negligible amount of time looking into a kmemleak that didn't exist in the code I was testing because there was an old .kmemleak file in the results directory. I don't think this is an intended behaviour, so I'm proposing to remove these files everytime we capture the result of a new scan.

---
 common/rc | 2 ++
 1 file changed, 2 insertions(+)

Changes since v1:
I realised that _capture_kmemleak() is called with /dev/null as argument, so this version is probably better.

common/rc +2 -0
index 741579af82d2..6850889e815e 100644
@@ -4433,6 +4433,8 @@ _capture_kmemleak()
 	local kern_knob="$DEBUGFS_MNT/kmemleak"
 	local leak_file="$1"
 
+	[ -f "$leak_file" ] && rm -f "$leak_file"
+
 	# Tell the kernel to scan for memory leaks.  Apparently the write
 	# returns before the scan is complete, so do it twice in the hopes
 	# that twice is enough to capture all the leaks.
#3 lore raw
Quoted 20 lines · Luís Henriques

I've spent a non-negligible amount of time looking into a kmemleak that didn't exist in the code I was testing because there was an old .kmemleak file in the results directory. I don't think this is an intended behaviour, so I'm proposing to remove these files everytime we capture the result of a new scan.

---
 common/rc | 2 ++
 1 file changed, 2 insertions(+)

Changes since v1:
I realised that _capture_kmemleak() is called with /dev/null as argument, so this version is probably better.

common/rc +0 -0
index 741579af82d2..6850889e815e 100644

common/rc _capture_kmemleak() · line 4436

Quoted 4 lines
common/rc +1 -0
@@ -4433,6 +4433,8 @@ _capture_kmemleak()
 	local kern_knob="$DEBUGFS_MNT/kmemleak"
 	local leak_file="$1"
 
+	[ -f "$leak_file" ] && rm -f "$leak_file"

I was hoping you'd incorporate the comment explaining why the test uses -f and not -e.

--D

Quoted 4 lines
common/rc +1 -0
+
 	# Tell the kernel to scan for memory leaks.  Apparently the write
 	# returns before the scan is complete, so do it twice in the hopes
 	# that twice is enough to capture all the leaks.
#4 lore raw
Quoted 24 lines · Darrick J. Wong
Quoted 23 lines · Luís Henriques

I've spent a non-negligible amount of time looking into a kmemleak that didn't exist in the code I was testing because there was an old .kmemleak file in the results directory. I don't think this is an intended behaviour, so I'm proposing to remove these files everytime we capture the result of a new scan.

---
 common/rc | 2 ++
 1 file changed, 2 insertions(+)

Changes since v1:
I realised that _capture_kmemleak() is called with /dev/null as argument, so this version is probably better.

common/rc +0 -0
index 741579af82d2..6850889e815e 100644
@@ -4433,6 +4433,8 @@ _capture_kmemleak()
 	local kern_knob="$DEBUGFS_MNT/kmemleak"
 	local leak_file="$1"
 
Quoted 4 lines

common/rc _capture_kmemleak() · line 4436

Quoted 1 line
common/rc +1 -0
+	[ -f "$leak_file" ] && rm -f "$leak_file"

I was hoping you'd incorporate the comment explaining why the test uses -f and not -e.

You're right. The reason I didn't was because I sent out v2 before seeing your email. Anyway, I'll send out v3 in a second. And thanks for the review, by the way!

Cheers,

Signature · 1 line
Luís
Quoted 7 lines

--D

Quoted 4 lines
common/rc +1 -0
+
 	# Tell the kernel to scan for memory leaks.  Apparently the write
 	# returns before the scan is complete, so do it twice in the hopes
 	# that twice is enough to capture all the leaks.
#5 lore raw
Quoted 26 lines · Luís Henriques
Quoted 24 lines · Darrick J. Wong
Quoted 23 lines · Luís Henriques

I've spent a non-negligible amount of time looking into a kmemleak that didn't exist in the code I was testing because there was an old .kmemleak file in the results directory. I don't think this is an intended behaviour, so I'm proposing to remove these files everytime we capture the result of a new scan.

---
 common/rc | 2 ++
 1 file changed, 2 insertions(+)

Changes since v1:
I realised that _capture_kmemleak() is called with /dev/null as argument, so this version is probably better.

common/rc +0 -0
index 741579af82d2..6850889e815e 100644
@@ -4433,6 +4433,8 @@ _capture_kmemleak()
 	local kern_knob="$DEBUGFS_MNT/kmemleak"
 	local leak_file="$1"
 
Quoted 8 lines
Quoted 4 lines

common/rc _capture_kmemleak() · line 4436

Quoted 1 line
common/rc +1 -0
+	[ -f "$leak_file" ] && rm -f "$leak_file"

I was hoping you'd incorporate the comment explaining why the test uses -f and not -e.

You're right. The reason I didn't was because I sent out v2 before seeing your email. Anyway, I'll send out v3 in a second. And thanks for the review, by the way!

aha, ok.

--D

Quoted 11 lines

Cheers,

Signature · 1 line
Luís
Quoted 7 lines

--D

Quoted 4 lines
common/rc +1 -0
+
 	# Tell the kernel to scan for memory leaks.  Apparently the write
 	# returns before the scan is complete, so do it twice in the hopes
 	# that twice is enough to capture all the leaks.