Deleted Added
full compact
memstat_uma.c (155549) memstat_uma.c (155550)
1/*-
2 * Copyright (c) 2005 Robert N. M. Watson
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 9 unchanged lines hidden (view full) ---

18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 *
1/*-
2 * Copyright (c) 2005 Robert N. M. Watson
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 9 unchanged lines hidden (view full) ---

18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 *
26 * $FreeBSD: head/lib/libmemstat/memstat_uma.c 155549 2006-02-11 18:55:03Z rwatson $
26 * $FreeBSD: head/lib/libmemstat/memstat_uma.c 155550 2006-02-11 19:19:29Z rwatson $
27 */
28
29#include <sys/param.h>
30#include <sys/sysctl.h>
31
32#define LIBMEMSTAT /* Cause vm_page.h not to include opt_vmpage.h */
33#include <vm/vm.h>
34#include <vm/vm_page.h>
35
36#include <vm/uma.h>
37#include <vm/uma_int.h>
38
39#include <err.h>
40#include <errno.h>
41#include <kvm.h>
42#include <nlist.h>
27 */
28
29#include <sys/param.h>
30#include <sys/sysctl.h>
31
32#define LIBMEMSTAT /* Cause vm_page.h not to include opt_vmpage.h */
33#include <vm/vm.h>
34#include <vm/vm_page.h>
35
36#include <vm/uma.h>
37#include <vm/uma_int.h>
38
39#include <err.h>
40#include <errno.h>
41#include <kvm.h>
42#include <nlist.h>
43#include <stddef.h>
43#include <stdio.h>
44#include <stdlib.h>
45#include <string.h>
46
47#include "memstat.h"
48#include "memstat_internal.h"
49
50static struct nlist namelist[] = {

--- 250 unchanged lines hidden (view full) ---

301 * UMA(9) statistics from a kernel core/memory file.
302 */
303int
304memstat_kvm_uma(struct memory_type_list *list, void *kvm_handle)
305{
306 LIST_HEAD(, uma_keg) uma_kegs;
307 struct memory_type *mtp;
308 struct uma_bucket *ubp, ub;
44#include <stdio.h>
45#include <stdlib.h>
46#include <string.h>
47
48#include "memstat.h"
49#include "memstat_internal.h"
50
51static struct nlist namelist[] = {

--- 250 unchanged lines hidden (view full) ---

302 * UMA(9) statistics from a kernel core/memory file.
303 */
304int
305memstat_kvm_uma(struct memory_type_list *list, void *kvm_handle)
306{
307 LIST_HEAD(, uma_keg) uma_kegs;
308 struct memory_type *mtp;
309 struct uma_bucket *ubp, ub;
309 struct uma_cache *ucp;
310 struct uma_cache *ucp, *ucp_array;
310 struct uma_zone *uzp, uz;
311 struct uma_keg *kzp, kz;
312 int hint_dontsearch, i, mp_maxid, ret;
313 char name[MEMTYPE_MAXNAME];
314 __cpumask_t all_cpus;
315 kvm_t *kvm;
316
317 kvm = (kvm_t *)kvm_handle;

--- 17 unchanged lines hidden (view full) ---

335 list->mtl_error = ret;
336 return (-1);
337 }
338 ret = kread_symbol(kvm, X_ALL_CPUS, &all_cpus, sizeof(all_cpus), 0);
339 if (ret != 0) {
340 list->mtl_error = ret;
341 return (-1);
342 }
311 struct uma_zone *uzp, uz;
312 struct uma_keg *kzp, kz;
313 int hint_dontsearch, i, mp_maxid, ret;
314 char name[MEMTYPE_MAXNAME];
315 __cpumask_t all_cpus;
316 kvm_t *kvm;
317
318 kvm = (kvm_t *)kvm_handle;

--- 17 unchanged lines hidden (view full) ---

336 list->mtl_error = ret;
337 return (-1);
338 }
339 ret = kread_symbol(kvm, X_ALL_CPUS, &all_cpus, sizeof(all_cpus), 0);
340 if (ret != 0) {
341 list->mtl_error = ret;
342 return (-1);
343 }
344 ucp_array = malloc(sizeof(struct uma_cache) * (mp_maxid + 1));
345 if (ucp_array == NULL) {
346 list->mtl_error = MEMSTAT_ERROR_NOMEMORY;
347 return (-1);
348 }
343 for (kzp = LIST_FIRST(&uma_kegs); kzp != NULL; kzp =
344 LIST_NEXT(&kz, uk_link)) {
345 ret = kread(kvm, kzp, &kz, sizeof(kz), 0);
346 if (ret != 0) {
349 for (kzp = LIST_FIRST(&uma_kegs); kzp != NULL; kzp =
350 LIST_NEXT(&kz, uk_link)) {
351 ret = kread(kvm, kzp, &kz, sizeof(kz), 0);
352 if (ret != 0) {
353 free(ucp_array);
347 _memstat_mtl_empty(list);
348 list->mtl_error = ret;
349 return (-1);
350 }
351 for (uzp = LIST_FIRST(&kz.uk_zones); uzp != NULL; uzp =
352 LIST_NEXT(&uz, uz_link)) {
353 ret = kread(kvm, uzp, &uz, sizeof(uz), 0);
354 if (ret != 0) {
354 _memstat_mtl_empty(list);
355 list->mtl_error = ret;
356 return (-1);
357 }
358 for (uzp = LIST_FIRST(&kz.uk_zones); uzp != NULL; uzp =
359 LIST_NEXT(&uz, uz_link)) {
360 ret = kread(kvm, uzp, &uz, sizeof(uz), 0);
361 if (ret != 0) {
362 free(ucp_array);
355 _memstat_mtl_empty(list);
356 list->mtl_error = ret;
357 return (-1);
358 }
363 _memstat_mtl_empty(list);
364 list->mtl_error = ret;
365 return (-1);
366 }
367 ret = kread(kvm, uzp, ucp_array,
368 sizeof(struct uma_cache) * (mp_maxid + 1),
369 offsetof(struct uma_zone, uz_cpu[0]));
370 if (ret != 0) {
371 free(ucp_array);
372 _memstat_mtl_empty(list);
373 list->mtl_error = ret;
374 return (-1);
375 }
359 ret = kread_string(kvm, uz.uz_name, name,
360 MEMTYPE_MAXNAME);
361 if (ret != 0) {
376 ret = kread_string(kvm, uz.uz_name, name,
377 MEMTYPE_MAXNAME);
378 if (ret != 0) {
379 free(ucp_array);
362 _memstat_mtl_empty(list);
363 list->mtl_error = ret;
364 return (-1);
365 }
366 if (hint_dontsearch == 0) {
367 mtp = memstat_mtl_find(list, ALLOCATOR_UMA,
368 name);
369 } else
370 mtp = NULL;
371 if (mtp == NULL)
372 mtp = _memstat_mt_allocate(list, ALLOCATOR_UMA,
373 name);
374 if (mtp == NULL) {
380 _memstat_mtl_empty(list);
381 list->mtl_error = ret;
382 return (-1);
383 }
384 if (hint_dontsearch == 0) {
385 mtp = memstat_mtl_find(list, ALLOCATOR_UMA,
386 name);
387 } else
388 mtp = NULL;
389 if (mtp == NULL)
390 mtp = _memstat_mt_allocate(list, ALLOCATOR_UMA,
391 name);
392 if (mtp == NULL) {
393 free(ucp_array);
375 _memstat_mtl_empty(list);
376 list->mtl_error = MEMSTAT_ERROR_NOMEMORY;
377 return (-1);
378 }
379 /*
380 * Reset the statistics on a current node.
381 */
382 _memstat_mt_reset_stats(mtp);
383 mtp->mt_numallocs = uz.uz_allocs;
384 mtp->mt_numfrees = uz.uz_frees;
385 mtp->mt_failures = uz.uz_fails;
386 if (kz.uk_flags & UMA_ZFLAG_INTERNAL)
387 goto skip_percpu;
388 for (i = 0; i < mp_maxid + 1; i++) {
389 if ((all_cpus & (1 << i)) == 0)
390 continue;
394 _memstat_mtl_empty(list);
395 list->mtl_error = MEMSTAT_ERROR_NOMEMORY;
396 return (-1);
397 }
398 /*
399 * Reset the statistics on a current node.
400 */
401 _memstat_mt_reset_stats(mtp);
402 mtp->mt_numallocs = uz.uz_allocs;
403 mtp->mt_numfrees = uz.uz_frees;
404 mtp->mt_failures = uz.uz_fails;
405 if (kz.uk_flags & UMA_ZFLAG_INTERNAL)
406 goto skip_percpu;
407 for (i = 0; i < mp_maxid + 1; i++) {
408 if ((all_cpus & (1 << i)) == 0)
409 continue;
391 ucp = &uz.uz_cpu[i];
410 ucp = &ucp_array[i];
392 mtp->mt_numallocs += ucp->uc_allocs;
393 mtp->mt_numfrees += ucp->uc_frees;
394
395 if (ucp->uc_allocbucket != NULL) {
396 ret = kread(kvm, ucp->uc_allocbucket,
397 &ub, sizeof(ub), 0);
398 if (ret != 0) {
411 mtp->mt_numallocs += ucp->uc_allocs;
412 mtp->mt_numfrees += ucp->uc_frees;
413
414 if (ucp->uc_allocbucket != NULL) {
415 ret = kread(kvm, ucp->uc_allocbucket,
416 &ub, sizeof(ub), 0);
417 if (ret != 0) {
418 free(ucp_array);
399 _memstat_mtl_empty(list);
400 list->mtl_error = ret;
401 return (-1);
402 }
403 mtp->mt_free += ub.ub_cnt;
404 }
405 if (ucp->uc_freebucket != NULL) {
406 ret = kread(kvm, ucp->uc_freebucket,
407 &ub, sizeof(ub), 0);
408 if (ret != 0) {
419 _memstat_mtl_empty(list);
420 list->mtl_error = ret;
421 return (-1);
422 }
423 mtp->mt_free += ub.ub_cnt;
424 }
425 if (ucp->uc_freebucket != NULL) {
426 ret = kread(kvm, ucp->uc_freebucket,
427 &ub, sizeof(ub), 0);
428 if (ret != 0) {
429 free(ucp_array);
409 _memstat_mtl_empty(list);
410 list->mtl_error = ret;
411 return (-1);
412 }
413 mtp->mt_free += ub.ub_cnt;
414 }
415 }
416skip_percpu:

--- 17 unchanged lines hidden (view full) ---

434 if (!((kz.uk_flags & UMA_ZONE_SECONDARY) &&
435 LIST_FIRST(&kz.uk_zones) != uzp)) {
436 mtp->mt_kegfree = kz.uk_free;
437 mtp->mt_free += mtp->mt_kegfree;
438 }
439 mtp->mt_free += mtp->mt_zonefree;
440 }
441 }
430 _memstat_mtl_empty(list);
431 list->mtl_error = ret;
432 return (-1);
433 }
434 mtp->mt_free += ub.ub_cnt;
435 }
436 }
437skip_percpu:

--- 17 unchanged lines hidden (view full) ---

455 if (!((kz.uk_flags & UMA_ZONE_SECONDARY) &&
456 LIST_FIRST(&kz.uk_zones) != uzp)) {
457 mtp->mt_kegfree = kz.uk_free;
458 mtp->mt_free += mtp->mt_kegfree;
459 }
460 mtp->mt_free += mtp->mt_zonefree;
461 }
462 }
463 free(ucp_array);
442 return (0);
443}
464 return (0);
465}