Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

To the systems programmer, users and applications serve only to provide a test load.


devel / comp.unix.programmer / Re: getrlimit RLMIT_NPROC

SubjectAuthor
* getrlimit RLMIT_NPROCKenny McCormack
+* getrlimit RLMIT_NPROCKalevi Kolttonen
|+* getrlimit RLMIT_NPROCKalevi Kolttonen
||+- getrlimit RLMIT_NPROCKalevi Kolttonen
||`* getrlimit RLMIT_NPROCKaz Kylheku
|| `- getrlimit RLMIT_NPROCKalevi Kolttonen
|`* getrlimit RLMIT_NPROCScott Lurndal
| `* getrlimit RLMIT_NPROCKalevi Kolttonen
|  +- getrlimit RLMIT_NPROCKalevi Kolttonen
|  `* getrlimit RLMIT_NPROCLew Pitcher
|   `- getrlimit RLMIT_NPROCKalevi Kolttonen
`* getrlimit RLMIT_NPROCKaz Kylheku
 `- getrlimit RLMIT_NPROCKenny McCormack

1
getrlimit RLMIT_NPROC

<uckueh$69ja$1@news.xmission.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=9970&group=comp.unix.programmer#9970

  copy link   Newsgroups: comp.unix.programmer
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!xmission!nnrp.xmission!.POSTED.shell.xmission.com!not-for-mail
From: gaze...@shell.xmission.com (Kenny McCormack)
Newsgroups: comp.unix.programmer
Subject: getrlimit RLMIT_NPROC
Date: Tue, 29 Aug 2023 14:13:37 -0000 (UTC)
Organization: The official candy of the new Millennium
Message-ID: <uckueh$69ja$1@news.xmission.com>
Injection-Date: Tue, 29 Aug 2023 14:13:37 -0000 (UTC)
Injection-Info: news.xmission.com; posting-host="shell.xmission.com:166.70.8.4";
logging-data="206442"; mail-complaints-to="abuse@xmission.com"
X-Newsreader: trn 4.0-test77 (Sep 1, 2010)
Originator: gazelle@shell.xmission.com (Kenny McCormack)
 by: Kenny McCormack - Tue, 29 Aug 2023 14:13 UTC

I have the following C program:

--- Cut Here ---
#include <stdio.h>
#include <sys/time.h>
#include <sys/resource.h>

int main(void)
{ struct rlimit rlim;
printf("Result: %d\n",getrlimit(RLIMIT_NPROC, &rlim));
printf("cur = %lu, max = %lu\n",rlim.rlim_cur,rlim.rlim_max);
printf("RLIM_INFINITY = %ld\n",RLIM_INFINITY);
return 0;
} --- Cut Here ---

When run on system A (Ubuntu - x64), the output is:

Result: 0
cur = 31411, max = 31411
RLIM_INFINITY = -1

What the heck is 31411???

When run on system B (Raspberry PiOS - ARM32), the output is:

Result: 0
cur = 6807, max = 6807
RLIM_INFINITY = -1

What the heck is 6807???

Neither of these results seem reasonable or tied to anything.

What is going on?

--
Kenny, I'll ask you to stop using quotes of mine as taglines.

- Rick C Hodgin -

Re: getrlimit RLMIT_NPROC

<ucl2io$2ads5$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=9971&group=comp.unix.programmer#9971

  copy link   Newsgroups: comp.unix.programmer
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: kal...@kolttonen.fi (Kalevi Kolttonen)
Newsgroups: comp.unix.programmer
Subject: Re: getrlimit RLMIT_NPROC
Date: Tue, 29 Aug 2023 15:24:08 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 40
Sender: <untosten@0.0.0.0>
Message-ID: <ucl2io$2ads5$1@dont-email.me>
References: <uckueh$69ja$1@news.xmission.com>
Injection-Date: Tue, 29 Aug 2023 15:24:08 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="ed7a5a5ed270f53efcfb6b57a41a577d";
logging-data="2439045"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/42u+5sCpZ33hffUY0yIE0fcyxuLssaw0="
User-Agent: tin/2.6.2-20221225 ("Pittyvaich") (Linux/6.4.12-200.fc38.x86_64 (x86_64))
Cancel-Lock: sha1:u/ldqnJH2AbtLveOT8H6speeq+c=
 by: Kalevi Kolttonen - Tue, 29 Aug 2023 15:24 UTC

