From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-io0-f197.google.com (mail-io0-f197.google.com [209.85.223.197]) by kanga.kvack.org (Postfix) with ESMTP id 8BA5C6B038D for ; Tue, 7 Mar 2017 16:24:46 -0500 (EST) Received: by mail-io0-f197.google.com with SMTP id f84so16553262ioj.6 for ; Tue, 07 Mar 2017 13:24:46 -0800 (PST) Received: from resqmta-ch2-05v.sys.comcast.net (resqmta-ch2-05v.sys.comcast.net. [2001:558:fe21:29:69:252:207:37]) by mx.google.com with ESMTPS id f77si1665666iof.203.2017.03.07.13.24.45 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 07 Mar 2017 13:24:46 -0800 (PST) Message-Id: <20170307212437.954282487@linux.com> Date: Tue, 07 Mar 2017 15:24:31 -0600 From: Christoph Lameter Subject: [RFC 2/6] slub: Add defrag_ratio field and sysfs support References: <20170307212429.044249411@linux.com> Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline; filename=defrag_ratio Sender: owner-linux-mm@kvack.org List-ID: To: Matthew Wilcox Cc: linux-mm@kvack.org, Pekka Enberg , akpm@linux-foundation.org, Mel Gorman , andi@firstfloor.org, Rik van Riel The defrag_ratio is used to set the threshold at which defragmentation should be attempted on a slab page. The allocation ratio is measured by the percentage of the available slots allocated. Add a defrag ratio field and set it to 30% by default. A limit of 30% specified that less than 3 out of 10 available slots for objects are in use before slab defragmeentation runs. Signed-off-by: Christoph Lameter --- Documentation/ABI/testing/sysfs-kernel-slab | 13 +++++++++++++ include/linux/slub_def.h | 6 ++++++ mm/slub.c | 23 +++++++++++++++++++++++ 3 files changed, 42 insertions(+) Index: linux/mm/slub.c =================================================================== --- linux.orig/mm/slub.c +++ linux/mm/slub.c @@ -3596,6 +3596,7 @@ static int kmem_cache_open(struct kmem_c else s->cpu_partial = 30; + s->defrag_ratio = 30; #ifdef CONFIG_NUMA s->remote_node_defrag_ratio = 1000; #endif @@ -5057,6 +5058,27 @@ static ssize_t reserved_show(struct kmem } SLAB_ATTR_RO(reserved); +static ssize_t defrag_ratio_show(struct kmem_cache *s, char *buf) +{ + return sprintf(buf, "%d\n", s->defrag_ratio); +} + +static ssize_t defrag_ratio_store(struct kmem_cache *s, + const char *buf, size_t length) +{ + unsigned long ratio; + int err; + + err = kstrtoul(buf, 10, &ratio); + if (err) + return err; + + if (ratio < 100) + s->defrag_ratio = ratio; + return length; +} +SLAB_ATTR(defrag_ratio); + #ifdef CONFIG_SLUB_DEBUG static ssize_t slabs_show(struct kmem_cache *s, char *buf) { @@ -5381,6 +5403,7 @@ static struct attribute *slab_attrs[] = &validate_attr.attr, &alloc_calls_attr.attr, &free_calls_attr.attr, + &defrag_ratio_attr.attr, #endif #ifdef CONFIG_ZONE_DMA &cache_dma_attr.attr, Index: linux/Documentation/ABI/testing/sysfs-kernel-slab =================================================================== --- linux.orig/Documentation/ABI/testing/sysfs-kernel-slab +++ linux/Documentation/ABI/testing/sysfs-kernel-slab @@ -180,6 +180,19 @@ Description: list. It can be written to clear the current count. Available when CONFIG_SLUB_STATS is enabled. +What: /sys/kernel/slab/cache/defrag_ratio +Date: August 2017 +KernelVersion: 4.13 +Contact: Christoph Lameter + Pekka Enberg , +Description: + The defrag_ratio files allows the control of how agressive + slab fragmentation reduction works at reclaiming objects from + sparsely populated slabs. This is a percentage. If a slab + contains less than this percentage of objects then reclaim + will attempt to reclaim objects so that the whole slab + page can be freed. The default is 30%. + What: /sys/kernel/slab/cache/deactivate_to_tail Date: February 2008 KernelVersion: 2.6.25 Index: linux/include/linux/slub_def.h =================================================================== --- linux.orig/include/linux/slub_def.h +++ linux/include/linux/slub_def.h @@ -82,6 +82,13 @@ struct kmem_cache { const char *name; /* Name (only for display!) */ struct list_head list; /* List of slab caches */ int red_left_pad; /* Left redzone padding size */ + + int defrag_ratio; /* + * Ratio used to check the percentage of + * objects allocate in a slab page. + * If less than this ratio is allocated + * then reclaim attempts are made. + */ #ifdef CONFIG_SYSFS struct kobject kobj; /* For sysfs */ #endif -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: email@kvack.org