This is an archive of the discontinued LLVM Phabricator instance.

Add virtual mem size when setting RSS limit on Apple platforms.
AbandonedPublic

Authored by fhahn on Feb 11 2022, 11:54 AM.

Details

Summary

On Apple platforms, RLIMIT_RSS is mapped to RLIMIT_AS [1] and setting
RLIMIT_AS to a value smaller than the current virtual memory size
will fail. To avoid issues, first get the current size of the virtual
memory and add the user requested limit.

[1] https://github.com/apple/darwin-xnu/blob/a1babec6b135d1f35b2590a1990af3c5c5393479/bsd/sys/resource.h

Event Timeline

fhahn requested review of this revision.Feb 11 2022, 11:54 AM
fhahn created this revision.
fhahn planned changes to this revision.Feb 11 2022, 12:51 PM

Using getpid is not supported on all platforms. I'll see if there's a workaround, otherwise we probably have to ignore RLIMIT_RSS for apple platforms.

fhahn requested review of this revision.Feb 11 2022, 2:39 PM

I checked again and the earlier failures where caused by a configuration issue. It should be ready for review!

ab added inline comments.Feb 11 2022, 2:49 PM
tools/timeit.c
347

We don't have to abort if proc_pidinfo fails, but we should be resilient to that. Maybe explicitly initialize task_info to 0 first? If you can't because it's opaque, I guess you do have to check for success after all ;)

fhahn updated this revision to Diff 408065.Feb 11 2022, 2:55 PM

Zero initialze struct.

fhahn added inline comments.Feb 11 2022, 2:56 PM
tools/timeit.c
347

Good point, I updated the code to zero initialize the struct.

ab accepted this revision.Feb 11 2022, 3:07 PM
This revision is now accepted and ready to land.Feb 11 2022, 3:07 PM
fhahn abandoned this revision.Feb 12 2022, 4:32 AM

I did some more testing and for some benchmarks the provided default value by llvm-lit is too small. Bumping the default is not straigth-forward, as on other platforms rlim_t may only be a unsigned long. And timeit uses atoi to parse the argument value. I don't think this is worth all the trouble and for now I just committed a change ignoring RLIMIT_RSS on Apple platforms (916fce4cbbfd) so the test-suite can be run again on Apple platforms that more strictly enforce the virtual memory limit.