Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp448905imu; Fri, 21 Dec 2018 01:46:25 -0800 (PST) X-Google-Smtp-Source: ALg8bN443TWOke5PyYS7MxaTrwSZGv6Vs0puk9T9Aa15mrDjqybQbYBIMxAcb69cVGFjx2u3CrwC X-Received: by 2002:a17:902:7c82:: with SMTP id y2mr1775134pll.33.1545385585823; Fri, 21 Dec 2018 01:46:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1545385585; cv=none; d=google.com; s=arc-20160816; b=AxHrwZgz5+/k38Ld0R/N7ZDK0YYX1nwLVtel13zA1mabI99vZkinJCpsePIRqt+o0+ r1F1/he4vOec2OVNz2ZSUJYEVb5Ip67ZerAWVch/1RPnPgmAD+Sss8EA2JgYTlI5X49l m7NJOxsC1IyQOFeqEVNwXJnNZ3rfFTWrDvDDCqDq/p00cIY8oOWguHmnWErQYRViEoMT yp8MhyKg/WjUBQjAYCU9Fcdf0ZlDfR46evSAAYT0eLjqeZ5nysDjNf7Kndlb7ptUh8H1 Tk3Z8dphIsFMbdFZEPc8Fg36FoUPe8+Oc8EXkYQAKKZnjoSI9Sl4B27C+Ift+VlRySkn B7PA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:feedback-id:content-disposition :mime-version:references:subject:cc:cc:cc:cc:cc:cc:cc:cc:cc:cc:cc:to :from:date:user-agent:message-id:dkim-signature; bh=Ivmf8KcU0nLZ7jKiUwDMxrV5SnY1/n4WH4SoklosWW0=; b=H8VzBo+dcJaTQKMPI1EflxdTsjxlCy1XJZK7fX5GUKoACe90RX/5+Mmx1B0jhRRCRE FYM8/CtlYA8N4pc0zC0A/xMMCyorfHVnjGM8MUqtVvEEwPzrPRfw8+QbM1fRixv7ji1Q molb7BNIt/IOpcF3MDPMsWFYzCxcXgiS238z/Cuo+fUijvwUIf5aqOmAa4XOlgVfsxzU g7XzZ2gpkdXsVFpXAJ89lnJxqLJBLpzjWqf4XWzGMBi/TnIamcxdgOE4V3yoDbDaxd80 zTO1U0F+M5TJVn9pxE5PGppm42oTDiAe1YsY7Et/8xTuSN27+nh191FGpfEZ0Qtd+7N5 q8Ow== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@amazonses.com header.s=ug7nbtf4gccmlpwj322ax3p6ow6yfsug header.b=OHCLLzJ6; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f22si20759760pgm.81.2018.12.21.01.46.10; Fri, 21 Dec 2018 01:46:25 -0800 (PST) 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; dkim=fail header.i=@amazonses.com header.s=ug7nbtf4gccmlpwj322ax3p6ow6yfsug header.b=OHCLLzJ6; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389383AbeLTTWC (ORCPT + 99 others); Thu, 20 Dec 2018 14:22:02 -0500 Received: from a9-30.smtp-out.amazonses.com ([54.240.9.30]:54192 "EHLO a9-30.smtp-out.amazonses.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389324AbeLTTV6 (ORCPT ); Thu, 20 Dec 2018 14:21:58 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/simple; s=ug7nbtf4gccmlpwj322ax3p6ow6yfsug; d=amazonses.com; t=1545333717; h=Message-Id:Date:From:To:Cc:Cc:Cc:CC:Cc:Cc:Cc:Cc:Cc:Cc:Cc:Subject:References:MIME-Version:Content-Type:Feedback-ID; bh=9RbM/jvYgrX3laKFEpjCMiN+ksJv3eWbjUkCaqrfwkE=; b=OHCLLzJ6oPFtcW68XCABgoUNOPVk6+3UQC2JsdbyVQyPQYljUakQzjMHr+tVlzug 2Vhpy7LZgA18mSKFfdg/iDG1ZWq+wKqvZZ43b68MiSQdWISkARuNc5UnrfGittJIxn7 ZDgfT1On7RLQBhryQyuP+CQHfiloPZZBUn9hI4OU= Message-ID: <01000167cd113a49-ada7b71e-0fa9-4897-b324-b7a2e1bd0f1c-000000@email.amazonses.com> User-Agent: quilt/0.65 Date: Thu, 20 Dec 2018 19:21:57 +0000 From: Christoph Lameter To: Matthew Wilcox Cc: linux-mm@kvack.org Cc: linux-kernel@vger.kernel.org Cc: Pekka Enberg CC: akpm@linux-foundation.org Cc: Mel Gorman Cc: andi@firstfloor.org Cc: Rik van Riel Cc: Dave Chinner Cc: Christoph Hellwig Cc: Michal Hocko Cc: Mike Kravetz Subject: [RFC 2/7] slub: Add defrag_ratio field and sysfs support References: <20181220192145.023162076@linux.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline; filename=defrag_ratio X-SES-Outgoing: 2018.12.20-54.240.9.30 Feedback-ID: 1.us-east-1.fQZZZ0Xtj2+TD7V5apTT/NrT6QKuPgzCT/IC7XYgDKI=:AmazonSES Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org "defrag_ratio" is used to set the threshold at which defragmentation should be attempted on a slab page. "defrag_ratio" is percentage in the range of 1 - 100. If more than that percentage of slots in a slab page are unused the the slab page will become subject to defragmentation. Add a defrag ratio field and set it to 30% by default. A limit of 30% specifies that less than 3 out of 10 available slots for objects need to be leftover before slab defragmentation will be attempted on the remaining objects. 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 @@ -3628,6 +3628,7 @@ static int kmem_cache_open(struct kmem_c set_cpu_partial(s); + s->defrag_ratio = 30; #ifdef CONFIG_NUMA s->remote_node_defrag_ratio = 1000; #endif @@ -5113,6 +5114,27 @@ static ssize_t destroy_by_rcu_show(struc } SLAB_ATTR_RO(destroy_by_rcu); +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) { @@ -5437,6 +5459,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: December 2018 +KernelVersion: 4.18 +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 + has more than this percentage of available object 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 @@ -104,6 +104,12 @@ struct kmem_cache { unsigned int red_left_pad; /* Left redzone padding size */ const char *name; /* Name (only for display!) */ struct list_head list; /* List of slab caches */ + 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 */ struct work_struct kobj_remove_work;