Re: Multi pthreaded RT application - mlock doubt

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, May 25, 2021, Dipen Patel wrote:
...
> Original example shown in above link uses the
> prove_thread_stack_use_is_safe same way. I just extended it to call it
> locally and calculate it locally because of the mutli thread.

As I said, the example is wrong, and it is not authoritative. It is just
an old obsolete wiki that no one maintains anymore.

The same problem exists in the program you posted:

> static void prove_thread_stack_use_is_safe(int stacksize)
> {
>  	volatile char buffer[stacksize];
>  	int i;
>
>    	for (i = 0; i < stacksize; i += sysconf(_SC_PAGESIZE))
>    		buffer[i] = i;
> }
...
> static void *my_rt_thread(void *args)
> {
...
> 	int last_majflt = 0, last_minflt = 0;
...
>
>    	getrusage(RUSAGE_SELF, &usage);
>
>    	printf("[%d]Pagefaults, Major:%ld, Minor:%ld \n",pthread_self(),
>    	       usage.ru_majflt - last_majflt,
>    	       usage.ru_minflt - last_minflt);
>
> 	last_majflt = usage.ru_majflt;
>    	last_minflt = usage.ru_minflt;
>
>    	prove_thread_stack_use_is_safe(MY_STACK_SIZE);
>
> 	getrusage(RUSAGE_SELF, &usage);
>
>    	printf("[%d]After stack usage:Pagefaults, Major:%ld, Minor:%ld \n",pthread_self(),
>    	       usage.ru_majflt - last_majflt,
>    	       usage.ru_minflt - last_minflt);
>

You're just measuring the effect of stack prefaulting, which will
obviously generate page faults (as expected).

Given your original email in this thread, it seems you're conflicting
mlockall() with page faults.

mlockall() just forces physical memory pages ** already mapped through
the process address space ** to be memory-resident; i.e., not getting
swapped.  Even with MCL_CURRENT| MCL_FUTURE, mlockall() does not prevent
"demand paging" page faults: it only says that if your process got
allocated a phsyical memory page, it will not get swapped.

So, technically, the mlockall() effect will start only after
prove_thread_stack_use_is_safe() gets allocated real/physical memory
pages by its code which prefauls the stack.

The source of confusion, I guess, is that
prove_thread_stack_use_is_safe() is horribly named. In its first
invocation, it does not "prove" anything, it is actually the entity
prefaulting the thread stack.

Hope this helps,

--
Ahmed S. Darwish
Linutronix GmbH



[Index of Archives]     [RT Stable]     [Kernel Newbies]     [IDE]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux ATA RAID]     [Samba]     [Video 4 Linux]     [Device Mapper]

  Powered by Linux