blktrace may allocate lots of memory, if the process is terminated by user or OOM, we need to provide one chance to remove the trace buffer, otherwise memory leak may be caused. Fix the issue by shutdown blktrace in case of task exiting in blkdev_close(). Signed-off-by: Ming Lei <ming.lei@xxxxxxxxxx> --- fs/block_dev.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/fs/block_dev.c b/fs/block_dev.c index 92ed7d5df677..1370eb731cea 100644 --- a/fs/block_dev.c +++ b/fs/block_dev.c @@ -34,6 +34,7 @@ #include <linux/part_stat.h> #include <linux/uaccess.h> #include <linux/suspend.h> +#include <linux/blktrace_api.h> #include "internal.h" struct bdev_inode { @@ -1646,6 +1647,11 @@ EXPORT_SYMBOL(blkdev_put); static int blkdev_close(struct inode * inode, struct file * filp) { struct block_device *bdev = I_BDEV(bdev_file_inode(filp)); + + /* shutdown blktrace in case of exiting which may be from OOM */ + if (current->flags & PF_EXITING) + blk_trace_shutdown(bdev->bd_disk->queue); + blkdev_put(bdev, filp->f_mode); return 0; } -- 2.29.2