[PATCH 2/2] trace-cmd: Close the trace file descriptor

From: Vaibhav Nagarnaik
Date: Mon Mar 19 2012 - 16:28:54 EST


trace-cmd opens "trace_raw" file descriptor to splice data continuously
through it to the CPU files. This causes a lot of pages being allocated
for the splice interface in the kernel. After the recorder instance is
destroyed, it doesn't close the file descriptor causing many of the
pages to remain in the cache. This gives an invalid view of memory lying
around in cache.

In any case, it is a good practice for the applications to close all the
descriptors that are opened.

This patch closes the open file descriptor which is used in the splice()
call and updates the check for disk file descriptor when closing it.

Signed-off-by: Vaibhav Nagarnaik <vnagarnaik@xxxxxxxxxx>
---
trace-recorder.c | 5 ++++-
1 files changed, 4 insertions(+), 1 deletions(-)

diff --git a/trace-recorder.c b/trace-recorder.c
index 4a01fb9..215affc 100644
--- a/trace-recorder.c
+++ b/trace-recorder.c
@@ -50,7 +50,10 @@ void tracecmd_free_recorder(struct tracecmd_recorder *recorder)
if (!recorder)
return;

- if (recorder->fd)
+ if (recorder->trace_fd >= 0)
+ close(recorder->trace_fd);
+
+ if (recorder->fd >= 0)
close(recorder->fd);

free(recorder);
--
1.7.7.3

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/