Re: Thoughts on swap_usage Crash extension?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Dave, Bryn,

I've made some changes (see the attachments) to support the following:

	ARM, X86, X86_64, ALPHA, IA64 and S390

Unfortunately these are the only definitions I could find at the moment.
As per your suggestion, the command name has been changed to "pswap" which
is more appropriate and the extension displays the swap count in pages by default.
The '-k' option is added to display in kilobytes.

The latest version is here [1].

Cheers,

Aaron
---
[1]: https://github.com/aktlin115/crash-extension/blob/master/swap_usage.c

----- Original Message -----
From: "Dave Anderson" <anderson@xxxxxxxxxx>
To: "Discussion list for crash utility usage, maintenance and development" <crash-utility@xxxxxxxxxx>
Sent: Wednesday, January 30, 2013 2:41:21 PM
Subject: Re:  Thoughts on swap_usage Crash extension?


Aaron,

Bryn's name change and pte_file() suggestion make good sense.

I also wonder if it's worth adding an option to alternatively display
the swap count in pages?  The only crash commands I can think of
off-hand that use kilobytes are the "ps" and "swap" commands, and
those were done that way because of the Linux commands of the same
name.  But when I want to see how much swap a process is using I 
do this to get a page count:

 crash> vm -p 1 | grep SWAP | wc -l
 382
 crash>

Or maybe just show both all the time?  Just a thought...

In any case, I've put the module in the crash extensions page as-is
for now.  When you're ready to update it, I'll just plug in your
latest-and-greatest version.

  http://people.redhat.com/anderson/extensions.html

Thanks,
  Dave

----- Original Message -----
> Hi Bryn,
> 
> Thanks for the feedback.
> I'll work on it. With regards to the name change, I think it's worth
> changing it to 'pswap'.
> 
> Cheers,
> Aaron
> 
> ----- Original Message -----
> From: "Bryn M. Reeves" <bmr@xxxxxxxxxx>
> To: "Discussion list for crash utility usage, maintenance and
> development" <crash-utility@xxxxxxxxxx>
> Cc: "Aaron Tomlin" <atomlin@xxxxxxxxxx>
> Sent: Wednesday, January 30, 2013 1:51:35 PM
> Subject: Re:  Thoughts on swap_usage Crash extension?
> 
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
> 
> On 01/30/2013 01:17 PM, Aaron Tomlin wrote:
> > I've made some changes [1] and included the help page, as per your
> > request. It's still x86_64 specific for now. What do you think?
> > [1]:
> > https://github.com/aktlin115/crash-extension/blob/master/swap_usage.c
> 
> Hi
> > 
> Aaron,
> 
> Extension looks useful. I was wondering about the name - would you
> consider renaming it as 'pswap'? It's less to type than swap_usage (as
> there's already a 'swap' command but nothing 'psw*').
> 
> For the _PAGE_FILE problem it might be possible to address this by
> providing a wrapper like the pte_file() interface defined by arch
> headers in the kernel sources.
> 
> There seem to be 11 arches (inc. x86 and powerpc) using (pte_val(pte)
> & _PAGE_FILE) idiom. Of the rest s390 has a well-commented explanation
> of its special cases and ARM uses a different name for the bit:
> 
> #define pte_file(pte)		(pte_val(pte) & L_PTE_FILE)
> 
> It seems like these could all be handled quite reasonably (actually
> the number that are identical maybe it's the case that this could be
> tidied up in the kernel so that arches that really need custom
> versions can override pte_file() but that's not really my area).
> 
> Regards,
> Bryn.
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.12 (GNU/Linux)
> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
> 
> iEYEARECAAYFAlEJJWcACgkQ6YSQoMYUY97PKwCfa6ZuC2MuTrYa2E42WSEkBPjM
> 234An1RQFlRxrDFgMu/cxdhEMzfsRGGZ
> =VY7a
> -----END PGP SIGNATURE-----
> 
> --
> Crash-utility mailing list
> Crash-utility@xxxxxxxxxx
> https://www.redhat.com/mailman/listinfo/crash-utility
> 

--
Crash-utility mailing list
Crash-utility@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/crash-utility
commit 2d0f0495bcb14bab089d4278b45cc4c34faad8e9
Author: Aaron Tomlin <atomlin@xxxxxxxxxx>
Date:   Mon Feb 4 08:43:13 2013 +0000

    swap usage: Display in pages by default.
    
    Added the option to print in kilobytes.

diff --git a/swap_usage.c b/swap_usage.c
index e5a7212..262eca0 100644
--- a/swap_usage.c
+++ b/swap_usage.c
@@ -17,6 +17,8 @@
 
 #include "defs.h"
 
+#define DISPLAY_KB      (0x2)
+
 #define MEMBER_FOUND 1
 #define MEMBER_NOT_FOUND 0
 #define PRINT_HEADER() \
@@ -50,7 +52,7 @@ _fini(void)
 }
 
 void
-show_swap_usage(struct task_context *tc, unsigned int exists) 
+show_swap_usage(struct task_context *tc, ulong exists, ulong flag) 
 {
 	struct task_mem_usage task_mem_usage, *tm;
 	tm = &task_mem_usage;
@@ -105,8 +107,11 @@ show_swap_usage(struct task_context *tc, unsigned int exists)
 			}
 		}
 	}
