linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] task_io_accounting, taskstats
@ 2010-06-02 21:56 Rafael Tinoco
  2010-06-03  1:58 ` Balbir Singh
  2010-06-04  1:07 ` Rafael Tinoco
  0 siblings, 2 replies; 3+ messages in thread
From: Rafael Tinoco @ 2010-06-02 21:56 UTC (permalink / raw)
  To: LKML, Balbir, Scrum - Linux, Juliano Martinez, Gleicon Moraes

Hello,

I'm proposing this patch to extend taskstats capability of
IO_ACCOUTING based on socket msg size.
Already discussed with Balbir about it. The idea was to keep the
"socket" accounting generic.
Not taking in consideration witch type of socket or protocol is used.
I'm using this in a user land tool called ustats for uid accounting
with very low overhead (cn_msg and taskstats through netlink).

Thanks

Rafael Tinoco

diff --git a/include/linux/task_io_accounting.h
b/include/linux/task_io_accounting.h
index bdf855c..ed54fab 100644
--- a/include/linux/task_io_accounting.h
+++ b/include/linux/task_io_accounting.h
@@ -41,5 +41,16 @@ struct task_io_accounting {
 	 * information loss in doing that.
 	 */
 	u64 cancelled_write_bytes;
+
+	/*
+	 * The number of bytes which this task has read from a socket
+	 */
+	u64 read_net_bytes;
+
+        /*
+	 * The number of bytes which this task has written to a socket
+	 */
+	u64 write_net_bytes;
+
 #endif /* CONFIG_TASK_IO_ACCOUNTING */
 };
diff --git a/include/linux/task_io_accounting_ops.h
b/include/linux/task_io_accounting_ops.h
index 4d090f9..f28aa4c 100644
--- a/include/linux/task_io_accounting_ops.h
+++ b/include/linux/task_io_accounting_ops.h
@@ -12,6 +12,11 @@ static inline void task_io_account_read(size_t bytes)
 	current->ioac.read_bytes += bytes;
 }

+static inline void task_io_account_read_net(size_t bytes)
+{
+        current->ioac.read_net_bytes += bytes;
+}
+
 /*
  * We approximate number of blocks, because we account bytes only.
  * A 'block' is 512 bytes
@@ -26,6 +31,11 @@ static inline void task_io_account_write(size_t bytes)
 	current->ioac.write_bytes += bytes;
 }

+static inline void task_io_account_write_net(size_t bytes)
+{
+        current->ioac.write_net_bytes += bytes;
+}
+
 /*
  * We approximate number of blocks, because we account bytes only.
  * A 'block' is 512 bytes
@@ -59,6 +69,10 @@ static inline void task_io_account_read(size_t bytes)
 {
 }

+static inline void task_io_account_read_net(size_t bytes)
+{
+}
+
 static inline unsigned long task_io_get_inblock(const struct task_struct *p)
 {
 	return 0;
@@ -68,6 +82,10 @@ static inline void task_io_account_write(size_t bytes)
 {
 }

+static inline void task_io_account_write_net(size_t bytes)
+{
+}
+
 static inline unsigned long task_io_get_oublock(const struct task_struct *p)
 {
 	return 0;
diff --git a/include/linux/taskstats.h b/include/linux/taskstats.h
index 341dddb..5067376 100644
--- a/include/linux/taskstats.h
+++ b/include/linux/taskstats.h
@@ -163,6 +163,10 @@ struct taskstats {
 	/* Delay waiting for memory reclaim */
 	__u64	freepages_count;
 	__u64	freepages_delay_total;
+
+        /* Per-task network I/O accounting */
+        __u64   read_net_bytes;         /* bytes of socket read I/O */
+        __u64   write_net_bytes;        /* bytes of socket write I/O */
 };


diff --git a/net/socket.c b/net/socket.c
index 769c386..93507a3 100644
--- a/net/socket.c
+++ b/net/socket.c
@@ -103,6 +103,8 @@
 #include <linux/sockios.h>
 #include <linux/atalk.h>

