[Crash-utility] [PATCH 2/2] Move NAME column in "kmem -s" output to the last of line

2018-07-30 Thread Kazuhito Hagio
For readability, move NAME column in "kmem -s" output to the last of line.
---
 help.c   | 136 +++
 memory.c |  44 +
 2 files changed, 78 insertions(+), 102 deletions(-)

diff --git a/help.c b/help.c
index 83cda7c..a189038 100644
--- a/help.c
+++ b/help.c
@@ -6692,8 +6692,8 @@ char *help_kmem[] = {
 "  Find all of the combined slab/page structures that are used by",
 "  the kmalloc-8192 slab cache:\n",
 "%s> kmem -s kmalloc-8192",
-"CACHENAME OBJSIZE  ALLOCATED TOTAL  SLABS  
SSIZE",
-"880215802e00 kmalloc-81928192 6580 20
32k",
+"CACHE OBJSIZE  ALLOCATED TOTAL  SLABS  SSIZE  NAME",
+"880215802e00 8192 6580 2032k  
kmalloc-8192",
 "%s> kmem -m slab_cache | grep 880215802e00",
 "ea0004117800  880215802e00  ",
 "ea00041ca600  880215802e00  ",
@@ -6889,72 +6889,72 @@ char *help_kmem[] = {
 " ",
 "  Display kmalloc() slab data:\n",
 "%s> kmem -s",
-"CACHE NAMEOBJSIZE  ALLOCATED TOTAL  SLABS  SSIZE",
-"c02eadc0 kmem_cache   232 5868  4 4k",
-"f79c2888 ip_vs_conn   128  0 0  0 4k",
-"f79c2970 tcp_tw_bucket 96  0 0  0 4k",
-"f79c2a58 tcp_bind_bucket   32 12   565  5 4k",
-"f79c2b40 tcp_open_request  64  059  1 4k",
-"f79c2c28 inet_peer_cache   64  159  1 4k",
-"f79c2d10 ip_fib_hash   32 11   339  3 4k",
-"f79c2df8 ip_dst_cache 160  8   120  5 4k",
-"f79c2ee0 arp_cache128  130  1 4k",
-"c8402970 blkdev_requests   96  30208 37800945 4k",
-"c8402a58 nfs_read_data384  0 0  0 4k",
-"c8402b40 nfs_write_data   384  0 0  0 4k",
-"c8402c28 nfs_page  96  0 0  0 4k",
-"c8402d10 dnotify cache 20  0 0  0 4k",
-"c8402df8 file lock cache   92  3   336  8 4k",
-"c8402ee0 fasync cache  16  0 0  0 4k",
-"c84027a0 uid_cache 32  3   339  3 4k",
-"c84026b8 skbuff_head_cache160320   624 26 4k",
-"c84025d0 sock 832 32   180 20 8k",
-"c84024e8 sigqueue 132  0   203  7 4k",
-"c8402400 cdev_cache64 19   472  8 4k",
-"c8402318 bdev_cache64  8   236  4 4k",
-"c8402230 mnt_cache 96 11   120  3 4k",
-"c8402148 inode_cache  480817   848106 4k",
-"c8402060 dentry_cache 128   1352  1470 49 4k",
-"c8403ee0 filp  96244   440 11 4k",
-"c8403df8 names_cache 4096  012 12 4k",
-"c8403d10 buffer_head   96  14936 16000400 4k",
-"c8403c28 mm_struct128 25   240  8 4k",
-"c8403b40 vm_area_struct64393  1298 22 4k",
-"c8403a58 fs_cache  64 30   472  8 4k",
-"c8403970 files_cache  416 30   135 15 4k",
-"c8403888 signal_act  1312 3299 33 4k",
-"c84037a0 size-131072(DMA)  131072  0 0  0   128k",
-"c84036b8 size-131072   131072  1 1  1   128k",
-"c84035d0 size-65536(DMA)65536  0 0  064k",
-"c84034e8 size-65536 65536  0 0  064k",
-"c8403400 size-32768(DMA)32768  0 0  032k",
-"c8403318 size-32768 32768  0 1  132k",
-"c8403230 size-16384(DMA)16384  0 0  016k",
-"c8403148 size-16384 16384  0 0  016k",
-"c8403060 size-8192(DMA)  8192  0 0  0 8k",
-"c8401ee0 size-8192   8192  1 2  2 8k",
-"c8401df8 size-4096(DMA)  4096  0 0  0 4k",
-"c8401d10 size-4096   4096 3030 30 4k",
-"c8401c28 size-2048(DMA)  2048  0 0  0 4k",
-"c8401b40 size-2048   2048 37   132 66 4k",
-"

[Crash-utility] [PATCH 1/2] Unify the three functions printing "kmem -s" line into one function

2018-07-30 Thread Kazuhito Hagio
In preparation for moving NAME column in "kmem -s" line, unify the three
functions printing it into one function.
---
 memory.c | 124 ---
 1 file changed, 39 insertions(+), 85 deletions(-)

diff --git a/memory.c b/memory.c
index 81ed689..2e48d7b 100644
--- a/memory.c
+++ b/memory.c
@@ -172,7 +172,6 @@ static void dump_kmem_cache(struct meminfo *);
 static void dump_kmem_cache_percpu_v1(struct meminfo *);
 static void dump_kmem_cache_percpu_v2(struct meminfo *);
 static void dump_kmem_cache_slub(struct meminfo *);
-static void dump_kmem_cache_info_v2(struct meminfo *);
 static void kmem_cache_list_common(void);
 static ulong get_cpu_slab_ptr(struct meminfo *, int, ulong *);
 static unsigned int oo_order(ulong);
@@ -9964,55 +9963,60 @@ ignore_cache(struct meminfo *si, char *name)
 #define KMEM_SLAB_OVERLOAD_PAGE (8)
 #define KMEM_SLAB_FREELIST  (9)
 
-#define DUMP_KMEM_CACHE_INFO_V1() \
-  {  \
-   char b1[BUFSIZE]; \
-   fprintf(fp, "%s %-18s  %8ld  ", \
-   mkstring(b1, VADDR_PRLEN, LJUST|LONG_HEX, MKSTR(si->cache)), \
-   buf, si->size); \
-fprintf(fp, "%9ld  %8ld  %5ld   %3ldk\n", \
-   vt->flags & PERCPU_KMALLOC_V1 ? \
-   si->inuse - si->cpucached_cache : \
-si->inuse, si->num_slabs * si->c_num, \
-si->num_slabs, si->slabsize/1024); \
-  }
-
-#define DUMP_KMEM_CACHE_INFO_V2()  dump_kmem_cache_info_v2(si) 
+#define DUMP_KMEM_CACHE_INFO()  dump_kmem_cache_info(si)
 
 static void
-dump_kmem_cache_info_v2(struct meminfo *si)
+dump_kmem_cache_info(struct meminfo *si)
 {
char b1[BUFSIZE];
char b2[BUFSIZE];
int namelen, sizelen, spacelen;
+   ulong objsize, allocated, total;
+
+   if (si->flags & SLAB_GATHER_FAILURE)
+   error(INFO, "%s: cannot gather relevant slab data\n", 
si->curname);
 
fprintf(fp, "%s ",
mkstring(b1, VADDR_PRLEN, LJUST|LONG_HEX, MKSTR(si->cache))); 
 
+   objsize = (vt->flags & KMALLOC_SLUB) ? si->objsize : si->size;
+
namelen = strlen(si->curname);
-   sprintf(b2, "%ld", si->size);
+   sprintf(b2, "%ld", objsize);
sizelen = strlen(b2);
spacelen = 0;
 
if (namelen++ > 18) {
spacelen = 29 - namelen - sizelen;
fprintf(fp, "%s%s%ld  ", si->curname,
-   space(spacelen <= 0 ? 1 : spacelen), si->size); 
+   space(spacelen <= 0 ? 1 : spacelen), objsize);
if (spacelen > 0)
spacelen = 1;
-   sprintf(b1, "%c%dld  ", '%', 9 + spacelen - 1);
+   if (si->flags & SLAB_GATHER_FAILURE)
+   sprintf(b1, "%c%ds  ", '%', 9 + spacelen - 1);
+   else
+   sprintf(b1, "%c%dld  ", '%', 9 + spacelen - 1);
} else {
-   fprintf(fp, "%-18s  %8ld  ", si->curname, si->size); 
-   sprintf(b1, "%c%dld  ", '%', 9);
+   fprintf(fp, "%-18s  %8ld  ", si->curname, objsize);
+   if (si->flags & SLAB_GATHER_FAILURE)
+   sprintf(b1, "%c%ds  ", '%', 9);
+   else
+   sprintf(b1, "%c%dld  ", '%', 9);
}
 
-fprintf(fp, b1, vt->flags & (PERCPU_KMALLOC_V2) ?
-si->inuse - si->cpucached_cache : si->inuse); 
-
-   fprintf(fp, "%8ld %s%5ld  %s%3ldk\n",
-   si->num_slabs * si->c_num, 
-   si->num_slabs < 10 ? " " : "", si->num_slabs, 
-   (si->slabsize/1024) < 1000 ? " " : "", si->slabsize/1024); 
+   if (si->flags & SLAB_GATHER_FAILURE) {
+   fprintf(fp, b1, "?");
+   fprintf(fp, "%8s  %5s  %4ldk\n",
+   "?", "?", si->slabsize/1024);
+   } else {
+   allocated = (vt->flags & (PERCPU_KMALLOC_V1|PERCPU_KMALLOC_V2)) 
?
+   si->inuse - si->cpucached_cache : si->inuse;
+   total = (vt->flags & KMALLOC_SLUB) ?
+   si->inuse + si->free : si->num_slabs * 
si->c_num;
+   fprintf(fp, b1, allocated);
+   fprintf(fp, "%8ld  %5ld  %4ldk\n", total,
+   si->num_slabs, si->slabsize/1024);
+   }
 }
 
 #define DUMP_SLAB_INFO() \
@@ -10152,7 +10156,7 @@ dump_kmem_cache(struct meminfo *si)
do_slab_chain(SLAB_GET_COUNTS, si);
 
if (!(si->flags & (ADDRESS_SPECIFIED|GET_SLAB_PAGES))) 
-   DUMP_KMEM_CACHE_INFO_V1();
+   DUMP_KMEM_CACHE_INFO();
 
if (si->flags == GET_SLAB_PAGES) 
si->retval += (si->num_slabs * 
@@ -10166,7 +10170,7 @@ dump_kmem_cache(struct meminfo *si)
 
if (si->found) {
fprintf(fp, "%s", 

[Crash-utility] [PATCH 0/2] Move NAME column in "kmem -s" output to the last of line

2018-07-30 Thread Kazuhito Hagio
Nowadays, "kmem -s" output can have long lines due to cache name with
memcg name, and I don't think that it's human-readable as it is.

crash> kmem -s
CACHENAME OBJSIZE  ALLOCATED TOTAL  SLABS  SSIZE
8a1522c15380 kmalloc-128(12536:session-11.scope) 128  111   128  4  
   4k
8a1522c15200 radix_tree_node(12536:session-11.scope) 576  340  434  
   31 8k
8a1523d15380 xfs_inode(12536:session-11.scope) 904  1567  1581 93   
 16k
8a1522c15080 nfs_inode_cache(12536:session-11.scope) 1072  140   
165 1116k
8a1523d14c00 shmem_inode_cache(12536:session-11.scope) 696  0   
46  216k

So, can we move the 'NAME' column to the last of line like this?

crash> kmem -s
CACHE OBJSIZE  ALLOCATED TOTAL  SLABS  SSIZE  NAME
8a1522c15380  128111   128  4 4k  
kmalloc-128(12536:session-11.scope)
8a1522c15200  576340   434 31 8k  
radix_tree_node(12536:session-11.scope)
8a1523d15380  904   1567  1581 9316k  
xfs_inode(12536:session-11.scope)
8a1522c15080 1072140   165 1116k  
nfs_inode_cache(12536:session-11.scope)
8a1523d14c00  696  046  216k  
shmem_inode_cache(12536:session-11.scope)

If we can, crash has the three functions to print them for each slab/slub
version and I think that it would be good to change all of them together.
Fortunately, the header is same among them, and it looks like we can unify
them into one function. [Patch 1]

And then, move it to the last of line. [Patch 2]

I tested this with some vmcores having PERCPU_KMALLOC_V2 or KMALLOC_SLUB
and found no problem, but I don't have any vmcores having PERCPU_KMALLOC_V1
or no flag.

Kazuhito Hagio (2):
  Unify the three functions printing "kmem -s" line into one function
  Move NAME column in "kmem -s" output to the last of line

 help.c   | 136 +++
 memory.c | 132 +++--
 2 files changed, 99 insertions(+), 169 deletions(-)

-- 
1.8.3.1

--
Crash-utility mailing list
Crash-utility@redhat.com
https://www.redhat.com/mailman/listinfo/crash-utility


Re: [Crash-utility] [PATCH 0/2] Move NAME column in "kmem -s" output to the last of line

2018-07-30 Thread anderson
Hi Kazu,
I'll be back from vacation next week, and I'll take a look at the patch then.  
Sounds like a reasonable idea, and I have plenty of "old" sample vmcores.
Thanks,  Dave




Sent from my Verizon, Samsung Galaxy smartphone
 Original message From: Kazuhito Hagio  
Date: 7/30/18  12:28 PM  (GMT-05:00) To: crash-utility@redhat.com Subject: 
[Crash-utility] [PATCH 0/2] Move NAME column in "kmem -s" output to
the last of line 
Nowadays, "kmem -s" output can have long lines due to cache name with
memcg name, and I don't think that it's human-readable as it is.

crash> kmem -s
CACHE    NAME OBJSIZE  ALLOCATED TOTAL  SLABS  SSIZE
8a1522c15380 kmalloc-128(12536:session-11.scope) 128  111   128  4  
   4k
8a1522c15200 radix_tree_node(12536:session-11.scope) 576  340  434  
   31 8k
8a1523d15380 xfs_inode(12536:session-11.scope) 904  1567  1581 93   
 16k
8a1522c15080 nfs_inode_cache(12536:session-11.scope) 1072  140   
165 11    16k
8a1523d14c00 shmem_inode_cache(12536:session-11.scope) 696  0   
46  2    16k

So, can we move the 'NAME' column to the last of line like this?

crash> kmem -s
CACHE OBJSIZE  ALLOCATED TOTAL  SLABS  SSIZE  NAME
8a1522c15380  128    111   128  4 4k  
kmalloc-128(12536:session-11.scope)
8a1522c15200  576    340   434 31 8k  
radix_tree_node(12536:session-11.scope)
8a1523d15380  904   1567  1581 93    16k  
xfs_inode(12536:session-11.scope)
8a1522c15080 1072    140   165 11    16k  
nfs_inode_cache(12536:session-11.scope)
8a1523d14c00  696  0    46  2    16k  
shmem_inode_cache(12536:session-11.scope)

If we can, crash has the three functions to print them for each slab/slub
version and I think that it would be good to change all of them together.
Fortunately, the header is same among them, and it looks like we can unify
them into one function. [Patch 1]

And then, move it to the last of line. [Patch 2]

I tested this with some vmcores having PERCPU_KMALLOC_V2 or KMALLOC_SLUB
and found no problem, but I don't have any vmcores having PERCPU_KMALLOC_V1
or no flag.

Kazuhito Hagio (2):
  Unify the three functions printing "kmem -s" line into one function
  Move NAME column in "kmem -s" output to the last of line

 help.c   | 136 +++
 memory.c | 132 +++--
 2 files changed, 99 insertions(+), 169 deletions(-)

-- 
1.8.3.1

--
Crash-utility mailing list
Crash-utility@redhat.com
https://www.redhat.com/mailman/listinfo/crash-utility

--
Crash-utility mailing list
Crash-utility@redhat.com
https://www.redhat.com/mailman/listinfo/crash-utility

[Crash-utility] [PATCH] fix open fds display when process using large amount of file descriptors

2018-07-30 Thread Tan Hu
Usually, structure fd_set only has 1024 bits size, when a process
using large amount of file descriptors that exceed the size of fd_set,
then the display of files and net sockets would mistake caused by the
out of bounds reading in loop.

Signed-off-by: Tan Hu 
---
 filesys.c | 24 ++--
 net.c | 17 +
 2 files changed, 31 insertions(+), 10 deletions(-)

diff --git a/filesys.c b/filesys.c
index 0ace8f4..47f5a24 100755
--- a/filesys.c
+++ b/filesys.c
@@ -2380,7 +2380,8 @@ open_files_dump(ulong task, int flags, struct reference 
*ref)
int max_fdset = 0;
int max_fds = 0;
ulong open_fds_addr;
-   fd_set open_fds;
+   int open_fds_size;
+   ulong *open_fds;
ulong fd;
ulong file;
ulong value;
@@ -2583,16 +2584,25 @@ open_files_dump(ulong task, int flags, struct reference 
*ref)
open_fds_addr = ULONG(files_struct_buf +
OFFSET(files_struct_open_fds));
 
+   open_fds_size = MAX(max_fdset, max_fds) / BITS_PER_BYTE;
+   open_fds = (ulong *)GETBUF(open_fds_size);
+   if (!open_fds) {
+   if (fdtable_buf)
+   FREEBUF(fdtable_buf);
+   FREEBUF(files_struct_buf);
+   return;
+   }
+
if (open_fds_addr) {
if (VALID_MEMBER(files_struct_open_fds_init) && 
(open_fds_addr == (files_struct_addr + 
OFFSET(files_struct_open_fds_init 
BCOPY(files_struct_buf + 
OFFSET(files_struct_open_fds_init),
-   _fds, sizeof(fd_set));
+   open_fds, open_fds_size);
else
-   readmem(open_fds_addr, KVADDR, _fds,
-   sizeof(fd_set), "fdtable open_fds",
+   readmem(open_fds_addr, KVADDR, open_fds,
+   open_fds_size, "fdtable open_fds",
FAULT_ON_ERROR);
} 
 
@@ -2607,6 +2617,7 @@ open_files_dump(ulong task, int flags, struct reference 
*ref)
if (fdtable_buf)
FREEBUF(fdtable_buf);
FREEBUF(files_struct_buf);
+   FREEBUF(open_fds);
return;
}
 
@@ -2617,11 +2628,11 @@ open_files_dump(ulong task, int flags, struct reference 
*ref)
j = 0;
for (;;) {
unsigned long set;
-   i = j * __NFDBITS;
+   i = j * BITS_PER_LONG;
if (((max_fdset >= 0) && (i >= max_fdset)) || 
(i >= max_fds))
 break;
-   set = open_fds.__fds_bits[j++];
+   set = open_fds[j++];
while (set) {
if (set & 1) {
readmem(fd + i*sizeof(struct file *), KVADDR, 
@@ -2665,6 +2676,7 @@ open_files_dump(ulong task, int flags, struct reference 
*ref)
if (fdtable_buf)
FREEBUF(fdtable_buf);
FREEBUF(files_struct_buf);
+   FREEBUF(open_fds);
 }
 
 /*
diff --git a/net.c b/net.c
index 4199091..f08f22a 100755
--- a/net.c
+++ b/net.c
@@ -1373,7 +1373,8 @@ dump_sockets_workhorse(ulong task, ulong flag, struct 
reference *ref)
int max_fdset = 0;
int max_fds = 0;
ulong open_fds_addr = 0;
-   fd_set open_fds;
+   ulong *open_fds;
+   int open_fds_size;
ulong fd;
ulong file;
int i, j;
@@ -1446,12 +1447,18 @@ dump_sockets_workhorse(ulong task, ulong flag, struct 
reference *ref)
sizeof(void *), "files_struct fd addr", FAULT_ON_ERROR);
}
 
+   open_fds_size = MAX(max_fdset, max_fds) / BITS_PER_BYTE;
+   open_fds = (ulong *)GETBUF(open_fds_size);
+   if (!open_fds)
+   return;
+
if (open_fds_addr) 
-   readmem(open_fds_addr, KVADDR, _fds, sizeof(fd_set),
+   readmem(open_fds_addr, KVADDR, open_fds, open_fds_size,
"files_struct open_fds", FAULT_ON_ERROR);
if (!open_fds_addr || !fd) { 
if (!NET_REFERENCE_CHECK(ref))
fprintf(fp, "No open sockets.\n");
+   FREEBUF(open_fds);
return;
}
 
@@ -1479,10 +1486,10 @@ dump_sockets_workhorse(ulong task, ulong flag, struct 
reference *ref)
j = 0;
for (;;) {
unsigned long set;
-   i = j * __NFDBITS;
+   i = j * BITS_PER_LONG;
if (((max_fdset >= 0) && (i >= max_fdset)) || (i >= max_fds))
break;
-   set = open_fds.__fds_bits[j++];
+   set = open_fds[j++];
while (set) {
if (set & 1) {
readmem(fd + i*sizeof(struct file *), KVADDR, 
@@ -1505,6 +1512,8 @@