Commit Graph

168 Commits

Author SHA1 Message Date
Tomasz Grabiec
454ee88bb6 core: make keep_doing() propagate failure 2014-10-15 15:59:42 +02:00
Tomasz Grabiec
ca077f33ef core: introduce or_terminate()
Calls std::terminate() when future fails. It can be used like this:

  do_something([] {}).or_terminate();
2014-10-15 15:59:41 +02:00
Tomasz Grabiec
277535ca75 core: introduce vector_data_sink 2014-10-15 15:59:41 +02:00
Tomasz Grabiec
dec042f9c2 core: introduce do_for_each()
Useful when composing iteration with async operations.
2014-10-15 15:59:41 +02:00
Tomasz Grabiec
ceeda85080 core: add more overloads of output_stream::write() 2014-10-15 15:59:41 +02:00
Tomasz Grabiec
6fabc8700f core: introduce timer::rearm() 2014-10-15 15:50:46 +02:00
Tomasz Grabiec
4e3317b072 core: fix formatting 2014-10-15 15:50:28 +02:00
Avi Kivity
b90670417b memory: fix off-by-one in to-resize
cpu_pages::initialize() established the one-past-the-end page as a sentinel
to avoid boundary conditions checks.  cpu_pages::do_resize() considers the
last page as the sentinel.  This discrepancy causes the last page to be
considered free by do_resize, which promptly ends up as a use-after-free
page.

Fix by aligning do_resize() with initialize().
2014-10-15 16:44:36 +03:00
Raphael S. Carvalho
2a7efbd884 core: introduce TRIM support
ioctl and fallocate are being used for TRIMMING effect on block and regular
files, respectively.
This feature is useful for SSDs, where write amplification can be reduced,
and drive life increased. Unlike HDD, SSD has to be explicitly notified of
blocks no longer used.
The interface consists of passing the range to the function, through offset
and length parameters.

Signed-off-by: Raphael S. Carvalho <raphaelsc@cloudius-systems.com>
2014-10-15 12:45:54 +03:00
Raphael S. Carvalho
f3e429bc43 core: add support for file classes
Intended to allow different file classes to implement their own
file operations; currently supporting regular and block device
files. This support would also be required for a native file
system, for example.

Signed-off-by: Raphael S. Carvalho <raphaelsc@cloudius-systems.com>
2014-10-15 12:45:54 +03:00
Asias He
20349885e3 queue: Add missing including of future.hh 2014-10-15 12:21:22 +03:00
Tomasz Grabiec
3765bec155 net: speculate EPOLLIN and EPOLLOUT on sendmsg/sendto/recvmsg
It improves memaslap score of UDP memcache by 30%.

Note that for recvmsg we always speculate because in case of UDP we
don't know the exact sizeof the datagram and thus we always specify
larger size in msghdr.
2014-10-14 12:01:31 +03:00
Avi Kivity
8445f66d91 app-template: make command line options override config file options
Instead of vice versa.
2014-10-13 17:48:23 +03:00
Glauber Costa
41c2fcb109 posix: provide mmap helper
For mmaps over a file descriptor, it makes sense to have the operation as a
method of file_desc.

Signed-off-by: Glauber Costa <glommer@cloudius-systems.com>
2014-10-13 15:51:43 +03:00
Avi Kivity
2d13f95a9f memory: support for non-hwloc builds 2014-10-13 15:41:18 +03:00
Avi Kivity
c630bd8171 Merge branch 'numa'
Add -m option for tuning memory size; and use mbind() and pinning so that
a cpu engine accesses local memory, if possible.
2014-10-13 13:07:46 +03:00
Avi Kivity
60b4756a36 smp: allow tuning memory size 2014-10-13 13:03:48 +03:00
Avi Kivity
56598903f6 memory: add support for reconfiguring memory
- add memory to a cpu
- bind that memory to a NUMA node
2014-10-13 13:03:46 +03:00
Avi Kivity
e2ea9336cd sockaddr: declare operator==() in global namespace
Needed for argument-dependent lookup; pointed out by clang.
2014-10-13 11:57:53 +03:00
Asias He
d5c8155e00 net: Split posix stack related code to net/posix-stack.cc
NOTE: This patch makes pollable_fd::get_file_desc public in order to
access it in posix_server_socket_impl::accept(). Maybe there is a better
solution. But, fow now, this avoids a lot of including game.
2014-10-13 11:33:57 +08:00
Avi Kivity
8d5924a734 posix: add function to pin the current thread 2014-10-12 16:37:30 +03:00
Avi Kivity
77f13169c0 core: add NUMA resource allocation functions
Add a wrapper around libhwloc to discover memory and processing resources,
and divide them among the configured cpu threads.
2014-10-12 16:35:48 +03:00
Avi Kivity
d89e09c9ed memory: switch page_list to use page indices instead of pointers
Two motivations:
1. reduce the size of struct page
2. allow relocating the page array; needed for dynamically changing
   the amount of memory supported.
2014-10-12 14:47:11 +03:00
Tomasz Grabiec
1bdb73e5da core: fix buffer overflow in to_sstring() 2014-10-09 20:04:53 +03:00
Tomasz Grabiec
eac955cc73 core: simplify output_stream::write() and flush() results
The result is not used for anything and I am not sure what it could be
used for, as the result carries little (write) to none (flush)
information. So I went ahead and simplified it to be future<> so that
it is easier to return it in places which expect future<>.
2014-10-09 20:02:11 +03:00
Avi Kivity
37ef3bc899 memory: request huge page backing for heap
Worth about 12% on httpd.
2014-10-07 15:23:30 +03:00
Avi Kivity
c6069ac4d9 core: set memory reclaim hook
Allow the memory manager to call us back requesting a reclaim.  Push
the task to the front of the queue, so we don't run out of memory waiting
for it to fire.
2014-10-07 15:14:44 +03:00
Avi Kivity
6746bcfd68 memory: reclaim support
Allow memory users to declare methods of reclaiming memory (reclaimers),
and allow the main loop to declare a safe point for calling these reclaimers.