+#include <linux/task_io_accounting_ops.h>
+
 static int sock_no_open(struct inode *irrelevant, struct file *dontcare);
 static ssize_t sock_aio_read(struct kiocb *iocb, const struct iovec *iov,
 			 unsigned long nr_segs, loff_t pos);
@@ -550,6 +552,9 @@ static inline int __sock_sendmsg(struct kiocb
*iocb, struct socket *sock,
 	if (err)
 		return err;

+        if(size > 0)
+            task_io_account_read_net(size);
+
 	return sock->ops->sendmsg(iocb, sock, msg, size);
 }

@@ -666,6 +671,7 @@ EXPORT_SYMBOL_GPL(sock_recv_ts_and_drops);
 static inline int __sock_recvmsg_nosec(struct kiocb *iocb, struct socket *sock,
 				       struct msghdr *msg, size_t size, int flags)
 {
+        int ret = 0;
 	struct sock_iocb *si = kiocb_to_siocb(iocb);

 	si->sock = sock;
@@ -674,7 +680,12 @@ static inline int __sock_recvmsg_nosec(struct
kiocb *iocb, struct socket *sock,
 	si->size = size;
 	si->flags = flags;

-	return sock->ops->recvmsg(iocb, sock, msg, size, flags);
+        ret = sock->ops->recvmsg(iocb, sock, msg, size, flags);
+
+        if(ret > 0)
+            task_io_account_read_net(ret);
+
+        return ret;
 }

 static inline int __sock_recvmsg(struct kiocb *iocb, struct socket *sock,

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] task_io_accounting, taskstats
  2010-06-02 21:56 [PATCH] task_io_accounting, taskstats Rafael Tinoco
@ 2010-06-03  1:58 ` Balbir Singh
  2010-06-04  1:07 ` Rafael Tinoco
  1 sibling, 0 replies; 3+ messages in thread
From: Balbir Singh @ 2010-06-03  1:58 UTC (permalink / raw)
  To: Rafael Tinoco; +Cc: LKML, Scrum - Linux, Juliano Martinez, Gleicon Moraes

* Rafael Tinoco <tinhocas@gmail.com> [2010-06-02 18:56:43]:

> Hello,
> 
> I'm proposing this patch to extend taskstats capability of
> IO_ACCOUTING based on socket msg size.
> Already discussed with Balbir about it. The idea was to keep the
> "socket" accounting generic.
> Not taking in consideration witch type of socket or protocol is used.
> I'm using this in a user land tool called ustats for uid accounting
> with very low overhead (cn_msg and taskstats through netlink).
> 

Hi, Rafael

You've not signed-off on the patch. The coding style/patch seems off.
Could you please run scripts/checkpatch.pl to verify the patch.

Other comments

1. Test results are good to see in the posting
2. Documentation Update
3. User space component updates - getdelays.c

Also cc'ing netdev for more feedback.


> diff --git a/include/linux/task_io_accounting.h
> b/include/linux/task_io_accounting.h
> index bdf855c..ed54fab 100644
> --- a/include/linux/task_io_accounting.h
> +++ b/include/linux/task_io_accounting.h
> @@ -41,5 +41,16 @@ struct task_io_accounting {
>  	 * information loss in doing that.
>  	 */
>  	u64 cancelled_write_bytes;
> +
> +	/*
> +	 * The number of bytes which this task has read from a socket
> +	 */
> +	u64 read_net_bytes;
> +
> +        /*
> +	 * The number of bytes which this task has written to a socket
> +	 */
> +	u64 write_net_bytes;
> +
>  #endif /* CONFIG_TASK_IO_ACCOUNTING */
>  };
> diff --git a/include/linux/task_io_accounting_ops.h
> b/include/linux/task_io_accounting_ops.h
> index 4d090f9..f28aa4c 100644
> --- a/include/linux/task_io_accounting_ops.h
> +++ b/include/linux/task_io_accounting_ops.h
> @@ -12,6 +12,11 @@ static inline void task_io_account_read(size_t bytes)
>  	current->ioac.read_bytes += bytes;
>  }
> 
> +static inline void task_io_account_read_net(size_t bytes)
> +{
> +        current->ioac.read_net_bytes += bytes;
> +}
> +
>  /*
>   * We approximate number of blocks, because we account bytes only.
>   * A 'block' is 512 bytes
> @@ -26,6 +31,11 @@ static inline void task_io_account_write(size_t bytes)
>  	current->ioac.write_bytes += bytes;
>  }
> 
> +static inline void task_io_account_write_net(size_t bytes)
> +{
> +        current->ioac.write_net_bytes += bytes;
> +}
> +
>  /*
>   * We approximate number of blocks, because we account bytes only.
>   * A 'block' is 512 bytes
> @@ -59,6 +69,10 @@ static inline void task_io_account_read(size_t bytes)
>  {
>  }
> 
> +static inline void task_io_account_read_net(size_t bytes)
> +{
> +}
> +
>  static inline unsigned long task_io_get_inblock(const struct task_struct *p)
>  {
>  	return 0;
> @@ -68,6 +82,10 @@ static inline void task_io_account_write(size_t bytes)
>  {
>  }
> 
> +static inline void task_io_account_write_net(size_t bytes)
> +{
> +}
> +
>  static inline unsigned long task_io_get_oublock(const struct task_struct *p)
>  {
>  	return 0;
> diff --git a/include/linux/taskstats.h b/include/linux/taskstats.h
> index 341dddb..5067376 100644
> --- a/include/linux/taskstats.h
> +++ b/include/linux/taskstats.h
> @@ -163,6 +163,10 @@ struct taskstats {
>  	/* Delay waiting for memory reclaim */
>  	__u64	freepages_count;
>  	__u64	freepages_delay_total;
> +
> +        /* Per-task network I/O accounting */
> +        __u64   read_net_bytes;         /* bytes of socket read I/O */
> +        __u64   write_net_bytes;        /* bytes of socket write I/O */
>  };
> 
> 
> diff --git a/net/socket.c b/net/socket.c
> index 769c386..93507a3 100644
> --- a/net/socket.c
> +++ b/net/socket.c
> @@ -103,6 +103,8 @@
>  #include <linux/sockios.h>
>  #include <linux/atalk.h>
> 
> +#include <linux/task_io_accounting_ops.h>
> +
>  static int sock_no_open(struct inode *irrelevant, struct file *dontcare);
>  static ssize_t sock_aio_read(struct kiocb *iocb, const struct iovec *iov,
>  			 unsigned long nr_segs, loff_t pos);
> @@ -550,6 +552,9 @@ static inline int __sock_sendmsg(struct kiocb
> *iocb, struct socket *sock,
>  	if (err)
>  		return err;
> 
> +        if(size > 0)
> +            task_io_account_read_net(size);
> +
>  	return sock->ops->sendmsg(iocb, sock, msg, size);
>  }
> 
> @@ -666,6 +671,7 @@ EXPORT_SYMBOL_GPL(sock_recv_ts_and_drops);
>  static inline int __sock_recvmsg_nosec(struct kiocb *iocb, struct socket *sock,
>  				       struct msghdr *msg, size_t size, int flags)
>  {
> +        int ret = 0;
>  	struct sock_iocb *si = kiocb_to_siocb(iocb);
> 
>  	si->sock = sock;
> @@ -674,7 +680,12 @@ static inline int __sock_recvmsg_nosec(struct
> kiocb *iocb, struct socket *sock,
>  	si->size = size;
>  	si->flags = flags;
> 
> -	return sock->ops->recvmsg(iocb, sock, msg, size, flags);
> +        ret = sock->ops->recvmsg(iocb, sock, msg, size, flags);
> +
> +        if(ret > 0)
> +            task_io_account_read_net(ret);
> +
> +        return ret;
>  }
> 
>  static inline int __sock_recvmsg(struct kiocb *iocb, struct socket *sock,

-- 
	Three Cheers,
	Balbir

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] task_io_accounting, taskstats
  2010-06-02 21:56 [PATCH] task_io_accounting, taskstats Rafael Tinoco
  2010-06-03  1:58 ` Balbir Singh
@ 2010-06-04  1:07 ` Rafael Tinoco
  1 sibling, 0 replies; 3+ messages in thread
From: Rafael Tinoco @ 2010-06-04  1:07 UTC (permalink / raw)
  To: LKML, Balbir, Scrum - Linux, Juliano Martinez, Gleicon Moraes

[-- Attachment #1: Type: text/plain, Size: 934 bytes --]

Balbir, sorry Ive made a mistake sending the patch, it was an
incomplete and wrong diff.
And Ive fixed all the "tab" and signed-off-by issues.

[inaddy][macbook][linux-2.6.33.5]$ ./scripts/checkpatch.pl
/home/inaddy/codes/ustats/us_2.6.33.x.patch
total: 0 errors, 0 warnings, 125 lines checked

Tests to confirm patch is working, commands:

# netcat -l -p 8080
# cat /etc/passwd | netcat localhost 8080
# cat /etc/passwd | wc -c
1126

# ./ustatsd (getting the 1126 bytes read and written for the netcat cmds)

proc_event_exit: pid 3704 uid 0 (ucpu: 4000) (scpu: 0) (rdisk: 0)
(wdisk: 0) (rnet: 0) (wnet: 1126) (comm: netcat)
proc_event_exit: pid 3702 uid 0 (ucpu: 4000) (scpu: 0) (rdisk: 0)
(wdisk: 0) (rnet: 1126) (wnet: 0) (comm: netcat)


The attached patch is working. Ill be releasing in this same mail
thread the userland code.

I'll send another email with [PATCH] to the maintainer and to the list.

Thank you.

Rafael Tinoco

[-- Attachment #2: us_2.6.33.x.patch --]
[-- Type: text/x-patch, Size: 4675 bytes --]

Signed-off-by: Rafael David Tinoco <tinhocas@gmail.com>
diff --git a/include/linux/task_io_accounting.h b/include/linux/task_io_accounting.h
index bdf855c..bd45b92 100644
--- a/include/linux/task_io_accounting.h
+++ b/include/linux/task_io_accounting.h
@@ -41,5 +41,12 @@ struct task_io_accounting {
 	 * information loss in doing that.
 	 */
 	u64 cancelled_write_bytes;
+
+	/* The number of bytes which this task has read from a socket */
+	u64 read_net_bytes;
+
+	/* The number of bytes which this task has written to a socket */
+	u64 write_net_bytes;
+
 #endif /* CONFIG_TASK_IO_ACCOUNTING */
 };
diff --git a/include/linux/task_io_accounting_ops.h b/include/linux/task_io_accounting_ops.h
index 4d090f9..ee8416f 100644
--- a/include/linux/task_io_accounting_ops.h
+++ b/include/linux/task_io_accounting_ops.h
@@ -12,6 +12,11 @@ static inline void task_io_account_read(size_t bytes)
 	current->ioac.read_bytes += bytes;
 }
 
+static inline void task_io_account_read_net(size_t bytes)
+{
+	current->ioac.read_net_bytes += bytes;
+}
+
 /*
  * We approximate number of blocks, because we account bytes only.
  * A 'block' is 512 bytes
@@ -26,6 +31,11 @@ static inline void task_io_account_write(size_t bytes)
 	current->ioac.write_bytes += bytes;
 }
 
+static inline void task_io_account_write_net(size_t bytes)
+{
+	current->ioac.write_net_bytes += bytes;
+}
+
 /*
  * We approximate number of blocks, because we account bytes only.
  * A 'block' is 512 bytes
@@ -59,6 +69,10 @@ static inline void task_io_account_read(size_t bytes)
 {
 }
 
+static inline void task_io_account_read_net(size_t bytes)
+{
+}
+
 static inline unsigned long task_io_get_inblock(const struct task_struct *p)
 {
 	return 0;
@@ -68,6 +82,10 @@ static inline void task_io_account_write(size_t bytes)
 {
 }
 
+static inline void task_io_account_write_net(size_t bytes)
+{
+}
+
 static inline unsigned long task_io_get_oublock(const struct task_struct *p)
 {
 	return 0;
diff --git a/include/linux/taskstats.h b/include/linux/taskstats.h
index 341dddb..b0c5990 100644
--- a/include/linux/taskstats.h
+++ b/include/linux/taskstats.h
@@ -163,6 +163,10 @@ struct taskstats {
 	/* Delay waiting for memory reclaim */
 	__u64	freepages_count;
 	__u64	freepages_delay_total;
+
+	/* Per-task network I/O accounting */
+	__u64   read_net_bytes;         /* bytes of socket read I/O */
+	__u64   write_net_bytes;        /* bytes of socket write I/O */
 };
 
 
diff --git a/kernel/tsacct.c b/kernel/tsacct.c
index 00d59d0..b279e69 100644
--- a/kernel/tsacct.c
+++ b/kernel/tsacct.c
@@ -104,10 +104,14 @@ void xacct_add_tsk(struct taskstats *stats, struct task_struct *p)
 	stats->read_bytes	= p->ioac.read_bytes;
 	stats->write_bytes	= p->ioac.write_bytes;
 	stats->cancelled_write_bytes = p->ioac.cancelled_write_bytes;
+	stats->read_net_bytes	= p->ioac.read_net_bytes;
+	stats->write_net_bytes	= p->ioac.write_net_bytes;
 #else
 	stats->read_bytes	= 0;
 	stats->write_bytes	= 0;
 	stats->cancelled_write_bytes = 0;
+	stats->read_net_bytes	= 0;
+	stats->write_net_bytes	= 0;
 #endif
 }
 #undef KB
