From owner-freebsd-current@freebsd.org Fri Feb 5 19:38:01 2016 Return-Path: Delivered-To: freebsd-current@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 48191A9CBE6 for ; Fri, 5 Feb 2016 19:38:01 +0000 (UTC) (envelope-from markjdb@gmail.com) Received: from mail-pa0-x233.google.com (mail-pa0-x233.google.com [IPv6:2607:f8b0:400e:c03::233]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G2" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 193FE1136; Fri, 5 Feb 2016 19:38:01 +0000 (UTC) (envelope-from markjdb@gmail.com) Received: by mail-pa0-x233.google.com with SMTP id yy13so38755878pab.3; Fri, 05 Feb 2016 11:38:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:date:from:to:cc:subject:message-id:references:mime-version :content-type:content-disposition:in-reply-to:user-agent; bh=2o54/MVcSV3fNeZcaTBSgokYxoEeYppZ4Kp6OT6qN7w=; b=NfeqwhnKcthuJ8Kw6ehykrSI6AKk0GTipYpaxm1eW4EmyM03YUjN8lwJLJsySQ3JDg NRf+g2cePn8zGXaB0J0tRx5yaO1LzJnJCw5WDnd8AbUmw6A8tWEFgnmPsXoVmxokbifb vG/0bEuUHSw9RBfB/EoPF3Qi8TIhqxOqf1ZA+IGyMq4W+xtoGRUGz2vsdNserz6y03VX FXysmWe2mIXB0E18jc5ktylQes7+Tor8sASUikQc8XQwPzS+hRn6F1dsip2ifkvLh9cQ luh3R521t96VmIlcTFeErSsZwbDo3weYSJmhkBPbxQzgm8onysRsXlQGF/jTC0KGlkOZ w15Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:date:from:to:cc:subject:message-id :references:mime-version:content-type:content-disposition :in-reply-to:user-agent; bh=2o54/MVcSV3fNeZcaTBSgokYxoEeYppZ4Kp6OT6qN7w=; b=D43AU8KXmsHVlKi5qw+VXjSe84Dwevb3Wa8WBt9yb7BWSxaoqIRNy8P99hACHUVwgc DJ5zVRS+OaIRTiqQ04mapc3FSPrp5GoVAOSB1sGGVvzlU4tfoSIwgiaG6GhiCUBE7Kk2 4HIv/nGuyHQKhCGpWR9ls6kRmdeGYi3/GX34kPGvl4mKHzkCMTrucuiUYhZ/l8e2llGF gr/+ridWsObxy6vLwHmLsoPeMF0yAr4059vYnoIAUi1SAT827TimVZ99X5T08LBdunvr JiyMjwTgjA6N6TqRxJTq6VPRRaBEeImtasifzGB/jycIry7SuLiw0unkS8PLsC3d3usc LWAg== X-Gm-Message-State: AG10YOSbkORI+rtAIFRLrpgy6EL/bahFHQ3uocf1tHkN0wYDEZSGKKAIoESguJ4EuC700g== X-Received: by 10.66.140.44 with SMTP id rd12mr22336777pab.86.1454701080684; Fri, 05 Feb 2016 11:38:00 -0800 (PST) Received: from wkstn-mjohnston.west.isilon.com (c-67-182-131-225.hsd1.wa.comcast.net. [67.182.131.225]) by smtp.gmail.com with ESMTPSA id w12sm26215449pfa.79.2016.02.05.11.37.59 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 05 Feb 2016 11:38:00 -0800 (PST) Sender: Mark Johnston Date: Fri, 5 Feb 2016 11:40:45 -0800 From: Mark Johnston To: Eric van Gyzen Cc: FreeBSD Current Subject: Re: Kernel memory leak with x11/nvidia-driver Message-ID: <20160205194044.GC1661@wkstn-mjohnston.west.isilon.com> References: <56B230CB.3050600@FreeBSD.org> <56B3E0B4.4090603@FreeBSD.org> <20160205020543.GA1661@wkstn-mjohnston.west.isilon.com> <56B4BA1C.5020507@FreeBSD.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <56B4BA1C.5020507@FreeBSD.org> User-Agent: Mutt/1.5.24 (2015-08-30) X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 05 Feb 2016 19:38:01 -0000 On Fri, Feb 05, 2016 at 09:05:00AM -0600, Eric van Gyzen wrote: > On 02/ 4/16 08:05 PM, Mark Johnston wrote: > > On Thu, Feb 04, 2016 at 05:37:24PM -0600, Eric van Gyzen wrote: > >> On 02/ 3/16 10:54 AM, Eric van Gyzen wrote: > >>> I just set up a new desktop running head with x11/nvidia-driver. I've > >>> discovered a memory leak where pages disappear from the queues, never to > >>> return. Specifically, the total of > >>> v_active_count > >>> v_inactive_count > >>> v_wire_count > >>> v_cache_count > >>> v_free_count > >>> drops, eventually becoming /much/ less than v_page_count. After leaving > >>> xscreensaver running overnight, cycling the saver every 10 minutes, the > >>> system was unusable, because it only had a few MB of memory. (It has 8 > >>> GB physical.) > >> In case anyone is curious, /usr/local/bin/xscreensaver-hacks/glmatrix > >> triggers a fairly fast leak--around 600 pages per second. > > I'm able to repro this on my workstation. With DTrace I can see that > > glmatrix is allocating pages for an SG object at roughly the rate > > they're being leaked. I took a look at r292373 (based on the history of > > sg_pager.c) and noticed a vm_page_free() call was lost when > > sg_pager_getpages() was simplified. > > > > The patch below seems to do the trick for me. Could you give it a try > > and confirm that it fixes the problem? I run current+nvidia-driver on > > multiple workstations but hadn't observed a leak until now, so maybe > > there's something additional going on in your case. Then again, I just > > use i3lock. :) > > > > diff --git a/sys/vm/sg_pager.c b/sys/vm/sg_pager.c > > index 84bfa49..2cccb7ea 100644 > > --- a/sys/vm/sg_pager.c > > +++ b/sys/vm/sg_pager.c > > @@ -189,6 +189,9 @@ sg_pager_getpages(vm_object_t object, vm_page_t *m, int count, int *rbehind, > > VM_OBJECT_WLOCK(object); > > TAILQ_INSERT_TAIL(&object->un_pager.sgp.sgp_pglist, page, plinks.q); > > vm_page_replace_checked(page, object, offset, m[0]); > > + vm_page_lock(m[0]); > > + vm_page_free(m[0]); > > + vm_page_unlock(m[0]); > > m[0] = page; > > page->valid = VM_PAGE_BITS_ALL; > > > > Your patch fixes the leak completely. Nice work, Mark! > > I didn't notice the leak until I unknowingly left the screensaver > cycling all overnight. In my normal workflow, I open the windows I need > and pretty much leave them there. This doesn't seem to trigger the > leak, at least not at a noticeable rate. > > Thanks for your help! Thank you. This was committed in r295330.