Transparent system call batching?

Discussions on more advanced topics such as monolithic vs micro-kernels, transactional memory models, and paging vs segmentation should go here. Use this forum to expand and improve the wiki!
Post Reply
User avatar
Roman
Member
Member
Posts: 568
Joined: Thu Mar 27, 2014 3:57 am
Location: Moscow, Russia
Contact:

Transparent system call batching?

Post by Roman »

Hi, OSDev, haven't been posting here for a while!

You might have heard about batch system calls that, however, have the drawback of requiring application support. What if instead of directly dispatching the issued system calls to the kernel the standard library would add them to a queue (without calling the kernel) which upon certain conditions (expiration of a time slice?) would be reaped by the kernel? This way the overhead of system calls could be shrank — such would be especially beneficial given the recent events (publication of Meltdown and Spectre whose mitigations require costlier system calls). I wonder if this technique is a good idea for either a POSIX system or a novel OS design.
"If you don't fail at least 90 percent of the time, you're not aiming high enough."
- Alan Kay
User avatar
bluemoon
Member
Member
Posts: 1761
Joined: Wed Dec 01, 2010 3:41 am
Location: Hong Kong

Re: Transparent system call batching?

Post by bluemoon »

The problem is you can't batch them if application want results immediately. To enable batched system call, the calls themselves needed to be designed with async nature in mind.

PS. interrupts on the other hand, can be batched that way (e.g. certain NIC support that) to reduce context switching.
User avatar
Roman
Member
Member
Posts: 568
Joined: Thu Mar 27, 2014 3:57 am
Location: Moscow, Russia
Contact:

Re: Transparent system call batching?

Post by Roman »

@bluemoon: I see your point, but if hybrid threading was used then the standard library could simply switch to a different thread with no system call overhead. If no non-blocked threads were found then it would call the kernel to process the queue prematurely.
"If you don't fail at least 90 percent of the time, you're not aiming high enough."
- Alan Kay
Korona
Member
Member
Posts: 1000
Joined: Thu May 17, 2007 1:27 pm
Contact:

Re: Transparent system call batching?

Post by Korona »

I think that this can work if it is combined with explicit (and not implicit) flushes. One problem with implicit flushing is that you actually want system calls to issue I/O requests as fast as possible to avoid introducing additional latency. However, the greatest problem here is that existing APIs like POSIX and the C and C++ standard libraries expect most calls (e.g. memory allocation, thread creation, thread synchronization, IPC and I/O) to be blocking and that does not work with explicit flushing: It forces you to flush for single system calls and thus does not improve performance.
managarm: Microkernel-based OS capable of running a Wayland desktop (Discord: https://discord.gg/7WB6Ur3). My OS-dev projects: [mlibc: Portable C library for managarm, qword, Linux, Sigma, ...] [LAI: AML interpreter] [xbstrap: Build system for OS distributions].
User avatar
bluemoon
Member
Member
Posts: 1761
Joined: Wed Dec 01, 2010 3:41 am
Location: Hong Kong

Re: Transparent system call batching?

Post by bluemoon »

Roman wrote:@bluemoon: I see your point, but if hybrid threading was used then the standard library could simply switch to a different thread with no system call overhead. If no non-blocked threads were found then it would call the kernel to process the queue prematurely.
This would make batch possible, but create a side effect that might not be desired: calling kernel means yielding a thread, if the scheduler itself is sophisticated it may create unpredictable results.
User avatar
lkurusa
Member
Member
Posts: 42
Joined: Wed Aug 08, 2012 6:39 am
Libera.chat IRC: Levex
Location: New York, NY
Contact:

Re: Transparent system call batching?

Post by lkurusa »

You might be interested in reading the FlexSC paper, where they implement a similar method.

https://www.usenix.net/legacy/events/os ... Soares.pdf
Cheers,

Lev
User avatar
Roman
Member
Member
Posts: 568
Joined: Thu Mar 27, 2014 3:57 am
Location: Moscow, Russia
Contact:

Re: Transparent system call batching?

Post by Roman »

lkurusa wrote:You might be interested in reading the FlexSC paper, where they implement a similar method.

https://www.usenix.net/legacy/events/os ... Soares.pdf
Thanks for the link, I'll definitely check it out.
"If you don't fail at least 90 percent of the time, you're not aiming high enough."
- Alan Kay
Post Reply