From owner-svn-src-all@freebsd.org Fri Oct 11 06:03:46 2019 Return-Path: Delivered-To: svn-src-all@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id B0BC113E3BA; Fri, 11 Oct 2019 06:03:46 +0000 (UTC) (envelope-from cse.cem@gmail.com) Received: from mail-ot1-f45.google.com (mail-ot1-f45.google.com [209.85.210.45]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "smtp.gmail.com", Issuer "GTS CA 1O1" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 46qHSx5bJjz42Sv; Fri, 11 Oct 2019 06:03:45 +0000 (UTC) (envelope-from cse.cem@gmail.com) Received: by mail-ot1-f45.google.com with SMTP id g13so6985423otp.8; Thu, 10 Oct 2019 23:03:45 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:reply-to :from:date:message-id:subject:to:cc; bh=7me31K5xElyVDBbydSJdiLEgz6pnnGYVY4Tsrj8ETAM=; b=qdvQWGowdU0fMfwETQa13kl9E+vwiBA8Icj3HP965EQ/TQppzS+DsttHcJOFKHX5Se kDrs7qOrVb1ozS708SuP3tHB/u7IkSLMzTCnMWR6Kg3XF/xUeD43wB3n2QW4Yn6GKzVa XqX3zggrB8JfgbN3qCyrHFgE5Zmg1/gK4iY5lsTbsEsHKabsP0eZmSds1yL/3azcvfmP iJEFOUOXiT32Uf/VrQCNfvKe9eV/oak8GW6aGINTRslCDmdfEcaM2C1qnpG1hB0lEfJ7 TzqwWOoBWSYlVlh9ZZRQO8MRNs2fvITU3/47lTa1XG+oyp+alPtgVJSBMA1Rzw5iKyNH gtFA== X-Gm-Message-State: APjAAAWqC9tSnAuAf+uCoR5gfz6iYSPnUEYpKXLhhA+fkDV3Z39PM5mc F2LV6aewwUSVna7wiw7hkRbRwnqM X-Google-Smtp-Source: APXvYqyXpUPa0Rpz3TdLPV+mDL1JRsl1RO/SiZmyVv9Ca8uPcqWjDzZucMWKyQ/H4yfe7ahy6wBUUg== X-Received: by 2002:a9d:6c10:: with SMTP id f16mr11506364otq.35.1570773824084; Thu, 10 Oct 2019 23:03:44 -0700 (PDT) Received: from mail-ot1-f51.google.com (mail-ot1-f51.google.com. [209.85.210.51]) by smtp.gmail.com with ESMTPSA id t18sm2445924otd.60.2019.10.10.23.03.43 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 10 Oct 2019 23:03:43 -0700 (PDT) Received: by mail-ot1-f51.google.com with SMTP id c10so6992304otd.9; Thu, 10 Oct 2019 23:03:43 -0700 (PDT) X-Received: by 2002:a05:6830:1154:: with SMTP id x20mr10495645otq.219.1570773823416; Thu, 10 Oct 2019 23:03:43 -0700 (PDT) MIME-Version: 1.0 References: <201910110131.x9B1VV1R047982@repo.freebsd.org> <201910110420.x9B4KinB006128@slippy.cwsent.com> In-Reply-To: <201910110420.x9B4KinB006128@slippy.cwsent.com> Reply-To: cem@freebsd.org From: Conrad Meyer Date: Thu, 10 Oct 2019 23:03:32 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: svn commit: r353429 - in head: share/man/man4 sys/kern sys/vm To: Cy Schubert Cc: Conrad Meyer , src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-Rspamd-Queue-Id: 46qHSx5bJjz42Sv X-Spamd-Bar: --- Authentication-Results: mx1.freebsd.org; dkim=none; dmarc=none; spf=pass (mx1.freebsd.org: domain of csecem@gmail.com designates 209.85.210.45 as permitted sender) smtp.mailfrom=csecem@gmail.com X-Spamd-Result: default: False [-3.10 / 15.00]; RCVD_VIA_SMTP_AUTH(0.00)[]; HAS_REPLYTO(0.00)[cem@freebsd.org]; TO_DN_SOME(0.00)[]; R_SPF_ALLOW(-0.20)[+ip4:209.85.128.0/17]; RWL_MAILSPIKE_GOOD(0.00)[45.210.85.209.rep.mailspike.net : 127.0.0.18]; REPLYTO_ADDR_EQ_FROM(0.00)[]; RCPT_COUNT_FIVE(0.00)[5]; RCVD_COUNT_THREE(0.00)[4]; MIME_BASE64_TEXT(0.10)[]; FORGED_SENDER(0.30)[cem@freebsd.org,csecem@gmail.com]; R_DKIM_NA(0.00)[]; FREEMAIL_ENVFROM(0.00)[gmail.com]; ASN(0.00)[asn:15169, ipnet:209.85.128.0/17, country:US]; FROM_NEQ_ENVFROM(0.00)[cem@freebsd.org,csecem@gmail.com]; TAGGED_FROM(0.00)[]; ARC_NA(0.00)[]; NEURAL_HAM_MEDIUM(-1.00)[-1.000,0]; MIME_TRACE(0.00)[0:+,1:+,2:~]; FROM_HAS_DN(0.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000,0]; MIME_GOOD(-0.10)[multipart/alternative,text/plain]; DMARC_NA(0.00)[freebsd.org]; TO_MATCH_ENVRCPT_SOME(0.00)[]; RCVD_IN_DNSWL_NONE(0.00)[45.210.85.209.list.dnswl.org : 127.0.5.0]; IP_SCORE(-1.20)[ip: (-0.55), ipnet: 209.85.128.0/17(-3.25), asn: 15169(-2.13), country: US(-0.05)]; RCVD_TLS_ALL(0.00)[] Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Content-Filtered-By: Mailman/MimeDel 2.1.29 X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.29 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: Fri, 11 Oct 2019 06:03:46 -0000 Thanks Cy, you=E2=80=99re totally right. That explains the crazy cachefree/= xfree numbers I was seeing. Should be fixed in 353430. Thanks, Conrad On Thu, Oct 10, 2019 at 21:20 Cy Schubert wrote= : > In message <201910110131.x9B1VV1R047982@repo.freebsd.org>, Conrad Meyer > writes: > > Author: cem > > Date: Fri Oct 11 01:31:31 2019 > > New Revision: 353429 > > URL: https://svnweb.freebsd.org/changeset/base/353429 > > > > Log: > > ddb: Add CSV option, sorting to 'show (malloc|uma)' > > > > Add /i option for machine-parseable CSV output. This allows ready > copy/ > > pasting into more sophisticated tooling outside of DDB. > > > > Add total zone size ("Memory Use") as a new column for UMA. > > > > For both, sort the displayed list on size (print the largest > zones/types > > first). This is handy for quickly diagnosing "where has my memory > gone?" a > > t > > a high level. > > > > Submitted by: Emily Pettigrew > (earlie > > r version) > > Sponsored by: Dell EMC Isilon > > > > Modified: > > head/share/man/man4/ddb.4 > > head/sys/kern/kern_malloc.c > > head/sys/vm/uma_core.c > > > > Modified: head/share/man/man4/ddb.4 > > > =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/share/man/man4/ddb.4 Fri Oct 11 00:02:00 2019 (r353428) > > +++ head/share/man/man4/ddb.4 Fri Oct 11 01:31:31 2019 (r353429) > > @@ -60,7 +60,7 @@ > > .\" > > .\" $FreeBSD$ > > .\" > > -.Dd September 9, 2019 > > +.Dd October 10, 2019 > > .Dt DDB 4 > > .Os > > .Sh NAME > > @@ -806,11 +806,15 @@ is included in the kernel. > > .It Ic show Cm locktree > > .\" > > .Pp > > -.It Ic show Cm malloc > > +.It Ic show Cm malloc Ns Op Li / Ns Cm i > > Prints > > .Xr malloc 9 > > memory allocator statistics. > > -The output format is as follows: > > +If the > > +.Cm i > > +modifier is specified, format output as machine-parseable > comma-separated > > +values ("CSV"). > > +The output columns are as follows: > > .Pp > > .Bl -tag -compact -offset indent -width "Requests" > > .It Ic Type > > @@ -1076,11 +1080,15 @@ Currently, those are: > > .Xr rmlock 9 . > > .\" > > .Pp > > -.It Ic show Cm uma > > +.It Ic show Cm uma Ns Op Li / Ns Cm i > > Show UMA allocator statistics. > > -Output consists five columns: > > +If the > > +.Cm i > > +modifier is specified, format output as machine-parseable > comma-separated > > +values ("CSV"). > > +The output contains the following columns: > > .Pp > > -.Bl -tag -compact -offset indent -width "Requests" > > +.Bl -tag -compact -offset indent -width "Total Mem" > > .It Cm "Zone" > > Name of the UMA zone. > > The same string that was passed to > > @@ -1094,9 +1102,18 @@ Number of slabs being currently used. > > Number of free slabs within the UMA zone. > > .It Cm "Requests" > > Number of allocations requests to the given zone. > > +.It Cm "Total Mem" > > +Total memory in use (either allocated or free) by a zone, in bytes. > > +.It Cm "XFree" > > +Number of free slabs within the UMA zone that were freed on a differen= t > NUMA > > +domain than allocated. > > +(The count in the > > +.Cm "Free" > > +column is inclusive of > > +.Cm "XFree" . ) > > .El > > .Pp > > -The very same information might be gathered in the userspace > > +The same information might be gathered in the userspace > > with the help of > > .Dq Nm vmstat Fl z . > > .\" > > > > Modified: head/sys/kern/kern_malloc.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/kern/kern_malloc.c Fri Oct 11 00:02:00 2019 > (r35342 > > 8) > > +++ head/sys/kern/kern_malloc.c Fri Oct 11 01:31:31 2019 > (r35342 > > 9) > > @@ -1205,35 +1205,90 @@ restart: > > } > > > > #ifdef DDB > > +static int64_t > > +get_malloc_stats(const struct malloc_type_internal *mtip, uint64_t > *allocs, > > + uint64_t *inuse) > > +{ > > + const struct malloc_type_stats *mtsp; > > + uint64_t frees, alloced, freed; > > + int i; > > + > > + *allocs =3D 0; > > + frees =3D 0; > > + alloced =3D 0; > > + freed =3D 0; > > + for (i =3D 0; i <=3D mp_maxid; i++) { > > + mtsp =3D zpcpu_get_cpu(mtip->mti_stats, i); > > + > > + *allocs +=3D mtsp->mts_numallocs; > > + frees +=3D mtsp->mts_numfrees; > > + alloced +=3D mtsp->mts_memalloced; > > + freed +=3D mtsp->mts_memfreed; > > + } > > + *inuse =3D *allocs - frees; > > + return (alloced - freed); > > +} > > + > > DB_SHOW_COMMAND(malloc, db_show_malloc) > > { > > - struct malloc_type_internal *mtip; > > - struct malloc_type_stats *mtsp; > > + const char *fmt_hdr, *fmt_entry; > > struct malloc_type *mtp; > > - uint64_t allocs, frees; > > - uint64_t alloced, freed; > > - int i; > > + uint64_t allocs, inuse; > > + int64_t size; > > + /* variables for sorting */ > > + struct malloc_type *last_mtype, *cur_mtype; > > + int64_t cur_size, last_size; > > + int ties; > > > > - db_printf("%18s %12s %12s %12s\n", "Type", "InUse", "MemUse", > > - "Requests"); > > - for (mtp =3D kmemstatistics; mtp !=3D NULL; mtp =3D mtp->ks_next)= { > > - mtip =3D (struct malloc_type_internal *)mtp->ks_handle; > > - allocs =3D 0; > > - frees =3D 0; > > - alloced =3D 0; > > - freed =3D 0; > > - for (i =3D 0; i <=3D mp_maxid; i++) { > > - mtsp =3D zpcpu_get_cpu(mtip->mti_stats, i); > > - allocs +=3D mtsp->mts_numallocs; > > - frees +=3D mtsp->mts_numfrees; > > - alloced +=3D mtsp->mts_memalloced; > > - freed +=3D mtsp->mts_memfreed; > > + if (modif[0] =3D=3D 'i') { > > + fmt_hdr =3D "%s,%s,%s,%s\n"; > > + fmt_entry =3D "\"%s\",%ju,%jdK,%ju\n"; > > + } else { > > + fmt_hdr =3D "%18s %12s %12s %12s\n"; > > + fmt_entry =3D "%18s %12ju %12jdK %12ju\n"; > > + } > > + > > + db_printf(fmt_hdr, "Type", "InUse", "MemUse", "Requests"); > > + > > + /* Select sort, largest size first. */ > > + last_mtype =3D NULL; > > + last_size =3D INT64_MAX; > > + for (;;) { > > + cur_mtype =3D NULL; > > + cur_size =3D -1; > > + ties =3D 0; > > + > > + for (mtp =3D kmemstatistics; mtp !=3D NULL; mtp =3D > mtp->ks_next) { > > + /* > > + * In the case of size ties, print out mtypes > > + * in the order they are encountered. That is, > > + * when we encounter the most recently output > > + * mtype, we have already printed all preceding > > + * ties, and we must print all following ties. > > + */ > > + if (mtp =3D=3D last_mtype) { > > + ties =3D 1; > > + continue; > > + } > > + size =3D get_malloc_stats(mtp->ks_handle, &allocs= , > > + &inuse); > > + if (size > cur_size && size < last_size + ties) { > > + cur_size =3D size; > > + cur_mtype =3D mtp; > > + } > > } > > - db_printf("%18s %12ju %12juK %12ju\n", > > - mtp->ks_shortdesc, allocs - frees, > > - (alloced - freed + 1023) / 1024, allocs); > > + if (cur_mtype =3D=3D NULL) > > + break; > > + > > + size =3D get_malloc_stats(cur_mtype->ks_handle, &allocs, > &inuse); > > + db_printf(fmt_entry, cur_mtype->ks_shortdesc, inuse, > > + howmany(size, 1024), allocs); > > + > > if (db_pager_quit) > > break; > > + > > + last_mtype =3D cur_mtype; > > + last_size =3D cur_size; > > } > > } > > > > > > Modified: head/sys/vm/uma_core.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/uma_core.c Fri Oct 11 00:02:00 2019 (r353428) > > +++ head/sys/vm/uma_core.c Fri Oct 11 01:31:31 2019 (r353429) > > @@ -4341,39 +4341,100 @@ uma_dbg_free(uma_zone_t zone, uma_slab_t slab, > void > > *i > > #endif /* INVARIANTS */ > > > > #ifdef DDB > > +static int64_t > > +get_uma_stats(uma_keg_t kz, uma_zone_t z, uint64_t *allocs, uint64_t > *used, > > + uint64_t *sleeps, uint64_t *xdomain, long *cachefree) > > xdomain and cachefree are reversed by callers of this function. Probably > simpler to change the definition here than the two use instances below. > > > +{ > > + uint64_t frees; > > + int i; > > + > > + if (kz->uk_flags & UMA_ZFLAG_INTERNAL) { > > + *allocs =3D counter_u64_fetch(z->uz_allocs); > > + frees =3D counter_u64_fetch(z->uz_frees); > > + *sleeps =3D z->uz_sleeps; > > + *cachefree =3D 0; > > + *xdomain =3D 0; > > + } else > > + uma_zone_sumstat(z, cachefree, allocs, &frees, sleeps, > > + xdomain); > > + if (!((z->uz_flags & UMA_ZONE_SECONDARY) && > > + (LIST_FIRST(&kz->uk_zones) !=3D z))) > > + *cachefree +=3D kz->uk_free; > > + for (i =3D 0; i < vm_ndomains; i++) > > + *cachefree +=3D z->uz_domain[i].uzd_nitems; > > + *used =3D *allocs - frees; > > + return (((int64_t)*used + *cachefree) * kz->uk_size); > > +} > > + > > DB_SHOW_COMMAND(uma, db_show_uma) > > { > > + const char *fmt_hdr, *fmt_entry; > > uma_keg_t kz; > > uma_zone_t z; > > - uint64_t allocs, frees, sleeps, xdomain; > > + uint64_t allocs, used, sleeps, xdomain; > > long cachefree; > > - int i; > > + /* variables for sorting */ > > + uma_keg_t cur_keg; > > + uma_zone_t cur_zone, last_zone; > > + int64_t cur_size, last_size, size; > > + int ties; > > > > - db_printf("%18s %8s %8s %8s %12s %8s %8s %8s\n", "Zone", "Size", > "Used" > > , > > - "Free", "Requests", "Sleeps", "Bucket", "XFree"); > > - LIST_FOREACH(kz, &uma_kegs, uk_link) { > > - LIST_FOREACH(z, &kz->uk_zones, uz_link) { > > - if (kz->uk_flags & UMA_ZFLAG_INTERNAL) { > > - allocs =3D counter_u64_fetch(z->uz_allocs= ); > > - frees =3D counter_u64_fetch(z->uz_frees); > > - sleeps =3D z->uz_sleeps; > > - cachefree =3D 0; > > - } else > > - uma_zone_sumstat(z, &cachefree, &allocs, > > - &frees, &sleeps, &xdomain); > > - if (!((z->uz_flags & UMA_ZONE_SECONDARY) && > > - (LIST_FIRST(&kz->uk_zones) !=3D z))) > > - cachefree +=3D kz->uk_free; > > - for (i =3D 0; i < vm_ndomains; i++) > > - cachefree +=3D z->uz_domain[i].uzd_nitems= ; > > + /* /i option produces machine-parseable CSV output */ > > + if (modif[0] =3D=3D 'i') { > > + fmt_hdr =3D "%s,%s,%s,%s,%s,%s,%s,%s,%s\n"; > > + fmt_entry =3D "\"%s\",%ju,%jd,%ld,%ju,%ju,%u,%jd,%ju\n"; > > + } else { > > + fmt_hdr =3D "%18s %6s %7s %7s %11s %7s %7s %10s %8s\n"; > > + fmt_entry =3D "%18s %6ju %7jd %7ld %11ju %7ju %7u %10jd > %8ju\n"; > > + } > > > > - db_printf("%18s %8ju %8jd %8ld %12ju %8ju %8u > %8ju\n", > > - z->uz_name, (uintmax_t)kz->uk_size, > > - (intmax_t)(allocs - frees), cachefree, > > - (uintmax_t)allocs, sleeps, z->uz_count, > xdomain); > > - if (db_pager_quit) > > - return; > > + db_printf(fmt_hdr, "Zone", "Size", "Used", "Free", "Requests", > > + "Sleeps", "Bucket", "Total Mem", "XFree"); > > + > > + /* Sort the zones with largest size first. */ > > + last_zone =3D NULL; > > + last_size =3D INT64_MAX; > > + for (;;) { > > + cur_zone =3D NULL; > > + cur_size =3D -1; > > + ties =3D 0; > > + LIST_FOREACH(kz, &uma_kegs, uk_link) { > > + LIST_FOREACH(z, &kz->uk_zones, uz_link) { > > + /* > > + * In the case of size ties, print out > zones > > + * in the order they are encountered. > That is, > > + * when we encounter the most recently > output > > + * zone, we have already printed all > preceding > > + * ties, and we must print all following > ties. > > + */ > > + if (z =3D=3D last_zone) { > > + ties =3D 1; > > + continue; > > + } > > + size =3D get_uma_stats(kz, z, &allocs, &u= sed, > > + &sleeps, &cachefree, &xdomain); > > cachefree and xdomain are reversed from the function header above. > > > + if (size > cur_size && size < last_size + > ties) > > + { > > + cur_size =3D size; > > + cur_zone =3D z; > > + cur_keg =3D kz; > > + } > > + } > > } > > + if (cur_zone =3D=3D NULL) > > + break; > > + > > + size =3D get_uma_stats(cur_keg, cur_zone, &allocs, &used, > > + &sleeps, &cachefree, &xdomain); > > cachefree and xdomain are reversed from the function header above. > > > + db_printf(fmt_entry, cur_zone->uz_name, > > + (uintmax_t)cur_keg->uk_size, (intmax_t)used, cachefre= e, > > + (uintmax_t)allocs, (uintmax_t)sleeps, > > + (unsigned)cur_zone->uz_count, (intmax_t)size, xdomain= ); > > + > > + if (db_pager_quit) > > + return; > > + last_zone =3D cur_zone; > > + last_size =3D cur_size; > > } > > } > > > > > > > > -- > Cheers, > Cy Schubert > FreeBSD UNIX: Web: http://www.FreeBSD.org > > The need of the many outweighs the greed of the few. > > >