[Devel] [PATCH RHEL7 COMMIT] files: Add new argument to expand_files()
Konstantin Khorenko
khorenko at virtuozzo.com
Thu Jan 18 18:05:14 MSK 2018
The commit is pushed to "branch-rh7-3.10.0-693.11.6.vz7.42.x-ovz" and will appear at https://src.openvz.org/scm/ovz/vzkernel.git
after rh7-3.10.0-693.11.6.vz7.42.1
------>
commit e458b6be3edf5d0e7189d6cd9db036726247c99b
Author: Kirill Tkhai <ktkhai at virtuozzo.com>
Date: Thu Jan 18 18:05:14 2018 +0300
files: Add new argument to expand_files()
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 <ktkhai at virtuozzo.com>
Reviewed-by: Cyrill Gorcunov <gorcunov at openvz.org>
---
fs/file.c | 16 ++++++++--------
1 file changed, 8 insertions(+), 8 deletions(-)
diff --git a/fs/file.c b/fs/file.c
index 05ff3c5a6ec8..9743283200e0 100644
--- a/fs/file.c
+++ b/fs/file.c
@@ -65,7 +65,7 @@ static void free_fdtable_rcu(struct rcu_head *rcu)
* Expand the fdset in the files_struct. 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;
@@ -144,7 +144,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, int nr)
+static int expand_fdtable(struct files_struct *files, int nr, bool shrink)
__releases(files->file_lock)
__acquires(files->file_lock)
{
@@ -172,7 +172,7 @@ static int expand_fdtable(struct files_struct *files, 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);
@@ -189,7 +189,7 @@ static int expand_fdtable(struct files_struct *files, 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, int nr)
+static int expand_files(struct files_struct *files, int nr, bool shrink)
__releases(files->file_lock)
__acquires(files->file_lock)
{
@@ -217,7 +217,7 @@ static int expand_files(struct files_struct *files, 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);
@@ -499,7 +499,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;
@@ -860,7 +860,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);
@@ -886,7 +886,7 @@ SYSCALL_DEFINE3(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;
More information about the Devel
mailing list