From owner-freebsd-arch@FreeBSD.ORG Thu Jul 22 17:41:25 2010 Return-Path: Delivered-To: freebsd-arch@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 09D221065675; Thu, 22 Jul 2010 17:41:25 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from mail.zoral.com.ua (mx0.zoral.com.ua [91.193.166.200]) by mx1.freebsd.org (Postfix) with ESMTP id 7C4358FC1F; Thu, 22 Jul 2010 17:41:24 +0000 (UTC) Received: from deviant.kiev.zoral.com.ua (root@deviant.kiev.zoral.com.ua [10.1.1.148]) by mail.zoral.com.ua (8.14.2/8.14.2) with ESMTP id o6MHfKA9026825 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Thu, 22 Jul 2010 20:41:20 +0300 (EEST) (envelope-from kostikbel@gmail.com) Received: from deviant.kiev.zoral.com.ua (kostik@localhost [127.0.0.1]) by deviant.kiev.zoral.com.ua (8.14.4/8.14.4) with ESMTP id o6MHfKAE027026; Thu, 22 Jul 2010 20:41:20 +0300 (EEST) (envelope-from kostikbel@gmail.com) Received: (from kostik@localhost) by deviant.kiev.zoral.com.ua (8.14.4/8.14.4/Submit) id o6MHfKEd027025; Thu, 22 Jul 2010 20:41:20 +0300 (EEST) (envelope-from kostikbel@gmail.com) X-Authentication-Warning: deviant.kiev.zoral.com.ua: kostik set sender to kostikbel@gmail.com using -f Date: Thu, 22 Jul 2010 20:41:20 +0300 From: Kostik Belousov To: mdf@freebsd.org Message-ID: <20100722174120.GR2381@deviant.kiev.zoral.com.ua> References: Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="ngluH3DisTFy0Cjl" Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.4.2.3i X-Virus-Scanned: clamav-milter 0.95.2 at skuns.kiev.zoral.com.ua X-Virus-Status: Clean X-Spam-Status: No, score=-2.2 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_50, DNS_FROM_OPENWHOIS autolearn=no version=3.2.5 X-Spam-Checker-Version: SpamAssassin 3.2.5 (2008-06-10) on skuns.kiev.zoral.com.ua Cc: freebsd-arch@freebsd.org Subject: Re: Multi-zone malloc(9) X-BeenThere: freebsd-arch@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Discussion related to FreeBSD architecture List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 22 Jul 2010 17:41:25 -0000 --ngluH3DisTFy0Cjl Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Thu, Jul 22, 2010 at 09:54:51AM -0700, mdf@freebsd.org wrote: > Occasionally we run into use-after-free and malloc'd buffer overrun > scenarios. When this happens it can be rather difficult to determine > what code is at fault, since e.g. every 64 byte allocation, regardless > of malloc type, comes from the same UMA zone. This means that an > overflow in M_TEMP will affect M_DEVBUF, etc. Adding multiple uma > zones for each bucket size means that we can hash on the malloc type's > shortdesc field so that there are fewer collisions and misused memory > from one malloc type only affects a subset of other malloc types. > Varying the hash means that, with several crashes due to memory stomp, > a single malloc type can usually be determined as the culprit. If the > bug isn't obvious from inspection at this point, MemGuard will help > catch the offender. >=20 > The patch at: >=20 > http://people.freebsd.org/~mdf/multizone_malloc.patch >=20 > implements an optional multi-zone malloc(9). By default there is a > single zone, and MALLOC_DEBUG_MAXZONES can be specified in the kernel > configuration file. A ddb function will print all the malloc types > that have a hash collision with the specified type. >=20 > A few questions for -arch@: >=20 > - We found this very useful at Isilon. Should this go into CURRENT? >=20 > - Should this be on by default for GENERIC? The memory overhead of 8 > uma zones per malloc allocation size shouldn't be very large. >=20 > - would a __FreeBSD_version bump be needed since the malloc_internal > type is known by user-space? Can you quantify the overhead, both in CPU time and memory usage terms ? I would much prefer to have debug and non-debug kernels to run similar code, in other words, can the multizone allocation be enabled unconditionally ? --ngluH3DisTFy0Cjl Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.10 (FreeBSD) iEUEARECAAYFAkxIgr8ACgkQC3+MBN1Mb4j2cwCfSRtigwr3xkLvmJ0eAbh4ho2y +70Al1bwaSE6Q4RtO+BaHj0hT6X8oRc= =mVa3 -----END PGP SIGNATURE----- --ngluH3DisTFy0Cjl--