criu/include
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
..
asm-generic cr: collect short integer aliases in the single place 2014-04-08 15:35:46 +04:00
action-scripts.h scripts: Use numeric action val in RPC notifications 2014-09-05 13:48:27 +04:00
bfd.h bfd: File-descriptors based buffered read 2014-09-23 20:48:38 +04:00
bug.h bug: Include <stdbool.h> 2014-02-21 16:27:16 +04:00
cgroup.h cg: add --cgroup-root option 2014-08-19 12:58:36 +04:00
compiler.h include/compiler.h: Cleanup 2013-02-15 17:34:38 +04:00
config-base.h config-base: Add F_SETPIPE_SZ/F_GETPIPE_SZ 2014-02-18 12:53:09 +04:00
cpu.h cpu: Make cpu routines being per-acrh 2013-02-18 18:42:08 +04:00
cr-service-const.h service: move constants to cr-service-const.h 2013-12-18 14:26:10 +04:00
cr-service.h scripts: Use numeric action val in RPC notifications 2014-09-05 13:48:27 +04:00
cr-show.h headers: Add \Newline-s for readability sake 2013-11-15 17:00:14 +04:00
cr_options.h restore: Introduce the --restore-sibling option 2014-09-10 18:30:30 +04:00
criu-log.h log: Add pr_warn_once helper 2014-02-28 13:34:29 +04:00
criu-plugin.h plugin: Explicit assign plugin hooks 2014-09-19 17:39:06 +04:00
crtools.h security: change CR_FD_PERM from rw-rw-r-- to rw-r--r-- 2014-09-18 20:16:50 +04:00
err.h headers: Add err.h header 2013-04-02 20:27:51 +04:00
errno.h headers: Move ERESTART codes to errno.h 2013-11-14 22:22:21 +04:00
eventfd.h anon-inode: Don't readlink fd/fd multiple times 2014-02-02 22:14:29 +04:00
eventpoll.h anon-inode: Don't readlink fd/fd multiple times 2014-02-02 22:14:29 +04:00
fcntl.h fsnotify: Open handle with O_PATH, v2 2014-02-25 23:38:35 +04:00
fdset.h headers: Add extern specificator to functions 2013-11-15 17:00:58 +04:00
fifo.h collect: Shorten common images collecting code 2013-08-21 03:52:18 +04:00
file-ids.h files-ids: generate id-s accoding with mnt_id, st->st_dev and st->st_ino 2014-04-21 22:39:28 +04:00
file-lock.h locks: Don't dump locks in per-task manner (v3) 2014-09-02 17:44:46 +04:00
files-reg.h link-remap: open link-remap files from correct mountpoints (v3) 2014-08-06 19:14:16 +04:00
files.h files: Split fs restore into prepare and restore 2014-07-04 15:09:03 +04:00
fs-magic.h remap: add a dead pid /proc remap 2014-09-19 17:42:48 +04:00
fsnotify.h fsnotify: merge fanotify mark image into fanotify image (v3) 2014-09-03 20:51:39 +04:00
image-desc.h eventpoll: merge eventpoll tfd into eventpoll image 2014-09-03 20:51:40 +04:00
image.h vdso: image -- Add VMA_AREA_VVAR flag 2014-06-24 22:48:40 +04:00
inet_diag.h headers: Unify include guards (in comments) and a few fixes 2012-12-25 22:40:24 +04:00
ipc_ns.h crtools: don't include crtools.h in other headers 2013-11-06 18:17:38 +04:00
irmap.h irmap: Introduce irmap on-disk cache 2014-01-30 16:20:16 +04:00
kcmp-ids.h headers: Add extern specificator to functions 2013-11-15 17:00:58 +04:00
kcmp.h headers: Move kcmp_type to kcmp.h 2013-11-14 22:13:59 +04:00
kerndat.h mount: detect the newinstance option for devpts (v2) 2014-04-08 15:32:35 +04:00
libnetlink.h headers: Unify include guards (in comments) and a few fixes 2012-12-25 22:40:24 +04:00
list.h criu: Several formatting fixes 2014-01-14 09:33:19 +04:00
lock.h atomic: Use atomic_read instead of atomic_get 2013-08-16 19:37:06 +04:00
log.h log: Add pr_quelled helper 2014-09-03 20:56:54 +04:00
magic.h timerfd: Add protobuf entries into the image 2014-08-06 19:18:34 +04:00
mem.h mem: Move shmem preparation routine and rename 2014-02-03 23:34:12 +04:00
mman.h headers: Move MADV definitions to own mman.h 2013-11-14 22:48:30 +04:00
mount.h stat: Pass namespace into phys_stat_resolve_dev, not mnt tree 2014-08-06 10:57:27 +04:00
namespaces.h mnt: Shorten the mntns dumping loop 2014-09-23 20:37:32 +04:00
net.h rpc: Add ability to specify veth pairs (--veth-pair option) 2014-02-12 00:33:02 +04:00
netfilter.h headers: Add extern specificator to functions 2013-11-15 17:00:58 +04:00
netlink_diag.h headers: Add missing __CR_ at last endif 2013-11-15 16:59:57 +04:00
packet_diag.h headers: Unify include guards (in comments) and a few fixes 2012-12-25 22:40:24 +04:00
page-pipe.h page-pipe: split dumping memory on chunks (v3) 2014-02-10 15:06:39 +04:00
page-read.h iov: Add iovec2pagemap() helper 2014-06-20 16:35:52 +04:00
page-xfer.h page-server: Don't setup options in parent task 2014-09-05 13:49:54 +04:00
pagemap-cache.h pagemap-cache: Use page.h helpers 2014-02-21 16:29:41 +04:00
parasite-syscall.h ptrace: Factor out pie stopping code 2014-09-23 20:36:10 +04:00
parasite.h dump: use breakpoints instead of tracing syscalls (v2) 2014-09-19 17:56:25 +04:00
pid.h headers: Add missing __CR_ at last endif 2013-11-15 16:59:57 +04:00
pipes.h collect: Shorten common images collecting code 2013-08-21 03:52:18 +04:00
plugin.h plugin: Rework plugins API, v2 2014-09-03 20:48:36 +04:00
posix-timer.h posix-timers: Helper for freeing proc parsed data 2014-04-17 12:01:02 +04:00
prctl.h Dump capabilities from the parasite 2014-08-15 23:10:44 +04:00
proc_parse.h eventpoll: parse_fdinfo_pid_s() returns allocated object for eventpol tfd 2014-09-02 16:08:17 +04:00
protobuf-desc.h timerfd: Add protobuf entries into the image 2014-08-06 19:18:34 +04:00
protobuf.h img: Add ability to check whether optional image collection happened 2014-08-12 14:38:22 +04:00
pstree.h dump: clean up shared_fdtable 2014-09-02 16:10:14 +04:00
ptrace.h ptrace: include config.h in ptrace.h 2014-02-07 15:32:17 +04:00
rbtree.h x86: moved x86-specific files into the directory arch/x86. 2013-01-09 17:02:47 +04:00
restorer.h restore: use breakpoints instead of tracing syscalls 2014-09-19 17:57:18 +04:00
rst-malloc.h whitespace-at-eol cleanup 2013-12-12 10:00:45 +04:00
rst_info.h restore: use breakpoints instead of tracing syscalls 2014-09-19 17:57:18 +04:00
servicefd.h cg: Restore tasks into proper cgroups 2014-05-27 23:48:06 +04:00
setproctitle.h crtools: check for setproctitle_init 2014-09-02 16:14:39 +04:00
shmem.h shmem: Explicitly initialize rst_shmems 2014-08-19 13:00:07 +04:00
sigframe.h parasite: don't include restorer.h in parasite-syscall.c 2013-11-06 12:39:36 +04:00
signalfd.h anon-inode: Don't readlink fd/fd multiple times 2014-02-02 22:14:29 +04:00
sk-inet.h headers: Add extern specificator to functions 2013-11-15 17:00:58 +04:00
sk-packet.h Make tpacket_req3 definition conditional 2014-02-10 14:31:02 +04:00
sk-queue.h crtools: move all stuff about vma together 2013-11-06 12:43:49 +04:00
sockets.h space-before-tab whitespace cleanup 2013-12-12 10:00:53 +04:00
stats.h stats: Fix restore pages stats 2014-02-04 14:03:10 +04:00
string.h make: config -- Add testing if we have libbsd installed 2014-03-26 01:44:23 +04:00
syscall-types.h mount: allow to dump and restore nested mount namespaces (v3) 2014-04-21 22:38:23 +04:00
sysctl.h headers: Unify include guards (in comments) and a few fixes 2012-12-25 22:40:24 +04:00
sysfs_parse.h Added AUFS support. 2014-08-21 18:35:22 +04:00
timerfd.h timerfd: Implement check routine 2014-08-07 10:18:09 +04:00
tty.h crtools: don't include crtools.h in other headers 2013-11-06 18:17:38 +04:00
tun.h headers: Add extern specificator to functions 2013-11-15 17:00:58 +04:00
unix_diag.h x86: moved x86-specific files into the directory arch/x86. 2013-01-09 17:02:47 +04:00
util-pie.h headers: Drop uintX_t usage 2013-12-12 10:03:07 +04:00
util.h page-server: Don't setup options in parent task 2014-09-05 13:49:54 +04:00
uts_ns.h headers: Add extern specificator to functions 2013-11-15 17:00:58 +04:00
vdso.h vdso: Implement vDSO proxification of any vvar/vdso order 2014-08-04 15:35:03 +04:00
vma.h Added AUFS support. 2014-08-21 18:35:22 +04:00
xmalloc.h core: Allocate CoreEntry (except arch) with single xmalloc 2014-03-14 13:39:28 +04:00