Closed Bug 1595627 Opened 5 years ago Closed 3 years ago

Implement low-memory detection on Mac OSX for automatic tabs discard

Categories

(Core :: Widget, enhancement, P2)

Unspecified
macOS
enhancement

Tracking

()

RESOLVED DUPLICATE of bug 1714382
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

Priority: P3 → --
Component: Widget: Gtk → Widget

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.

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!
Assignee: nobody → mstange
Status: NEW → ASSIGNED

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.

Attachment #9110057 - Attachment description: Bug 1595627 - Observer memory pressure on macOS using a GCD DISPATCH_SOURCE_TYPE_MEMORYPRESSURE source. r=spohl,gsvelto → Bug 1595627 - Observe memory pressure on macOS using a GCD DISPATCH_SOURCE_TYPE_MEMORYPRESSURE source. r=spohl,gsvelto

Haik is now committed to this work.

Assignee: mstange.moz → haftandilian
Fission Milestone: --- → M8
Priority: -- → P2

Depends on D109995

Attachment #9110057 - Attachment is obsolete: true

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.

Fission Milestone: M8 → MVP
OS: Unspecified → macOS

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.

Whiteboard: fission-soft-blocker

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.

Status: ASSIGNED → RESOLVED
Closed: 3 years ago
Resolution: --- → DUPLICATE
Attachment #9211944 - Attachment is obsolete: true
Attachment #9211945 - Attachment is obsolete: true
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: