drivers: Make block device init silent by default

We now print disk probe information like:

virtio-scsi: Add scsi device target=1, lun=0   as vblk0, devsize=10842275840

Disable it by default. The --verbose option will make this info
available which is useful when debug.

Reported-by: Pekka Enberg <penberg@cloudius-systems.com>
Signed-off-by: Asias He <asias@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
libc: add scandir() from musl

Add missing scandir() function from musl 1.0.0. Fixes #237.

Signed-off-by: Nadav Har'El <nyh@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
ahci: Limit max size of a bio request

One PRDT entry can contain 4MB buffer at most, we currently only use one
PRDT per AHCI cmd. Limit the size of a bio request to respect it. Larger
bio will be split into smaller bios by multiplex_strategy.

Signed-off-by: Asias He <asias@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
ahci: Align cmd_table tables to 128-byte address

AHCI spec '4.2.2 Command List Structure' says 'Command Table Descriptor
Base Address' must be aligned to 128-byte cache line, indicated by bits
06:00 being reserved.

All the 32 cmd_table are allocated in one linear space. The size of
cmd_table is 144 bytes for now which is larger than 128 bytes. So we pad
cmd_table to 256 byes.

Signed-off-by: Asias He <asias@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
ahci: Assert data buffer address

Assert to make sure the data buffer address satisfies the AHCI spec's data
alignment requirement.

Signed-off-by: Asias He <asias@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
ahci: Use all the cmd slots

AHCI has 32 cmd slots to issue cmd. Only first slot is used currently
which makes the queue-depth 1.

This patch uses all the cmd slots and makes the cmd completion async.
Now, the queue-depth is 32.

Test with "/tests/misc-bdev-write.so" on VBOX shows improvements:

   Before: ~10MB/s
   After: ~20MB/s

1000 round of "/tests/misc-bdev-rw.so" tests passed on VBOX and QEMU.

Signed-off-by: Asias He <asias@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
sched: Add assert to capture rescheduling attempt in nested exception

Rescheduling in nested exception is not supported since nested exception
stack is per cpu, but without the assert such reschedule will cause
stack corruption which will be hard to debug.

Reviewed-by: Nadav Har'El <nyh@cloudius-systems.com>
Signed-off-by: Gleb Natapov <gleb@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
mempool: Contiguous physical memory holder class

Signed-off-by: Takuya ASADA <syuu@cloudius-systems.com>
[ penberg: fix formatting ]
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
Add vmxnet3 driver

Signed-off-by: Takuya ASADA <syuu@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
Add vmxnet3 argument on run.py

Signed-off-by: Takuya ASADA <syuu@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
Support VMDK and VDI format

Add osv.vmdk and osv.vdi targets on Makefile.

Signed-off-by: Takuya ASADA <syuu@cloudius-systems.com>
Signed-off-by: Asias He <asias@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
scripts/gen-vbox-ova.sh: Add --vga option to vdi image

Generate osv.vdi image from 'make osv.vdi' Makefile target which will
convert to the image to vdi as well as add the --vga option.

Reviewed-by: Nadav Har'El <nyh@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
networking: remove double socket unlock

sogeneric_send(), in one error case, unlocks the socket before doing
'goto release' which unlocks the socket again, resulting in an assertion
failure (unlocking an unlocked mutex) and crash.

This patch removes the extra unlock.

Fixes #248.

Signed-off-by: Nadav Har'El <nyh@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
balloon: Fix JNI detach in request_memory()

The request_memory() function has an early exit condition where we
forgot to call _detach().  Fix that up by attaching later in the
function which ensures we eventually will detach.

Signed-off-by: wangbicheng <wangbicheng@huawei.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
balloon: fix move-to-itself bug

While working in the reclaim policy, I came across an unhandled balloon case
that seem to happen in some certain low memory conditions. The balloon will be
moved to the same address it was before. While this seems weird at first, it is
perfectly plausible if we think that we can have a space before the balloon almost
a page in size. If the JVM is only shifting the elements slightly, they will end up
at the same ballooned region.