Kenny McCormack <gazelle@shell.xmission.com> wrote:
> Neither of these results seem reasonable or tied to anything.

On my Fedora 38 amd64 "uname -a" shows e.g.

6.4.12-200.fc38.x86_64 #1 SMP PREEMPT_DYNAMIC Wed Aug 23 17:46:49 UTC 2023 x86_64 GNU/Linux

and the result of running your program is:

Result: 0
cur = 60988, max = 60988
RLIM_INFINITY = -1

> What is going on?

You used "%lu" and that is correct based on the Linux
headers. On my Fedora 38 we have these:

struct rlimit {
__kernel_ulong_t rlim_cur;
__kernel_ulong_t rlim_max;
};

#define RLIM64_INFINITY (~0ULL)

struct rlimit64 {
__u64 rlim_cur;
__u64 rlim_max;
};

Using grep, I was unable to find where 60988 is set
on my Fedora 38. So my best guess is that this value
has been set when compiling the kernel.

Have you tried using a recursive grep invocation
to find the values you mentioned?

br,
KK

Re: getrlimit RLMIT_NPROC

<ucl3q2$2ailn$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=9972&group=comp.unix.programmer#9972

  copy link   Newsgroups: comp.unix.programmer
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: kal...@kolttonen.fi (Kalevi Kolttonen)
Newsgroups: comp.unix.programmer
Subject: Re: getrlimit RLMIT_NPROC
Date: Tue, 29 Aug 2023 15:45:06 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 18
Sender: <untosten@0.0.0.0>
Message-ID: <ucl3q2$2ailn$1@dont-email.me>
References: <uckueh$69ja$1@news.xmission.com> <ucl2io$2ads5$1@dont-email.me>
Injection-Date: Tue, 29 Aug 2023 15:45:06 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="ed7a5a5ed270f53efcfb6b57a41a577d";
logging-data="2443959"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/023/obS+Wa/9xm//B3OQrTntyqdZihCk="
User-Agent: tin/2.6.2-20221225 ("Pittyvaich") (Linux/6.4.12-200.fc38.x86_64 (x86_64))
Cancel-Lock: sha1:zAZ6d9iwNfgVlI0omead9SPgMrY=
 by: Kalevi Kolttonen - Tue, 29 Aug 2023 15:45 UTC

Kalevi Kolttonen <kalevi@kolttonen.fi> wrote:
> Using grep, I was unable to find where 60988 is set
> on my Fedora 38. So my best guess is that this value
> has been set when compiling the kernel.

I downloaded the current Fedora 38 kernel sources. The
value 60988 is nowhere to be found. Some possible reasons:

1) Maybe 60988 value was given as a command line parameter
when running "make". I suppose this is quite unlikely and
I did not investigate the Makefiles to see whether that
is even supported.

2) Maybe the Linux kernel sets the default value based
on how much RAM is available.

br,
KK

Re: getrlimit RLMIT_NPROC

<ucl4p2$2amp0$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=9973&group=comp.unix.programmer#9973

  copy link   Newsgroups: comp.unix.programmer
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: kal...@kolttonen.fi (Kalevi Kolttonen)
Newsgroups: comp.unix.programmer
Subject: Re: getrlimit RLMIT_NPROC
Date: Tue, 29 Aug 2023 16:01:38 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 43
Sender: <untosten@0.0.0.0>
Message-ID: <ucl4p2$2amp0$1@dont-email.me>
References: <uckueh$69ja$1@news.xmission.com> <ucl2io$2ads5$1@dont-email.me> <ucl3q2$2ailn$1@dont-email.me>
Injection-Date: Tue, 29 Aug 2023 16:01:38 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="ed7a5a5ed270f53efcfb6b57a41a577d";
logging-data="2448160"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19/Sd6vNb/tiN4qc6G4/JIlp3rHKtUcp1A="
User-Agent: tin/2.6.2-20221225 ("Pittyvaich") (Linux/6.4.12-200.fc38.x86_64 (x86_64))
Cancel-Lock: sha1:Cc33kO9XS39rX5i9sPC+B8ShNws=
 by: Kalevi Kolttonen - Tue, 29 Aug 2023 16:01 UTC

