From owner-freebsd-stable@FreeBSD.ORG Wed Jul 26 11:52:46 2006 Return-Path: X-Original-To: stable@freebsd.org Delivered-To: freebsd-stable@FreeBSD.ORG Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 5FAF316A4DD for ; Wed, 26 Jul 2006 11:52:46 +0000 (UTC) (envelope-from rwatson@FreeBSD.org) Received: from cyrus.watson.org (cyrus.watson.org [209.31.154.42]) by mx1.FreeBSD.org (Postfix) with ESMTP id 12E0143D46 for ; Wed, 26 Jul 2006 11:52:45 +0000 (GMT) (envelope-from rwatson@FreeBSD.org) Received: from fledge.watson.org (fledge.watson.org [209.31.154.41]) by cyrus.watson.org (Postfix) with ESMTP id EF59846C14; Wed, 26 Jul 2006 07:52:44 -0400 (EDT) Date: Wed, 26 Jul 2006 12:52:44 +0100 (BST) From: Robert Watson X-X-Sender: robert@fledge.watson.org To: Stephane Dupille In-Reply-To: Message-ID: <20060726124251.W4612@fledge.watson.org> References: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed Cc: stable@freebsd.org Subject: Re: Memory management X-BeenThere: freebsd-stable@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Production branch of FreeBSD source code List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 26 Jul 2006 11:52:46 -0000 On Wed, 26 Jul 2006, Stephane Dupille wrote: > I have a computer running FreeBSD 6.1. > > As time passing by, the memory fills up. When the machine starts, memory is > occupied to 30 %, and after two or three weeks memory is occupied to 100 % > and it begins to use swap. > > It is "inactive" pages that fills up the memory. > > I tried to restart every process, but memory usage does not decrease. Only > a reboot can fix that. And I'm not able to see which process leaks. > > I was not able to find a correct definition of what "inactive" memory is. > First, I would like to know what are these kind of pages : wired, active, > inactive, cache and free. > > Is that normal that inactive memory usage grows ? What should I do ? > > Do you have any tools to monitor memory usage of processes ? You can find an article discussing some of the FreeBSD VM system design here: http://www.freebsd.org/doc/en_US.ISO8859-1/articles/vm-design/article.html This document is gradually aging, and doesn't cover certain elements of the design, including some recent optimizations, SMP behavior, etc, but still makes quite a good read. It could be that you have applications leaking memory, but it's more likely that the VM system is simply being efficient. Free memory is, in effect, wasted memory, since it's not being used. FreeBSD will agressively cache file system data, and either drop or page out unused pages (depending on whether they are dirty) in order to maximize the amount of memory available for actively used data. This means it will swap out dirty pages allocated by a process if the process isn't using them, rather than keep them in memory preventing that memory from being used by processes that need it. The result is that at any given moment, an active system should have almost no free memory, and instead should be providing as much memory as possible to active pages, and the largest possible file system cache. This may seem counter-intuitive compared to some other systems where a premium is placed on free pages as representing the resources available to run additional applications. We consider memory floating around "unused" to be a waste of memory that could be used to improve system performance. "systat -vmstat 1" is a good tool to monitor the VM system, as it will let you monitor memory use, in particular, the vnode and swap paging rates. You can use ps(1) with various parameters to inspect process memory use. A popular combination is "aux", which views all processes and displays, among other things, their virtual and resident sizes. The resident size is the figure you want to look at, as it represents the number of pages actually in memory, rather than pages that could be paged in. Robert N M Watson Computer Laboratory University of Cambridge