The problem with that is that evacuate() is called first - the vma is still in place,
so it will be found, and it will call delete. When the jvm fault handler executes,
it will also call delete and we will have a double free.

This patch avoids the delete, but the problem is actually more intricate than
that: if we just follow the normal path, we will remove the newly created
address from the candidates list right after we insert it (because the
addresses are the same). Also, if the address is *not* the same, but falls in
the same region (this is theoretical), evacuate will be called and split the region
in two. Our code to handle finish_move would have to be significantly complicated
to deal with this fact. This patch also handles this theoretical case by making
sure that the whole region is always disposed at once (by finishing the old balloon
manually before evacuate is called)

Why I am using a new mmu flag: when we search for the old vma, we need to
identify which type of vma we are dealing with. If it is an anonymous or
ballooned area. I use an extra flag to avoid a type field or anything like
that.

Couldn't we just take the vma out of the list before we delete it? In this case
the region would be empty, and we could assume that was a ballooned region.
That would also be a solution, but because we are copying the flag from the
previous vma, we would have to fallback to a default flag set. The solution
of marking the JVM vma and leaving it in place allows the flag information to
be carried on.

Signed-off-by: Glauber Costa <glommer@cloudius-systems.com>
balloon: use a shared ptr for the balloon object

The old explicit pattern would break if the vma that holds the balloon
was already destroyed. Use a shared pointer to avoid the complications from it

Signed-off-by: Glauber Costa <glommer@cloudius-systems.com>
reclaimer: implement a stronger data structure for waking sleepers

After Avi's last comments, here is a new take for the reclaimer's wake queue.
It does not abuse semaphore's in any way, so there is no need to extend it.
(After this patch is applied, the semaphore extension patch can be reverted)

In this new approach, we will not only check for free memory as a scalar, but
will instead transverse the remaining page ranges (notice that in case of
fragmentation this can be a *large* set) and try to find a range that would
allow our allocation to happen.

Also, because we are implementing both the wait and the "post" methods, the
waking of the reclaimer happens atomically and the problem that Tomek described
(wake before waiters is set) no longer exists.

Finally, another advantage of this approach is that we no longer need to keep
track of the amount of memory we have freed when making OOM decisions: if we
can wake someone up, we can continue. Otherwise, we OOM. This will be specially
helpful for the FS shrinkers, since they may not always be able to synchronously
return a meaningful number accurately (due to, for instance, writeback).

Signed-off-by: Glauber Costa <glommer@cloudius-systems.com>
jvm_balloon: better define boundaries for the balloon.

Right now, we are starting the jvm with the maximum amount of memory we can.
This is, however, terribly bad. The reason is that if that if we go to reclaim
during a heap allocation, this will easily crash the system. That will be just
for granted if that allocation turns out to be done on behalf of the GC. In
that case, no other Java threads will make progress, meaning the balloon cannot
be activated.

Even if the balloon is no longer part of the shrinker infrastructure, it may
still be a problem, because we may need to use it to deflate memory. The best
solution is to just limit heap usage to 90 % of the available memory, which is
the reclaim criteria.

Also, it is pointless to activate the balloon for very low memory conditions.
So if our heap size is less than 2 balloons in size, just leave it alone.

Signed-off-by: Glauber Costa <glommer@cloudius-systems.com>
java: heuristically determine the heap regions at startup

We can determine which mappings from the JVM are heap areas in a more
robust way by flipping a flag when we start JVM creation, and flipping
it back when we are finished. Doing this early is more robust and should
work better with a bigger set of GCs.

Although this is a heuristic, Calle agrees this is safe, and it has
been tested and confirmed to work with the following options:

    -XX:+UseSerialGC
    -XX:+UseG1GC
    -XX:+UseParallelGC
    -XX:+UseParallelOldGC
    -XX:+UseParNewGC
    -XX:+UseConcMarkSweepGC
    -XX:+UseConcMarkSweepGC

which pretty much covers all relevant GCs

Signed-off-by: Glauber Costa <glommer@cloudius-systems.com>
jvm_balloon: remove the probe

New method does not rely on physical memory accounting, so the probe
is useless.

Signed-off-by: Glauber Costa <glommer@cloudius-systems.com>