Kalevi Kolttonen <kalevi@kolttonen.fi> wrote:
> 2) Maybe the Linux kernel sets the default value based
> on how much RAM is available.

Inspecting kernel/fork.c, we see:

static void set_max_threads(unsigned int max_threads_suggested)
{ u64 threads;
unsigned long nr_pages = totalram_pages();

/*
* The number of threads shall be limited such that the thread
* structures may only consume a small part of the available memory.
*/
if (fls64(nr_pages) + fls64(PAGE_SIZE) > 64)
threads = MAX_THREADS;
else
threads = div64_u64((u64) nr_pages * (u64) PAGE_SIZE,
(u64) THREAD_SIZE * 8UL);

if (threads > max_threads_suggested)
threads = max_threads_suggested;

max_threads = clamp_t(u64, threads, MIN_THREADS, MAX_THREADS);
}

It seems to me that that eventually sets "max_threads" based on
available RAM, with the limitation that "max_threads_suggested"
must not be exceeded.

Further, fork_init() we have:

init_task.signal->rlim[RLIMIT_NPROC].rlim_cur = max_threads/2;
init_task.signal->rlim[RLIMIT_NPROC].rlim_max = max_threads/2;

It looks like RLIMIT_NRPOC limits are based on the value of max_threads/2.

In conclusion, I believe the values you and I saw are based on how much
RAM our Linux systems have.

br,
KK

Re: getrlimit RLMIT_NPROC

<RBpHM.724633$mPI2.444965@fx15.iad>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=9975&group=comp.unix.programmer#9975

  copy link   Newsgroups: comp.unix.programmer
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer03.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx15.iad.POSTED!not-for-mail
X-newsreader: xrn 9.03-beta-14-64bit
Sender: scott@dragon.sl.home (Scott Lurndal)
From: sco...@slp53.sl.home (Scott Lurndal)
Reply-To: slp53@pacbell.net
Subject: Re: getrlimit RLMIT_NPROC
Newsgroups: comp.unix.programmer
References: <uckueh$69ja$1@news.xmission.com> <ucl2io$2ads5$1@dont-email.me>
Lines: 44
Message-ID: <RBpHM.724633$mPI2.444965@fx15.iad>
X-Complaints-To: abuse@usenetserver.com
NNTP-Posting-Date: Tue, 29 Aug 2023 17:08:01 UTC
Organization: UsenetServer - www.usenetserver.com
Date: Tue, 29 Aug 2023 17:08:01 GMT
X-Received-Bytes: 1820
 by: Scott Lurndal - Tue, 29 Aug 2023 17:08 UTC

kalevi@kolttonen.fi (Kalevi Kolttonen) writes:
>Kenny McCormack <gazelle@shell.xmission.com> wrote:
>> Neither of these results seem reasonable or tied to anything.
>
>On my Fedora 38 amd64 "uname -a" shows e.g.
>
>6.4.12-200.fc38.x86_64 #1 SMP PREEMPT_DYNAMIC Wed Aug 23 17:46:49 UTC 2023 x86_64 GNU/Linux
>
>and the result of running your program is:
>
>Result: 0
>cur = 60988, max = 60988
>RLIM_INFINITY = -1
>
>> What is going on?
>
>You used "%lu" and that is correct based on the Linux
>headers. On my Fedora 38 we have these:
>
>struct rlimit {
> __kernel_ulong_t rlim_cur;
> __kernel_ulong_t rlim_max;
>};
>
>#define RLIM64_INFINITY (~0ULL)
>
>struct rlimit64 {
> __u64 rlim_cur;
> __u64 rlim_max;
>};
>
>
>Using grep, I was unable to find where 60988 is set
>on my Fedora 38. So my best guess is that this value
>has been set when compiling the kernel.
>
>Have you tried using a recursive grep invocation
>to find the values you mentioned?

