__range_close() closes through filp_close() so every file the caller held the last reference to is punted to task work. That costs one cmpxchg per file plus a list entry for any later task_work_cancel() to search under ->pi_lock. close_range(2) exists to close many descriptors in one go fast. So convert it to the same synchronous treatment as close(2) and close_files(). Flush and put each file inline while ->file_lock is dropped. close_range(2) now behaves like close(2). Signed-off-by: Christian Brauner (Amutable) --- fs/file.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/fs/file.c b/fs/file.c index b7deb4e634c1..82b17fe50d25 100644 --- a/fs/file.c +++ b/fs/file.c @@ -813,7 +813,8 @@ static inline void __range_close(struct files_struct *files, unsigned int fd, file = file_close_fd_locked(files, fd); if (file) { spin_unlock(&files->file_lock); - filp_close(file, files); + filp_flush(file, files); + fput_close_sync(file); cond_resched(); spin_lock(&files->file_lock); fdt = files_fdtable(files); -- 2.53.0