Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp1334753ybi; Wed, 17 Jul 2019 13:26:12 -0700 (PDT) X-Google-Smtp-Source: APXvYqzduBygm7koe6/e0qsPbj18tcn4PFgXKNUTjqJlGfa4essdBL56RMRezSE3BXJgfelj0Jqd X-Received: by 2002:a63:eb06:: with SMTP id t6mr38440652pgh.107.1563395172732; Wed, 17 Jul 2019 13:26:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563395172; cv=none; d=google.com; s=arc-20160816; b=SC9ZgENnJFGxYtYLFpfMqKkBrR8ayW++LWUD2nohFdgR4OvDJqqNI0gHZ85rx6hZk3 6urDBGHnzecW26eNMTOFW6xziL7ktbLPWvo09u2hQxgxDQ8GctIen25ZQMEh/HYNvm3e gmyUwJm6ZVXrwAA7wMV++i+CtAihwKt6G+llP5F4ipKsYSlUewjZX2Sak4pYRzZgJY/4 7PlS5ml6mmDt142K8g6IZTPB5zK85uQXAPjfU9UsmR4Z5FPyi2RWHzIEPYLxENrodWvv djzfU/zX6ybMkg+oEY8yGLQyxRbtwtMsZ1ZryKju84u6t5y8AeiKoitw19yBtb/j93sS 5faw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=8l1yD18FgMCNHAuwCMb8dBirbWqz0p44kpnGc3Oqgw8=; b=aAm6VnPKgL8MmYZ1GCOPjzZgdCm7buDc/wNZuzcZQT1+oXwsdWvbNAmCfugBeED9ys AqvKb8bfm/jyxubPfgvsQnVxZBVjJXR9/rnZGt79ilhGzlt6d9kJyB0JPeGexEubqOSy K+RlAO2rsXcR+qgVUrQXbGFR/Ih5St8tAAr5M5902enNqx33YqwqLgqHgcLDagVic9j2 ImPeaL4zqywtcnw8wOrpiV1HlGkmnPnXnNKd+SbkqULTbAlVQU6CbLDN9+QdHhnHHo6r bT9F5rkRZDtkvRmveb4Y8X2tOwSB/tQ7u3PdwNnz69ls225JJ2KcbGl1/GGKWT3TWacR 9h3w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x1si7643369plb.28.2019.07.17.13.25.55; Wed, 17 Jul 2019 13:26:12 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728122AbfGQUZf (ORCPT + 99 others); Wed, 17 Jul 2019 16:25:35 -0400 Received: from mx1.redhat.com ([209.132.183.28]:38366 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727104AbfGQUZe (ORCPT ); Wed, 17 Jul 2019 16:25:34 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0C66030842A0; Wed, 17 Jul 2019 20:25:34 +0000 (UTC) Received: from llong.com (dhcp-17-160.bos.redhat.com [10.18.17.160]) by smtp.corp.redhat.com (Postfix) with ESMTP id AB95B5C260; Wed, 17 Jul 2019 20:25:31 +0000 (UTC) From: Waiman Long To: Christoph Lameter , Pekka Enberg , David Rientjes , Joonsoo Kim , Andrew Morton Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Michal Hocko , Roman Gushchin , Johannes Weiner , Shakeel Butt , Vladimir Davydov , Waiman Long 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 Message-Id: <20190717202413.13237-3-longman@redhat.com> In-Reply-To: <20190717202413.13237-1-longman@redhat.com> References: <20190717202413.13237-1-longman@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.40]); Wed, 17 Jul 2019 20:25:34 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The show method of /sys/kernel/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 --- 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 #include #include +#include #include @@ -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