pagecache: unify rmap flush and access scanning classes.

As Avi pointed ptep_flush and ptep_accessed classes can be replaced by
general map-reduce mechanism with customizable map and reduce functions.
The patch implements that.

Signed-off-by: Gleb Natapov <gleb@cloudius-systems.com>
pagecache: make  msync pagecache aware

Current msync implementation is scanning all pages in msync are via
pagetables to find dirty pages, but pagecache already knows what pages are
potentially dirty for given file/offsets, so it is can check if they are
dirty via rmap.

Signed-off-by: Gleb Natapov <gleb@cloudius-systems.com>
mmu: clear pte in unmap() function.

This will allow pagecache code to atomically clear pte and
check for a dirty bit.

Signed-off-by: Gleb Natapov <gleb@cloudius-systems.com>
pagecache: do not write back clean pages during write pages eviction

Not all pages in the write page cache are dirty sync msync() may write
some of them back. Check for that and do not write back clean pages
needlessly.

Signed-off-by: Gleb Natapov <gleb@cloudius-systems.com>
elf: resolve R_X86_64_DPTMOD64 properly

R_X86_64_DPTMOD64 may not be associated with any symbol (which is common
when the linker uses local dynamic TLS mode) in which case it should be
resovled to the index of the current module.

Signed-off-by: Pawel Dziepak <pdziepak@quarnos.org>
Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
Merge branch 'pagecache' of https://github.com/gleb-cloudius/osv

"Nothing spectacular here, just making msync() pagecache aware. Reduces
code size a bit if nothing else"

Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
include/api: Remove dead code

The code in <api/x86/reloc.h> is not used. Avi says it's dead code that
originates fro Musl.

Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
libc: Add fdopendir from musl to fix missing symbol

When using 'zpool.so import' fdopendir symbol is missed.
Code taken from musl libc.

Additional details:
fcntl(fd, F_SETFD, FD_CLOEXEC) call was removed as the close-on-exec
flag is left unchanged on Linux (Glauber Costa).
Also removing struct __DIR_s definition from fs/vfs/main.c, and
referencing the new one added into libc/dirent/dirent.h.

Reviewed-by: Glauber Costa <glommer@cloudius-systems.com>
Signed-off-by: Raphael S. Carvalho <raphaelsc@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>