While the defaults are compiled into the kernel, the
login values are generally specified in
/etc/security/limits.conf on systems that use PAM authentication.

$ man pam_limits

Re: getrlimit RLMIT_NPROC

<ucl9hc$2bh2k$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=9976&group=comp.unix.programmer#9976

  copy link   Newsgroups: comp.unix.programmer
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: kal...@kolttonen.fi (Kalevi Kolttonen)
Newsgroups: comp.unix.programmer
Subject: Re: getrlimit RLMIT_NPROC
Date: Tue, 29 Aug 2023 17:22:52 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 16
Sender: <untosten@0.0.0.0>
Message-ID: <ucl9hc$2bh2k$1@dont-email.me>
References: <uckueh$69ja$1@news.xmission.com> <ucl2io$2ads5$1@dont-email.me> <RBpHM.724633$mPI2.444965@fx15.iad>
Injection-Date: Tue, 29 Aug 2023 17:22:52 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="ed7a5a5ed270f53efcfb6b57a41a577d";
logging-data="2475092"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18VgrAgSBEs1P7wQgi+CJH5xTqgajx5ugM="
User-Agent: tin/2.6.2-20221225 ("Pittyvaich") (Linux/6.4.12-200.fc38.x86_64 (x86_64))
Cancel-Lock: sha1:ZHFRWJIUDp14XNTOQvUvEts/yGs=
 by: Kalevi Kolttonen - Tue, 29 Aug 2023 17:22 UTC

Scott Lurndal <scott@slp53.sl.home> wrote:
> While the defaults are compiled into the kernel,

I just checked out some of the Linux kernel
sources and I am pretty convinced that the
RLIMIT_PROC defaults are actually dynamically
calculated based on available RAM.

> the login values are generally specified in
> /etc/security/limits.conf on systems that use PAM authentication.

Yes, I know that very well. But in this case they
are irrelevant to the problem discussed.

br,
KK

Re: getrlimit RLMIT_NPROC

<ucla0f$2bjha$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=9977&group=comp.unix.programmer#9977

  copy link   Newsgroups: comp.unix.programmer
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: kal...@kolttonen.fi (Kalevi Kolttonen)
Newsgroups: comp.unix.programmer
Subject: Re: getrlimit RLMIT_NPROC
Date: Tue, 29 Aug 2023 17:30:55 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 19
Sender: <untosten@0.0.0.0>
Message-ID: <ucla0f$2bjha$1@dont-email.me>
References: <uckueh$69ja$1@news.xmission.com> <ucl2io$2ads5$1@dont-email.me> <RBpHM.724633$mPI2.444965@fx15.iad> <ucl9hc$2bh2k$1@dont-email.me>
Injection-Date: Tue, 29 Aug 2023 17:30:55 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="ed7a5a5ed270f53efcfb6b57a41a577d";
logging-data="2477610"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19Q3fcahzGHMVzueNL2njNq/clMJohQwdw="
User-Agent: tin/2.6.2-20221225 ("Pittyvaich") (Linux/6.4.12-200.fc38.x86_64 (x86_64))
Cancel-Lock: sha1:egcInv34Z1qOOVQPDkyU2IU/FV0=
 by: Kalevi Kolttonen - Tue, 29 Aug 2023 17:30 UTC

Kalevi Kolttonen <kalevi@kolttonen.fi> wrote:
> Scott Lurndal <scott@slp53.sl.home> wrote:
>
>> the login values are generally specified in
>> /etc/security/limits.conf on systems that use PAM authentication.
>
> Yes, I know that very well. But in this case they
> are irrelevant to the problem discussed.

That was perhaps too strong a statement, because
I have no access to Kenny's system, so I cannot
be 100% sure whether they are specified there.

But certainly my Fedora 38 gets the values from
the Linux kernel and not from the PAM configuration
files.

br,
KK

Re: getrlimit RLMIT_NPROC

