[PATCH getrusage: return ru_maxrss

Previous thread: [PATCH] kernel/printk.c: Concerns about the console handover by Maciej W. Rozycki on Thursday, September 20, 2007 - 1:28 pm. (11 messages)

Next thread: [Announce] LessWatts.org power saving project by Arjan van de Ven on Thursday, September 20, 2007 - 2:08 pm. (2 messages)
To: linux-kernel <linux-kernel@...>
Date: Thursday, September 20, 2007 - 1:57 pm

Properly support the ru_maxrss field of the rusage structure returned by
getrusage(). This patch includes documentation both of the getrusage()
implementation in general and of the ru_maxrss implementation
specifically. This implementation matches that of FreeBSD, which is the
only other OS of which I'm aware that implements this field.

Like a number of other folks, we recently had a need for a non-/proc way
of getting the RSS of a process and happened on getrusage(). Unlike the
rest, though, we fixed the system call to do what we want. I wrote a
wrong implementation and submitted it while I was sick; this time I took
my time and I think I got it right.

A test program that has been run against a number of systems (of which
only FreeBSD and Linux 2.6 with this patch applied passed) is also
available at
http://www.exit.com/Archives/Linux/

Signed-off-by: Frank Mayhar <fmayhar@google.com>

---
diff --git a/include/linux/sched.h b/include/linux/sched.h
index 3de7901..85735af 100644
--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -518,6 +518,7 @@ struct signal_struct {
unsigned long nvcsw, nivcsw, cnvcsw, cnivcsw;
unsigned long min_flt, maj_flt, cmin_flt, cmaj_flt;
unsigned long inblock, oublock, cinblock, coublock;
+ unsigned long cmaxrss;

/*
* Cumulative ns of scheduled CPU time for dead threads in the
@@ -1027,6 +1028,8 @@ #endif
struct timespec real_start_time; /* boot based time */
/* mm fault and swap info: this can arguably be seen as either mm-specific or thread-specific */
unsigned long min_flt, maj_flt;
+/* maxrss gets the hiwater_rss in do_exit() */
+ unsigned long maxrss;

cputime_t it_prof_expires, it_virt_expires;
unsigned long long it_sched_expires;
diff --git a/kernel/exit.c b/kernel/exit.c
index 06b24b3..390d834 100644
--- a/kernel/exit.c
+++ b/kernel/exit.c
@@ -127,6 +127,8 @@ static void __exit_signal(struct task_st
sig->inblock += task_io_get_inblock(tsk);
sig->oublock += task_io_get_oublock...

To: Frank Mayhar <fmayhar@...>
Cc: linux-kernel <linux-kernel@...>
Date: Monday, September 24, 2007 - 3:57 am

Nice patch, but the Vaio always wins ;)

It boots OK, but when I ssh into the machine:

[ 56.310698] sonypi: ioport 0x1080 busy, using sony-laptop? if not use check_ioport=0
[ 56.314186] sonypi: failed to request ioports
[ 56.317362] sonypi: probe of sonypi failed with error -16
[ 57.017983] ipw2200: Radio Frequency Kill Switch is On:
[ 57.017985] Kill switch must be turned off for wireless networking to work.
[ 57.124331] ipw2200: Failed to send WEP_KEY: Aborted due to RF kill switch.
[ 57.242396] ipw2200: Failed to send WEP_KEY: Command timed out.
[ 60.343396] BUG: unable to handle kernel NULL pointer dereference at virtual address 0000009c
[ 60.343573] printing eip: c012ba9c *pde = 00000000
[ 60.343680] Oops: 0000 [#1] PREEMPT
[ 60.343763] last sysfs file: /devices/system/cpu/cpu0/cpufreq/scaling_setspeed
[ 60.343894] Modules linked in: ipw2200 sonypi ipv6 autofs4 hidp l2cap bluetooth sunrpc nf_conntrack_netbios_ns ipt_REJECT nf_conntrack_ipv4 xt_state nf_conntrack nfnetlink xt_tcpudp iptable_filter ip_tables x_tables acpi_cpufreq sbs sbshc nvram ohci1394 ieee1394 ehci_hcd uhci_hcd sg joydev snd_hda_intel snd_seq_dummy snd_seq_oss snd_seq_midi_event snd_seq snd_seq_device snd_pcm_oss snd_mixer_oss ieee80211 sr_mod cdrom snd_pcm ieee80211_crypt snd_timer i2c_i801 i2c_core snd pcspkr soundcore piix snd_page_alloc battery button ac generic ext3 jbd ide_disk ide_core
[ 60.345225]
[ 60.345258] Pid: 2503, comm: zsh Not tainted (2.6.23-rc7-mm1 #9)
[ 60.345367] EIP: 0060:[<c012ba9c>] EFLAGS: 00010046 CPU: 0
[ 60.345472] EIP is at getrusage+0x181/0x21f
[ 60.345551] EAX: 00000000 EBX: 00000000 ECX: c2370ec0 EDX: 00000000
[ 60.345665] ESI: c2370ec0 EDI: 00000002 EBP: c3cc3f1c ESP: c3cc3ec0
[ 60.345779] DS: 007b ES: 007b FS: 0000 GS: 0033 SS: 0068
[ 60.345878] Process zsh (pid: 2503, ti=c3cc2000 task=c3cc0e00 task.ti=c3cc2000)
[ 60.346009] last branch before last exception/interrupt
[ 60.346112] from c012ba9c (getrusage+0x181/0x21f)
[ 60....

To: Frank Mayhar <fmayhar@...>
Cc: linux-kernel <linux-kernel@...>
Date: Thursday, September 20, 2007 - 2:09 pm

Acked-by: Rik van Riel <riel@redhat.com>

--
All Rights Reversed
-

Previous thread: [PATCH] kernel/printk.c: Concerns about the console handover by Maciej W. Rozycki on Thursday, September 20, 2007 - 1:28 pm. (11 messages)

Next thread: [Announce] LessWatts.org power saving project by Arjan van de Ven on Thursday, September 20, 2007 - 2:08 pm. (2 messages)