Skip to content

Commit

Permalink
arm64: Fix "vtop" command to display swap information on Linux 5.19 a…
Browse files Browse the repository at this point in the history
…nd later

Kernel commit 570ef363509b ("arm64/pgtable: support
__HAVE_ARCH_PTE_SWP_EXCLUSIVE"), which is contained in Linux 5.19 and
later kernels, changed the format of swap entries on arm64.  Without the
patch, the "vtop" command cannot display swap information.

Before:
  crash> vtop 70504000
  VIRTUAL     PHYSICAL
  70504000    (not mapped)

  PAGE DIRECTORY: ffffff80f265c000
     PGD: ffffff80f265c008 => 800000141537003
     PMD: ffffff8101537c10 => 800000141538003
     PTE: ffffff8101538820 => 12bc3e04

    PTE     vtop: cannot determine swap location

After:
  crash> vtop 70504000
  VIRTUAL     PHYSICAL
  70504000    (not mapped)

  PAGE DIRECTORY: ffffff80f265c000
     PGD: ffffff80f265c008 => 800000141537003
     PMD: ffffff8101537c10 => 800000141538003
     PTE: ffffff8101538820 => 12bc3e04

    PTE                     SWAP                  OFFSET
  12bc3e04  /first_stage_ramdisk/dev/block/zram0  1227838

        VMA           START       END     FLAGS FILE
  ffffff80dfe7b578   70504000   707bd000 100073

  SWAP: /first_stage_ramdisk/dev/block/zram0  OFFSET: 1227838

Signed-off-by: chenguanyou <chenguanyou@xiaomi.com>
Signed-off-by: Kazuhito Hagio <k-hagio-ab@nec.com>
  • Loading branch information
chenguanyou authored and k-hagio committed Sep 28, 2023
1 parent a9291fc commit c9a732d
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions arm64.c
Expand Up @@ -468,8 +468,16 @@ arm64_init(int when)
}
}


if (THIS_KERNEL_VERSION >= LINUX(4,0,0)) {
if (THIS_KERNEL_VERSION >= LINUX(5,19,0)) {
ms->__SWP_TYPE_BITS = 5;
ms->__SWP_TYPE_SHIFT = 3;
ms->__SWP_TYPE_MASK = ((1UL << ms->__SWP_TYPE_BITS) - 1);
ms->__SWP_OFFSET_SHIFT = (ms->__SWP_TYPE_BITS + ms->__SWP_TYPE_SHIFT);
ms->__SWP_OFFSET_BITS = 50;
ms->__SWP_OFFSET_MASK = ((1UL << ms->__SWP_OFFSET_BITS) - 1);
ms->PTE_PROT_NONE = (1UL << 58);
ms->PTE_FILE = 0; /* unused */
} else if (THIS_KERNEL_VERSION >= LINUX(4,0,0)) {
ms->__SWP_TYPE_BITS = 6;
ms->__SWP_TYPE_SHIFT = 2;
ms->__SWP_TYPE_MASK = ((1UL << ms->__SWP_TYPE_BITS) - 1);
Expand Down

0 comments on commit c9a732d

Please sign in to comment.