<commit_before>+++
title = "RSoC: improving drivers and kernel (largely io_uring)"
author = "4lDO2"
date = "2020-06-24T00:45:43+02:00"
+++

# Introduction
This is my first year of Redox Summer of Code, and my intent is continuing my
prior work (outside of RSoC) on improving the Redox drivers and the kernel. I
started this week by quite a minor change: implementing a more advanced syscall
for allocating physical memory, namely `physalloc3`. Unlike the more basic
`physalloc` which only takes a size as parameter, `physalloc3` also takes a
flags and minimal size; this allows a driver to request a large range and fall
back to multiple small ranges, if the physical memory space were to be too
fragmented, by using scatter-gather lists (a form of vectored I/O like `preadv`
for hardware). It also adds support for 32-bit-only allocation for devices that
do not support the entire 64-bit physical address space.

# `io_uring`
However, the arguably most interesting thing that I have worked on this week,
is a Redox-flavored `io_uring` interface, which is very similar to [the Linux
`io_uring` kernel interface for asynchronous
I/O](https://kernel.dk/io_uring.pdf), although with a few major differences.
The idea, just as with Linux, is to use two kernel-managed SPSC queues (rings)
as an alternative syscall interface, rather than relying on a direct context
switch to the kernel, via register parameters and the syscall instruction;
instead, a syscall is made by pushing a new entry onto the _Completion Queue_,
then doing other useful work, and then eventually popping an entry from the
_Completion Queue_, which indicates that the syscall has completed with a<commit_msg>Fix typo from previous io_uring blog post.<commit_after>+++
title = "RSoC: improving drivers and kernel (largely io_uring)"
author = "4lDO2"
date = "2020-06-24T00:45:43+02:00"
+++

# Introduction
This is my first year of Redox Summer of Code, and my intent is continuing my
prior work (outside of RSoC) on improving the Redox drivers and the kernel. I
started this week by quite a minor change: implementing a more advanced syscall
for allocating physical memory, namely `physalloc3`. Unlike the more basic
`physalloc` which only takes a size as parameter, `physalloc3` also takes a
flags and minimal size; this allows a driver to request a large range and fall
back to multiple small ranges, if the physical memory space were to be too
fragmented, by using scatter-gather lists (a form of vectored I/O like `preadv`
for hardware). It also adds support for 32-bit-only allocation for devices that
do not support the entire 64-bit physical address space.

# `io_uring`
However, the arguably most interesting thing that I have worked on this week,
is a Redox-flavored `io_uring` interface, which is very similar to [the Linux
`io_uring` kernel interface for asynchronous
I/O](https://kernel.dk/io_uring.pdf), although with a few major differences.
The idea, just as with Linux, is to use two kernel-managed SPSC queues (rings)
as an alternative syscall interface, rather than relying on a direct context
switch to the kernel, via register parameters and the syscall instruction;
instead, a syscall is made by pushing a new entry onto the _Submission Queue_,
then doing other useful work, and then eventually popping an entry from the
_Completion Queue_, which indicates that the syscall has completed with a
{'fraction_non_alphanumeric': 0.05471753918958888, 'fraction_numerical': 0.015380065069506064, 'mean_word_length': 4.933333333333334, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7217604', 'n_tokens_mistral': 937, 'n_tokens_neox': 870, 'n_words': 513}