<uclag5$2b3ua$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=9978&group=comp.unix.programmer#9978

  copy link   Newsgroups: comp.unix.programmer
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: lew.pitc...@digitalfreehold.ca (Lew Pitcher)
Newsgroups: comp.unix.programmer
Subject: Re: getrlimit RLMIT_NPROC
Date: Tue, 29 Aug 2023 17:39:17 -0000 (UTC)
Organization: The Pitcher Digital Freehold
Lines: 40
Message-ID: <uclag5$2b3ua$1@dont-email.me>
References: <uckueh$69ja$1@news.xmission.com>
<ucl2io$2ads5$1@dont-email.me> <RBpHM.724633$mPI2.444965@fx15.iad>
<ucl9hc$2bh2k$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Tue, 29 Aug 2023 17:39:17 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="473d95e3e52fc1bf15ba2d1c4dc2be33";
logging-data="2461642"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18p3Od9F39XUBM1vuCQ4t2kMohQO2tLBlg="
User-Agent: Pan/0.139 (Sexual Chocolate; GIT bf56508
git://git.gnome.org/pan2)
Cancel-Lock: sha1:r0B7GOYPc9y4KWlj2SXUYPtFCic=
 by: Lew Pitcher - Tue, 29 Aug 2023 17:39 UTC

On Tue, 29 Aug 2023 17:22:52 +0000, Kalevi Kolttonen wrote:

> Scott Lurndal <scott@slp53.sl.home> wrote:
>> While the defaults are compiled into the kernel,
>
> I just checked out some of the Linux kernel
> sources and I am pretty convinced that the
> RLIMIT_PROC defaults are actually dynamically
> calculated based on available RAM.
>
>> the login values are generally specified in
>> /etc/security/limits.conf on systems that use PAM authentication.
>
> Yes, I know that very well. But in this case they
> are irrelevant to the problem discussed.

I would disagree; Scott's point is quite relevant to Kenny's
(very information free) quesion.

More specifically, Kenny only mentioned the values obtained
(31411 and 6807), and asked "What is going on?" Each of those
two values occur in two places: the "curr" limit and the "max"
limit. While others have discussed how the "max" limit is
derived, no one (other than Scott) has mentioned how the "curr"
limit may (or may not) have been set.

AFAICT, Kenny's question was open-ended enough that Scott's
answer is as on-topic as the rest of the discussion.

FWIW, as Kenny asked "What the heck is 31411???" and
"What the heck is 6807???", /I/ was tempted to answer literally,
and tell him that those values are the current (soft-limit) maximum,
and hard maximum of the number of processes/threads a single UID
can launch. But, then again, if Kenny has already coded the
getrlimit() call for RLIMIT_NPROC, he probably already knows this.

--
Lew Pitcher
"In Skills We Trust"

Re: getrlimit RLMIT_NPROC

<uclana$2bmpe$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=9979&group=comp.unix.programmer#9979

  copy link   Newsgroups: comp.unix.programmer
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: kal...@kolttonen.fi (Kalevi Kolttonen)
Newsgroups: comp.unix.programmer
Subject: Re: getrlimit RLMIT_NPROC
Date: Tue, 29 Aug 2023 17:43:06 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 24
Sender: <untosten@0.0.0.0>
Message-ID: <uclana$2bmpe$1@dont-email.me>
References: <uckueh$69ja$1@news.xmission.com> <ucl2io$2ads5$1@dont-email.me> <RBpHM.724633$mPI2.444965@fx15.iad> <ucl9hc$2bh2k$1@dont-email.me> <uclag5$2b3ua$1@dont-email.me>
Injection-Date: Tue, 29 Aug 2023 17:43:06 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="ed7a5a5ed270f53efcfb6b57a41a577d";
logging-data="2480942"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/wW7sOkFK+Hr+fzhpcI9nyeDPDi02u1vU="
User-Agent: tin/2.6.2-20221225 ("Pittyvaich") (Linux/6.4.12-200.fc38.x86_64 (x86_64))
Cancel-Lock: sha1:d446rO6NBk4Zswfj1aWVGZOmT2s=
 by: Kalevi Kolttonen - Tue, 29 Aug 2023 17:43 UTC

Lew Pitcher <lew.pitcher@digitalfreehold.ca> wrote:
> I would disagree; Scott's point is quite relevant to Kenny's
> (very information free) quesion.
>
> More specifically, Kenny only mentioned the values obtained
> (31411 and 6807), and asked "What is going on?" Each of those
> two values occur in two places: the "curr" limit and the "max"
> limit. While others have discussed how the "max" limit is
> derived, no one (other than Scott) has mentioned how the "curr"
> limit may (or may not) have been set.

Yes, I already posted a new message telling that this
information *could* indeed be relevant in Kenny's case.

But it was not really relevant to my Fedora 38. The values
were not set there, but came from the Linux kernel based
on the amount of available RAM.

So I cannot know for the certain whether Kenny's values
came from the PAM configuration files or from the Linux
kernel, but I suspect the latter.

br,
KK

Re: getrlimit RLMIT_NPROC

<20230829113025.50@kylheku.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=9981&group=comp.unix.programmer#9981

  copy link   Newsgroups: comp.unix.programmer
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: 864-117-...@kylheku.com (Kaz Kylheku)
Newsgroups: comp.unix.programmer
Subject: Re: getrlimit RLMIT_NPROC
Date: Tue, 29 Aug 2023 18:39:29 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 47
Message-ID: <20230829113025.50@kylheku.com>
References: <uckueh$69ja$1@news.xmission.com>
Injection-Date: Tue, 29 Aug 2023 18:39:29 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="3c0f43010e46fd6ed1f1ed87a863f28a";
logging-data="2496045"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+9oZ4weblXEC4okvgwwEVBOVW803Go8/Y="
User-Agent: slrn/pre1.0.4-9 (Linux)
Cancel-Lock: sha1:RgoZLV7CbmRS/nj0GWEd9G99a0g=
 by: Kaz Kylheku - Tue, 29 Aug 2023 18:39 UTC

On 2023-08-29, Kenny McCormack <gazelle@shell.xmission.com> wrote:
> I have the following C program:
>
> --- Cut Here ---
> #include <stdio.h>
> #include <sys/time.h>
> #include <sys/resource.h>
>
> int main(void)
> {
> struct rlimit rlim;
> printf("Result: %d\n",getrlimit(RLIMIT_NPROC, &rlim));
> printf("cur = %lu, max = %lu\n",rlim.rlim_cur,rlim.rlim_max);
> printf("RLIM_INFINITY = %ld\n",RLIM_INFINITY);
> return 0;
> }

That's a waste of time; the existing "ulimit" tool reads these
limits. "ulimit -a" gives you all of them; "ulimit -u" gives
us that one ([u]ser processes).

> What the heck is 31411???
>
> What the heck is 6807???

Pre-release version of Motrola 6809? ;)

