[PATCH] D119572: Add virtual mem size when setting RSS limit on Apple platforms.
Florian Hahn via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Feb 11 11:54:59 PST 2022
fhahn created this revision.
fhahn added reviewers: ab, aprantl, cmatthews.
fhahn requested review of this revision.
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
Repository:
rT test-suite
https://reviews.llvm.org/D119572
Files:
tools/timeit.c
Index: tools/timeit.c
===================================================================
--- tools/timeit.c
+++ tools/timeit.c
@@ -19,6 +19,10 @@
#include <sys/time.h>
#include <sys/wait.h>
+#if defined(__APPLE__)
+#include <sys/proc_info.h>
+#endif
+
/* Enumeration for our exit status codes. */
enum ExitCode {
/* \brief Indicates a failure monitoring the target. */
@@ -333,7 +337,17 @@
if (g_target_data_size_limit != ~(rlim_t) 0) {
set_resource_limit(RLIMIT_DATA, g_target_data_size_limit);
}
+
if (g_target_rss_size_limit != ~(rlim_t) 0) {
+#if defined(__APPLE__)
+ // On Apple platforms, RLIMIT_RSS is mapped to RLIMIT_AS 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.
+ struct proc_taskinfo task_info;
+ proc_pidinfo(getpid(), PROC_PIDTASKINFO, 0, &task_info, sizeof(task_info));
+ g_target_rss_size_limit += task_info.pti_virtual_size;
+#endif
set_resource_limit(RLIMIT_RSS, g_target_rss_size_limit);
}
if (g_target_file_size_limit != ~(rlim_t) 0) {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D119572.407974.patch
Type: text/x-patch
Size: 1172 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220211/3b5ef20a/attachment.bin>
More information about the llvm-commits
mailing list