Date: Fri, 16 Oct 2020 11:23:30 +0000 (UTC) From: Edward Tomasz Napierala <trasz@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r366756 - head/sys/compat/linux Message-ID: <202010161123.09GBNUhp073737@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: trasz Date: Fri Oct 16 11:23:30 2020 New Revision: 366756 URL: https://svnweb.freebsd.org/changeset/base/366756 Log: Set default stack size for Linux apps to 8MB. This matches Linux' defaults, makes core files smaller, and fixes applications which use pthread_join(3) in a wrong way, namely Steam. This is based on a patch submitted by Jason Yang, which I've reworked to set the limit instead of only changing the value reported (which is enough to fix the bug for Linux pthreads, but could be confusing). PR: 248225 Submitted by: Jason_YH_Yang at wistron.com (earlier version) Analyzed by: Alex S <iwtcex@gmail.com> Reviewed by: emaste MFC after: 2 weeks Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D26778 Modified: head/sys/compat/linux/linux_emul.c head/sys/compat/linux/linux_mib.c head/sys/compat/linux/linux_mib.h Modified: head/sys/compat/linux/linux_emul.c ============================================================================== --- head/sys/compat/linux/linux_emul.c Fri Oct 16 11:22:29 2020 (r366755) +++ head/sys/compat/linux/linux_emul.c Fri Oct 16 11:23:30 2020 (r366756) @@ -115,6 +115,29 @@ linux_set_default_openfiles(struct thread *td, struct KASSERT(error == 0, ("kern_proc_setrlimit failed")); } +/* + * The default stack size limit in Linux is 8MB. + */ +static void +linux_set_default_stacksize(struct thread *td, struct proc *p) +{ + struct rlimit rlim; + int error; + + if (linux_default_stacksize < 0) + return; + + PROC_LOCK(p); + lim_rlimit_proc(p, RLIMIT_STACK, &rlim); + PROC_UNLOCK(p); + if (rlim.rlim_cur != rlim.rlim_max || + rlim.rlim_cur <= linux_default_stacksize) + return; + rlim.rlim_cur = linux_default_stacksize; + error = kern_proc_setrlimit(td, p, RLIMIT_STACK, &rlim); + KASSERT(error == 0, ("kern_proc_setrlimit failed")); +} + void linux_proc_init(struct thread *td, struct thread *newtd, int flags) { @@ -145,6 +168,7 @@ linux_proc_init(struct thread *td, struct thread *newt newtd->td_emuldata = em; linux_set_default_openfiles(td, p); + linux_set_default_stacksize(td, p); } else { p = td->td_proc; Modified: head/sys/compat/linux/linux_mib.c ============================================================================== --- head/sys/compat/linux/linux_mib.c Fri Oct 16 11:22:29 2020 (r366755) +++ head/sys/compat/linux/linux_mib.c Fri Oct 16 11:23:30 2020 (r366756) @@ -72,6 +72,11 @@ SYSCTL_INT(_compat_linux, OID_AUTO, default_openfiles, &linux_default_openfiles, 0, "Default soft openfiles resource limit, or -1 for unlimited"); +int linux_default_stacksize = 8 * 1024 * 1024; +SYSCTL_INT(_compat_linux, OID_AUTO, default_stacksize, CTLFLAG_RWTUN, + &linux_default_stacksize, 0, + "Default soft stack size resource limit, or -1 for unlimited"); + int linux_ignore_ip_recverr = 1; SYSCTL_INT(_compat_linux, OID_AUTO, ignore_ip_recverr, CTLFLAG_RWTUN, &linux_ignore_ip_recverr, 0, "Ignore enabling IP_RECVERR"); Modified: head/sys/compat/linux/linux_mib.h ============================================================================== --- head/sys/compat/linux/linux_mib.h Fri Oct 16 11:22:29 2020 (r366755) +++ head/sys/compat/linux/linux_mib.h Fri Oct 16 11:23:30 2020 (r366756) @@ -64,6 +64,7 @@ int linux_kernver(struct thread *td); extern int linux_debug; extern int linux_default_openfiles; +extern int linux_default_stacksize; extern int linux_ignore_ip_recverr; extern int linux_preserve_vstatus; extern bool linux_map_sched_prio;
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202010161123.09GBNUhp073737>