On 8/24/20 12:35 AM, Waldek Hebisch wrote: > On Sun, Aug 23, 2020 at 10:04:29PM +0800, oldk1331 wrote: >> Actually we can stick to hexadecimal for pid >> less than 1 million as well. >> >> Current possible max pid is defined by PID_MAX_LIMIT in kernel, >> which is 2^22, around 4 million. > > I would not count too much on this limit. I have heard that > currently 32GB modules are resonably priced. With such > modules cheap 128 GB home machine is possible. With > multiprocessor (server) board 512GB should be easily > available. Such machines may support several million > processes. While demand for large number of true > processes is probably low, IIUC Linux allocated thread > identifiers from the same pool. At least some folks > tried to run with really large number of threads. So > I would expect that some people will increase the limit... >
With 512G memory and 4 million processes, so each process can get 128K memory? Besides, process creation is expensive, it's never a good idea in practice to have so many process. The linux kernel seems to indicate that each core can support 1k processes, so 4M limit seems pretty reasonable in a few decades. Thread identifiers is different, see comment below. So I believe my following patch is relatively simple to address the original bug, and it is future-proof for at least 20 years, and it's easily extendable beyond that. - Qian diff --git a/src/lib/sockio-c.c b/src/lib/sockio-c.c index 30e0eba5..e9d8a02e 100644 --- a/src/lib/sockio-c.c +++ b/src/lib/sockio-c.c @@ -857,9 +857,17 @@ int make_server_name(char *name,char * base) { + /* Try to fit the contents of 'name' into char[14], + which is Sock::addr::u_addr::sa_data. + Normally 'base' is "/tmp/.x", so that leaves room + for 6 chars to put 'spad_server_number'/'SPADNUM', + which is the PID of sman. So use hexadecimal to + represent PID. + */ char *num; + int pid; if (spad_server_number != -1) { - sprintf(name, "%s%d", base, spad_server_number); + sprintf(name, "%s%x", base, spad_server_number); return 0; } num = getenv("SPADNUM"); @@ -869,7 +877,8 @@ */ return -1; } - sprintf(name, "%s%s", base, num); + pid = atoi(num); + sprintf(name, "%s%x", base, pid); return 0; } =====include/linux/threads.h======== /* * A maximum of 4 million PIDs should be enough for a while. * [NOTE: PID/TIDs are limited to 2^30 ~= 1 billion, see FUTEX_TID_MASK.] */ #define PID_MAX_LIMIT (CONFIG_BASE_SMALL ? PAGE_SIZE * 8 : \ (sizeof(long) > 4 ? 4 * 1024 * 1024 : PID_MAX_DEFAULT)) /* * Define a minimum number of pids per cpu. Heuristically based * on original pid max of 32k for 32 cpus. Also, increase the * minimum settable value for pid_max on the running system based * on similar defaults. See kernel/pid.c:pidmap_init() for details. */ -- You received this message because you are subscribed to the Google Groups "FriCAS - computer algebra system" group. To unsubscribe from this group and stop receiving emails from it, send an email to fricas-devel+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/fricas-devel/15f1512c-9094-9272-0eee-ac7f92416f50%40gmail.com.