[Devel] [PATCH RHEL7 COMMIT] ms/vfs: grab the lock instead of blocking in __fd_install during resizing

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 8f16c2a003c438f6b3120dc64bdd59a8febf1d3a
Author: Mateusz Guzik <mguzik at redhat.com>
Date:   Thu Jan 18 18:05:14 2018 +0300

    ms/vfs: grab the lock instead of blocking in __fd_install during resizing
    
    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:
    
    ms commit: c02b1a9b41c2
    
    Explicit locking in the fallback case provides a safe state of the
    table. Getting rid of blocking semantics makes __fd_install usable
    again in non-sleepable contexts, which easies backporting efforts.
    
    There is a side effect of slightly nicer assembly for the common case
    as might_sleep can now be removed.
    
    Signed-off-by: Mateusz Guzik <mguzik at redhat.com>
    Signed-off-by: Al Viro <viro at zeniv.linux.org.uk>
    
    Signed-off-by: Kirill Tkhai <ktkhai at virtuozzo.com>
    Reviewed-by: Cyrill Gorcunov <gorcunov at openvz.org>
---
 fs/file.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/fs/file.c b/fs/file.c
index adc42eccfd67..05ff3c5a6ec8 100644
--- a/fs/file.c
+++ b/fs/file.c
@@ -586,13 +586,16 @@ void __fd_install(struct files_struct *files, unsigned int fd,
 {
 	struct fdtable *fdt;
 
-	might_sleep();
 	rcu_read_lock_sched();
 
-	while (unlikely(files->resize_in_progress)) {
+	if (unlikely(files->resize_in_progress)) {
 		rcu_read_unlock_sched();
-		wait_event(files->resize_wait, !files->resize_in_progress);
-		rcu_read_lock_sched();
+		spin_lock(&files->file_lock);
+		fdt = files_fdtable(files);
+		BUG_ON(fdt->fd[fd] != NULL);
+		rcu_assign_pointer(fdt->fd[fd], file);
+		spin_unlock(&files->file_lock);
+		return;
 	}
 	/* coupled with smp_wmb() in expand_fdtable() */
 	smp_rmb();


More information about the Devel mailing list