]> git.baikalelectronics.ru Git - kernel.git/commitdiff
x86/mm: track linear mapping split events
authorSaravanan D <saravanand@fb.com>
Wed, 5 May 2021 01:38:03 +0000 (18:38 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Wed, 5 May 2021 18:27:25 +0000 (11:27 -0700)
To help with debugging the sluggishness caused by TLB miss/reload, we
introduce monotonic hugepage [direct mapped] split event counts since
system state: SYSTEM_RUNNING to be displayed as part of /proc/vmstat in
x86 servers

The lifetime split event information will be displayed at the bottom of
/proc/vmstat
  ....
  swap_ra 0
  swap_ra_hit 0
  direct_map_level2_splits 94
  direct_map_level3_splits 4
  nr_unstable 0
  ....

One of the many lasting sources of direct hugepage splits is kernel
tracing (kprobes, tracepoints).

Note that the kernel's code segment [512 MB] points to the same physical
addresses that have been already mapped in the kernel's direct mapping
range.

Source : Documentation/x86/x86_64/mm.rst

When we enable kernel tracing, the kernel has to modify
attributes/permissions of the text segment hugepages that are direct
mapped causing them to split.

Kernel's direct mapped hugepages do not coalesce back after split and
remain in place for the remainder of the lifetime.

An instance of direct page splits when we turn on dynamic kernel tracing
....
cat /proc/vmstat | grep -i direct_map_level
direct_map_level2_splits 784
direct_map_level3_splits 12
bpftrace -e 'tracepoint:raw_syscalls:sys_enter { @ [pid, comm] =
count(); }'
cat /proc/vmstat | grep -i
direct_map_level
direct_map_level2_splits 789
direct_map_level3_splits 12
....

Link: https://lkml.kernel.org/r/20210218235744.1040634-1-saravanand@fb.com
Signed-off-by: Saravanan D <saravanand@fb.com>
Acked-by: Tejun Heo <tj@kernel.org>
Acked-by: Johannes Weiner <hannes@cmpxchg.org>
Acked-by: Dave Hansen <dave.hansen@linux.intel.com>
Cc: Ingo Molnar <mingo@redhat.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
arch/x86/mm/pat/set_memory.c
include/linux/vm_event_item.h
mm/vmstat.c

index 427980617557c173b533fe6f8b258f5dab29c014..156cd235659f3d516a4323f5a0498676b63fdbe6 100644 (file)
@@ -16,6 +16,8 @@
 #include <linux/pci.h>
 #include <linux/vmalloc.h>
 #include <linux/libnvdimm.h>
+#include <linux/vmstat.h>
+#include <linux/kernel.h>
 
 #include <asm/e820/api.h>
 #include <asm/processor.h>
@@ -91,6 +93,12 @@ static void split_page_count(int level)
                return;
 
        direct_pages_count[level]--;
+       if (system_state == SYSTEM_RUNNING) {
+               if (level == PG_LEVEL_2M)
+                       count_vm_event(DIRECT_MAP_LEVEL2_SPLIT);
+               else if (level == PG_LEVEL_1G)
+                       count_vm_event(DIRECT_MAP_LEVEL3_SPLIT);
+       }
        direct_pages_count[level - 1] += PTRS_PER_PTE;
 }
 
index 21d7c7f72f1c728d03ee6274fe2cde5287d5a9b9..ae0dd1948c2b0521dd8461f5d8828b7f6d25f7ed 100644 (file)
@@ -124,6 +124,10 @@ enum vm_event_item { PGPGIN, PGPGOUT, PSWPIN, PSWPOUT,
 #ifdef CONFIG_SWAP
                SWAP_RA,
                SWAP_RA_HIT,
+#endif
+#ifdef CONFIG_X86
+               DIRECT_MAP_LEVEL2_SPLIT,
+               DIRECT_MAP_LEVEL3_SPLIT,
 #endif
                NR_VM_EVENT_ITEMS
 };
index 06cd78dc914d74b2242d6f4724bba2f40f315682..5ba118521ded089f45d2a5663316f6b7bdfe55db 100644 (file)
@@ -1369,6 +1369,10 @@ const char * const vmstat_text[] = {
        "swap_ra",
        "swap_ra_hit",
 #endif
+#ifdef CONFIG_X86
+       "direct_map_level2_splits",
+       "direct_map_level3_splits",
+#endif
 #endif /* CONFIG_VM_EVENT_COUNTERS || CONFIG_MEMCG */
 };
 #endif /* CONFIG_PROC_FS || CONFIG_SYSFS || CONFIG_NUMA || CONFIG_MEMCG */