From: Kirill Tkhai <ktk...@virtuozzo.com> Patchset description: Shrink big fdtable on criu restore
This patchset allows to avoid memory overuse introduced by service fds on criu restore. The solution is simple: smartly check for closed fd number, and shrink fdtable if this could be made. The checks are happen in is_pseudosuper mode, so we do not affect performance on normal work mode. The problem is we can't solve this for 100% case in userspace. Kernel allows to fix that completely. https://jira.sw.ru/browse/PSBM-78827 Eric Dumazet (1): ms/fs/file.c: don't acquire files->file_lock in fd_install() Kirill Tkhai (3): files: Add new argument to expand_files() files: Add fdtable_align() helper files: Shrink big fdtable on close in is_pseudosuper mode Mateusz Guzik (1): ms/vfs: grab the lock instead of blocking in __fd_install during resizing ============================================================ This patch description: Add argument "shrink" to the functions. This is refactoring, which will be used in next patches. Signed-off-by: Kirill Tkhai <ktk...@virtuozzo.com> Reviewed-by: Cyrill Gorcunov <gorcu...@openvz.org> (cherry picked from 997f6cab4a45431595860a6235380506e59694fe) Signed-off-by: Andrey Zhadchenko <andrey.zhadche...@virtuozzo.com> --- fs/file.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/fs/file.c b/fs/file.c index 915f7ad..866912f 100644 --- a/fs/file.c +++ b/fs/file.c @@ -68,7 +68,7 @@ static void copy_fd_bitmaps(struct fdtable *nfdt, struct fdtable *ofdt, * Copy all file descriptors from the old table to the new, expanded table and * clear the extra space. Called with the files spinlock held for write. */ -static void copy_fdtable(struct fdtable *nfdt, struct fdtable *ofdt) +static void copy_fdtable(struct fdtable *nfdt, struct fdtable *ofdt, bool shrink) { unsigned int cpy, set; @@ -145,7 +145,7 @@ static struct fdtable * alloc_fdtable(unsigned int nr) * Return <0 error code on error; 1 on successful completion. * The files->file_lock should be held on entry, and will be held on exit. */ -static int expand_fdtable(struct files_struct *files, unsigned int nr) +static int expand_fdtable(struct files_struct *files, unsigned int nr, bool shrink) __releases(files->file_lock) __acquires(files->file_lock) { @@ -173,7 +173,7 @@ static int expand_fdtable(struct files_struct *files, unsigned int nr) } cur_fdt = files_fdtable(files); BUG_ON(nr < cur_fdt->max_fds); - copy_fdtable(new_fdt, cur_fdt); + copy_fdtable(new_fdt, cur_fdt, shrink); rcu_assign_pointer(files->fdt, new_fdt); if (cur_fdt != &files->fdtab) call_rcu(&cur_fdt->rcu, free_fdtable_rcu); @@ -190,7 +190,7 @@ static int expand_fdtable(struct files_struct *files, unsigned int nr) * expanded and execution may have blocked. * The files->file_lock should be held on entry, and will be held on exit. */ -static int expand_files(struct files_struct *files, unsigned int nr) +static int expand_files(struct files_struct *files, unsigned int nr, bool shrink) __releases(files->file_lock) __acquires(files->file_lock) { @@ -218,7 +218,7 @@ static int expand_files(struct files_struct *files, unsigned int nr) /* All good, so we try */ files->resize_in_progress = true; - expanded = expand_fdtable(files, nr); + expanded = expand_fdtable(files, nr, shrink); files->resize_in_progress = false; wake_up_all(&files->resize_wait); @@ -501,7 +501,7 @@ int __alloc_fd(struct files_struct *files, if (fd >= end) goto out; - error = expand_files(files, fd); + error = expand_files(files, fd, false); if (error < 0) goto out; @@ -900,7 +900,7 @@ int replace_fd(unsigned fd, struct file *file, unsigned flags) return -EBADF; spin_lock(&files->file_lock); - err = expand_files(files, fd); + err = expand_files(files, fd, false); if (unlikely(err < 0)) goto out_unlock; return do_dup2(files, file, fd, flags); @@ -926,7 +926,7 @@ static int ksys_dup3(unsigned int oldfd, unsigned int newfd, int flags) return -EBADF; spin_lock(&files->file_lock); - err = expand_files(files, newfd); + err = expand_files(files, newfd, false); file = fcheck(oldfd); if (unlikely(!file)) goto Ebadf; -- 1.8.3.1 _______________________________________________ Devel mailing list Devel@openvz.org https://lists.openvz.org/mailman/listinfo/devel