A contemporary system set up, with default parameters is configured with the next system broad file limits:
- Kernel Max Recordsdata: 12288
- Max Recordsdata per Course of: 10240
Present kernel sysctl parameters might be seen with sysctl command:
$ sysctl -a |grep kern.maxf
kern.maxfiles: 12288
kern.maxfilesperproc: 10240
Now let’s verify limits values, utilizing ulimit command:
For SOFT limits: [we can see that: open files = 256]
$ ulimit -aS
core file dimension (blocks, -c) 0
information seg dimension (kbytes, -d) limitless
file dimension (blocks, -f) limitless
max locked reminiscence (kbytes, -l) limitless
max reminiscence dimension (kbytes, -m) limitless
open information (-n) 256
pipe dimension (512 bytes, -p) 1
stack dimension (kbytes, -s) 8192
cpu time (seconds, -t) limitless
max person processes (-u) 266
digital reminiscence (kbytes, -v) limitless
For HARD limits: [we can see that: open files = Unlimited]
$ ulimit -aH
core file dimension (blocks, -c) limitless
information seg dimension (kbytes, -d) limitless
file dimension (blocks, -f) limitless
max locked reminiscence (kbytes, -l) limitless
max reminiscence dimension (kbytes, -m) limitless
open information (-n) limitless
pipe dimension (512 bytes, -p) 1
stack dimension (kbytes, -s) 65532
cpu time (seconds, -t) limitless
max person processes (-u) 532
digital reminiscence (kbytes, -v) limitless
launchctl has the capability to configure restrict values, or present present values.
Utilizing launchctl restrict
it reveals all the present Delicate and Exhausting limits, and we are able to see that smooth restrict is 256 and onerous restrict is ‘limitless’ for the merchandise maxfiles. (the identical info we received utilizing ulimit command above)
$ uname -a
18.6.0 Darwin Kernel Model 18.6.0: Thu Apr 25 23:16:27 PDT 2019; root:xnu-4903.261.4~2/RELEASE_X86_64 x86_64
$ launchctl restrict
cpu limitless limitless
filesize limitless limitless
information limitless limitless
stack 8388608 67104768
core 0 limitless
rss limitless limitless
memlock limitless limitless
maxproc 266 532
maxfiles 256 limitless
To filter, we are able to simply use launchctl restrict maxfiles
$ launchctl restrict maxfiles
maxfiles 256 limitless
Utilizing your command line as instance:
sudo launchctl restrict maxfiles 10000 limitless
However after it, after I execute once more the command to show the bounds, we are able to see that:
- the Delicate restrict was adjusted from 256 to 10000,
- however the Exhausting restrict was diminished from ‘limitless’ to ‘10240’
sudo launchctl restrict
maxfiles 10000 10240
And from now, it’s unattainable to get it again to limitless!
We are able to see that after executing it, it additionally modified the kernel sysctl parameters
$ sysctl -A |grep max
kern.maxfiles: 10240
kern.maxfilesperproc: 10000
The phrase ‘limitless‘ when used as a parameter for setting maxfiles,
is identical as utilizing worth ‘10240‘.As a result of launchctl don’t settle for the string ‘limitless’ and convert it
to the worth 10240![I will prove it below, with the source code of launchclt and source of MacOS Mojave kernel]
However first, let see if we are able to use an even bigger worth like 2 million:
sudo launchctl restrict maxfiles 10000 2000000
$ launchctl restrict maxfiles
maxfiles 10000 2000000
Sure, we are able to, it accepted the larger worth.
It’s hardcoded on the supply code to not settle for ‘limitless‘ as a worth, so as soon as we modified it, we are able to by no means put it again.
However what’s the worth that corresponds to ‘limitless’ ?
- R: The worth of ‘limitless‘ is INT_MAX, which is ‘2147483647‘ (the utmost worth of the Integer Kind)
Supply code evaluation of launchclt.c and Kernel routines of MacOS
10.14 Mojave about why just isn’t attainable to set maxfiles to ‘limitless’ through launchctl command line.All info under is my evaluation, utilizing the supply code from
Apple, that may be obtained through:Rafael Prado – 2019/08/09
/* START OF CODE ANALYSIS */
// --------------- Analisys Remark ----------------------------------
// Taking a look at MacOS system core header file syslimits.h there's
// a definition of OPEN_MAX with worth 10240.
//
// That is the bottom worth that will probably be utilized by default for
// maxfiles worth throughout system startup.
//
// This remark you're studying right here is mine.
//
/* FILE: sys/syslimits.h */
// *****************************************************************
#outline OPEN_MAX 10240 /* max open information per course of - todo, make a config possibility? */
// *****************************************************************
//
// --------------- Analisys Remark ---------------------------------
// Now we are able to see inside kernel config, that maxfiles parameter
// is a subprodut of OPEN_MAX, by including 2048 to its worth,
// which give us the quantity 12288.
//
// This may grew to become the default worth for sysctl kern.maxfiles: 12288
//
/* FILE: conf/param.c */
// *****************************************************************
#outline MAXFILES (OPEN_MAX + 2048)
int maxfiles = MAXFILES;
// *****************************************************************
//
// --------------- Analisys Remark ---------------------------------
// Now right here is why it's unattainable to set 'limitless' worth utilizing
// the command line of launchctl:
//
/* FILE: launchd/help/launchctl.c */
// *****************************************************************
//
// (:..) Perform lim2str() on line 2810
const char *
lim2str(rlim_t val, char *buf)
{
if (val == RLIM_INFINITY)
strcpy(buf, "limitless");
else
sprintf(buf, "%lld", val);
return buf;
}
// (:..) Perform srt2lim() on line 2821
bool
str2lim(const char *buf, rlim_t *res)
{
char *endptr;
*res = strtoll(buf, &endptr, 10);
if (!strcmp(buf, "limitless")) {
*res = RLIM_INFINITY;
return false;
} else if (*endptr == ' ') {
return false;
}
return true;
}
// (:..) Perform limit_cmd() discovered on line 2835
int
limit_cmd(int argc, char *const argv[])
{
// ------------------------------------------------------------
// This remark just isn't a part of the supply file, it's
// my analisys remark about what this perform does.
//
// Right here it's studying the parameters of 'launchctl restrict argv2 argv3'
// and can name perform srt2lim() to transform the args to restrict values
//
// Perform srt2lim() is printed above.
// ------------------------------------------------------------
//
// (:....) skipping to line 2850 inside this perform
if (argc >= 3 && str2lim(argv[2], &slim))
badargs = true;
else
hlim = slim;
if (argc == 4 && str2lim(argv[3], &hlim))
badargs = true;
// ------------------------------------------------------------
// However earlier than settin the values, there's a verification that
// prohibits utilizing the phrase 'limitless' as a parameter (solely
// if used for 'maxfiles') and this verify returns error, exiting
// the limit_cmd() perform [the function we are now inside] and
// the system kernel paramter isn't adjusted if we use
// the phrase 'limitless' as a worth.
//
// This remark was written by me
// and isn't a part of the supply file.
// ------------------------------------------------------------
//
// (:....) skiping to line 2906 inside this perform
bool maxfiles_exceeded = false;
if (strncmp(argv[1], "maxfiles", sizeof("maxfiles")) == 0) {
if (argc > 2) {
maxfiles_exceeded = (strncmp(argv[2], "limitless", sizeof("limitless")) == 0);
}
if (argc > 3) strncmp(argv[3], "limitless", sizeof("limitless")) == 0);
if (maxfiles_exceeded) {
launchctl_log(LOG_ERR, "Neither the onerous nor smooth restrict for "maxfiles" might be limitless. Please use a numeric parameter for each.");
return 1;
}
}
// -------------------------------------------------------------
// We are able to see above, that it's prohibited to make use of the 'limitless' worth
// And after we use it, the system assumes the
// default worth of OPEN_MAX which is 10240 !
//
// This explains and show why setting 'limitless' offers us 10240
// --------------------------------------------------------------
// *****************************************************************
//
// --------------- Analisys Remark ---------------------------------
// Taking a look at one other file from Kernel supply, we are able to discover one other
// place the place it checks for 'limitless' worth, and likewise there's
// an evidence by Apple on it.
//
// The remark BELOW IS Authentic remark from Apple Builders and
// it's contained in the file kern_resource.c from MacOS Kernel Supply.
//
/* FILE: kern/kern_resource.c */
// *****************************************************************
case RLIMIT_NOFILE:
/*
* Solely root can set the maxfiles limits, as it's
* systemwide useful resource. If we expect POSIX conduct,
* as a substitute of clamping the worth, return EINVAL. We do that
* as a result of traditionally, folks have been in a position to try and
* set RLIM_INFINITY to get "regardless of the most is".
*/
if ( kauth_cred_issuser(kauth_cred_get()) ) {
if (limp->rlim_cur != alimp->rlim_cur &&
limp->rlim_cur > (rlim_t)maxfiles) {
if (posix) {
error = EINVAL;
goto out;
}
limp->rlim_cur = maxfiles;
}
if (limp->rlim_max != alimp->rlim_max &&
limp->rlim_max > (rlim_t)maxfiles)
limp->rlim_max = maxfiles;
}
else {
if (limp->rlim_cur != alimp->rlim_cur &&
limp->rlim_cur > (rlim_t)maxfilesperproc) {
if (posix) {
error = EINVAL;
goto out;
}
limp->rlim_cur = maxfilesperproc;
}
if (limp->rlim_max != alimp->rlim_max &&
limp->rlim_max > (rlim_t)maxfilesperproc)
limp->rlim_max = maxfilesperproc;
}
break;
// *****************************************************************
/* END OF CODE ANALYSIS */
This explains why it’s unattainable to set ‘limitless’ once more, after altering it for another worth.
RLIM_INFINITY is outlined on line 416 of <sys/sources.h>
/*
* Symbolic constants for useful resource limits; since all limits are representable
* as a kind rlim_t, we're permitted to outline RLIM_SAVED_* by way of
* RLIM_INFINITY.
*/
#outline RLIM_INFINITY (((__uint64_t)1 << 63) - 1) /* no restrict */
#outline RLIM_SAVED_MAX RLIM_INFINITY /* Unrepresentable onerous restrict */
#outline RLIM_SAVED_CUR RLIM_INFINITY /* Unrepresentable smooth restrict */
In apply, for the present platform, the limitless INFINITY most worth is restricted to INT_MAX (which is the utmost worth of the Integer Kind)
Contemplating that, it signifies that ‘limitless‘ means INT_MAX, which is the worth 2147483647.
A attainable workaround could also be set the restrict worth of 2147483647:
sudo launchctl restrict maxfiles 2147483647 2147483647
As a result of that is the utmost attainable worth.
Since it is a attainable workaround. I must go deeper into supply to verify if this actually means ‘the identical factor’ as ‘limitless’.
Warning:
PS: Please, do not set it larger than 2147483647, as a result of it’s SIGNED INT, and if you happen to put 2147483648 (discover the quantity eight, I simply add +1 to that most worth), the SIGNED INT will probably be interpreted as damaging, and you’ll immediately virtually crash your macOS, as a result of it won’t be able to open another file descriptor, together with the one you will have to revert this worth again, if making an attempt to regulate it once more by executing launchctl
with totally different parameters.
The one answer will probably be to onerous reset your system if you happen to do this. And it’s possible you’ll unfastened all of your unsaved issues. Attempt it on some MacOS digital machine for testing functions
Supply code References:
<sys/useful resource.h>
/supply/xnu/xnu-4903.221.2/bsd/sys/useful resource.h.auto.html
<dev/unix_startup.c>
/supply/xnu/xnu-4903.221.2/bsd/dev/unix_startup.c.auto.html
<kern/kern_resource.c>
/supply/xnu/xnu-4903.221.2/bsd/kern/kern_resource.c.auto.html
<conf/param.c>
/supply/xnu/xnu-4903.221.2/bsd/conf/param.c.auto.html
<sys/syslimits.h>
/supply/xnu/xnu-4903.221.2/bsd/sys/syslimits.h.auto.html
launchctl.c
/supply/launchd/launchd-442.21/help/launchctl.c.auto.html