Commit Graph

9935 Commits

Author SHA1 Message Date
Josef Grieb
2820edc207 Fixed SubmissionQueue full issue
Motivation:

we should use kHead(with acquire memory barrier) instead of sqeHead as submit() is called internally when sqe is full

Modification:

-submit is called internally when sqe is full
-added a new sqe full test

Result:

you no longer need to check if the sqe is full when you add a new event
2020-08-31 07:01:25 +02:00
Josef Grieb
242890899e Fixed segmentation fault error in IovecArrayPool
Motivation:

segmentation is caused in IovecArrayPool.release because the default of iovecMemoryAddress is 0

Modification:

-set default to -1
-some cleanups
-added new testsuite tests

Result:

fixed segmentation error
2020-08-31 06:41:46 +02:00
Josef Grieb
05289a3f5e
Merge pull request #8 from normanmaurer/poll_mask
Fallback to simple write when we can not allocate iovec array and cor…
2020-08-31 06:18:26 +02:00
Norman Maurer
076c35f785 Fallback to simple write when we can not allocate iovec array and correctly handle poll mask 2020-08-30 21:13:52 +02:00
Josef Grieb
f77aa54f18
Merge pull request #7 from normanmaurer/iouring_error
Correctly handle POLL*, handle errors, cleanup
2020-08-30 14:59:03 +02:00
Norman Maurer
a3585492e9 Correctly handle POLL*, handle errors, cleanup
Motivation:

We not correctly handled errors and also had some problems with home POLL* was handled.

Modifictions:

- Cleanup
- No need to for links anymore
- Add error handling for most operations (poll still missing)
- Add better handling for RDHUP
- Correctly handle writeScheduled flag for writev

Result:

Cleaner and more correct code
2020-08-30 14:41:39 +02:00
Josef Grieb
43fc06e9cf
Merge pull request #6 from normanmaurer/submit
Only need to do syscall if something was submitted
2020-08-30 14:06:08 +02:00
Norman Maurer
f6e6f543c0 Only need to do syscall if something was submitted 2020-08-30 13:41:08 +02:00
Josef Grieb
37944ccffd Add writev operation
Motivation:

writev which allows to write data into multiple buffers

Modification:

-Added iovec array pool to manage iov memory
-flush override to make sure that write is not called

Result:

performance is much better
2020-08-29 21:22:15 +02:00
Josef Grieb
9a5449a790 Poll & tests cleanups
Motivation:

we should remove pollIn link, as we don't use pollIn linking anymore

Modification:

-some cleanups in the tests and in IOUring
-pollIn linking was removed

Result:

clean code
2020-08-29 10:40:17 +02:00
Josef Grieb
356ce5fdc0
Update README.md 2020-08-29 09:12:43 +02:00
Josef Grieb
946dc3973f
Merge pull request #5 from normanmaurer/polling
Correctly handle polling
2020-08-28 17:59:05 +02:00
Norman Maurer
b863aacad4 Correctly handle polling
Motivation:

We must correctly use the polling support of io_uring to reduce the number of events in flight + only allocate buffers if really needed. For this we should respect the different poll masks and only do the corresponding IO action once the fd becomes ready for it.

Modification:

- Correctly respect poll masks and so only schedule an IO event if the fd is ready for it
- Move some code for cleanup

Result:

More correct usage of io_uring and less memory usage
2020-08-28 17:00:03 +02:00
Josef Grieb
15e7f910f0 Add README 2020-08-28 10:13:43 +02:00
Josef Grieb
8096b2c15f Add connect
Motivation:

if connect returns EINPROGRESS we send POLL OUT and check
via socket.finishConnect if the connection is successful

Modifications:

-added new io_uring connect op
-use a directbuffer for the socket address

Result:

you are able to connect to a peer
2020-08-28 09:26:35 +02:00
Josef Grieb
9fcd2926f1
Merge pull request #3 from normanmaurer/native_test_close
Correctly close ring buffer in tests so we dont leak memory
2020-08-27 11:31:31 +02:00
Norman Maurer
11e169e17a Correctly close ring buffer in tests so we dont leak memory 2020-08-27 11:29:33 +02:00
Josef Grieb
3cdb1d60ae
Merge pull request #2 from normanmaurer/io_uring_break
Add missing break statement and cleanup
2020-08-27 10:57:52 +02:00
Norman Maurer
65e8540042 Add missing break statement and cleanup 2020-08-27 10:47:03 +02:00
Josef Grieb
56ace4228f Fix server socket address already in use error even if close is called
Motivation:

when you submit a poll, io_uring still hold reference to it even if close is called
source io_uring mailing list(https://lore.kernel.org/io-uring/27657840-4E8E-422D-93BB-7F485F21341A@kernel.dk/T/#t)

Modification:

-To delete fd reference in io_uring, we use POLL_REMOVE to avoid a server socket address error
-Added a POLL_REMOVE test

Result:

server can be closed and restarted
2020-08-27 06:33:17 +02:00
Josef Grieb
6ab424f3c6 Fix checkstyle errors
Motivation:

-to fix checkstyle error and missing licence

Modification:

-Added missing license and fixed checkstyle error

Result:

it's a non functional change
2020-08-26 14:12:41 +02:00
Josef Grieb
63c490470c
Merge pull request #1 from normanmaurer/io-uring-gc
Reduce GC by remove creation of objects related to completion queue a…
2020-08-26 13:07:22 +02:00
Norman Maurer
49449b300e Reduce GC by remove creation of objects related to completion queue and submission queue
Motivation:

We did create a lot of objects related to the completion queue and submission queue which produced a lot of GC. Beside this we also did maintain an extra map which is not really needed as we can encode everything that we need in the user_data field.

Modification:

- Reduce complexity and GC pressure by store needed informations in the user_data field
- Small refactoring of the code to move channel related logic to the channel
- Remove unused classes
- Use callback to process stuff in the completion queue and so remove all GC created by it
- Simplify by not storing channel and buffer in the event

Result:

Less GC pressure and no extra lookups for events needed
2020-08-26 12:32:27 +02:00
Norman Maurer
3229d7e553 Make use of MPSC queue to reduce overhead 2020-08-25 19:04:30 +02:00
Norman Maurer
9576c939d8 Remove debugging cruft 2020-08-25 18:50:07 +02:00
Norman Maurer
e13cc929dc Correctly handle eventfd in io_uring
Motivation:

We use eventfd in our io_uring based transport to wakeup the eventloop. When doing so we need to be careful that we read any data previous written to it.

Modification:

- Correctly read data that was written to eventfd before submit another event related to it to the submission queue as otherwise we will see another completion event related to it asap
- Ensure we not remove the wrong event from the storted event ids (we did remove the wrong before because we reused the Event object)
- ensure we only use the submission queue from the EventLoop thread in all cases
- add another unit test

Result:

Wakeups via eventfd work as expected
2020-08-25 18:39:21 +02:00
Norman Maurer
191f0de6ee Make logging less noisy 2020-08-25 17:22:30 +02:00
Norman Maurer
16530998a3 Correctly calculate timeout for io_uring
Motivation:

We need to use deadlineToDelayNanos(...) to calculate the timeout for io_uring as otherwise the timeout will be scheduled at the wrong time in the future

Modifications:

Make use of deadlineToDelayNanos(...)

Result:

Correctly schedule timeou
2020-08-25 14:27:33 +02:00
Norman Maurer
b62668d1d0 Fix bug in IOUringEventLoop which may caused eventfd_write to not unblock and make processing more efficient
Motivation:

There was a bug in the implemention so we missed to submit what was in the submission queue. This could lead to a deadlock. Beside this we should also process all events that we can poll without blocking and only after that process tasks. This will ensure we drain the ringbuffers in a timely manner

Modifications:

- Add missing submit() call
- Rename peek() to poll() as we consume the data so peek() is missleading
- Process all events that can be processed without blocking

Result:

Fix a bug, clarify and better performance
2020-08-25 12:48:01 +02:00
Josef Grieb
8435c0ce1f Reproduce error: it hangs itself up in echo test
Motiviation:

after each pass all channel sockets are closed, after the allocator is changed(4. iteration) the server socket BeginRead wont be called after server socket creation, however, both allocators work in netty example

Modification:

increased the timeout, other tests were commented out

Result:

testsuite changes will be undone later
2020-08-24 12:11:35 +02:00
Josef Grieb
d9b3f293a5 Add read exception handling to shutdown channels
Motivation:

-at the moment we dont shutdown when we get a read error message
-missing autoread support

Modifications:

-even if autoread is disable, should do check if the read event is already submitted
-added new Handle exception method to shutdown the channels

Result:

EL read event can handle read errors
2020-08-24 11:12:40 +02:00
Josef Grieb
b10b4ca6e7 Add polling POLLOUT
Motivation:

no checks for non writeable sockets

Modifications:

-Added a linked write poll to make sure that the socket does not write if it is not writeable
-Added a new boolean to avoid to submit a second write operation

Result:

writeable socket check
2020-08-24 11:12:40 +02:00
Josef Grieb
d3a0395ac2 Add polling RdHup
Motivation:

when the channel connection is lost, we dont get any notification(unless the customer has not submitted a writer or read event)

Modifications:

add rhup polling to be notified when the connection is lost

Result:

the eventloop is notified on connection losts
2020-08-24 11:12:40 +02:00
Josef Grieb
0160284301 Add abstract stream channel
Motivation:

to shutdown child channels we should create new abstact client class instead of using AbstractIOUringChannel

Modifications:

-Added new child channel abstract class
-Add shutdown methods to close a channel when the connection is lost

Result:

the channels can be closed when the connection is lost
2020-08-24 11:12:40 +02:00
Josef Grieb
96e0e5cc91 Release timeout memory for scheduled tasks
Motivation:

fix memory leak

Modification:

added a new release method and it will be called in ring buffer

Result:

to avoid memory leaks
2020-08-24 11:12:40 +02:00
Josef Grieb
8d464d5ab4 Include LinuxSocket TCP options
Motivation:

some tcp options (like TcpFastopen or TcpFastopenConnect etc.) are required for testsuite tests

Modification:

-copied the class LinuxSocket from epoll and  JNI to load this module in io_uring jni
-some configurations have been adjusted

Result:

more tcp options are available
2020-08-24 11:12:40 +02:00
Josef Grieb
1117c6fdb8 io_uring availability check
Motivation:

availability io_uring check for each test case

Modification:

added ioUringExit method to munmap the shared memory and close ring file descriptor which is required for the availability check

Result:

it's able to integrate testsuite tests
2020-08-20 12:27:10 +02:00
Josef Grieb
bf6a14effb Removed poll before the read event
Motivation:

no need to poll in front of the read operation since IORING_FEAT_FAST_POLL polls anyway

Modification:

removed poll before the read event

Result:

netty echo prototype works on a custom kernel https://github.com/1Jo1/linux/tree/io_uring_off7(merge linux-block/io_uring-5.9 branch into 5.8.0) and Linux 5.9-rc1 should work as well(not tested yet)
2020-08-18 06:45:42 +02:00
Josef Grieb
71c33eaec3 Add Poll before the accept/read operation
Motivation:

The problem is that if io_uring accept/read non blocking doesnt return -EAGAIN for non-blocking sockets
in general, then it removes a way for the application to tell if
there's ever any data there.
There is a fix in Kernel 5.8 https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?h=v5.8&id=e697deed834de15d2322d0619d51893022c90ea2 which means we need to add poll before the accept/read event(poll<link>read/accept) to fix in netty as well

Modification:

-add poll before the accept/read event with this flag IOSQE_IO_LINK

Result:

netty prototype works on Kernel 5.8
2020-08-10 09:53:38 +02:00
Josef Grieb
bc9ada411b Add wakeup and timeout
Motivation:

wake up the blocking call io_uring which is called when a new task is added(not from the eventloop thread)

Modification:

-Added timeout operation for scheduled task(not tested yet)
-Added Poll operation
-Added two tests to reproduce the polling signal issue

Result:
io_uring_enter doesnt get any polling signal from eventFdWrite if both functions are executed in different threads
2020-08-04 19:56:18 +02:00
Josef Grieb
d3c28143a8 Cleanup PR
Motivation:

unnecessary use of LinuxSocket class, missing CRLF etc.

Modification:

-Add CRLF
-remove IOUringChannelConfig and LinuxSocket class

Result:
less code and cleanup
2020-07-28 22:52:32 +02:00
Josef Grieb
a29b8c5cb3 write all messages
Motivation:

write until there is nothing left in the buffer

Modification:

eventloop executes the next write event

Result:
write all messages
2020-07-28 21:36:11 +02:00
Josef Grieb
df84759128 fix bind address exception
Motivation:

if you run a io_uring example two times in a row, you gonna get bind address exception

Modification:
-set SO_REUSEADDR as default

Result:
fixed bug
2020-07-28 21:19:46 +02:00
Josef Grieb
97b4537ab1 Use socket non-blocking instead of blocking
Motivation:

non-blocking sockets are more efficient

Modification:
-use socket non blocking
-some PR cleanups

Result:
probably better performance
2020-07-27 20:41:26 +02:00
Josef Grieb
eb1c8e4991 Cleanup
Motivation:

fix checkstyle errors and many classes are unnecessarily public

Modification:
-fixed maven checkstyle errors
-using package-private and final classes

Result:
better code quality
2020-07-22 14:01:48 +02:00
Josef Grieb
8c9b874a2d First running prototype 🎉
Motivation:
missing eventLoop completionQueue logic

Modification:
-mapping between channel and eventloop
-added new prototype blocking example

Result:
First running prototype
2020-07-20 23:49:00 +02:00
Josef Grieb
339d5f1565 Added native unix common module
Motivation:

unix common tools native C modules were not loaded in netty_io_uring_native.c

```
Caused by: java.lang.UnsatisfiedLinkError: io.netty.channel.unix.LimitsStaticallyReferencedJniMethods.udsSunPathSize()I
        at io.netty.channel.unix.LimitsStaticallyReferencedJniMethods.udsSunPathSize(Native Method)
        at io.netty.channel.unix.Socket.<clinit>(Socket.java:49)
        at io.netty.channel.uring.IOUringServerSocketChannel.<init>(IOUringServerSocketChannel.java:29)
        ... 11 more

```

Modification:

Added unix common tools native in netty_io_uring_native.c and small cleanup

Result:

fix UnsatisfiedLinkError exception
2020-07-16 03:03:36 +02:00
Josef Grieb
247e14a2b1 Add channel configs
Motivation:
-missing channel configs
-we dont store byteBuf and channel for the read operation to execute channel.fireChannelReadComplete

Modifications:
-add channels configs
-new Event properties for the processing completionQueue

Result:
with these changes it will be much easier to implement the eventloop
2020-07-15 17:51:51 +02:00
Josef Grieb
8a56cd1959 Read Event test and documentation
Motivation:

missing documentation and read event test

Modifications:

add documentation and read event test

Result:

better documentation and tests
2020-07-10 09:24:49 +02:00
Josef Grieb
692238f6da Move ring buffer logic to Java
Motivation:
JNI ring buffer implementation is inflexible and not really efficient

Modifications:

-RingBuffer instance is created in JNI which contains io_uring ring buffer information
-move the JNI ring buffer logic to Java
-added Todos
-using unsafe memory barriers loadFence and storeFence
-revert epoll file

Result:

this java ring buffer implementation is more flexible and efficient
2020-07-07 13:06:45 +02:00