- ledger_get_balance(pmap->ledger,
- task_ledgers.phys_footprint,
- &bal);
- if (bal != 0) {
- do_panic = TRUE;
- printf("LEDGER BALANCE proc %d (%s) "
- "\"phys_footprint\" = %lld\n",
- pid, procname, bal);
- if (bal > 0) {
- pmap_ledgers_drift.phys_footprint_over++;
- pmap_ledgers_drift.phys_footprint_over_total += bal;
- if (bal > pmap_ledgers_drift.phys_footprint_over_max) {
- pmap_ledgers_drift.phys_footprint_over_max = bal;
- }
- } else {
- pmap_ledgers_drift.phys_footprint_under++;
- pmap_ledgers_drift.phys_footprint_under_total += bal;
- if (bal < pmap_ledgers_drift.phys_footprint_under_max) {
- pmap_ledgers_drift.phys_footprint_under_max = bal;
- }
- }
- }
- ledger_get_balance(pmap->ledger,
- task_ledgers.internal,
- &bal);
- if (bal != 0) {
- do_panic = TRUE;
- printf("LEDGER BALANCE proc %d (%s) "
- "\"internal\" = %lld\n",
- pid, procname, bal);
- if (bal > 0) {
- pmap_ledgers_drift.internal_over++;
- pmap_ledgers_drift.internal_over_total += bal;
- if (bal > pmap_ledgers_drift.internal_over_max) {
- pmap_ledgers_drift.internal_over_max = bal;
- }
- } else {
- pmap_ledgers_drift.internal_under++;
- pmap_ledgers_drift.internal_under_total += bal;
- if (bal < pmap_ledgers_drift.internal_under_max) {
- pmap_ledgers_drift.internal_under_max = bal;
- }
- }
- }
- ledger_get_balance(pmap->ledger,
- task_ledgers.internal_compressed,
- &bal);
- if (bal != 0) {
- do_panic = TRUE;
- printf("LEDGER BALANCE proc %d (%s) "
- "\"internal_compressed\" = %lld\n",
- pid, procname, bal);
- if (bal > 0) {
- pmap_ledgers_drift.internal_compressed_over++;
- pmap_ledgers_drift.internal_compressed_over_total += bal;
- if (bal > pmap_ledgers_drift.internal_compressed_over_max) {
- pmap_ledgers_drift.internal_compressed_over_max = bal;
- }
- } else {
- pmap_ledgers_drift.internal_compressed_under++;
- pmap_ledgers_drift.internal_compressed_under_total += bal;
- if (bal < pmap_ledgers_drift.internal_compressed_under_max) {
- pmap_ledgers_drift.internal_compressed_under_max = bal;
- }
- }
- }
- ledger_get_balance(pmap->ledger,
- task_ledgers.iokit_mapped,
- &bal);
- if (bal != 0) {
- do_panic = TRUE;
- printf("LEDGER BALANCE proc %d (%s) "
- "\"iokit_mapped\" = %lld\n",
- pid, procname, bal);
- if (bal > 0) {
- pmap_ledgers_drift.iokit_mapped_over++;
- pmap_ledgers_drift.iokit_mapped_over_total += bal;
- if (bal > pmap_ledgers_drift.iokit_mapped_over_max) {
- pmap_ledgers_drift.iokit_mapped_over_max = bal;
- }
- } else {
- pmap_ledgers_drift.iokit_mapped_under++;
- pmap_ledgers_drift.iokit_mapped_under_total += bal;
- if (bal < pmap_ledgers_drift.iokit_mapped_under_max) {
- pmap_ledgers_drift.iokit_mapped_under_max = bal;
- }
- }
- }
- ledger_get_balance(pmap->ledger,
- task_ledgers.alternate_accounting,
- &bal);
- if (bal != 0) {
- do_panic = TRUE;
- printf("LEDGER BALANCE proc %d (%s) "
- "\"alternate_accounting\" = %lld\n",
- pid, procname, bal);
- if (bal > 0) {
- pmap_ledgers_drift.alternate_accounting_over++;
- pmap_ledgers_drift.alternate_accounting_over_total += bal;
- if (bal > pmap_ledgers_drift.alternate_accounting_over_max) {
- pmap_ledgers_drift.alternate_accounting_over_max = bal;
- }
- } else {
- pmap_ledgers_drift.alternate_accounting_under++;
- pmap_ledgers_drift.alternate_accounting_under_total += bal;
- if (bal < pmap_ledgers_drift.alternate_accounting_under_max) {
- pmap_ledgers_drift.alternate_accounting_under_max = bal;
- }
- }
- }
- ledger_get_balance(pmap->ledger,
- task_ledgers.alternate_accounting_compressed,
- &bal);
- if (bal != 0) {
- do_panic = TRUE;
- printf("LEDGER BALANCE proc %d (%s) "
- "\"alternate_accounting_compressed\" = %lld\n",
- pid, procname, bal);
- if (bal > 0) {
- pmap_ledgers_drift.alternate_accounting_compressed_over++;
- pmap_ledgers_drift.alternate_accounting_compressed_over_total += bal;
- if (bal > pmap_ledgers_drift.alternate_accounting_compressed_over_max) {
- pmap_ledgers_drift.alternate_accounting_compressed_over_max = bal;
- }
- } else {
- pmap_ledgers_drift.alternate_accounting_compressed_under++;
- pmap_ledgers_drift.alternate_accounting_compressed_under_total += bal;
- if (bal < pmap_ledgers_drift.alternate_accounting_compressed_under_max) {
- pmap_ledgers_drift.alternate_accounting_compressed_under_max = bal;
- }
- }
- }
- ledger_get_balance(pmap->ledger,
- task_ledgers.page_table,
- &bal);
- if (bal != 0) {
- do_panic = TRUE;
- printf("LEDGER BALANCE proc %d (%s) "
- "\"page_table\" = %lld\n",
- pid, procname, bal);
- if (bal > 0) {
- pmap_ledgers_drift.page_table_over++;
- pmap_ledgers_drift.page_table_over_total += bal;
- if (bal > pmap_ledgers_drift.page_table_over_max) {
- pmap_ledgers_drift.page_table_over_max = bal;
- }
- } else {
- pmap_ledgers_drift.page_table_under++;
- pmap_ledgers_drift.page_table_under_total += bal;
- if (bal < pmap_ledgers_drift.page_table_under_max) {
- pmap_ledgers_drift.page_table_under_max = bal;
- }
- }
- }
- ledger_get_balance(pmap->ledger,
- task_ledgers.purgeable_volatile,
- &bal);
- if (bal != 0) {
- do_panic = TRUE;
- printf("LEDGER BALANCE proc %d (%s) "
- "\"purgeable_volatile\" = %lld\n",
- pid, procname, bal);
- if (bal > 0) {
- pmap_ledgers_drift.purgeable_volatile_over++;
- pmap_ledgers_drift.purgeable_volatile_over_total += bal;
- if (bal > pmap_ledgers_drift.purgeable_volatile_over_max) {
- pmap_ledgers_drift.purgeable_volatile_over_max = bal;
- }
- } else {
- pmap_ledgers_drift.purgeable_volatile_under++;
- pmap_ledgers_drift.purgeable_volatile_under_total += bal;
- if (bal < pmap_ledgers_drift.purgeable_volatile_under_max) {
- pmap_ledgers_drift.purgeable_volatile_under_max = bal;
- }
- }
- }
- ledger_get_balance(pmap->ledger,
- task_ledgers.purgeable_nonvolatile,
- &bal);
- if (bal != 0) {
- do_panic = TRUE;
- printf("LEDGER BALANCE proc %d (%s) "
- "\"purgeable_nonvolatile\" = %lld\n",
- pid, procname, bal);
- if (bal > 0) {
- pmap_ledgers_drift.purgeable_nonvolatile_over++;
- pmap_ledgers_drift.purgeable_nonvolatile_over_total += bal;
- if (bal > pmap_ledgers_drift.purgeable_nonvolatile_over_max) {
- pmap_ledgers_drift.purgeable_nonvolatile_over_max = bal;
- }
- } else {
- pmap_ledgers_drift.purgeable_nonvolatile_under++;
- pmap_ledgers_drift.purgeable_nonvolatile_under_total += bal;
- if (bal < pmap_ledgers_drift.purgeable_nonvolatile_under_max) {
- pmap_ledgers_drift.purgeable_nonvolatile_under_max = bal;
- }
- }
- }
- ledger_get_balance(pmap->ledger,
- task_ledgers.purgeable_volatile_compressed,
- &bal);
- if (bal != 0) {
- do_panic = TRUE;
- printf("LEDGER BALANCE proc %d (%s) "
- "\"purgeable_volatile_compressed\" = %lld\n",
- pid, procname, bal);
- if (bal > 0) {
- pmap_ledgers_drift.purgeable_volatile_compressed_over++;
- pmap_ledgers_drift.purgeable_volatile_compressed_over_total += bal;
- if (bal > pmap_ledgers_drift.purgeable_volatile_compressed_over_max) {
- pmap_ledgers_drift.purgeable_volatile_compressed_over_max = bal;
- }
- } else {
- pmap_ledgers_drift.purgeable_volatile_compressed_under++;
- pmap_ledgers_drift.purgeable_volatile_compressed_under_total += bal;
- if (bal < pmap_ledgers_drift.purgeable_volatile_compressed_under_max) {
- pmap_ledgers_drift.purgeable_volatile_compressed_under_max = bal;
- }
- }
- }
- ledger_get_balance(pmap->ledger,
- task_ledgers.purgeable_nonvolatile_compressed,
- &bal);
- if (bal != 0) {
- do_panic = TRUE;
- printf("LEDGER BALANCE proc %d (%s) "
- "\"purgeable_nonvolatile_compressed\" = %lld\n",
- pid, procname, bal);
- if (bal > 0) {
- pmap_ledgers_drift.purgeable_nonvolatile_compressed_over++;
- pmap_ledgers_drift.purgeable_nonvolatile_compressed_over_total += bal;
- if (bal > pmap_ledgers_drift.purgeable_nonvolatile_compressed_over_max) {
- pmap_ledgers_drift.purgeable_nonvolatile_compressed_over_max = bal;
- }
- } else {
- pmap_ledgers_drift.purgeable_nonvolatile_compressed_under++;
- pmap_ledgers_drift.purgeable_nonvolatile_compressed_under_total += bal;
- if (bal < pmap_ledgers_drift.purgeable_nonvolatile_compressed_under_max) {
- pmap_ledgers_drift.purgeable_nonvolatile_compressed_under_max = bal;
- }
- }
- }
+#define LEDGER_CHECK_BALANCE(__LEDGER) \
+MACRO_BEGIN \
+ int panic_on_negative = TRUE; \
+ ledger_get_balance(pmap->ledger, \
+ task_ledgers.__LEDGER, \
+ &bal); \
+ ledger_get_panic_on_negative(pmap->ledger, \
+ task_ledgers.__LEDGER, \
+ &panic_on_negative); \
+ if (bal != 0) { \
+ if (panic_on_negative || \
+ (pmap_ledgers_panic && \
+ pmap_ledgers_panic_leeway > 0 && \
+ (bal > (pmap_ledgers_panic_leeway * PAGE_SIZE) || \
+ bal < (pmap_ledgers_panic_leeway * PAGE_SIZE)))) { \
+ do_panic = TRUE; \
+ } \
+ printf("LEDGER BALANCE proc %d (%s) " \
+ "\"%s\" = %lld\n", \
+ pid, procname, #__LEDGER, bal); \
+ if (bal > 0) { \
+ pmap_ledgers_drift.__LEDGER##_over++; \
+ pmap_ledgers_drift.__LEDGER##_over_total += bal; \
+ if (bal > pmap_ledgers_drift.__LEDGER##_over_max) { \
+ pmap_ledgers_drift.__LEDGER##_over_max = bal; \
+ } \
+ } else if (bal < 0) { \
+ pmap_ledgers_drift.__LEDGER##_under++; \
+ pmap_ledgers_drift.__LEDGER##_under_total += bal; \
+ if (bal < pmap_ledgers_drift.__LEDGER##_under_max) { \
+ pmap_ledgers_drift.__LEDGER##_under_max = bal; \
+ } \
+ } \
+ } \
+MACRO_END
+
+ LEDGER_CHECK_BALANCE(phys_footprint);
+ LEDGER_CHECK_BALANCE(internal);
+ LEDGER_CHECK_BALANCE(internal_compressed);
+ LEDGER_CHECK_BALANCE(iokit_mapped);
+ LEDGER_CHECK_BALANCE(alternate_accounting);
+ LEDGER_CHECK_BALANCE(alternate_accounting_compressed);
+ LEDGER_CHECK_BALANCE(page_table);
+ LEDGER_CHECK_BALANCE(purgeable_volatile);
+ LEDGER_CHECK_BALANCE(purgeable_nonvolatile);
+ LEDGER_CHECK_BALANCE(purgeable_volatile_compressed);
+ LEDGER_CHECK_BALANCE(purgeable_nonvolatile_compressed);
+ LEDGER_CHECK_BALANCE(network_volatile);
+ LEDGER_CHECK_BALANCE(network_nonvolatile);
+ LEDGER_CHECK_BALANCE(network_volatile_compressed);
+ LEDGER_CHECK_BALANCE(network_nonvolatile_compressed);