CA-135774: don't preallocate memory, use malloc and cache it instead

Signed-off-by: Thanos Makatos <thanos.makatos@citrix.com>
Reviewed-by: Felipe Franciosi <felipe.franciosi@citrix.com>
CA-135774: Wait before releasing request-associated buffers

Signed-off-by: Felipe Franciosi <felipe.franciosi@citrix.com>
Reviewed-by: Thanos Makatos <thanos.makatos@citrix.com>
CA-135774: Replace libcrypto with minimal md5 implementation

libcrypto uses about 150KB or private dirty memory per tapdisk process.
Replace libcrypto's md5 implementation with a public domain OpenSSL
compatible md5 implementation to save memory.

Signed-off-by: Ross Lagerwall <ross.lagerwall@citrix.com>
Reviewed-by: Thanos Makatos <thanos.makatos@citrix.com>
CA-135774: Use mmap rather than posix_memalign for allocating memory

Use mmap rather than posix_memalign so that memory can be properly
returned to the OS rather than simply returned to a free pool.

Signed-off-by: Ross Lagerwall <ross.lagerwall@citrix.com>
Reviewed-by: Thanos Makatos <thanos.makatos@citrix.com>
CA-135774: Return the correct number of requests copied

Previously, it was possible that the caller asked for 1 request to be
copied but the valued returned was > 1.

Signed-off-by: Ross Lagerwall <ross.lagerwall@citrix.com>
Reviewed-by: Thanos Makatos <thanos.makatos@citrix.com>
CA-135774: Limit memory used when under memory pressure

Force tapdisk to process requests 1 at a time when under memory pressure
to limit the amount of memory used.  Always keep at least 1 request in
the bufcache for this purpose.

Use memory cgroups to listen to critical memory pressure notifications.
The algorithm used is as follows:
Enter low memory mode when a memory pressure notification is received.
Use truncated exponential backoff to decide when to exit low memory
mode.  Add a random factor to prevent all tapdisks entering and exiting
at the same time.
If no notification is received in a set period of time when in normal
mode, reset the backoff factor.

Signed-off-by: Ross Lagerwall <ross.lagerwall@citrix.com>
Reviewed-by: Thanos Makatos <thanos.makatos@citrix.com>
Merge branch 'CA-135774' into xs64bit

Signed-off-by: Ross Lagerwall <ross.lagerwall@citrix.com>

GitHub: closes #104 on xapi-project/blktap