Good question; do these valuas come from some boot scripts on that
system, or are they in the kernel?

Ubuntu 18, 32 bit:

$ ulimit -u
15791

Indeed, weird numbers; it's as if they are concocted by some formula
applied to various other system parameters.

I think you have to hunt down the kernel code where the initial/default
values are prepared.

It could be the work of a boot script, or ... dare I utter it ... systemd.

--
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
Mastodon: @Kazinator@mstdn.ca

Re: getrlimit RLMIT_NPROC

<20230829113945.477@kylheku.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=9982&group=comp.unix.programmer#9982

  copy link   Newsgroups: comp.unix.programmer
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: 864-117-...@kylheku.com (Kaz Kylheku)
Newsgroups: comp.unix.programmer
Subject: Re: getrlimit RLMIT_NPROC
Date: Tue, 29 Aug 2023 19:01:25 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 65
Message-ID: <20230829113945.477@kylheku.com>
References: <uckueh$69ja$1@news.xmission.com> <ucl2io$2ads5$1@dont-email.me>
<ucl3q2$2ailn$1@dont-email.me>
Injection-Date: Tue, 29 Aug 2023 19:01:25 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="3c0f43010e46fd6ed1f1ed87a863f28a";
logging-data="2505246"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19kWM1p6l4h8c7V8FydftcdNXXgzdFH93k="
User-Agent: slrn/pre1.0.4-9 (Linux)
Cancel-Lock: sha1:RKmcqKRHvPKFlzWGyv/ZssDvndM=
 by: Kaz Kylheku - Tue, 29 Aug 2023 19:01 UTC

