From: Waiman Long <longman@redhat.com>
To: Christoph Lameter <cl@linux.com>,
Pekka Enberg <penberg@kernel.org>,
David Rientjes <rientjes@google.com>,
Joonsoo Kim <iamjoonsoo.kim@lge.com>,
Andrew Morton <akpm@linux-foundation.org>
Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org,
Michal Hocko <mhocko@kernel.org>, Roman Gushchin <guro@fb.com>,
Johannes Weiner <hannes@cmpxchg.org>,
Shakeel Butt <shakeelb@google.com>,
Vladimir Davydov <vdavydov.dev@gmail.com>,
Waiman Long <longman@redhat.com>
Subject: [PATCH v2 2/2] mm, slab: Show last shrink time in us when slab/shrink is read
Date: Wed, 17 Jul 2019 16:24:13 -0400 [thread overview]
Message-ID: <20190717202413.13237-3-longman@redhat.com> (raw)
In-Reply-To: <20190717202413.13237-1-longman@redhat.com>
The show method of /sys/kernel/slab/<slab>/shrink sysfs file currently
returns nothing. This is now modified to show the time of the last
cache shrink operation in us.
CONFIG_SLUB_DEBUG depends on CONFIG_SYSFS. So the new shrink_us field
is always available to the shrink methods.
Signed-off-by: Waiman Long <longman@redhat.com>
---
Documentation/ABI/testing/sysfs-kernel-slab | 2 ++
include/linux/slub_def.h | 1 +
mm/slub.c | 12 +++++++++---
3 files changed, 12 insertions(+), 3 deletions(-)
diff --git a/Documentation/ABI/testing/sysfs-kernel-slab b/Documentation/ABI/testing/sysfs-kernel-slab
index 94ffd47fc8d7..9869a3f57dc3 100644
--- a/Documentation/ABI/testing/sysfs-kernel-slab
+++ b/Documentation/ABI/testing/sysfs-kernel-slab
@@ -437,6 +437,8 @@ Description:
write for shrinking the cache. Other input values are
considered invalid. If it is a root cache, all the
child memcg caches will also be shrunk, if available.
+ When read, the time in us of the last cache shrink
+ operation is shown.
What: /sys/kernel/slab/cache/slab_size
Date: May 2007
diff --git a/include/linux/slub_def.h b/include/linux/slub_def.h
index d2153789bd9f..055474197e83 100644
--- a/include/linux/slub_def.h
+++ b/include/linux/slub_def.h
@@ -113,6 +113,7 @@ struct kmem_cache {
/* For propagation, maximum size of a stored attr */
unsigned int max_attr_size;
#ifdef CONFIG_SYSFS
+ unsigned int shrink_us; /* Cache shrink time in us */
struct kset *memcg_kset;
#endif
#endif
diff --git a/mm/slub.c b/mm/slub.c
index 9736eb10dcb8..77d67a55ce43 100644
--- a/mm/slub.c
+++ b/mm/slub.c
@@ -34,6 +34,7 @@
#include <linux/prefetch.h>
#include <linux/memcontrol.h>
#include <linux/random.h>
+#include <linux/sched/clock.h>
#include <trace/events/kmem.h>
@@ -5287,16 +5288,21 @@ SLAB_ATTR(failslab);
static ssize_t shrink_show(struct kmem_cache *s, char *buf)
{
- return 0;
+ return sprintf(buf, "%u\n", s->shrink_us);
}
static ssize_t shrink_store(struct kmem_cache *s,
const char *buf, size_t length)
{
- if (buf[0] == '1')
+ if (buf[0] == '1') {
+ u64 start = sched_clock();
+
kmem_cache_shrink_all(s);
- else
+ s->shrink_us = (unsigned int)div_u64(sched_clock() - start,
+ NSEC_PER_USEC);
+ } else {
return -EINVAL;
+ }
return length;
}
SLAB_ATTR(shrink);
--
2.18.1
next prev parent reply other threads:[~2019-07-17 20:25 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-07-17 20:24 [PATCH v2 0/2] mm, slab: Extend slab/shrink to shrink all memcg caches Waiman Long
2019-07-17 20:24 ` [PATCH v2 1/2] " Waiman Long
2019-07-18 11:38 ` Christopher Lameter
2019-07-18 17:05 ` Roman Gushchin
2019-07-19 6:20 ` Michal Hocko
2019-07-19 14:09 ` Waiman Long
2019-07-17 20:24 ` Waiman Long [this message]
2019-07-18 11:39 ` [PATCH v2 2/2] mm, slab: Show last shrink time in us when slab/shrink is read Christopher Lameter
2019-07-18 14:36 ` Waiman Long
2019-07-18 18:04 ` Waiman Long
2019-07-19 6:14 ` Michal Hocko
2019-07-19 14:07 ` Waiman Long
2019-07-19 14:29 ` Michal Hocko
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=20190717202413.13237-3-longman@redhat.com \
--to=longman@redhat.com \
--cc=akpm@linux-foundation.org \
--cc=cl@linux.com \
--cc=guro@fb.com \
--cc=hannes@cmpxchg.org \
--cc=iamjoonsoo.kim@lge.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mhocko@kernel.org \
--cc=penberg@kernel.org \
--cc=rientjes@google.com \
--cc=shakeelb@google.com \
--cc=vdavydov.dev@gmail.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