From: Pavel Emelyanov <xemul-GEFAQzZX7r8dnm+yROfE0A@public.gmane.org>
To: Christoph Lameter <clameter-sJ/iWh9BUns@public.gmane.org>
Cc: Linux Containers <containers-qjLDD68F18O7TbgM5vRIOg@public.gmane.org>
Subject: [PATCH 2/4] Switch caches notification dynamically
Date: Mon, 17 Sep 2007 16:30:45 +0400 [thread overview]
Message-ID: <46EE7375.3040902@openvz.org> (raw)
In-Reply-To: <46EE70B4.6060902-GEFAQzZX7r8dnm+yROfE0A@public.gmane.org>
The /sys/slab/<name>/cache_notify attribute controls
whether the cache <name> is to be accounted or not.
For the reasons described before kmalloc caches cannot
be turned on.
By default no caches are accountable. Simply make
# echo -n 1 > /sys/slab/<name>cache_notify
to turn notification of this cache on.
If we turn accounting on on some cache and this cache
is merged with some other, this "other" will be notified
as well. We can solve this by disabling of cache merging,
but maybe we can do it some other way.
Turning the notification off is possible only when this
cache is empty. The reason for this is that the pages,
that are full of objects are not linked in any list, so
we wouldn't be able to walk these pages and notify others
that these objects are no longer tracked.
Signed-off-by: Pavel Emelyanov <xemul-GEFAQzZX7r8dnm+yROfE0A@public.gmane.org>
---
mm/slub.c | 45 +++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 45 insertions(+)
diff --git a/mm/slub.c b/mm/slub.c
index 1802645..bfb7c21 100644
--- a/mm/slub.c
+++ b/mm/slub.c
@@ -2338,6 +2440,14 @@ EXPORT_SYMBOL(kmem_cache_destroy);
struct kmem_cache kmalloc_caches[PAGE_SHIFT] __cacheline_aligned;
EXPORT_SYMBOL(kmalloc_caches);
+static inline int is_kmalloc_cache(struct kmem_cache *s)
+{
+ int km_idx;
+
+ km_idx = s - kmalloc_caches;
+ return km_idx >= 0 && km_idx < ARRAY_SIZE(kmalloc_caches);
+}
+
#ifdef CONFIG_ZONE_DMA
static struct kmem_cache *kmalloc_caches_dma[PAGE_SHIFT];
#endif
@@ -3753,6 +3874,42 @@ static ssize_t defrag_ratio_store(struct
SLAB_ATTR(defrag_ratio);
#endif
+static ssize_t cache_notify_show(struct kmem_cache *s, char *buf)
+{
+ return sprintf(buf, "%d\n", !!(s->flags & SLAB_NOTIFY));
+}
+
+static ssize_t cache_notify_store(struct kmem_cache *s,
+ const char *buf, size_t length)
+{
+ if (buf[0] == '1') {
+ if (is_kmalloc_cache(s))
+ /*
+ * cannot just make these caches accountable
+ */
+ return -EINVAL;
+
+ s->flags |= SLAB_NOTIFY;
+ return length;
+ }
+
+ if (buf[0] == '0') {
+ if (any_slab_objects(s))
+ /*
+ * we cannot turn this off because of the
+ * full slabs cannot be found in this case
+ */
+ return -EBUSY;
+
+ s->flags &= ~SLAB_NOTIFY;
+ return length;
+ }
+
+ return -EINVAL;
+}
+
+SLAB_ATTR(cache_notify);
+
static struct attribute * slab_attrs[] = {
&slab_size_attr.attr,
&object_size_attr.attr,
@@ -3783,6 +3940,7 @@ static struct attribute * slab_attrs[] =
#ifdef CONFIG_NUMA
&defrag_ratio_attr.attr,
#endif
+ &cache_notify_attr.attr,
NULL
};
next prev parent reply other threads:[~2007-09-17 12:30 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-09-17 12:19 [PATCH 0/4] Kernel memory accounting container (v3) Pavel Emelyanov
[not found] ` <46EE70B4.6060902-GEFAQzZX7r8dnm+yROfE0A@public.gmane.org>
2007-09-17 12:26 ` [PATCH 1/4] Add notification about some major slab events Pavel Emelyanov
[not found] ` <46EE726F.1010707-GEFAQzZX7r8dnm+yROfE0A@public.gmane.org>
2007-09-17 18:25 ` Christoph Lameter
[not found] ` <Pine.LNX.4.64.0709171122150.27057-RYO/mD75kfhx2SFC9UQUAuF7EQX82lMiAL8bYrjMMd8@public.gmane.org>
2007-09-18 8:03 ` Pavel Emelyanov
[not found] ` <46EF865F.4050409-GEFAQzZX7r8dnm+yROfE0A@public.gmane.org>
2007-09-18 19:35 ` Christoph Lameter
2007-09-19 10:08 ` Pavel Emelyanov
[not found] ` <46F0F520.1010804-GEFAQzZX7r8dnm+yROfE0A@public.gmane.org>
2007-09-19 17:45 ` Christoph Lameter
2007-09-17 12:30 ` Pavel Emelyanov [this message]
[not found] ` <46EE7375.3040902-GEFAQzZX7r8dnm+yROfE0A@public.gmane.org>
2007-09-17 18:29 ` [PATCH 2/4] Switch caches notification dynamically Christoph Lameter
[not found] ` <Pine.LNX.4.64.0709171128380.27057-RYO/mD75kfhx2SFC9UQUAuF7EQX82lMiAL8bYrjMMd8@public.gmane.org>
2007-09-18 6:51 ` Pavel Emelyanov
2007-09-17 18:32 ` Christoph Lameter
[not found] ` <Pine.LNX.4.64.0709171130470.27057-RYO/mD75kfhx2SFC9UQUAuF7EQX82lMiAL8bYrjMMd8@public.gmane.org>
2007-09-18 6:54 ` Pavel Emelyanov
[not found] ` <46EF7610.1060302-GEFAQzZX7r8dnm+yROfE0A@public.gmane.org>
2007-09-18 19:36 ` Christoph Lameter
2007-09-17 12:33 ` [PATCH 3/4] Setup the container Pavel Emelyanov
2007-09-17 12:35 ` [PATCH 4/4] Account for the slub objects Pavel Emelyanov
[not found] ` <46EE74AF.70105-GEFAQzZX7r8dnm+yROfE0A@public.gmane.org>
2007-09-17 16:08 ` Dave Hansen
2007-09-18 6:27 ` Pavel Emelyanov
2007-09-17 16:09 ` Dave Hansen
2007-09-18 6:28 ` Pavel Emelyanov
2007-09-17 18:27 ` [PATCH 0/4] Kernel memory accounting container (v3) Christoph Lameter
[not found] ` <Pine.LNX.4.64.0709171126330.27057-RYO/mD75kfhx2SFC9UQUAuF7EQX82lMiAL8bYrjMMd8@public.gmane.org>
2007-09-17 20:51 ` Balbir Singh
[not found] ` <46EEE8B7.2070805-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>
2007-09-17 21:19 ` Christoph Lameter
[not found] ` <Pine.LNX.4.64.0709171417330.28926-RYO/mD75kfhx2SFC9UQUAuF7EQX82lMiAL8bYrjMMd8@public.gmane.org>
2007-09-18 6:56 ` Pavel Emelyanov
2007-09-18 6:25 ` Pavel Emelyanov
[not found] ` <46EF6F6C.60702-GEFAQzZX7r8dnm+yROfE0A@public.gmane.org>
2007-09-18 19:37 ` Christoph Lameter
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=46EE7375.3040902@openvz.org \
--to=xemul-gefaqzzx7r8dnm+yrofe0a@public.gmane.org \
--cc=clameter-sJ/iWh9BUns@public.gmane.org \
--cc=containers-qjLDD68F18O7TbgM5vRIOg@public.gmane.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.