From owner-svn-src-all@freebsd.org Wed Sep 19 16:13:53 2018 Return-Path: Delivered-To: svn-src-all@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 B454610A0660 for ; Wed, 19 Sep 2018 16:13:53 +0000 (UTC) (envelope-from shawn.webb@hardenedbsd.org) Received: from mail-wm1-x341.google.com (mail-wm1-x341.google.com [IPv6:2a00:1450:4864:20::341]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 256B5883E1 for ; Wed, 19 Sep 2018 16:13:53 +0000 (UTC) (envelope-from shawn.webb@hardenedbsd.org) Received: by mail-wm1-x341.google.com with SMTP id c14-v6so6902390wmb.4 for ; Wed, 19 Sep 2018 09:13:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=hardenedbsd.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=t7uTJ3gidu1o2m7Ra6g0Wowxi8se3U1ltUVPpybRDQQ=; b=Lt0CbYwMdt3uWEh/lIBMfm83YSMQXW+s2ngQNywpFwlKFG+mUJq1GvRSiH4JXvQiaw 1RN135qMVe+3ueEmTJHv08EVdSLTwumnbI+TVs4RUbT+UEA8SKIAp/jED45pgcCk1//+ Yko6D0cgXVD+x82W/rn8hApI0D8Luz8foiJkiMbHnMa2NV8zlJOuLy09K6bZT4sLLksI vaj0RFDE2UxEzY89RZ72sx+wd/d948cyYGqTCUm+BT3xh17HQhczzmkm+aDAFBtraLCc MLe8u7pVMrpsG18+3ejDaRpbrpMAPU6YXXa7dD2cbQujTKyawJ0XsU81XSEkpf8IX2v8 e9KA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=t7uTJ3gidu1o2m7Ra6g0Wowxi8se3U1ltUVPpybRDQQ=; b=TtoqpvfD4D/8ePD0x5ZIpNoZLvtD/iaWgfCLDK6/bbCKgPWYR7+YxwnXT9EvAzbO+0 Ld+Qh7ZUU/ixM+QcexRUWTDBKBSml9AZ4e7N5wql/ClvyG2hywFPMFmJPbI6P9s57Nax KI0WjcT3imGWSAi10nXEdfx2A9Fh8SI9k+BVlqi9b/f2cr6Sq4GcqaAR4Xqu486ckdt5 PrcFneZb4xJ7tpUY7vcx4E2AnkCSv2MgqhYrWjdXBKS+my+R0XVpNc6X5/RgvC8fwtTP QNUMYjeZUhNlTt7iWycCjNfsgxmK09PJ2AxGGaMTv9CJr5Sw0gmWCdOISXiG7yxu76/i IwQQ== X-Gm-Message-State: APzg51AF2NHGleRyIg0+NLmOZTSVmZTBDg+b//JALHtajDx6ewTIV8v0 +pF518FE+sHZyL1KImuV145UuA== X-Google-Smtp-Source: ANB0VdYBOFgQRSzCoTQulzft4UyziIQWIAoKFXCE7ZZRoEMAOiWJKLYm6ea8vp9zPZMdd+kx1sHD1Q== X-Received: by 2002:a1c:ee57:: with SMTP id m84-v6mr20543892wmh.9.1537373631882; Wed, 19 Sep 2018 09:13:51 -0700 (PDT) Received: from mutt-hbsd ([193.19.118.171]) by smtp.gmail.com with ESMTPSA id 14-v6sm10677803wmp.32.2018.09.19.09.13.48 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 19 Sep 2018 09:13:50 -0700 (PDT) Date: Wed, 19 Sep 2018 12:13:43 -0400 From: Shawn Webb To: Mateusz Guzik Cc: Mateusz Guzik , src-committers , svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: Re: svn commit: r338802 - head/sys/vm Message-ID: <20180919161343.ltn7ykiop2lzzgcj@mutt-hbsd> References: <201809191602.w8JG2Y0X046254@repo.freebsd.org> <20180919160819.lfzrey3upzri4tll@mutt-hbsd> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="7k4dlpxs4gushcjn" Content-Disposition: inline In-Reply-To: X-Operating-System: FreeBSD mutt-hbsd 12.0-ALPHA5 FreeBSD 12.0-ALPHA5 X-PGP-Key: http://pgp.mit.edu/pks/lookup?op=vindex&search=0x6A84658F52456EEE User-Agent: NeoMutt/20180622 X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 19 Sep 2018 16:13:53 -0000 --7k4dlpxs4gushcjn Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Wed, Sep 19, 2018 at 06:12:29PM +0200, Mateusz Guzik wrote: > On Wed, Sep 19, 2018 at 6:08 PM, Shawn Webb > wrote: >=20 > > On Wed, Sep 19, 2018 at 04:02:34PM +0000, Mateusz Guzik wrote: > > > Author: mjg > > > Date: Wed Sep 19 16:02:33 2018 > > > New Revision: 338802 > > > URL: https://svnweb.freebsd.org/changeset/base/338802 > > > > > > Log: > > > vm: check for empty kstack cache before locking > > > > > > The current cache logic checks the total number of stacks in the > > kernel, > > > which even on small boxes significantly exceeds the 128 limit (e.g.= an > > > 8-way box with zfs has almost 800 stacks allocated). > > > > > > Stacks are cached earlier for each main thread. > > > > > > As a result the code is rarely executed, but when it is then (on bo= xes > > like > > > the above) it always fails. Since there are no provisions made for > > NUMA and > > > release time is approaching, just do a quick check to avoid acquiri= ng > > the > > > lock. > > > > > > Approved by: re (kib) > > > > > > Modified: > > > head/sys/vm/vm_glue.c > > > > > > Modified: head/sys/vm/vm_glue.c > > > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > > > --- head/sys/vm/vm_glue.c Wed Sep 19 15:39:16 2018 (r33880= 1) > > > +++ head/sys/vm/vm_glue.c Wed Sep 19 16:02:33 2018 (r33880= 2) > > > @@ -327,7 +327,7 @@ vm_thread_new(struct thread *td, int pages) > > > else if (pages > KSTACK_MAX_PAGES) > > > pages =3D KSTACK_MAX_PAGES; > > > > > > - if (pages =3D=3D kstack_pages) { > > > + if (pages =3D=3D kstack_pages && kstack_cache !=3D NULL) { > > > mtx_lock(&kstack_cache_mtx); > > > if (kstack_cache !=3D NULL) { > > > ks_ce =3D kstack_cache; > > > > Since kstack_cache is guaranteed not to be NULL, can the second > > conditional that checks for kstack_cache not being NULL be removed? > > > > > The one with the lock held? By the time we get there someone else might > have removed the last cached stack making the pointer NULL. >=20 > Checking a condition before locking and then checking again is a common > optimization pattern for cases where the condition is likely false. Ah, I understand now. Thanks for the clarification! --=20 Shawn Webb Cofounder and Security Engineer HardenedBSD Tor-ified Signal: +1 443-546-8752 Tor+XMPP+OTR: lattera@is.a.hacker.sx GPG Key ID: 0x6A84658F52456EEE GPG Key Fingerprint: 2ABA B6BD EF6A F486 BE89 3D9E 6A84 658F 5245 6EEE --7k4dlpxs4gushcjn Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEKrq2ve9q9Ia+iT2eaoRlj1JFbu4FAluidbYACgkQaoRlj1JF bu47pw//ZB5VcPYu/cXoOkHWlSxfUgIN1xwQqbEQiI4O50S3DSUBi97JJD3s9zRx b8x4Cc4Cq1C5KdJzrg7KBOWZLOJL/Y3K4r1q6T2ADgn3Hd8qjCriqZhvLz3lZvQ5 q4eBwo19G/M6v6lcPJIZEwrUaZh3GgVqGbqvntlzmOkbrNwogE1x6f0EUp0RSbRQ qCEePYihRFlKuwdVzykcQj8bzbK4BaT3oEKvTq4aJ71JAdWDo/CebDA6eKMAeS9q nq9EKZNT9u9E+jjONIJ6JGQ/q3LF+4QHH+Omkj8JQD05/7oef6Otoq/yaSw4ghu0 2WdgT8PuZAdi/sS84Ma0C8ujXO3g9bflyYcS2smMyFXXEqPzDgEBRJQ5v6JnvTOn kr5yR70EdefLbcTHhg2YbnjlBnQ7Wv3Vo5LclpNOEPLHCjrjLzAvyvh7Xg9cLbQX 6JaOsWXkA2uVIsGnMahu2dvFnFIzguBcgEB1gzaGsSVdYJgiS0BryIhbTpigbuv+ 0ydKXKr2qFdJw+iBJMkCuFRqE1SwqlF6MIYb7LJOJGbJxtQI8mNEMq+77Kt1Fb1E ZyAJLkcIZmo8W7nYxOPjuB+u/oCjcaRKsyioY2qNcdbQMwvBXeZQgEpHobnV4/3q zGY8qBGKTISTxox7aqsa4ltIRwKfyv0PlLJjOunOcO/9/6m3CG0= =n6/0 -----END PGP SIGNATURE----- --7k4dlpxs4gushcjn--