Received: by 2002:ac0:aed5:0:0:0:0:0 with SMTP id t21csp5584558imb; Thu, 7 Mar 2019 20:16:32 -0800 (PST) X-Google-Smtp-Source: APXvYqyLywnOQIBjK6m+WEESLRi8nmFt7Tv6Ee1u7m/B92Cbn3/HS/FMndsj2IZ7ukf2juAz8sTR X-Received: by 2002:a17:902:6b47:: with SMTP id g7mr17026587plt.100.1552018592404; Thu, 07 Mar 2019 20:16:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1552018592; cv=none; d=google.com; s=arc-20160816; b=sriaLKcmIib+FRk6zy6sPXrz3TGF1StWGK5YlEtg6uDRqZHcUb47E2NZRRZ6sfLKc5 nnDQ5Z1+aLfMlSQWqKmOuD13yF0UtKSHws4dbToGk/mbQA9ZbXCnywDSBzPCMe+GeVX2 pTbF0LQUkUdq7SmaIL7WnsQDbZjl8D+7p7wh1jtqc/0EKNHFq9YBpK4LrYzGAfKRN5tZ gfiY4LcZgywkxhoo4lCaqcvfCbfSz4Bfuiep4oqmDNO6oWKzJqxAb/ZlC6ecW1zBMG04 vZyHUvOjMeYseZBFEK4TSUMjRs8NtJLxOYgPcZfvbaicepixmxZTvp8JJOBFS3m+DxAw ++Ng== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=7KlkGOfn94pNrR5k4Aw3I2CbER2w6gJmF5fBjSSPEBI=; b=rtSASONNbhSnDYHtYQR9pLaoyDFb3WvO4xF2QSlyGm/b+/kXrLV/7KVFGT0Cvnsf1/ CfanVND7eF88URhwDsy4cysF4YPbQ76tHKzlafnYHyJ8LRzVomjAxqhtFO17c2BlZHW9 HQhf1oNErxdEAHrGqr5zQ0k0/gUDar8a9G0guivvBWTrvDvJrMnTwR5RIk54UdUd+joj OthuOsRGh25jqM4tktsIu5pue6+6hA9Xsj/7NsJ25sRCsiWIfWmHnxcwUxJDdLPiSl7Q fjdXvKFlcgXbX+Inp31q7TW18G3QDUcF3M9RAVxSgc/ojllHNwTw/8uTnRGIgPQr+CvU JXNw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b=6IBJtDUG; 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=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b1si6208664pld.351.2019.03.07.20.16.16; Thu, 07 Mar 2019 20:16:32 -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=pass header.i=@messagingengine.com header.s=fm2 header.b=6IBJtDUG; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726480AbfCHEPa (ORCPT + 99 others); Thu, 7 Mar 2019 23:15:30 -0500 Received: from wout2-smtp.messagingengine.com ([64.147.123.25]:36927 "EHLO wout2-smtp.messagingengine.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726449AbfCHEPZ (ORCPT ); Thu, 7 Mar 2019 23:15:25 -0500 Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailout.west.internal (Postfix) with ESMTP id D48D234AD; Thu, 7 Mar 2019 23:15:23 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute3.internal (MEProxy); Thu, 07 Mar 2019 23:15:24 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:date:from :in-reply-to:message-id:mime-version:references:subject:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm2; bh=7KlkGOfn94pNrR5k4Aw3I2CbER2w6gJmF5fBjSSPEBI=; b=6IBJtDUG jLqtpyAzG6aFaZlCfeLvOnLxWfO1jabUczoqCLk7mqzrK2HVQC5UXOECilcK3dxQ zXtgiiEJp1hsugZUgJUyEiFKgooWTLvx7Tol42sg7kViarMkIAvlWlRw733oMLwn kdqfyezNHWAOifKGI1s3dTd4OPmRij+AzuhQVZmy8Xqy1sIDq4KsLkSe7Tu2Btps iXfHRe9JIhvEHQRKO+Y3lTl2x10ZdvGwZFADEjgOD3pi/ecBq9+woSLAdanhdpEd K0FUH/nZILktpcgtrxj2OiB6OVsIND0pzQULCFezSZvHEXBoG2EFNxOreyZM/YtW 6pjuI2Sr61CC2w== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedutddrfeelgdeifecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpefhvffufffkofgjfhgggfestdekredtredttdenucfhrhhomhepfdfvohgsihhn ucevrdcujfgrrhguihhnghdfuceothhosghinheskhgvrhhnvghlrdhorhhgqeenucfkph epuddvgedrudeiledrhedrudehkeenucfrrghrrghmpehmrghilhhfrhhomhepthhosghi nheskhgvrhhnvghlrdhorhhgnecuvehluhhsthgvrhfuihiivgepie X-ME-Proxy: Received: from eros.localdomain (124-169-5-158.dyn.iinet.net.au [124.169.5.158]) by mail.messagingengine.com (Postfix) with ESMTPA id 736AAE4548; Thu, 7 Mar 2019 23:15:20 -0500 (EST) From: "Tobin C. Harding" To: Andrew Morton Cc: "Tobin C. Harding" , Christopher Lameter , Pekka Enberg , Matthew Wilcox , Tycho Andersen , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [RFC 07/15] slub: Add defrag_used_ratio field and sysfs support Date: Fri, 8 Mar 2019 15:14:18 +1100 Message-Id: <20190308041426.16654-8-tobin@kernel.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190308041426.16654-1-tobin@kernel.org> References: <20190308041426.16654-1-tobin@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In preparation for enabling defragmentation of slab pages. "defrag_used_ratio" is used to set the threshold at which defragmentation should be attempted on a slab page. "defrag_used_ratio" is a percentage in the range of 0 - 100 (inclusive). If less than that percentage of slots in a slab page are in use then 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 more than 3 out of 10 available slots for objects need to be in use otherwise slab defragmentation will be attempted on the remaining objects. Co-developed-by: Christoph Lameter Signed-off-by: Tobin C. Harding --- Documentation/ABI/testing/sysfs-kernel-slab | 14 ++++++++++++ include/linux/slub_def.h | 7 ++++++ mm/slub.c | 24 +++++++++++++++++++++ 3 files changed, 45 insertions(+) diff --git a/Documentation/ABI/testing/sysfs-kernel-slab b/Documentation/ABI/testing/sysfs-kernel-slab index 29601d93a1c2..7770c03be6b4 100644 --- a/Documentation/ABI/testing/sysfs-kernel-slab +++ b/Documentation/ABI/testing/sysfs-kernel-slab @@ -180,6 +180,20 @@ Description: list. It can be written to clear the current count. Available when CONFIG_SLUB_STATS is enabled. +What: /sys/kernel/slab/cache/defrag_used_ratio +Date: February 2019 +KernelVersion: 5.0 +Contact: Christoph Lameter + Pekka Enberg , +Description: + The defrag_used_ratio file allows the control of how aggressive + slab fragmentation reduction works at reclaiming objects from + sparsely populated slabs. This is a percentage. If a slab has + less than this percentage of objects allocated then reclaim will + attempt to reclaim objects so that the whole slab page can be + freed. 0% specifies no reclaim attempt (defrag disabled), 100% + specifies attempt to reclaim all pages. The default is 30%. + What: /sys/kernel/slab/cache/deactivate_to_tail Date: February 2008 KernelVersion: 2.6.25 diff --git a/include/linux/slub_def.h b/include/linux/slub_def.h index a7340a1ed5dc..6da6197ca973 100644 --- a/include/linux/slub_def.h +++ b/include/linux/slub_def.h @@ -107,6 +107,13 @@ 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_used_ratio; /* + * Ratio used to check against the + * percentage of objects allocated 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; diff --git a/mm/slub.c b/mm/slub.c index f37103e22d3f..515db0f36c55 100644 --- a/mm/slub.c +++ b/mm/slub.c @@ -3642,6 +3642,7 @@ static int kmem_cache_open(struct kmem_cache *s, slab_flags_t flags) set_cpu_partial(s); + s->defrag_used_ratio = 30; #ifdef CONFIG_NUMA s->remote_node_defrag_ratio = 1000; #endif @@ -5261,6 +5262,28 @@ static ssize_t destroy_by_rcu_show(struct kmem_cache *s, char *buf) } SLAB_ATTR_RO(destroy_by_rcu); +static ssize_t defrag_used_ratio_show(struct kmem_cache *s, char *buf) +{ + return sprintf(buf, "%d\n", s->defrag_used_ratio); +} + +static ssize_t defrag_used_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_used_ratio = ratio; + + return length; +} +SLAB_ATTR(defrag_used_ratio); + #ifdef CONFIG_SLUB_DEBUG static ssize_t slabs_show(struct kmem_cache *s, char *buf) { @@ -5585,6 +5608,7 @@ static struct attribute *slab_attrs[] = { &validate_attr.attr, &alloc_calls_attr.attr, &free_calls_attr.attr, + &defrag_used_ratio_attr.attr, #endif #ifdef CONFIG_ZONE_DMA &cache_dma_attr.attr, -- 2.21.0