All of lore.kernel.org
 help / color / mirror / Atom feed
From: Li Zefan <lizefan@huawei.com>
To: Tejun Heo <tj@kernel.org>
Cc: LKML <linux-kernel@vger.kernel.org>, Cgroups <cgroups@vger.kernel.org>
Subject: [PATCH 4/8] cgroup: don't bother to resize pid array
Date: Tue, 12 Mar 2013 14:50:47 +0800	[thread overview]
Message-ID: <513ED047.9060507@huawei.com> (raw)
In-Reply-To: <513ED010.5060906@huawei.com>

When we open cgroup.procs, we'll allocate an buffer and store all tasks'
tgid in it, and then duplicate entries will be stripped. If that results
in a much smaller pid list, we'll re-allocate a smaller buffer.

But we've already sucessfully allocated memory and reading the procs
file is a short period and the memory will be freed very soon, so why
bother to re-allocate memory.

Signed-off-by: Li Zefan <lizefan@huawei.com>
---
 kernel/cgroup.c | 37 +++----------------------------------
 1 file changed, 3 insertions(+), 34 deletions(-)

diff --git a/kernel/cgroup.c b/kernel/cgroup.c
index be524ac..58ae040 100644
--- a/kernel/cgroup.c
+++ b/kernel/cgroup.c
@@ -3400,35 +3400,14 @@ static void pidlist_free(void *p)
 	else
 		kfree(p);
 }
-static void *pidlist_resize(void *p, int newcount)
-{
-	void *newlist;
-	/* note: if new alloc fails, old p will still be valid either way */
-	if (is_vmalloc_addr(p)) {
-		newlist = vmalloc(newcount * sizeof(pid_t));
-		if (!newlist)
-			return NULL;
-		memcpy(newlist, p, newcount * sizeof(pid_t));
-		vfree(p);
-	} else {
-		newlist = krealloc(p, newcount * sizeof(pid_t), GFP_KERNEL);
-	}
-	return newlist;
-}
 
 /*
  * pidlist_uniq - given a kmalloc()ed list, strip out all duplicate entries
- * If the new stripped list is sufficiently smaller and there's enough memory
- * to allocate a new buffer, will let go of the unneeded memory. Returns the
- * number of unique elements.
+ * Returns the number of unique elements.
  */
-/* 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)
+static int pidlist_uniq(pid_t *list, 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
@@ -3449,16 +3428,6 @@ static int pidlist_uniq(pid_t **p, int length)
 		dest++;
 	}
 after:
-	/*
-	 * 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 = pidlist_resize(list, dest);
-		if (newlist)
-			*p = newlist;
-	}
 	return dest;
 }
 
@@ -3554,7 +3523,7 @@ static int pidlist_array_load(struct cgroup *cgrp, enum cgroup_filetype type,
 	/* now sort & (if procs) strip out duplicates */
 	sort(array, length, sizeof(pid_t), cmppid, NULL);
 	if (type == CGROUP_FILE_PROCS)
-		length = pidlist_uniq(&array, length);
+		length = pidlist_uniq(array, length);
 	l = cgroup_pidlist_find(cgrp, type);
 	if (!l) {
 		pidlist_free(array);
-- 
1.8.0.2

  parent reply	other threads:[~2013-03-12  6:50 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-03-12  6:49 [PATCH 0/8] cgroup: a bunch of cleanups Li Zefan
2013-03-12  6:49 ` Li Zefan
2013-03-12  6:50 ` [PATCH 1/8] cgroup: remove cgroup_is_descentant() Li Zefan
2013-03-12  6:50 ` [PATCH 2/8] cgroup: remove unused variables in cgroup_destroy_locked() Li Zefan
2013-03-12  6:50 ` [PATCH 3/8] cgroup: hold cgroup_mutex before calling css_offline() Li Zefan
2013-03-12  6:50 ` Li Zefan [this message]
2013-03-12  6:50 ` [PATCH 5/8] cgroup: remove useless code in cgroup_write_event_control() Li Zefan
2013-03-12  6:53 ` [PATCH 6/8] cgroup: remove unneeded includes from cgroup.h Li Zefan
     [not found] ` <513ED010.5060906-hv44wF8Li93QT0dZR+AlfA@public.gmane.org>
2013-03-12  6:51   ` [PATCH 0/8] cgroup: a bunch of cleanups Li Zefan
2013-03-12  6:51     ` Li Zefan
2013-03-12  6:52   ` [PATCH 7/8] cgroup: fix an almost harmless off-by-one bug Li Zefan
2013-03-12  6:52     ` Li Zefan
2013-03-12  6:52   ` [PATCH 8/8] cgroup: consolidate cgroup_attach_task() and cgroup_attach_proc() Li Zefan
2013-03-12  6:52     ` Li Zefan
2013-03-12 22:38   ` [PATCH 0/8] cgroup: a bunch of cleanups Tejun Heo
2013-03-12 22:38     ` Tejun Heo
     [not found]     ` <20130312223839.GM25266-Gd/HAXX7CRxy/B6EtB590w@public.gmane.org>
2013-03-13  1:06       ` Li Zefan
2013-03-13  1:06         ` Li Zefan

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=513ED047.9060507@huawei.com \
    --to=lizefan@huawei.com \
    --cc=cgroups@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=tj@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.