5 ms·
> OS paging is blocking as hell No, Linux is rubbish. Seriously. FreeBSD does this properly. Edit: FreeBSD, Windows, OSX, Solaris, AIX, HP-UX(?)...
by smegel 10y ago
> OS paging is blocking as hell
No, Linux is rubbish. Seriously. FreeBSD does this properly.
Edit: FreeBSD, Windows, OSX, Solaris, AIX, HP-UX(?)...
- deleted 10y ago[deleted]
- trungaczne 10y agoDo you have any articles that talk about how FreeBSD does memory management differently?
- smegel 10y agohttps://people.freebsd.org/~jlemon/papers/kqueue.pdf https://people.freebsd.org/~jlemon/papers/kqueue.pdf
- wmf 10y agoAdmittedly I didn't read it in detail, but I don't see anything about page-ins there. Can you explain the connection between kqueue and paging?
- tedunangst 10y agoThere is no connection. FreeBSD does page faults just like everybody else. Your process blocks until the memory is read in.
- smegel 10y agoSure it would be my pleasure. Kqueue allows a read request to be scheduled that is non-blocking on a page fault. Linux always blocks the thread executing read() on a page fault. This is still true using aio_read(), as all that does is run another thread to call read() which blocks. Which is great for small numbers of read requests but scales poorly. And the bit from the paper that is relevant: > A non kqueue-aware application using the asynchronous I/O (aio) facility starts an I/O request by issuing aio read() or aio write() The request then proceeds independently of the application, which must call aio error() repeatedly to check whether the request has completed, and then eventually call aio return() to collect the completion status of the request. The AIO filter replaces this polling model by allowing the user to register the aio request with a specified kqueue at the time the I/O request is issued, and an event is returned under the same conditions when aio error() would successfully return. This allows the application to issue an aio read() call, proceed with the main event loop, and then call aio return() when the kevent corresponding to the aio is returned from the kqueue, saving several system calls in the process.
- wmf 10y agoOK, so you're talking about AIO and other people here are talking about mmap. If you have working AIO then you can indeed write a fully async server at the cost of extra memory copies.
- SamReidHughes 10y agoLinux's family of async I/O functions is io_submit and friends, not aio_read. That paper is too old to be relevant. Also, using a worker pool for I/O scales just fine and has no real disadvantages when talking to a disk or SSD.
- lgunsch 10y agoRead and write system calls have nothing to do with jump instructions causing a page fault by traversing data structures. That is what Redis is all about - in memory data structures available to clients.
- doublerebel 10y agoThe way SmartOS performs under memory pressure is completely different from Linux, the OS is still usable where Linux would be completely frozen. Admittedly I don't know the underlying implementation behind this feature.
- smarnach 10y agoWhat else can you do other than blocking until the page has been loaded? How would it be possible to resume a single-threaded process while the memory it's trying to access is not available?
- smegel 10y agoYou say "hey process, this data is not available yet, but if you listen on this event port I will sent you a notification when it is ready, then you can do whatever you want with it. In the meantime, continue to serve up data that is in memory". Pretty simple stuff really.
- smarnach 10y agoYou might be able to do that in response to a system call asking whether a memory page is available, but not in response to a page fault. A page fault occurs if the process tries to access a virtual memory page that's not currently mapped to physical memory. Unless I'm missing something, the only reasonable way of resuming the process at the machine code instruction that caused the page fault is to first make sure the memory is available. Otherwise you will simply get another page fault.
- dllthomas 10y agoYou don't necessarily need to resume the process at the machine code instruction that caused the page fault.
- Dylan16807 10y agoPlease tell me how it's possible to do something like socket.write(data), when data has been swapped out, without blocking.
- smegel 10y ago1. make a non-blocking read on the data 2. while it is being paged into memory, <DO OTHER STUFF> 3. now your data is in memory and you can update it (writes are async by default even on Linux, as the write just goes into memory and will get synced out by the kernels page sync mechanism but you can override that by setting the O_SYNC flag).
- Dylan16807 10y agoTriggering a non-blocking read and continuing execution requires either writing different code or an extremely elaborate page fault feature that can dynamically rewrite your execution flow behind your back. Writing different code is not the question I asked. That's not an OS feature. Do the OSes you like have the latter ability, or are you blowing smoke?
- deleted 10y ago[deleted]
- smegel 10y ago> Triggering a non-blocking read and continuing execution requires either writing different code Well you are asking about doing something non-blocking. That means you must be in some kind of event-loop scenario, otherwise you would be happy with synchronous operations. And yes, you would need to add a read event on the file, and then trigger the socket.send() once the data is in memory. I never said it was free. But at least it is viable.
- Dylan16807 10y agoYour response to paging being blocking was to blame Linux. Every OS has paging be blocking. Linux has ways to do non-blocking IO. There is no reason to blame Linux.