From owner-svn-src-head@freebsd.org Tue Dec 11 02:54:38 2018 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id E36CF13147FA; Tue, 11 Dec 2018 02:54:37 +0000 (UTC) (envelope-from kib@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 834FA7E244; Tue, 11 Dec 2018 02:54:37 +0000 (UTC) (envelope-from kib@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4C95A29196; Tue, 11 Dec 2018 02:54:37 +0000 (UTC) (envelope-from kib@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id wBB2sbDZ047793; Tue, 11 Dec 2018 02:54:37 GMT (envelope-from kib@FreeBSD.org) Received: (from kib@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id wBB2sa1P047791; Tue, 11 Dec 2018 02:54:36 GMT (envelope-from kib@FreeBSD.org) Message-Id: <201812110254.wBB2sa1P047791@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: kib set sender to kib@FreeBSD.org using -f From: Konstantin Belousov Date: Tue, 11 Dec 2018 02:54:36 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r341810 - in head/sys: kern x86/x86 X-SVN-Group: head X-SVN-Commit-Author: kib X-SVN-Commit-Paths: in head/sys: kern x86/x86 X-SVN-Commit-Revision: 341810 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: 834FA7E244 X-Spamd-Result: default: False [-2.95 / 15.00]; local_wl_from(0.00)[FreeBSD.org]; NEURAL_HAM_MEDIUM(-1.00)[-0.998,0]; NEURAL_HAM_SHORT(-0.96)[-0.958,0]; NEURAL_HAM_LONG(-1.00)[-0.998,0]; ASN(0.00)[asn:11403, ipnet:2610:1c1:1::/48, country:US] X-Rspamd-Server: mx1.freebsd.org X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 11 Dec 2018 02:54:38 -0000 Author: kib Date: Tue Dec 11 02:54:36 2018 New Revision: 341810 URL: https://svnweb.freebsd.org/changeset/base/341810 Log: Free bootstacks after AP startup. Bootstacks are unused after APs executed sched_throw() in init_secondary_tail() and started executing on proper idle thread stack. Add sysinit that detects that the idle thread for each CPU was scheduled at least once, and free corresponding bootstack. Slight addition of the code (~200 bytes) is compensated by the saving, because even on typical small modern desktop CPU we leak 128K of memory otherwise (4 pages x 8 threads). Reviewed by: jhb MFC after: 1 week Differential revision: https://reviews.freebsd.org/D18486 Modified: head/sys/kern/kern_thread.c head/sys/x86/x86/mp_x86.c Modified: head/sys/kern/kern_thread.c ============================================================================== --- head/sys/kern/kern_thread.c Tue Dec 11 02:48:49 2018 (r341809) +++ head/sys/kern/kern_thread.c Tue Dec 11 02:54:36 2018 (r341810) @@ -197,7 +197,7 @@ thread_ctor(void *mem, int size, void *arg, int flags) td = (struct thread *)mem; td->td_state = TDS_INACTIVE; - td->td_oncpu = NOCPU; + td->td_lastcpu = td->td_oncpu = NOCPU; td->td_tid = tid_alloc(); Modified: head/sys/x86/x86/mp_x86.c ============================================================================== --- head/sys/x86/x86/mp_x86.c Tue Dec 11 02:48:49 2018 (r341809) +++ head/sys/x86/x86/mp_x86.c Tue Dec 11 02:54:36 2018 (r341810) @@ -1071,9 +1071,23 @@ init_secondary_tail(void) /* NOTREACHED */ } -/******************************************************************* - * local functions and data - */ +static void +smp_after_idle_runnable(void *arg __unused) +{ + struct thread *idle_td; + int cpu; + + for (cpu = 1; cpu < mp_ncpus; cpu++) { + idle_td = pcpu_find(cpu)->pc_idlethread; + while (idle_td->td_lastcpu == NOCPU && + idle_td->td_oncpu == NOCPU) + cpu_spinwait(); + kmem_free((vm_offset_t)bootstacks[cpu], kstack_pages * + PAGE_SIZE); + } +} +SYSINIT(smp_after_idle_runnable, SI_SUB_SMP, SI_ORDER_ANY, + smp_after_idle_runnable, NULL); /* * We tell the I/O APIC code about all the CPUs we want to receive