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

[issues] getpid: to cache or not to cache



Dear eglibc developers.

eglibc, like glibc, uses a cache for getpid under Linux.
This is a wonderful optimization to reduce the number of user/kernel
mode switching time.
The result of getpid usually does not change, so a previous value may be
returned instead of issuing a system call for each request.
I am referring to the code in:
/nptl/sysdeps/unix/sysv/linux/getpid.c

Unfortunately in some cases this is not true. Sometimes people want to
block (freeze) processes, save their memory state and restart them
later. In this way new pids get assigned (cached getpid values became 
inconsistent).

I propose to add an externally visible function like the following one:

void
getpid_cache_clear (void)
{
#ifndef NOT_IN_libc
	THREAD_SETMEM (THREAD_SELF, tid, 0);
	THREAD_SETMEM (THREAD_SELF, pid, 0);
#endif
}

This is the clean way to force eglibc to reload the value of tid and pid
at the next getpid call.

thank you
		renzo

leader of the virtualsquare.org lab.