On 2023-08-29, Kalevi Kolttonen <kalevi@kolttonen.fi> wrote:
> Kalevi Kolttonen <kalevi@kolttonen.fi> wrote:
>> Using grep, I was unable to find where 60988 is set
>> on my Fedora 38. So my best guess is that this value
>> has been set when compiling the kernel.
>
> I downloaded the current Fedora 38 kernel sources. The
> value 60988 is nowhere to be found. Some possible reasons:
>
> 1) Maybe 60988 value was given as a command line parameter
> when running "make". I suppose this is quite unlikely and
> I did not investigate the Makefiles to see whether that
> is even supported.

Pretty much nobody is going to do

#define DEFAULT_THING 60988 // or other weird number.

Plus, we are seeing different numbers on different systems

> 2) Maybe the Linux kernel sets the default value based
> on how much RAM is available.

Precisely. It looks calculated. You have to find the area of the kernel
where the rlimit sysdcalls are implemented. Find out which fields in the
task struct they are coming from, then search where those are set up.

I'm looking at 4.9.211 (a kernel I work with in in my embedded work).

In kernel/fork.c, there is a fork_init() function with these lines:

init_task.signal->rlim[RLIMIT_NPROC].rlim_cur = max_threads/2;
init_task.signal->rlim[RLIMIT_NPROC].rlim_max = max_threads/2;

max_threads is a tunable global variable initialized earlier
in that same function by call to set_max_threads(MAX_THREADS).
That function only uses the parameter as an upper bound clamp.

It perpetrates a complex calculation from totalram_pages and
thread context size:

static void set_max_threads(unsigned int max_threads_suggested)
{
u64 threads;

/*
* The number of threads shall be limited such that the thread
* structures may only consume a small part of the available memory.
*/
if (fls64(totalram_pages) + fls64(PAGE_SIZE) > 64)
threads = MAX_THREADS;
else
threads = div64_u64((u64) totalram_pages * (u64) PAGE_SIZE,
(u64) THREAD_SIZE * 8UL);

if (threads > max_threads_suggested)
threads = max_threads_suggested;

max_threads = clamp_t(u64, threads, MIN_THREADS, MAX_THREADS);
}

--
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
Mastodon: @Kazinator@mstdn.ca

Re: getrlimit RLMIT_NPROC

<uclgn1$2cimi$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=9983&group=comp.unix.programmer#9983

  copy link   Newsgroups: comp.unix.programmer
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: kal...@kolttonen.fi (Kalevi Kolttonen)
Newsgroups: comp.unix.programmer
Subject: Re: getrlimit RLMIT_NPROC
Date: Tue, 29 Aug 2023 19:25:21 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 53
Sender: <untosten@0.0.0.0>
Message-ID: <uclgn1$2cimi$1@dont-email.me>
References: <uckueh$69ja$1@news.xmission.com> <ucl2io$2ads5$1@dont-email.me> <ucl3q2$2ailn$1@dont-email.me> <20230829113945.477@kylheku.com>
Injection-Date: Tue, 29 Aug 2023 19:25:21 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="ed7a5a5ed270f53efcfb6b57a41a577d";
logging-data="2509522"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19Mz03F5s6Gw7uXG9L1l6JaOCiW1Vy8/pM="
User-Agent: tin/2.6.2-20221225 ("Pittyvaich") (Linux/6.4.12-200.fc38.x86_64 (x86_64))
Cancel-Lock: sha1:s+v7O6rtFnJSKQ9/GI//QOoxxRs=
 by: Kalevi Kolttonen - Tue, 29 Aug 2023 19:25 UTC

