<!DOCTYPE html><html><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  </head>
  <body>
    <p>Hi Lianbo,<br>
    </p>
    <div class="moz-cite-prefix">在 2023/10/30 10:11, lijiang 写道:<br>
    </div>
    <blockquote type="cite" cite="mid:CANU+ZyfdfQMceGZTyMuwOECVEq=h0NReSx7um6+Pv_iFpJCu7g@mail.gmail.com">
      
      <div dir="ltr">
        <div dir="ltr">On Tue, Oct 24, 2023 at 3:12 PM <<a href="mailto:crash-utility-request@redhat.com" moz-do-not-send="true" class="moz-txt-link-freetext">crash-utility-request@redhat.com</a>>
          wrote:</div>
        <div class="gmail_quote">
          <blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
            Date: Tue, 24 Oct 2023 15:12:08 +0800<br>
            From: Huang Shijie <<a href="mailto:shijie@os.amperecomputing.com" target="_blank" moz-do-not-send="true" class="moz-txt-link-freetext">shijie@os.amperecomputing.com</a>><br>
            To: <a href="mailto:crash-utility@redhat.com" target="_blank" moz-do-not-send="true" class="moz-txt-link-freetext">crash-utility@redhat.com</a><br>
            Cc: <a href="mailto:patches@amperecomputing.com" target="_blank" moz-do-not-send="true" class="moz-txt-link-freetext">patches@amperecomputing.com</a>,
            <a href="mailto:k-hagio-ab@nec.com" target="_blank" moz-do-not-send="true" class="moz-txt-link-freetext">k-hagio-ab@nec.com</a>,
            Huang Shijie<br>
                    <<a href="mailto:shijie@os.amperecomputing.com" target="_blank" moz-do-not-send="true" class="moz-txt-link-freetext">shijie@os.amperecomputing.com</a>><br>
            Subject: [Crash-utility] [PATCH v2] add "files -n" command
            for an<br>
                    inode<br>
            Message-ID: <<a href="mailto:20231024071208.48472-1-shijie@os.amperecomputing.com" target="_blank" moz-do-not-send="true" class="moz-txt-link-freetext">20231024071208.48472-1-shijie@os.amperecomputing.com</a>><br>
            Content-Type: text/plain<br>
            <br>
            In the NUMA machine, it is useful to know the memory
            distribution of<br>
            an inode page cache:<br>
                    How many pages in the node 0?<br>
                    How many pages in the node 1?<br>
            <br>
            Add "files -n" command to get the memory distribution
            information:<br>
                    1.) Add new argument for
            dump_inode_page_cache_info()<br>
                    2.) make page_to_nid() a global function.<br>
                    3.) Add summary_inode_page() to check each page's
            node<br>
                        information.<br>
                    4.) Use print_inode_summary_info() to print the<br>
                        memory distribution information of an inode.<br>
            <br>
          </blockquote>
          <div><br>
          </div>
          <div>Thank you for the update, Shijie.</div>
          <div> </div>
          <blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
            Tested with the /proc/kcore.        <br>
            <br>
          </blockquote>
          <div><br>
          </div>
          <div>I just tested it and got an error:</div>
          <div><br>
          </div>
          <div>crash> files<br>
            PID: 286752   TASK: ffff8ea8421d8000  CPU: 11   COMMAND:
            "crash"<br>
            ROOT: /    CWD: /home/test/crash<br>
             FD       FILE            DENTRY           INODE       TYPE
            PATH<br>
              0 ffff8ea8514d0d00 ffff8ea87f2c9200 ffff8ea844548ea0 CHR
             /dev/pts/0<br>
              1 ffff8ea8514d0d00 ffff8ea87f2c9200 ffff8ea844548ea0 CHR
             /dev/pts/0<br>
              2 ffff8ea8514d0d00 ffff8ea87f2c9200 ffff8ea844548ea0 CHR
             /dev/pts/0<br>
              3 ffff8ea87bf81000 ffff8ea87040e780 ffff8ea872112a18 CHR
             /dev/null<br>
              4 ffff8ea84ade4a00 ffff8ea872e0c240 ffff8ea872ec64e0 REG
             /proc/kcore<br>
              5 ffff8ea84ade4700 ffff8ea8539c6540 ffff8ea84c130938 REG
             /home/linux/vmlinux<br>
              6 ffff8ea84ade5800 ffff8ea88ed22e40 ffff8ea874a9ee50 FIFO</div>
          <div><br>
          </div>
          <div>crash> files -n 0xffff8ea84c130938<br>
                 INODE        NRPAGES<br>
            ffff8ea84c130938    62845<br>
            <br>
            files: page_to_nid: invalid page: 0<br>
          </div>
        </div>
      </div>
    </blockquote>
    <p>It seem you meet an invalid page..</p>
    <p>I guess there is something wrong in the page_to_nid().</p>
    <p><br>
    </p>
    <p>Thanks</p>
    <p>Huang Shijie<br>
    </p>
    <blockquote type="cite" cite="mid:CANU+ZyfdfQMceGZTyMuwOECVEq=h0NReSx7um6+Pv_iFpJCu7g@mail.gmail.com">
      <div dir="ltr">
        <div class="gmail_quote">
          <div>files: do_xarray: callback operation failed: entry: 1
             item: 0<br>
            <br>
            crash> files -n 0xffff8ea844548ea0<br>
                 INODE        NRPAGES<br>
            ffff8ea844548ea0        0<br>
            <br>
                 NODE           PAGES<br>
                  0                 0<br>
                  1                 0<br>
          </div>
          <div><br>
          </div>
          <div>Did I miss anything or Is this another issue? </div>
          <div><br>
          </div>
          <div>Thanks.</div>
          <div>Lianbo</div>
          <div><br>
          </div>
          <blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
            Signed-off-by: Huang Shijie <<a href="mailto:shijie@os.amperecomputing.com" target="_blank" moz-do-not-send="true" class="moz-txt-link-freetext">shijie@os.amperecomputing.com</a>><br>
            ---<br>
            v1 --> v2:<br>
                    1.) rebased the code on the latest tree.<br>
                    2.) added return value for summary_inode_page().<br>
                    3.) Changed the output format.<br>
                    4.) Changed the ulong.<br>
                    5.) others.     <br>
            ---<br>
             defs.h    |  1 +<br>
             filesys.c | 55
            ++++++++++++++++++++++++++++++++++++++++++++++++++-----<br>
             help.c    | 12 +++++++++++-<br>
             memory.c  |  3 +--<br>
             4 files changed, 63 insertions(+), 8 deletions(-)<br>
            <br>
            diff --git a/defs.h b/defs.h<br>
            index 788f63a..1fe2d0b 100644<br>
            --- a/defs.h<br>
            +++ b/defs.h<br>
            @@ -5750,6 +5750,7 @@ int dump_inode_page(ulong);<br>
             ulong valid_section_nr(ulong);<br>
             void display_memory_from_file_offset(ulonglong, long, void
            *);<br>
             void swap_info_init(void);<br>
            +int page_to_nid(ulong);<br>
            <br>
             /*<br>
              *  filesys.c <br>
            diff --git a/filesys.c b/filesys.c<br>
            index 1d0ee7f..81be108 100644<br>
            --- a/filesys.c<br>
            +++ b/filesys.c<br>
            @@ -49,7 +49,7 @@ static int match_file_string(char *, char
            *, char *);<br>
             static ulong get_root_vfsmount(char *);<br>
             static void check_live_arch_mismatch(void);<br>
             static long get_inode_nrpages(ulong);<br>
            -static void dump_inode_page_cache_info(ulong);<br>
            +static void dump_inode_page_cache_info(ulong, void
            *callback);<br>
            <br>
             #define DENTRY_CACHE (20)<br>
             #define INODE_CACHE  (20)<br>
            @@ -2192,8 +2192,33 @@ get_inode_nrpages(ulong i_mapping)<br>
                    return nrpages;<br>
             }<br>
            <br>
            +/* Used to collect the numa information for an inode */<br>
            +static ulong *numa_node;<br>
            +<br>
            +static void<br>
            +print_inode_summary_info(void)<br>
            +{<br>
            +       int i;<br>
            +<br>
            +       fprintf(fp, "     NODE           PAGES\n");<br>
            +       for (i = 0; i < vt->numnodes; i++)<br>
            +               fprintf(fp, "     %2d          %8ld\n", i,
            numa_node[i]);<br>
            +}<br>
            +<br>
            +static int<br>
            +summary_inode_page(ulong page)<br>
            +{<br>
            +       int node = page_to_nid(page);<br>
            +<br>
            +       if (0 <= node && node <
            vt->numnodes) {<br>
            +               numa_node[node]++;<br>
            +               return 1;<br>
            +       }<br>
            +       return 0;<br>
            +}<br>
            +<br>
             static void<br>
            -dump_inode_page_cache_info(ulong inode)<br>
            +dump_inode_page_cache_info(ulong inode, void *callback)<br>
             {<br>
                    char *inode_buf;<br>
                    ulong i_mapping, nrpages, root_rnode, xarray, count;<br>
            @@ -2236,7 +2261,7 @@ dump_inode_page_cache_info(ulong
            inode)<br>
                            root_rnode = i_mapping +
            OFFSET(address_space_page_tree);<br>
            <br>
                    lp.index = 0;<br>
            -       lp.value = (void *)&dump_inode_page;<br>
            +       lp.value = callback;<br>
            <br>
                    if (root_rnode)<br>
                            count = do_radix_tree(root_rnode,
            RADIX_TREE_DUMP_CB, &lp);<br>
            @@ -2276,7 +2301,7 @@ cmd_files(void)<br>
                     ref = NULL;<br>
                     refarg = NULL;<br>
            <br>
            -        while ((c = getopt(argcnt, args, "d:R:p:c")) !=
            EOF) {<br>
            +        while ((c = getopt(argcnt, args, "d:n:R:p:c")) !=
            EOF) {<br>
                             switch(c)<br>
                            {<br>
                            case 'R':<br>
            @@ -2295,11 +2320,31 @@ cmd_files(void)<br>
                                    display_dentry_info(value);<br>
                                    return;<br>
            <br>
            +               case 'n':<br>
            +                       if
            (VALID_MEMBER(address_space_page_tree) &&<br>
            +                           VALID_MEMBER(inode_i_mapping)) {<br>
            +                               value = htol(optarg,
            FAULT_ON_ERROR, NULL);<br>
            +<br>
            +                               /* Allocate the array for
            this inode */<br>
            +                               numa_node =
            malloc(sizeof(ulong) * vt->numnodes);<br>
            +                               BZERO(numa_node,
            sizeof(ulong) * vt->numnodes);<br>
            +<br>
            +                             
             dump_inode_page_cache_info(value, (void
            *)&summary_inode_page);<br>
            +<br>
            +                               /* Print out the NUMA node
            information for this inode */<br>
            +                               print_inode_summary_info();<br>
            +<br>
            +                               free(numa_node);<br>
            +                               numa_node = NULL;<br>
            +                       } else<br>
            +                               option_not_supported('n');<br>
            +                       return;<br>
            +<br>
                            case 'p':<br>
                                    if
            (VALID_MEMBER(address_space_page_tree) &&<br>
                                        VALID_MEMBER(inode_i_mapping)) {<br>
                                            value = htol(optarg,
            FAULT_ON_ERROR, NULL);<br>
            -                             
             dump_inode_page_cache_info(value);<br>
            +                             
             dump_inode_page_cache_info(value, (void
            *)&dump_inode_page);<br>
                                    } else<br>
                                            option_not_supported('p');<br>
                                    return;<br>
            diff --git a/help.c b/help.c<br>
            index cc7ab20..f0f9139 100644<br>
            --- a/help.c<br>
            +++ b/help.c<br>
            @@ -7850,7 +7850,7 @@ NULL<br>
             char *help_files[] = {<br>
             "files",<br>
             "open files",<br>
            -"[-d dentry] | [-p inode] | [-c] [-R reference] [pid |
            taskp] ... ",<br>
            +"[-d dentry] | [-p inode] | [-n inode] | [-c] [-R
            reference] [pid | taskp] ... ",<br>
             "  This command displays information about open files of a
            context.",<br>
             "  It prints the context's current root directory and
            current working", <br>
             "  directory, and then for each open file descriptor it
            prints a pointer",<br>
            @@ -7863,6 +7863,8 @@ char *help_files[] = {<br>
             "  specific, and only shows the data requested.\n",<br>
             "     -d dentry  given a hexadecimal dentry address,
            display its inode,",<br>
             "                super block, file type, and full
            pathname.",<br>
            +"     -n inode   given a hexadecimal inode address, check
            all the pages",<br>
            +"                in the page cache, and display a NUMA node
            distribution.",<br>
             "     -p inode   given a hexadecimal inode address, dump
            all of its pages",<br>
             "                that are in the page cache.",<br>
             "     -c         for each open file descriptor, prints a
            pointer to its",<br>
            @@ -7974,6 +7976,14 @@ char *help_files[] = {<br>
             "    ca1ddde0  2eeef000  f59b91ac        3  2 82c
            referenced,uptodate,lru,private",<br>
             "    ca36b300  3b598000  f59b91ac        4  2 82c
            referenced,uptodate,lru,private",<br>
             "    ca202680  30134000  f59b91ac        5  2 82c
            referenced,uptodate,lru,private",<br>
            +"    ",<br>
            +"    %s> files -n ffff07ff8c6f97f8",<br>
            +"      INODE        NRPAGES",<br>
            +" ffff07ff8c6f97f8    25240",<br>
            +"    ",<br>
            +"      NODE           PAGES",<br>
            +"       0             25240",<br>
            +"       1                 0",<br>
             " ",<br>
             NULL               <br>
             };<br>
            diff --git a/memory.c b/memory.c<br>
            index 86ccec5..ed1a4fb 100644<br>
            --- a/memory.c<br>
            +++ b/memory.c<br>
            @@ -300,7 +300,6 @@ static int dump_vm_event_state(void);<br>
             static int dump_page_states(void);<br>
             static int generic_read_dumpfile(ulonglong, void *, long,
            char *, ulong);<br>
             static int generic_write_dumpfile(ulonglong, void *, long,
            char *, ulong);<br>
            -static int page_to_nid(ulong);<br>
             static int get_kmem_cache_list(ulong **);<br>
             static int get_kmem_cache_root_list(ulong **);<br>
             static int get_kmem_cache_child_list(ulong **, ulong);<br>
            @@ -19846,7 +19845,7 @@ is_kmem_cache_addr_common(ulong
            vaddr, char *kbuf)<br>
             /*<br>
              *  Kernel-config-neutral page-to-node evaluator.<br>
              */<br>
            -static int <br>
            +int<br>
             page_to_nid(ulong page)<br>
             {<br>
                     int i;<br>
            -- <br>
            2.40.1<br>
          </blockquote>
        </div>
      </div>
    </blockquote>
  </body>
</html>