1. 01 Oct, 2014 5 commits
  2. 30 Sep, 2014 21 commits
  3. 29 Sep, 2014 8 commits
    • Pavel Emelyanov's avatar
      bfd: Multiple buffers management (v2) · 5eb39aad
      Pavel Emelyanov authored
      I plan to re-use the bfd engine for images buffering. Right
      now this engine uses one buffer that gets reused by all
      bfdopen()-s. This works for current usage (one-by-pne proc
      files access), but for images we'll need more buffers.
      
      So this patch just puts buffers in a list and organizes a
      stupid R-R with refill on it.
      
      v2:
        Check for buffer allocation errors
        Print buffer mem pointer in debug
      Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
      Acked-by: 's avatarAndrew Vagin <avagin@parallels.com>
      5eb39aad
    • Pavel Emelyanov's avatar
      dump: Don't close pid-proc in vain · 1a2e6cbd
      Pavel Emelyanov authored
      The open_pid_proc engine knows itself how to cache
      per-pid descriptors. No need in closing it by hands.
      Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
      1a2e6cbd
    • Pavel Emelyanov's avatar
      proc: Keep /proc/self cached separately from /proc/pid · abeae267
      Pavel Emelyanov authored
      When dumping tasks we do a lot of open_proc()-s and to
      speed this up the /proc/pid directory is opened first
      and the fd is kept cached. So next open_proc()-s do just
      openat(cached_fd, name).
      
      The thing is that we sometimes call open_proc(PROC_SELF)
      in between and proc helpers cache the /proc/self too. As
      the result we have a bunch of
      
        open(/proc/pid)
        close()
        open(/proc/self)
        close()
      
      see-saw-s in the middle of dumping tasks.
      
      To fix this we may cache the /proc/self separately from
      the /proc/pid descriptor. This eliminates quite a lot
      of pointless open-s and close-s.
      Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
      abeae267
    • Pavel Emelyanov's avatar
      fd: Close caches proc-pid stuff before restoring files · 829d4332
      Pavel Emelyanov authored
      We have a bug. If someone opens proc with open_pid_proc or alike
      with PROC_SELF of real PID before going to restore fds, then the
      fd cached by proc helpers would be cached in fd 0 (we close all
      fds beforehead) and it may clash with restored fds.
      
      We don't hit this right now simply due to being too lucky -- we
      call open_proc(PROC_GEN) on "locks" which first closes the cached
      the per-pid descriptor and then reports back just the /proc one
      which sits in service area.
      
      But once we change this (next patch) things would get broken.
      Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
      829d4332
    • Pavel Emelyanov's avatar
      proc: Sanitate empty lines · 1c8ab40e
      Pavel Emelyanov authored
      Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
      1c8ab40e
    • Pavel Emelyanov's avatar
      filemap: Get vma mnt_id early · e651a6eb
      Pavel Emelyanov authored
      We have a, well, issue with how we calculate the vma's mnt_id.
      
      Right now get one via criu side file descriptor that it got by
      opening the /proc/pid/map_files/ link. The problem is that these
      descriptors are 'merged' or 'borrowed' by adjacent vmas from
      previous ones. Thus, getting the mnt_id value for each of them
      makes no sense -- these files are the same.
      
      So move this mnt_id getting earlier into vma parsing code. This
      brings a potential problem -- if we have two adjacent vmas
      mapping the same inode (dev:ino pair) but living in different
      mount namespaces -- this check would produce wrong result.
      "Wrong" from the perspective that on restore correct file would
      be opened from wrong namespace.
      
      I propose to live with it, since this is not worse than the
      --evasive-devices option, it's _very_ unlikely, but saves a lot
      of openeings.
      
      Note, that in case app switched mount namespace and then mapped
      some new library (with dlopen) things would work correctly -- new
      vmas will likely be not adjacent and for different dev:ino.
      Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
      e651a6eb
    • Pavel Emelyanov's avatar
      vma: Add comments about some dump fields of vma_area · f84d19e0
      Pavel Emelyanov authored
      We have non-obvious handling of vm_file_fd/vm_socket_id
      pair and the vma->file_borrowed.
      
      Comment these to in the structure.
      Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
      f84d19e0
    • Pavel Emelyanov's avatar
      vma: Reshuffle the struct vma_area · cf8c9ae8
      Pavel Emelyanov authored
      We have some fields, that are dump-only and some that
      are restore only (quite a lot of them actually).
      
      Reshuffle them on the vma_area to explicitly show which
      one is which. And rename some of them for easier grep.
      Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
      cf8c9ae8
  4. 24 Sep, 2014 2 commits
  5. 23 Sep, 2014 4 commits
    • Pavel Emelyanov's avatar
      cfce460b
    • Pavel Emelyanov's avatar
      cc4a67b3
    • Pavel Emelyanov's avatar
      2c8af6b8
    • Pavel Emelyanov's avatar
      bfd: File-descriptors based buffered read · 53771adc
      Pavel Emelyanov authored
      This sounds strange, but we kinda need one. Here's the
      justification for that.
      
      We heavily open /proc/pid/foo files. To speed things up we
      do pid_dir = open("/proc/pid") then openat(pid_dir, foo).
      This really saves time on big trees, up to 10%.
      
      Sometimes we need line-by-line scan of these files, and for
      that we currently use the fdopen() call. It takes a file
      descriptor (obtained with openat from above) and wraps one
      into a FILE*.
      
      The problem with the latter is that fdopen _always_ mmap()s
      a buffer for reads and this buffer always (!) gets unmapped
      back on fclose(). This pair of mmap() + munmap() eats time
      on big trees, up to 10% in my experiments with p.haul tests.
      
      The situation is made even worse by the fact that each fgets
      on the file results in a new page allocated in the kernel
      (since the mapping is new). And also this fgets copies data,
      which is not big deal, but for e.g. smaps file this results
      in ~8K bytes being just copied around.
      
      Having said that, here's a small but fast way of reading a
      descriptor line-by-line using big buffer for reducing the
      amount of read()s.
      
      After all per-task fopen_proc()-s get reworked on this engine
      (next 4 patches) the results on p.haul test would be
      
              Syscall     Calls      Time (% of time)
      Now:
                 mmap:      463  0.012033 (3.2%)
               munmap:      447  0.014473 (3.9%)
      Patched:
               munmap:       57  0.002106 (0.6%)
                 mmap:       74  0.002286 (0.7%)
      
      The amount of read()s and open()s doesn't change since FILE*
      also uses page-sized buffer for reading.
      
      Also this eliminates some amount of lseek()s and fstat()s
      the fdopen() does every time to catch up with file position
      and to determine what sort of buffering it should use (for
      terminals it's \n-driven, for files it's not).
      Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
      53771adc