The memory mananger will then schedule calls to reclaimers when memory runs
low.
2014-10-07 15:14:44 +03:00
Gleb Natapov
19addf6e64 Implement smp handling for posix networking stack
The idea is that only one thread opens listen socket and runs accept().
Other threads emulate listen()/accept() by waiting for connected
socket from the main thread. Main thread distributes connected sockets
according to round robin pattern. Patch introduce new specialization
for server_socket_impl and network_stack: posix_ap_server_socket_impl
and posix_ap_network_stack respectively. _ap_ stand for auxiliary processor.
2014-10-07 11:03:49 +03:00
Gleb Natapov
526312253f Introduce smp::main_thread() function
Sometimes we need to know if we are running on main thread during engine
initialization, before engine._id is available. This function will be
used for that.
2014-10-07 11:03:43 +03:00
Gleb Natapov
850545df6d Catch exception in app template
Print it out and exit program gracefully.
2014-10-07 11:03:39 +03:00
Gleb Natapov
20dcbbd12d Provide engine::exit() call to exit smp program gracefully 2014-10-07 11:03:37 +03:00
Raphael S. Carvalho
5ca6ddc281 reactor: introduce reactor::stat
Basically, wrapping stat around _thread_pool as it might block
waiting for metadata to be read from the underlying device.

Signed-off-by: Raphael S. Carvalho <raphaelsc@cloudius-systems.com>
2014-10-06 21:37:30 +03:00
Avi Kivity
4a080eb008 core: switch to spsc_queue for interthread communication
It's much faster than a normal queue.
2014-10-06 21:37:22 +03:00
Tomasz Grabiec
e4d55258c1 tests: add UDP tests
To start the server:

  $ build/release/tests/udp_server

To start the client:

  $ build/release/tests/udp_client --server localhost:10000
2014-10-06 18:36:42 +02:00
Tomasz Grabiec
f907f6a999 reactor: add getter for network stack 2014-10-06 18:34:43 +02:00
Tomasz Grabiec
ba49d24b01 net: add support for UDPv4 in native and posix stack 2014-10-06 18:34:40 +02:00
Tomasz Grabiec
cf7a084457 core: move some of the networking abstractions to net/api.hh 2014-10-06 18:34:28 +02:00
Tomasz Grabiec
3775dae6fb net: convert ipv4_addr.host from array to uint32_t
It will be easier to convert it to a format on which the native stack
works.
2014-10-06 18:34:28 +02:00
Tomasz Grabiec
269b05afc2 core: add queue::push_eventually()
It's an asynchronous version of blocking push().
2014-10-06 18:34:28 +02:00
Tomasz Grabiec
57bc48ddbb core: add queue::pop_eventually()
It's an asynchronous version of blocking pop().
2014-10-06 18:34:28 +02:00
Nadav Har'El
5db2c1b506 build: Compile-time option to use default memory allocator
Add a compile-time option, DEFAULT_ALLOCATOR, to use the existing
memory allocator (malloc() and friends) instead of redefining it.

This option is a workaround needed to run Seastar on OSv.

Without this workaround, what seems to happen is that some code compiled
into the kernel (notably, libboost_program_options.a) uses the standard
malloc(), while inline code compiled into Seastar uses the seastar free()
to try and free that memory, resulting in a spectacular crash.

Signed-off-by: Nadav Har'El <nyh@cloudius-systems.com>
2014-10-06 14:59:36 +03:00
Avi Kivity
255c3ec7a7 reactor.hh: get rid of errant #include 2014-10-05 21:08:12 +03:00
Avi Kivity
2b12c13055 memory: support sized deallocation
With N3778, the compiler can provide us with the size of the object,
so we can avoid looking it up in the page array.  Unfortunately only
implemented in clang at the moment.
2014-10-05 20:24:00 +03:00
Avi Kivity
9cd0e4f405 memory: improve allocation density
Instead of rounding up to a power-of-two, have four equally spaced
regions between powers of two.  For example:

   1024
   1280 (+256)
   1536 (+256)
   1792 (+256)
   2048 (+256)
   2560 (+512)
   3072 (+512)
   3584 (+512)
   4096 (+512)
2014-10-05 19:58:12 +03:00
Avi Kivity
3db75b272e bitops: mark functions as constexpr
Luckily, the gcc builtins are also constexpr.
2014-10-05 19:58:12 +03:00
Avi Kivity
e42158aea6 memory: small allocation support
Allocate small objects within spans, minimizing waste.

Each object size class has its own pool, and its own freelist.  On overflow
free objects are pushed into the spans; if a span is completely free, it is
returned to the main free list.
2014-10-05 19:58:10 +03:00
Avi Kivity
c407f5e091 memory: hook standard library allocation functions 2014-10-05 19:57:46 +03:00
Avi Kivity
b849b6b4cd memory: add support for aligned large allocations 2014-10-05 19:57:46 +03:00
Avi Kivity
86c0b7b7c9 memory: add per-cpu memory allocator
Largely inspired by tcmalloc, but simpler.  No support for small allocations
at the moment.
2014-10-05 19:57:40 +03:00