Commit graph

9 commits

Author SHA1 Message Date
Andrew Vagin
1d8fcb6b94 bfd: add breadchr
Reading stops after an EOF or a specified charecter.

Signed-off-by: Andrew Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-10-27 22:51:09 +03:00
Pavel Emelyanov
7ede4697cf bfd: Don't leak image-open flags into bfdopen
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-03-16 15:58:14 +03:00
Pavel Emelyanov
2e91a9c814 bfd: Don't flush read-only images
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-11-05 15:38:17 +04:00
Pavel Emelyanov
1ef5ca8235 bfd: Check images got flushed at the end
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-11-05 15:37:39 +04:00
Cyrill Gorcunov
ae96d21a07 bfd: Use ERR_PTR and such instead of BREADERR
No need to invent new error codes here, simply
use ERR_PTR/IS_ERR_OR_NULL and such.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Acked-by: Andrew Vagin <avagin@parallels.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-10-02 14:56:39 +04:00
Pavel Emelyanov
b90ae65c4c img: Prepare to use bfd engine
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
Acked-by: Cyrill Gorcunov <gorcunov@openvz.org>
2014-09-30 21:48:53 +04:00
Pavel Emelyanov
67bbc7ea0b bfd: Rename fields
For reads and writes the names pos and bleft will
have strange meaning, so rename them into smth more
appropriate.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
Acked-by: Cyrill Gorcunov <gorcunov@openvz.org>
2014-09-30 21:48:51 +04:00
Pavel Emelyanov
5eb39aad4d bfd: Multiple buffers management (v2)
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: Pavel Emelyanov <xemul@parallels.com>
Acked-by: Andrew Vagin <avagin@parallels.com>
2014-09-29 15:37:14 +04:00
Pavel Emelyanov
53771adcaa bfd: File-descriptors based buffered read
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: Pavel Emelyanov <xemul@parallels.com>
2014-09-23 20:48:38 +04:00