+	if (flag & DISPLAY_KB)
+		swap_usage  <<= (PAGESHIFT()-10);
+
 	fprintf(fp, "%5ld  %5ld\t%s\n",
-	tc->pid, swap_usage  << (PAGESHIFT()-10), tc->comm);
+	tc->pid, swap_usage, tc->comm);
 }
 
 
@@ -117,16 +122,20 @@ cmd_pswap(void)
 	int i;
 	int c;
 	ulong value;
+	ulong flag = 0;
 	int subsequent = 0;
-	unsigned int exists = MEMBER_NOT_FOUND;
+	ulong exists = MEMBER_NOT_FOUND;
 
 	if (MEMBER_EXISTS("mm_struct", "_swap_usage")) {
 		swap_usage_offset = MEMBER_OFFSET("mm_struct", "_swap_usage");
 		exists = MEMBER_FOUND;
 	}
 
-	while ((c = getopt(argcnt, args, "")) != EOF) {
+	while ((c = getopt(argcnt, args, "k")) != EOF) {
 		switch (c) {
+                case 'k':
+                        flag |= DISPLAY_KB;
+                        break;
 		default:
 			argerrs++;
 			break;
@@ -141,7 +150,7 @@ cmd_pswap(void)
                 tc = FIRST_CONTEXT();
                 for (i = 0; i < RUNNING_TASKS(); i++, tc++) {
                         if (!is_kernel_thread(tc->task))
-                                show_swap_usage(tc, exists);
+                                show_swap_usage(tc, exists, flag);
                 }   
 		return;
         }
@@ -152,7 +161,7 @@ cmd_pswap(void)
 		case STR_PID:
 			for (tc = pid_to_context(value); tc; tc = tc->tc_next) {
 				if (!is_kernel_thread(tc->task)) {
-					show_swap_usage(tc, exists);
+					show_swap_usage(tc, exists, flag);
 				} else {
 					error(INFO, "only specify a user task or pid: %s\n",
 						args[optind]);
@@ -163,7 +172,7 @@ cmd_pswap(void)
 		case STR_TASK:
 			for (; tc; tc = tc->tc_next) {
 				if (!is_kernel_thread(tc->task)) {
-					show_swap_usage(tc, exists);
+					show_swap_usage(tc, exists, flag);
 				} else {
 					error(INFO, "only specify a user task or pid: %s\n",
 						args[optind]);
@@ -182,12 +191,13 @@ cmd_pswap(void)
 	}
 }
 
-char *help_swap_usage[] = {
+char *help_pswap[] = {
 	"pswap",
 	"Returns the actual swap consumption of a user process",
-	"[pid | taskp]",
+	"[-k] [pid | taskp]",
 
-	"  This command obtains the swap consumption (in kilobytes) of a user process.",
+	"  This command obtains the swap consumption (in pages) of a user process.",
+        "  The -k option can be used to print in kilobytes."
 	"  Supported on x86_64 only.",
 	"\nEXAMPLE",
 	"    Show the swap consumption for pid 1288, 1232 and 663:\n",
diff --git a/swap_usage.c b/swap_usage.c
index 262eca0..30338c4 100644
--- a/swap_usage.c
+++ b/swap_usage.c
@@ -19,6 +19,33 @@
 
 #define DISPLAY_KB      (0x2)
 
+#ifdef	ARM
+#define _PAGE_FILE	(1 << 2)
+#endif	/* ARM */
+
+#ifdef	X86
+#define _PAGE_FILE	(1 << 6) /* _PAGE_BIT_DIRTY */
+#endif	/* X86 */
+
+#ifdef	X86_64
+/* set in defs.h already */
+#define _PAGE_FILE	0x040
+#endif /* X86_64 */
+
+#ifdef	ALPHA
+#define	_PAGE_FILE	0x80000 /* set:pagecache, unset:swap */
+#endif	/* ALPHA */
+
+#ifdef	IA64
+#define	_PAGE_FILE	(1 << 1) /* see swap & file pte remarks below */
+#endif	/* IA64 */
+
+#ifdef	S390
+#define	_PAGE_FILE	0x601
+#endif	/* S390 */
+
+#define pte_file_present(pte) (pte & _PAGE_FILE)
+
 #define MEMBER_FOUND 1
 #define MEMBER_NOT_FOUND 0
 #define PRINT_HEADER() \
@@ -99,7 +126,7 @@ show_swap_usage(struct task_context *tc, ulong exists, ulong flag)
 			while (vm_start < vm_end) {
 				if (!uvtop(tc, vm_start, &paddr, 0)) {
 
-					if (paddr && !(paddr & _PAGE_FILE)) {
+					if (paddr && !(pte_file_present(paddr))) {
 						swap_usage++;
 					}
 				}
@@ -198,7 +225,7 @@ char *help_pswap[] = {
 
 	"  This command obtains the swap consumption (in pages) of a user process.",
         "  The -k option can be used to print in kilobytes."
-	"  Supported on x86_64 only.",
+	"  Supported on ARM, X86, X86_64, ALPHA, IA64 and S390 only.",
 	"\nEXAMPLE",
 	"    Show the swap consumption for pid 1288, 1232 and 663:\n",
 	"  	crash> pswap 1288 1232 663",
--
Crash-utility mailing list
Crash-utility@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/crash-utility

[Index of Archives]     [Fedora Development]     [Fedora Desktop]     [Fedora SELinux]     [Yosemite News]     [KDE Users]     [Fedora Tools]

 

Powered by Linux