Implement low-memory detection on Mac OSX for automatic tabs discard
Categories
(Core :: Widget, enhancement, P2)
Tracking
()
Fission Milestone | MVP |
Tracking | Status | |
---|---|---|
firefox92 | --- | affected |
People
(Reporter: jesup, Assigned: haik)
References
Details
(Whiteboard: fission-soft-blocker)
Attachments
(2 files, 3 obsolete files)
We need low memory monitoring for tab unloading (and other reasons). some possible pointers to low memory monitoring on Mac OSX (Note: I'm not a mac expert!!)
http://newosxbook.com/articles/MemoryPressure.html and (related) https://apple.stackexchange.com/questions/107126/what-scale-or-measure-does-mavericks-and-yosemites-memory-pressure-adhere-to
Also: https://stackoverflow.com/questions/20852833/responding-to-memory-pressure-on-mavericks
Reporter | ||
Updated•5 years ago
|
Reporter | ||
Updated•5 years ago
|
Comment 1•5 years ago
|
||
This is very helpful. The EVFILT_VM
and EVFILT_MEMORYSTATUS
event seem the most promising (provided we can access and test them). Apple headers contain a number of interesting defines associated with them:
/*
* data/hint fflags for EVFILT_VM, shared with userspace.
*/
#define NOTE_VM_PRESSURE 0x80000000 /* will react on memory pressure */
#define NOTE_VM_PRESSURE_TERMINATE 0x40000000 /* will quit on memory pressure, possibly after cleaning up dirty state */
#define NOTE_VM_PRESSURE_SUDDEN_TERMINATE 0x20000000 /* will quit immediately on memory pressure */
[...]
/*
* data/hint fflags for EVFILT_MEMORYSTATUS, shared with userspace.
*/
#define NOTE_MEMORYSTATUS_PRESSURE_NORMAL 0x00000001 /* system memory pressure has returned to normal */
#define NOTE_MEMORYSTATUS_PRESSURE_WARN 0x00000002 /* system memory pressure has changed to the warning state */
#define NOTE_MEMORYSTATUS_PRESSURE_CRITICAL 0x00000004 /* system memory pressure has changed to the critical state */
#define NOTE_MEMORYSTATUS_LOW_SWAP 0x00000008 /* system is in a low-swap state */
#define NOTE_MEMORYSTATUS_PROC_LIMIT_WARN 0x00000010 /* process memory limit has hit a warning state */
#define NOTE_MEMORYSTATUS_PROC_LIMIT_CRITICAL 0x00000020 /* process memory limit has hit a critical state - soft limit */
#define NOTE_MEMORYSTATUS_MSL_STATUS 0xf0000000 /* bits used to request change to process MSL status */
#define NOTE_VM_PRESSURE_SUDDEN_TERMINATE 0x20000000 /* will quit immediately on memory pressure */
Also this promising enum:
typedef enum vm_pressure_level {
kVMPressureNormal = 0,
kVMPressureWarning = 1,
kVMPressureUrgent = 2,
kVMPressureCritical = 3,
} vm_pressure_level_t;
Let's hope this stuff is exposed to userspace.
Comment 2•5 years ago
|
||
Randell found another hint, which looks even more promising: The iOS docs say:
It delivers a warning to dispatch queues of type
DISPATCH_SOURCE_TYPE_MEMORYPRESSURE
.
And it turns out DISPATCH_SOURCE_TYPE_MEMORYPRESSURE
is available on macOS as well! And here's a snippet that shows how to use it. The snippet contains the following comment:
// Test with sudo memory_pressure -l critical. Don't forget to re-set afterwards!
This could be useful, too: https://developer.apple.com/documentation/dispatch/dispatchsource/memorypressureevent
Updated•5 years ago
|
Comment 4•5 years ago
|
||
This sets up a memory pressure observer in the parent process only.
Memory pressure can be simulated on macOS using the memory_pressure command line tool.
For example, to simulate memory pressure of level "warn" for two seconds, use:
% sudo memory_pressure -l warn -s 2 -S
Without the "-S" flag, this tool will create real memory pressure by allocating actual memory.
Updated•5 years ago
|
Comment 5•4 years ago
|
||
Haik is now committed to this work.
Updated•4 years ago
|
Assignee | ||
Comment 6•4 years ago
|
||
Assignee | ||
Comment 7•4 years ago
|
||
Depends on D109995
Assignee | ||
Comment 8•4 years ago
|
||
Depends on D109996
Assignee | ||
Comment 9•4 years ago
|
||
Depends on D109997
Assignee | ||
Updated•4 years ago
|
Comment 10•4 years ago
•
|
||
Tab unloading is a nice-to-have for our Fission Release experiment, but doesn't need to block it. I will move this bug from Fission Milestone M8 to MVP.
Comment 11•4 years ago
|
||
This bug is a soft blocker for Fission MVP. We'd like to fix it before our Release channel rollout, but we won't delay the rollout waiting for it.
Assignee | ||
Comment 12•3 years ago
|
||
Closing this bug as a dupe of bug 1714382 which included the low memory detection on macOS.
Bug 1730066 will use the low memory detection to trigger tab unloading.
Updated•11 months ago
|
Updated•11 months ago
|
Description
•