From owner-svn-src-head@freebsd.org Wed Sep 19 16:12:31 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 0137310A059B; Wed, 19 Sep 2018 16:12:31 +0000 (UTC) (envelope-from mjguzik@gmail.com) Received: from mail-qt0-x244.google.com (mail-qt0-x244.google.com [IPv6:2607:f8b0:400d:c0d::244]) (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 90A2488035; Wed, 19 Sep 2018 16:12:30 +0000 (UTC) (envelope-from mjguzik@gmail.com) Received: by mail-qt0-x244.google.com with SMTP id l2-v6so450681qtr.12; Wed, 19 Sep 2018 09:12:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=vgZ3VoZKBjSqYD82gDl0Smoc8ZF5v0ZAaexyYfmQ8V4=; b=HEgOgW4vfgUiem/JEroOHcO1VcjftnuIbKo8KxjWzLhC50LVZagfteOOpH/QrGIiSk www4dsosOXuKFBeFw+KM0iUfg77Qet0kBpox96x3YR3JFUIF94lHYOiCzDXvJDrIBI/d sEBegRdaXA1VG232PegqO3xtT/oiRLKHNDJUmKcsALiU/cp3H9l+GvlssFbdCaY1G0dH 3jQXYFDRJhjYrxojArikUkewYTI7IOxeIwEBMX/yudOZNAV9HK9gvQnZ1PR7GMUpwi/E awYS102a6IuE7tuZZW8R1N6DdNwkLQRe4KuNLFHeM6QBnGO0QaWmrzfX3dXjhUdAust8 wLvA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=vgZ3VoZKBjSqYD82gDl0Smoc8ZF5v0ZAaexyYfmQ8V4=; b=s5OS/4kLeKhzcS4064uw1GHrUPejyG2BYbeLIQOzqDhy5UGOkPXUn4Ih44BqLPtzGE WAWZg3IlF4RmiqAORavO43C+AVEsnM2oWkmPZvepJEnBC9viZcZSOf9OSJ4YgSOOXS3/ 87JzK+yTpPi62fy/UH3/tF0BV/Y5rDkiC0m09PoSdaEjXCYIepiVoqLqa8TIt4InL3pd IB96Xgfq8CKalUzImDD5qmShnyToun4/tlVliOsqVreFJuBbP3p7GA3HRbv4JS/EQdve ELibImILW08uu3/oM/KUPK60ZweEXF5luMsMLaJUW0UZCp11ftvPg4PaSdb4VrtgFTBQ KA4g== X-Gm-Message-State: APzg51ASpWVv4aJSLlPhQyzURlNhpUp30WU6eyQIF4PlqokrikR9woyE AD8KhV1GBQl4ck1X+e41Hm4ShigNtKhM3rWXJZC1ww== X-Google-Smtp-Source: ANB0VdYpBJaKRvf2+cuZlf9SEivhGz97pNSZNgqDyhULM4u84kNSs6DfXY2P85T+WFJRm5zhqkN3Rq8JGDpjDh2nsQw= X-Received: by 2002:aed:3244:: with SMTP id y62-v6mr24329489qtd.292.1537373550152; Wed, 19 Sep 2018 09:12:30 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:ac8:3602:0:0:0:0:0 with HTTP; Wed, 19 Sep 2018 09:12:29 -0700 (PDT) In-Reply-To: <20180919160819.lfzrey3upzri4tll@mutt-hbsd> References: <201809191602.w8JG2Y0X046254@repo.freebsd.org> <20180919160819.lfzrey3upzri4tll@mutt-hbsd> From: Mateusz Guzik Date: Wed, 19 Sep 2018 18:12:29 +0200 Message-ID: Subject: Re: svn commit: r338802 - head/sys/vm To: Shawn Webb Cc: Mateusz Guzik , src-committers , svn-src-all@freebsd.org, svn-src-head@freebsd.org Content-Type: text/plain; charset="UTF-8" X-Content-Filtered-By: Mailman/MimeDel 2.1.27 X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.27 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: Wed, 19 Sep 2018 16:12:31 -0000 On Wed, Sep 19, 2018 at 6:08 PM, Shawn Webb wrote: > 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 boxes > 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 acquiring > the > > lock. > > > > Approved by: re (kib) > > > > Modified: > > head/sys/vm/vm_glue.c > > > > Modified: head/sys/vm/vm_glue.c > > ============================================================ > ================== > > --- head/sys/vm/vm_glue.c Wed Sep 19 15:39:16 2018 (r338801) > > +++ head/sys/vm/vm_glue.c Wed Sep 19 16:02:33 2018 (r338802) > > @@ -327,7 +327,7 @@ vm_thread_new(struct thread *td, int pages) > > else if (pages > KSTACK_MAX_PAGES) > > pages = KSTACK_MAX_PAGES; > > > > - if (pages == kstack_pages) { > > + if (pages == kstack_pages && kstack_cache != NULL) { > > mtx_lock(&kstack_cache_mtx); > > if (kstack_cache != NULL) { > > ks_ce = 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. Checking a condition before locking and then checking again is a common optimization pattern for cases where the condition is likely false. -- Mateusz Guzik