"User-space data may not be resident in RAM"
"User-space data may not be resident in RAM"
Posted Jul 8, 2020 6:34 UTC (Wed) by epa (subscriber, #39769)Parent article: Sleepable BPF programs
Posted Jul 8, 2020 12:32 UTC (Wed)
by k3ninho (subscriber, #50375)
[Link] (1 responses)
K3n.
Posted Jul 8, 2020 12:54 UTC (Wed)
by epa (subscriber, #39769)
[Link]
Posted Jul 8, 2020 13:59 UTC (Wed)
by corbet (editor, #1)
[Link] (15 responses)
Posted Jul 8, 2020 20:38 UTC (Wed)
by epa (subscriber, #39769)
[Link] (4 responses)
As far as I know, Android systems don't have swap space. I would expect most embedded Linux systems to do without it also. A spinning disk is too slow, and swapping to flash memory wears it out. Meanwhile supercomputers will normally run a specialized application designed to fit into physical RAM. It's the medium-sized systems that still use swap, as a kind of last resort before breaking out the OOM killer. I think this middle space is likely to shrink in the years to come.
I take your point that programs may allocate a huge address space and then use little of it. That's a slightly different issue from swap: no 64-bit system has a swap file big enough for the whole virtual address space that some process might make, and you can have huge (but mostly empty) address spaces with no swap at all. But it would invalidate the property that access to user memory can never block. If the page had been allocated but not touched, a page fault would still be needed on first use.
(*) I know this rule came from various old systems and Unix variants in simpler times. I use it as a rough example of a fairly generous allocation of swap space, not that I am advocating it on current systems. My point is that even if swap is much bigger than RAM, that's still less than an order of magnitude to overcome.
Posted Jul 9, 2020 8:14 UTC (Thu)
by farnz (subscriber, #17727)
[Link] (2 responses)
My Android devices do have swap - it's backed by a zram compressed RAM device, but it's swap nonetheless.
Posted Jul 9, 2020 11:03 UTC (Thu)
by epa (subscriber, #39769)
[Link] (1 responses)
I wonder whether for Android devices an old-fashioned task swapper might work better than demand paging, with an app that you've switched away from (and which does not run in the background) being swapped out to zram and swapped back in when you open it.
Posted Jul 9, 2020 11:29 UTC (Thu)
by farnz (subscriber, #17727)
[Link]
Android effectively has that, by requiring all apps to be capable of writing their own state to storage and exiting while backgrounded. However, swap helps because it allows more processes to sit idle in memory, ready for an on-demand "instant" switch instead of a slightly slower restore from storage.
Posted Jul 9, 2020 9:40 UTC (Thu)
by gray_-_wolf (subscriber, #131074)
[Link]
I like to be able to hibernate my machine though...
Posted Jul 9, 2020 0:50 UTC (Thu)
by Fowl (subscriber, #65667)
[Link] (9 responses)
Posted Jul 9, 2020 6:28 UTC (Thu)
by epa (subscriber, #39769)
[Link] (8 responses)
As for ordinary fork() where you won't immediately exec() afterwards, that might not spoil things, as it's only *writing* to user-space memory that can cause a copy-on-write fault, not reading it. And a system call to read bytes from a file into some memory may as well reserve the physical space in advance, rather than allocating it only once data comes back from the disk.
Posted Jul 9, 2020 6:35 UTC (Thu)
by Cyberax (✭ supporter ✭, #52523)
[Link] (3 responses)
Posted Jul 9, 2020 8:55 UTC (Thu)
by epa (subscriber, #39769)
[Link] (2 responses)
Posted Jul 9, 2020 13:28 UTC (Thu)
by Fowl (subscriber, #65667)
[Link]
So you'd have to not write in *both* the parent and the child until the child execs.
Posted Jul 9, 2020 17:54 UTC (Thu)
by Cyberax (✭ supporter ✭, #52523)
[Link]
Posted Jul 9, 2020 13:13 UTC (Thu)
by Fowl (subscriber, #65667)
[Link] (2 responses)
Hey, Oh and how does thread-local storage work? Can you move it between threads? Is it even common? Does it depends on the thread ID? Is it possible to fake the TID? I don't know
Hmm and how do you know when you can free the stack you've just allocated for this new out-of-process-but-same-address-space thread you've just started? And I bet python and other runtime-y things are not going to be happy with two threads that think they're the same. Maybe block the parent until the child Anyway, I had fun spending 15 minutes thinking about it.
Posted Jul 9, 2020 13:20 UTC (Thu)
by Fowl (subscriber, #65667)
[Link] (1 responses)
Still, fun.
Posted Jul 9, 2020 17:06 UTC (Thu)
by JGR (subscriber, #93631)
[Link]
Posted Jul 9, 2020 21:39 UTC (Thu)
by ibukanov (subscriber, #3942)
[Link]
Posted Jul 8, 2020 17:24 UTC (Wed)
by zlynx (guest, #2285)
[Link]
"User-space data may not be resident in RAM"
You're still going to LRU files listed in the VFS cache, and maybe that would go away when you've got enough spare RAM to pin a mount point into the cache -- operating (eg root and home partitions) from RAM at the cost of being write heavy keeping disk in fsync().
"User-space data may not be resident in RAM"
That would be so hugely wasteful of RAM that I have a hard time seeing it ever happening. Programs have a tendency to never access large parts of their address spaces. And that's before you get into other tricks, like copy-on-write or memory shared with devices, that can cause faults. You'll be waiting a long time waiting for that particular simplification, I think.
"User-space data may not be resident in RAM"
"User-space data may not be resident in RAM"
"User-space data may not be resident in RAM"
"User-space data may not be resident in RAM"
"User-space data may not be resident in RAM"
"User-space data may not be resident in RAM"
"User-space data may not be resident in RAM"
"User-space data may not be resident in RAM"
"User-space data may not be resident in RAM"
Unless you're writing from other threads...
"User-space data may not be resident in RAM"
"User-space data may not be resident in RAM"
"User-space data may not be resident in RAM"
Ha, that's an interesting idea - "User-space data may not be resident in RAM"
fork_nocow()
. Exist in the parent's address space until exec()
.
clone(2)
already exists! A trampoline to spill all your registers to memory and you're done. Except for having to be careful not to leak any memory, as the memory would leak in the parent too, it's probably a friendlier environment than using regular fork - all your threads are still there. Oh and locks, who knows what's going on with that.
exec
s? I'm going to wave my magic wand and proclaim that if you did this you could then share the same stack on both sides of this new fork_nocow
.
Oh I'm an idiot. "User-space data may not be resident in RAM"
fork
has to return - of course you can't share a stack. Copying/COWing just the stack would mess up all those RAII and scope based resource cleanup things. More likely to work with a callback, but then you've thrown away the almost-compatibility with existing code that was the whole point.
"User-space data may not be resident in RAM"
"User-space data may not be resident in RAM"
"User-space data may not be resident in RAM"