Kaz Kylheku <864-117-4973@kylheku.com> wrote:
> On 2023-08-29, Kalevi Kolttonen <kalevi@kolttonen.fi> wrote:
>> Kalevi Kolttonen <kalevi@kolttonen.fi> wrote:
>>> Using grep, I was unable to find where 60988 is set
>>> on my Fedora 38. So my best guess is that this value
>>> has been set when compiling the kernel.
>>
>> I downloaded the current Fedora 38 kernel sources. The
>> value 60988 is nowhere to be found. Some possible reasons:
>>
>> 1) Maybe 60988 value was given as a command line parameter
>> when running "make". I suppose this is quite unlikely and
>> I did not investigate the Makefiles to see whether that
>> is even supported.
>
> Pretty much nobody is going to do
>
> #define DEFAULT_THING 60988 // or other weird number.

If you read closely, that is not what I suggested. I only
suggested that the weird value 60988 was maybe specified
for "make" using command-line. So the #define:d value in the
source tree could have been something saner.

In any case, I pretty much rejected the idea anyway. It
is not likely that Red Hat/Fedora maintainers would
specify anything using "make" command-lines.

> Plus, we are seeing different numbers on different systems

Yes, but that does not disprove my theory above. Different
numbers could easily be explained by different distros
having different maintainers. They could have set different
default values. But again, I did not take that case
very seriously.

>> 2) Maybe the Linux kernel sets the default value based
>> on how much RAM is available.
>
> Precisely. It looks calculated. You have to find the area
> of the kernel where [...]

I already did and posted the results, but Usenet being
the way it is, my article has not reached you yet.

Your findings seem pretty much identical to mine.

The only question that remains is whether Kenny's
/etc/security/limits.conf has any active settings,
but somehow I doubt it.

br,
KK

Re: getrlimit RLMIT_NPROC

<uclmnb$6mde$1@news.xmission.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=9985&group=comp.unix.programmer#9985

  copy link   Newsgroups: comp.unix.programmer
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!xmission!nnrp.xmission!.POSTED.shell.xmission.com!not-for-mail
From: gaze...@shell.xmission.com (Kenny McCormack)
Newsgroups: comp.unix.programmer
Subject: Re: getrlimit RLMIT_NPROC
Date: Tue, 29 Aug 2023 21:07:55 -0000 (UTC)
Organization: The official candy of the new Millennium
Message-ID: <uclmnb$6mde$1@news.xmission.com>
References: <uckueh$69ja$1@news.xmission.com> <20230829113025.50@kylheku.com>
Injection-Date: Tue, 29 Aug 2023 21:07:55 -0000 (UTC)
Injection-Info: news.xmission.com; posting-host="shell.xmission.com:166.70.8.4";
logging-data="219566"; mail-complaints-to="abuse@xmission.com"
X-Newsreader: trn 4.0-test77 (Sep 1, 2010)
Originator: gazelle@shell.xmission.com (Kenny McCormack)
 by: Kenny McCormack - Tue, 29 Aug 2023 21:07 UTC

In article <20230829113025.50@kylheku.com>,
Kaz Kylheku <864-117-4973@kylheku.com> wrote:
....
>That's a waste of time; the existing "ulimit" tool reads these
>limits. "ulimit -a" gives you all of them; "ulimit -u" gives
>us that one ([u]ser processes).

I think I wrote the C program (it was quite a while ago) because I had been
investigating the shell "ulimit" command and it seemed to be displaying a
bogus result (31411), which I didn't trust. As most of us now see, these
numbers just don't look "normal" (in the computer-ish sense).

So, I wrote the C program, and got the same (bogus-looking) result as the
shell command.

>> What the heck is 31411???
>>
>> What the heck is 6807???
>
>Pre-release version of Motrola 6809? ;)
>
>Good question; do these valuas come from some boot scripts on that
>system, or are they in the kernel?
>
>Ubuntu 18, 32 bit:
>
>$ ulimit -u
>15791
>
>Indeed, weird numbers; it's as if they are concocted by some formula
>applied to various other system parameters.

Yup.

>I think you have to hunt down the kernel code where the initial/default
>values are prepared.
>
>It could be the work of a boot script, or ... dare I utter it ... systemd.

Heh heh...

--
The randomly chosen signature file that would have appeared here is more than 4
lines long. As such, it violates one or more Usenet RFCs. In order to remain
in compliance with said RFCs, the actual sig can be found at the following URL:
http://user.xmission.com/~gazelle/Sigs/God

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor