News for hackers. Stuff that matters.
Re:Put an io_uring on it – Exploiting the Linux Kernel by refulgentis on Friday June 16, 2023 @12:38PM (#36359557)
> If the operation can be done without blocking, it will be completed synchronously in the context of the calling thread.

My careers been in mobile, I thought “blocking” and “synchronous” were synonymous.

Does blocking in this context mean “needs to make a system call?”

Re:Put an io_uring on it – Exploiting the Linux Kernel by skulk on Friday June 16, 2023 @12:40PM (#36359609)
I think it means "entering a state where the thread has nothing to do but wait." An "add" instruction is synchronous but I wouldn't say it "blocks".
Re:Put an io_uring on it – Exploiting the Linux Kernel by Arnavion on Friday June 16, 2023 @12:56PM (#36359929)
>I think it means "entering a state where the thread has nothing to do but wait."

No. Neither thread involved here (the userspace thread or the kernel thread) will "wait" in either scenario. The userspace thread will either work on the syscall (because it was ready to be performed immediately) or it will be released to go do something else. The kernel thread will either not be involved (because the syscall was performed by the userspace thread already) or it will start working on the syscall.

Re:Put an io_uring on it – Exploiting the Linux Kernel by formerly_proven on Friday June 16, 2023 @12:41PM (#36359618)
In Linux, file systems are comparatively uninvolved in I/O (or can choose to be so), so for example the kernel can figure out (in common cases) that e.g. a read of a file can be served entirely out of the page cache without going into file system code at all, then it can just do that right on the spot.
Re:Put an io_uring on it – Exploiting the Linux Kernel by Arnavion on Friday June 16, 2023 @12:52PM (#36359842)
"Blocking" == "can be completed immediately" in this context, ie whether the equivalent syscall would complete immediately or if it would return EAGAIN. So if the operation can be completed immediately, it will be completed in the context of the calling thread without involving the kernel work queue. Otherwise it cannot be completed immediately, so the kernel work queue will take it and start working on it.
Re:Put an io_uring on it – Exploiting the Linux Kernel by ithkuil on Friday June 16, 2023 @12:56PM (#36359928)
"Blocking (on IO)" in OS jargon means that the thread can yield the CPU to other threads because it's otherwise waiting for some external event (e.g. some IO operation to complete).

When the IO operation is ready the thread is then marked to be awakened and the scheduler will context switch back to it whenever it sees fit (given other considerations like thread priority, etc).

From the POV of the thread that blocks nothing really happens while it's waiting. Once it awakens it has the result of the operation (or an error) and it can observe that more time has passed by inspecting the timer. For all intents and purposes the operation was "synchronous" from the POV of the thread.

Re:Put an io_uring on it – Exploiting the Linux Kernel by refulgentis on Sunday June 18, 2023 @06:04PM (#36385002)
Ty for this, Flutters been unreasonably effective for me, with an absurdly simple concurrency system, and I never quite understood why. Now I see why the simple idea of never-blocking is so effective. This comment probably sounds silly, I’m groping for words to describe my old vs. new understanding, but anyways, thanks :)