From: Shailabh Nagar <nagar@watson.ibm.com>
To: Jay Lan <jlan@sgi.com>,
csturtiv@sgi.com, Balbir Singh <balbir@in.ibm.com>
Cc: linux-kernel <linux-kernel@vger.kernel.org>
Subject: [Patch][RFC] Disabling per-tgid stats on task exit in taskstats
Date: Fri, 09 Jun 2006 03:41:04 -0400 [thread overview]
Message-ID: <44892610.6040001@watson.ibm.com> (raw)
Jay, Chris,
Could you check if this patch does the needful ?
Its tested and runs fine for me. A quick response would
be appreciated so that it can be included in -mm before
the 2.6.18 merge window begins.
I decided against adding the configuration to the taskstats
interface directly (as another command) since the sysfs solution
is much simpler and the configuration operation is infrequent.
Balbir, all, comments welcome.
--Shailabh
Selective sending of per-tgid statistics in taskstats interface
The taskstats interface currently sends both per-pid and per-tgid stats
whenever a thread exits and its thread group is non-empty. Some potential
users of taskstats, currently SGI's CSA, do not need the per-tgid stats.
Hence, this patch introduces a configuration parameter
/sys/kernel/taskstats_tgid_exit
through which a privileged user can turn on/off sending of per-tgid stats on
task exit. The default is on. Regardless of the parameter, explicit commands
requesting per-tgid stats are always satisfied.
--
Signed-Off-By: Shailabh Nagar <nagar@watson.ibm.com>
Documentation/accounting/taskstats.txt | 42 ++++++++++++++++++++++++---------
include/linux/taskstats_kern.h | 14 +++--------
kernel/ksysfs.c | 9 +++++++
kernel/taskstats.c | 26 ++++++++++++++++++++
4 files changed, 70 insertions(+), 21 deletions(-)
Index: linux-2.6.17-rc5-mm3/include/linux/taskstats_kern.h
===================================================================
--- linux-2.6.17-rc5-mm3.orig/include/linux/taskstats_kern.h 2006-06-09 02:02:31.000000000 -0400
+++ linux-2.6.17-rc5-mm3/include/linux/taskstats_kern.h 2006-06-09 02:04:42.000000000 -0400
@@ -18,13 +18,6 @@ enum {
#ifdef CONFIG_TASKSTATS
extern kmem_cache_t *taskstats_cache;
-static inline void taskstats_exit_alloc(struct taskstats **ptidstats,
- struct taskstats **ptgidstats)
-{
- *ptidstats = kmem_cache_zalloc(taskstats_cache, SLAB_KERNEL);
- *ptgidstats = kmem_cache_zalloc(taskstats_cache, SLAB_KERNEL);
-}
-
static inline void taskstats_exit_free(struct taskstats *tidstats,
struct taskstats *tgidstats)
{
@@ -34,17 +27,18 @@ static inline void taskstats_exit_free(s
kmem_cache_free(taskstats_cache, tgidstats);
}
+extern void taskstats_exit_alloc(struct taskstats **, struct taskstats **);
extern void taskstats_exit_send(struct task_struct *, struct taskstats *,
struct taskstats *);
extern void taskstats_init_early(void);
#else
-static inline void taskstats_exit_alloc(struct taskstats **ptidstats,
- struct taskstats **ptgidstats)
-{}
static inline void taskstats_exit_free(struct taskstats *ptidstats,
struct taskstats *ptgidstats)
{}
+static inline void taskstats_exit_alloc(struct taskstats **ptidstats,
+ struct taskstats **ptgidstats)
+{}
static inline void taskstats_exit_send(struct task_struct *tsk,
struct taskstats *tidstats,
struct taskstats *tgidstats)
Index: linux-2.6.17-rc5-mm3/kernel/ksysfs.c
===================================================================
--- linux-2.6.17-rc5-mm3.orig/kernel/ksysfs.c 2006-06-09 02:02:31.000000000 -0400
+++ linux-2.6.17-rc5-mm3/kernel/ksysfs.c 2006-06-09 02:04:42.000000000 -0400
@@ -63,6 +63,12 @@ static ssize_t kexec_crash_loaded_show(s
KERNEL_ATTR_RO(kexec_crash_loaded);
#endif /* CONFIG_KEXEC */
+#ifdef CONFIG_TASKSTATS
+extern ssize_t taskstats_tgid_exit_show(struct subsystem *subsys, char *page);
+extern ssize_t taskstats_tgid_exit_store(struct subsystem *subsys, const char *page, size_t count);
+KERNEL_ATTR_RW(taskstats_tgid_exit);
+#endif
+
decl_subsys(kernel, NULL, NULL);
EXPORT_SYMBOL_GPL(kernel_subsys);
@@ -75,6 +81,9 @@ static struct attribute * kernel_attrs[]
&kexec_loaded_attr.attr,
&kexec_crash_loaded_attr.attr,
#endif
+#ifdef CONFIG_TASKSTATS
+ &taskstats_tgid_exit_attr.attr,
+#endif
NULL
};
Index: linux-2.6.17-rc5-mm3/kernel/taskstats.c
===================================================================
--- linux-2.6.17-rc5-mm3.orig/kernel/taskstats.c 2006-06-09 02:02:31.000000000 -0400
+++ linux-2.6.17-rc5-mm3/kernel/taskstats.c 2006-06-09 02:04:42.000000000 -0400
@@ -24,6 +24,7 @@
static DEFINE_PER_CPU(__u32, taskstats_seqnum) = { 0 };
static int family_registered = 0;
+static int tgid_exit_send = 1; /* Should tgid stats be sent on exit */
kmem_cache_t *taskstats_cache;
static DEFINE_MUTEX(taskstats_exit_mutex);
@@ -229,6 +230,15 @@ err:
return rc;
}
+void taskstats_exit_alloc(struct taskstats **ptidstats,
+ struct taskstats **ptgidstats)
+{
+ *ptidstats = kmem_cache_zalloc(taskstats_cache, SLAB_KERNEL);
+ *ptgidstats = NULL;
+ if (tgid_exit_send)
+ *ptgidstats = kmem_cache_zalloc(taskstats_cache, SLAB_KERNEL);
+}
+
/* Send pid data out on exit */
void taskstats_exit_send(struct task_struct *tsk, struct taskstats *tidstats,
struct taskstats *tgidstats)
@@ -254,6 +264,7 @@ void taskstats_exit_send(struct task_str
size = nla_total_size(sizeof(u32)) +
nla_total_size(sizeof(struct taskstats)) + nla_total_size(0);
+ /* Allocation should not depend on tgid_exit_send value */
if (is_thread_group)
size = 2 * size; /* PID + STATS + TGID + STATS */
@@ -271,6 +282,9 @@ void taskstats_exit_send(struct task_str
*tidstats);
nla_nest_end(rep_skb, na);
+ /* Do not check tgid_exit_send value here. If it was unset during
+ * taskstats_exit_alloc(), tgidstats will be NULL
+ */
if (!is_thread_group || !tgidstats) {
send_reply(rep_skb, 0, TASKSTATS_MSG_MULTICAST);
goto ret;
@@ -345,3 +359,15 @@ err:
* mechanisms precedes initialization of the taskstats interface
*/
late_initcall(taskstats_init);
+
+/* configuration through sysfs */
+ssize_t taskstats_tgid_exit_show(struct subsystem *subsys, char *page)
+{
+ return sprintf(page, "%d\n", tgid_exit_send);
+}
+ssize_t taskstats_tgid_exit_store(struct subsystem *subsys, const char *page, size_t count)
+{
+ char *p = (char *)page;
+ tgid_exit_send = simple_strtoul(p, &p, 10);
+ return count;
+}
Index: linux-2.6.17-rc5-mm3/Documentation/accounting/taskstats.txt
===================================================================
--- linux-2.6.17-rc5-mm3.orig/Documentation/accounting/taskstats.txt 2006-06-07 12:03:14.000000000 -0400
+++ linux-2.6.17-rc5-mm3/Documentation/accounting/taskstats.txt 2006-06-09 02:35:07.000000000 -0400
@@ -32,13 +32,28 @@ The response contains statistics for a t
statistics for all tasks of the process (if tgid is specified).
To obtain statistics for tasks which are exiting, userspace opens a multicast
-netlink socket. Each time a task exits, two records are sent by the kernel to
-each listener on the multicast socket. The first the per-pid task's statistics
-and the second is the sum for all tasks of the process to which the task
-belongs (the task does not need to be the thread group leader). The need for
-per-tgid stats to be sent for each exiting task is explained in the per-tgid
-stats section below.
+netlink socket. Each time a task exits, its per-pid statistics are sent by
+the kernel to each listener on the multicast socket.
+If
+a) the value of /sys/kernel/taskstats_tgid_exit is non-zero and
+b) the task's thread_group has other members
+then a second record is also sent, consisting of the sum for all tasks of the
+thread group to which the task belongs. The task does not need to be the thread
+group leader. The utility for per-tgid stats to be sent for each exiting task
+is explained in the per-tgid stats section below.
+
+# echo 0 > /sys/kernel/taskstats_tgid_exit
+turns off sending of per-tgid stats on task exit
+
+# echo 1 > /sys/kernel/taskstats_tgid_exit
+turns it back on (which is the default)
+
+Commands requesting per-tgid stats are not affected by this configuration
+parameter and are always satisified by the kernel. Also, when the last thread
+of a thread group, or a solitary thread exits, only the per-pid stats are sent
+since they are identical to the per-tgid stats at that point in time.
+
getdelays.c is a simple utility demonstrating usage of the taskstats interface
for reporting delay accounting statistics.
@@ -100,8 +115,8 @@ per-tgid stats
Taskstats provides per-process stats, in addition to per-task stats, since
resource management is often done at a process granularity and aggregating task
-stats in userspace alone is inefficient and potentially inaccurate (due to lack
-of atomicity).
+stats in userspace alone is inefficient and potentially inaccurate due to lack
+of atomicity.
However, maintaining per-process, in addition to per-task stats, within the
kernel has space and time overheads. Hence the taskstats implementation
@@ -115,9 +130,14 @@ statistic from the kernel.
The approach taken by taskstats is to return the per-tgid stats *each* time
a task exits, in addition to the per-pid stats for that task. Userspace can
-maintain task<->process mappings and use them to maintain the per-process stats
-in userspace, updating the aggregate appropriately as the tasks of a process
-exit.
+maintain task<->process mappings and use them to maintain the per-process
+stats, updating the aggregate appropriately as the tasks of a process
+exit. Userspace must also expect only per-pid stats to be sent when the last
+thread of a thread group exits (also when that is the only thread in the thread
+group, which is a common case).
+
+Installations that don't need per-tgid stats can disable their collection and
+sending on task exit as described in the Usage section.
Extending taskstats
-------------------
next reply other threads:[~2006-06-09 7:41 UTC|newest]
Thread overview: 134+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-06-09 7:41 Shailabh Nagar [this message]
2006-06-09 8:00 ` [Patch][RFC] Disabling per-tgid stats on task exit in taskstats Andrew Morton
2006-06-09 10:51 ` Balbir Singh
2006-06-09 11:21 ` Andrew Morton
2006-06-09 13:20 ` Shailabh Nagar
2006-06-09 18:25 ` Jay Lan
2006-06-09 19:12 ` Shailabh Nagar
2006-06-09 15:36 ` Balbir Singh
2006-06-09 18:35 ` Jay Lan
2006-06-09 19:31 ` Shailabh Nagar
2006-06-09 21:56 ` Shailabh Nagar
2006-06-09 22:42 ` Jay Lan
2006-06-09 23:22 ` Andrew Morton
2006-06-09 23:47 ` Jay Lan
2006-06-09 23:56 ` Andrew Morton
2006-06-10 12:21 ` Shailabh Nagar
2006-06-12 18:31 ` Jay Lan
2006-06-12 21:57 ` Shailabh Nagar
2006-06-10 13:05 ` Shailabh Nagar
2006-06-12 18:54 ` Jay Lan
2006-06-21 19:11 ` Jay Lan
2006-06-21 19:14 ` Jay Lan
2006-06-21 19:34 ` Shailabh Nagar
2006-06-21 23:35 ` Jay Lan
2006-06-21 23:45 ` Shailabh Nagar
2006-06-23 17:14 ` Shailabh Nagar
2006-06-23 18:19 ` Jay Lan
2006-06-23 18:53 ` Shailabh Nagar
2006-06-23 20:00 ` Jay Lan
2006-06-23 20:16 ` Shailabh Nagar
2006-06-23 20:36 ` Jay Lan
2006-06-23 21:19 ` Andrew Morton
2006-06-23 22:07 ` Jay Lan
2006-06-23 23:47 ` Andrew Morton
2006-06-24 2:59 ` Shailabh Nagar
2006-06-24 4:39 ` Andrew Morton
2006-06-24 5:59 ` Shailabh Nagar
2006-06-26 17:33 ` Jay Lan
2006-06-26 17:52 ` Shailabh Nagar
2006-06-26 17:55 ` Andrew Morton
2006-06-26 18:00 ` Shailabh Nagar
2006-06-26 18:12 ` Andrew Morton
2006-06-26 18:26 ` Jay Lan
2006-06-26 18:39 ` Andrew Morton
2006-06-26 18:49 ` Shailabh Nagar
2006-06-26 19:00 ` Jay Lan
2006-06-28 21:30 ` Jay Lan
2006-06-28 21:53 ` Andrew Morton
2006-06-28 22:02 ` Jay Lan
2006-06-29 8:40 ` Paul Jackson
2006-06-29 12:30 ` Valdis.Kletnieks
2006-06-29 16:44 ` Paul Jackson
2006-06-29 18:01 ` Andrew Morton
2006-06-29 18:07 ` Paul Jackson
2006-06-29 18:26 ` Paul Jackson
2006-06-29 19:15 ` Shailabh Nagar
2006-06-29 19:41 ` Paul Jackson
2006-06-29 21:42 ` Shailabh Nagar
2006-06-29 21:54 ` Jay Lan
2006-06-29 22:09 ` Shailabh Nagar
2006-06-29 22:23 ` Paul Jackson
2006-06-30 0:15 ` Shailabh Nagar
2006-06-30 0:40 ` Paul Jackson
2006-06-30 1:00 ` Shailabh Nagar
2006-06-30 1:05 ` Paul Jackson
[not found] ` <44A46C6C.1090405@watson.ibm.com>
2006-06-30 0:38 ` Paul Jackson
2006-06-30 2:21 ` Paul Jackson
2006-06-30 2:46 ` Shailabh Nagar
2006-06-30 2:54 ` Paul Jackson
2006-06-30 3:02 ` Paul Jackson
2006-06-29 19:22 ` Shailabh Nagar
2006-06-29 19:10 ` Shailabh Nagar
2006-06-29 19:23 ` Paul Jackson
2006-06-29 19:33 ` Andrew Morton
2006-06-29 19:43 ` Shailabh Nagar
2006-06-29 20:00 ` Andrew Morton
2006-06-29 22:13 ` Shailabh Nagar
2006-06-29 23:00 ` jamal
2006-06-29 20:01 ` Shailabh Nagar
2006-06-29 21:22 ` Paul Jackson
2006-06-29 22:54 ` jamal
2006-06-30 0:38 ` Shailabh Nagar
2006-06-30 1:05 ` Andrew Morton
2006-06-30 1:11 ` Shailabh Nagar
2006-06-30 1:30 ` jamal
2006-06-30 3:01 ` Shailabh Nagar
2006-06-30 12:45 ` jamal
2006-06-30 2:25 ` Paul Jackson
2006-06-30 2:35 ` Andrew Morton
2006-06-30 2:43 ` Paul Jackson
2006-06-29 19:33 ` Jay Lan
2006-06-30 18:53 ` Shailabh Nagar
2006-06-30 19:10 ` Shailabh Nagar
2006-06-30 19:19 ` Shailabh Nagar
2006-06-30 20:19 ` jamal
2006-06-30 22:50 ` Andrew Morton
2006-07-01 2:20 ` Shailabh Nagar
2006-07-01 2:43 ` Andrew Morton
2006-07-01 3:37 ` Shailabh Nagar
2006-07-01 3:51 ` Andrew Morton
2006-07-03 21:11 ` Shailabh Nagar
2006-07-03 21:41 ` Andrew Morton
2006-07-04 0:13 ` Shailabh Nagar
2006-07-04 0:38 ` Andrew Morton
2006-07-04 20:19 ` Paul Jackson
2006-07-04 20:22 ` Paul Jackson
2006-07-04 0:54 ` Shailabh Nagar
2006-07-04 1:01 ` Andrew Morton
2006-07-04 13:05 ` jamal
2006-07-04 15:18 ` Shailabh Nagar
2006-07-04 16:37 ` Shailabh Nagar
2006-07-04 19:24 ` jamal
2006-07-05 14:09 ` Shailabh Nagar
2006-07-05 20:25 ` Chris Sturtivant
2006-07-05 20:32 ` Shailabh Nagar
2006-07-03 4:53 ` Paul Jackson
2006-07-03 15:02 ` Shailabh Nagar
2006-07-03 15:55 ` Paul Jackson
2006-07-03 16:31 ` Paul Jackson
2006-07-04 0:09 ` Shailabh Nagar
2006-07-04 19:59 ` Paul Jackson
2006-07-05 17:20 ` Jay Lan
2006-07-05 18:18 ` Shailabh Nagar
2006-06-30 22:56 ` Andrew Morton
2006-06-29 18:05 ` Nick Piggin
2006-06-29 12:42 ` Shailabh Nagar
2006-06-24 3:08 ` Shailabh Nagar
2006-06-21 20:38 ` Andrew Morton
2006-06-21 21:31 ` Shailabh Nagar
2006-06-21 21:45 ` Jay Lan
2006-06-21 21:54 ` Andrew Morton
2006-06-21 22:19 ` Jay Lan
2006-06-21 21:59 ` Shailabh Nagar
2006-06-09 15:55 ` Chris Sturtivant
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=44892610.6040001@watson.ibm.com \
--to=nagar@watson.ibm.com \
--cc=balbir@in.ibm.com \
--cc=csturtiv@sgi.com \
--cc=jlan@sgi.com \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox