public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Li Zefan <lizf@cn.fujitsu.com>
To: Ben Blum <bblum@google.com>
Cc: linux-kernel@vger.kernel.org,
	containers@lists.linux-foundation.org, akpm@linux-foundation.org,
	serue@us.ibm.com, menage@google.com
Subject: Re: [PATCH 1/3] Adds a read-only "procs" file similar to "tasks" that	shows only unique tgids
Date: Mon, 13 Jul 2009 11:46:10 +0800	[thread overview]
Message-ID: <4A5AAE02.7060106@cn.fujitsu.com> (raw)
In-Reply-To: <20090710230154.16778.58053.stgit@hastromil.mtv.corp.google.com>

Ben Blum wrote:
> Adds a read-only "procs" file similar to "tasks" that shows only unique tgids
> 
> struct cgroup used to have a bunch of fields for keeping track of the pidlist
> for the tasks file. Those are now separated into a new struct cgroup_pidlist,
> of which two are had, one for procs and one for tasks. The way the seq_file
> operations are set up is changed so that just the pidlist struct gets passed
> around as the private data.
> 
> Interface example: suppose a process with tgid 1000 has additional threads
> with ids 1001 and 1002. The tasks file will show ids 1000, 1001, and 1002, and
> the procs file will only show id 1000.
> 

I think a better demonstration is:

  $ cat tasks
  1000
  1001
  1002

  $ cat procs
  1000

> Possible future functionality is making the procs file writable for purposes
> of adding all threads with the same tgid at once.
> 
> Signed-off-by: Ben Blum <bblum@google.com>
> 
> ---
> 
>  include/linux/cgroup.h |   22 ++--
>  kernel/cgroup.c        |  282 ++++++++++++++++++++++++++++++------------------
>  2 files changed, 190 insertions(+), 114 deletions(-)
...
> +/* is the size difference enough that we should re-allocate the array? */
> +#define PIDLIST_REALLOC_DIFFERENCE(old,new) ((old) - PAGE_SIZE >= (new))
> +static int pidlist_uniq(pid_t **p, int length)
> +{
> +	int src, dest = 1;
> +	pid_t *list = *p;
> +	pid_t *newlist;
> +
> +	/*
> +	 * we presume the 0th element is unique, so i starts at 1. trivial
> +	 * edge cases first; no work needs to be done for either
> +	 */
> +	if (length == 0 || length == 1)
> +		return length;
> +	/* src and dest walk down the list; dest counts unique elements */
> +	for (src = 1; src < length; src++) {
> +		/* find next unique element */
> +		while (list[src] == list[src-1]) {
> +			src++;
> +			if (src == length)
> +				break;

'goto' is better

> +		}
> +		if (src == length)
> +			break;
> +		/* dest always points to where the next unique element goes */
> +		list[dest] = list[src];
> +		dest++;
> +	}
> +	/*
> +	 * if the length difference is large enough, we want to allocate a
> +	 * smaller buffer to save memory. if this fails due to out of memory,
> +	 * we'll just stay with what we've got.
> +	 */
> +	if (PIDLIST_REALLOC_DIFFERENCE(length, dest)) {
> +		newlist = kmalloc(dest * sizeof(pid_t), GFP_KERNEL);

krealloc()

> +		if (newlist) {
> +			memcpy(newlist, list, dest * sizeof(pid_t));
> +			kfree(list);
> +			*p = newlist;
> +		}
> +	}
> +	return dest;
> +}

  reply	other threads:[~2009-07-13  3:46 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-07-10 23:01 [PATCH v2 0/3] CGroups: cgroup member list enhancement/fix Ben Blum
2009-07-10 23:01 ` [PATCH 1/3] Adds a read-only "procs" file similar to "tasks" that shows only unique tgids Ben Blum
2009-07-13  3:46   ` Li Zefan [this message]
2009-07-13 15:25     ` Benjamin Blum
2009-07-14 18:34   ` Dave Hansen
2009-07-14 21:26     ` Benjamin Blum
2009-07-14 21:49       ` Dave Hansen
2009-07-14 22:55         ` Benjamin Blum
2009-07-15  1:31         ` Li Zefan
2009-07-10 23:02 ` [PATCH 2/3] Ensures correct concurrent opening/reading of pidlists across pid namespaces Ben Blum
2009-07-11 21:59   ` Serge E. Hallyn
2009-07-10 23:02 ` [PATCH 3/3] Quick vmalloc vs kmalloc fix to the case where array size is too large Ben Blum
2009-07-13  3:03   ` Li Zefan
2009-07-13  6:03     ` KAMEZAWA Hiroyuki
2009-07-13 15:27       ` Benjamin Blum
2009-07-13 23:49         ` KAMEZAWA Hiroyuki
2009-07-14  3:50           ` Paul Menage
2009-07-14  3:53             ` KAMEZAWA Hiroyuki
2009-07-14  4:04               ` Paul Menage
2009-07-14  4:25                 ` KAMEZAWA Hiroyuki
2009-07-14 17:26                   ` Benjamin Blum
2009-07-14 17:28                   ` Paul Menage
2009-07-14 17:47                     ` Dave Hansen
2009-07-14 17:50                       ` Paul Menage
2009-07-14 21:30                         ` Benjamin Blum

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=4A5AAE02.7060106@cn.fujitsu.com \
    --to=lizf@cn.fujitsu.com \
    --cc=akpm@linux-foundation.org \
    --cc=bblum@google.com \
    --cc=containers@lists.linux-foundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=menage@google.com \
    --cc=serue@us.ibm.com \
    /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