From 9fb41b70a2c784d0b66f02d4bdedc0969ccb01ac Mon Sep 17 00:00:00 2001 From: Palak Chaturvedi Date: Fri, 7 Aug 2026 12:24:27 +0000 Subject: [PATCH] test_shmem: log smaps accounting details Add temporary LOG-level diagnostics around the existing /proc/self/smaps traversal. Record the target and contiguous VMA headers, each accounting field and running total, the stopping VMA, and the returned byte count without changing traversal or assertions. --- src/test/modules/test_shmem/test_shmem.c | 35 ++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/src/test/modules/test_shmem/test_shmem.c b/src/test/modules/test_shmem/test_shmem.c index 83f8ea9cc3c..d7a88f6f797 100644 --- a/src/test/modules/test_shmem/test_shmem.c +++ b/src/test/modules/test_shmem/test_shmem.c @@ -373,6 +373,9 @@ test_shmem_usage(PG_FUNCTION_ARGS) errcode_for_file_access(), errmsg("could not open /proc/self/smaps: %m")); + elog(LOG, "test_shmem smaps begin: pid=%d target=%p huge_pages=%s", + MyProcPid, resizable_shmem, use_hugetlb ? "on" : "off"); + while (fgets(line, sizeof(line), f) != NULL) { unsigned long start; @@ -388,10 +391,22 @@ test_shmem_usage(PG_FUNCTION_ARGS) * different mapping. */ if (start != prev_end) + { + elog(LOG, "test_shmem smaps stop before VMA: %.*s", + (int) strcspn(line, "\n"), line); break; + } + + elog(LOG, "test_shmem smaps include contiguous VMA: %.*s", + (int) strcspn(line, "\n"), line); } else + { in_target_vma = (target >= start && target < end); + if (in_target_vma) + elog(LOG, "test_shmem smaps include target VMA: %.*s", + (int) strcspn(line, "\n"), line); + } prev_end = end; } @@ -400,14 +415,29 @@ test_shmem_usage(PG_FUNCTION_ARGS) if (use_hugetlb) { if (sscanf(line, "Shared_Hugetlb: %ld kB", &val) == 1) + { total_shared_hugetlb_kb += val; + elog(LOG, "test_shmem smaps Shared_Hugetlb=" INT64_FORMAT + " kB, total=" INT64_FORMAT " kB", + val, total_shared_hugetlb_kb); + } } else { if (sscanf(line, "Rss: %ld kB", &val) == 1) + { total_rss_kb += val; + elog(LOG, "test_shmem smaps Rss=" INT64_FORMAT + " kB, total=" INT64_FORMAT " kB", + val, total_rss_kb); + } else if (sscanf(line, "Swap: %ld kB", &val) == 1) + { total_swap_kb += val; + elog(LOG, "test_shmem smaps Swap=" INT64_FORMAT + " kB, total=" INT64_FORMAT " kB", + val, total_swap_kb); + } } } } @@ -422,6 +452,11 @@ test_shmem_usage(PG_FUNCTION_ARGS) result = add_size(result, mul_size(total_swap_kb, 1024)); } + elog(LOG, "test_shmem smaps result: rss=" INT64_FORMAT + " kB swap=" INT64_FORMAT " kB shared_hugetlb=" INT64_FORMAT + " kB bytes=%zu", + total_rss_kb, total_swap_kb, total_shared_hugetlb_kb, result); + PG_RETURN_INT64(result); } -- 2.43.0