diff --git a/net/socket.c b/net/socket.c
index 769c386..dd7dbb6 100644
--- a/net/socket.c
+++ b/net/socket.c
@@ -87,6 +87,7 @@
 #include <linux/wireless.h>
 #include <linux/nsproxy.h>
 #include <linux/magic.h>
+#include <linux/task_io_accounting_ops.h>
 
 #include <asm/uaccess.h>
 #include <asm/unistd.h>
@@ -538,6 +539,7 @@ EXPORT_SYMBOL(sock_tx_timestamp);
 static inline int __sock_sendmsg(struct kiocb *iocb, struct socket *sock,
 				 struct msghdr *msg, size_t size)
 {
+	int ret;
 	struct sock_iocb *si = kiocb_to_siocb(iocb);
 	int err;
 
@@ -550,7 +552,12 @@ static inline int __sock_sendmsg(struct kiocb *iocb, struct socket *sock,
 	if (err)
 		return err;
 
-	return sock->ops->sendmsg(iocb, sock, msg, size);
+	ret = sock->ops->sendmsg(iocb, sock, msg, size);
+
+	if (ret > 0)
+		task_io_account_write_net(ret);
+
+	return ret;
 }
 
 int sock_sendmsg(struct socket *sock, struct msghdr *msg, size_t size)
@@ -666,6 +673,7 @@ EXPORT_SYMBOL_GPL(sock_recv_ts_and_drops);
 static inline int __sock_recvmsg_nosec(struct kiocb *iocb, struct socket *sock,
 				       struct msghdr *msg, size_t size, int flags)
 {
+	int ret = 0;
 	struct sock_iocb *si = kiocb_to_siocb(iocb);
 
 	si->sock = sock;
@@ -674,7 +682,12 @@ static inline int __sock_recvmsg_nosec(struct kiocb *iocb, struct socket *sock,
 	si->size = size;
 	si->flags = flags;
 
-	return sock->ops->recvmsg(iocb, sock, msg, size, flags);
+	ret = sock->ops->recvmsg(iocb, sock, msg, size, flags);
+
+	if (ret > 0)
+		task_io_account_read_net(ret);
+
+	return ret;
 }
 
 static inline int __sock_recvmsg(struct kiocb *iocb, struct socket *sock,

^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2010-06-04  1:07 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-06-02 21:56 [PATCH] task_io_accounting, taskstats Rafael Tinoco
2010-06-03  1:58 ` Balbir Singh
2010-06-04  1:07 ` Rafael Tinoco

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).