Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp289601imu; Thu, 20 Dec 2018 22:29:06 -0800 (PST) X-Google-Smtp-Source: ALg8bN5t44teUTaMGbF0M2PCV3ICcBhnu1ve0QOK8RUaasOeJDvBP+ieOyU0dmNdVxgLnO3byqWP X-Received: by 2002:a65:500c:: with SMTP id f12mr1201374pgo.226.1545373746635; Thu, 20 Dec 2018 22:29:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1545373746; cv=none; d=google.com; s=arc-20160816; b=VcH0kykYS92o6vVwyenzBiPar2O2MT/KYoZu5iNywRgzUhbto7b0hdKAe/9QOj1APc jmsOf9Un9KDpVyOlKYKfZcTFbyOByk5WcfHKQ3SrBYV4bXtapnxhezuCRddXKCitAKyi X/rcndecTwBnQ5BbcKgby1iMb8jHKSxshLXtTJqVpiTBaCelulrV0aThgCXZ7yPEqN6J XvOdgTIJRmya57gv48EMuuYsyv6KznNT+Ec3SHRx6GOh73uo82eHt7n6EvJq0MUUeXoF 3/BjxWEs9pJsbn3493f7YLX2FevMbwtOldv6hBEk4c4NKm0myxMnNkdkUNLO7jYrp2jY O+6g== 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=tMJflD5NVJ4V9q8P29WkibQrcq00hjoERQHQ4TCQo7A=; b=zlEO3rUwLL3acHI3KgJkMWJ4ntB7q5viUmiIW74hME76o15TxAHH/h/ZYmTU6R7mXB YWPB61ZmhYqoO9Z54EQ1n/yVVrPogYhVWlFsbAUghTSXe8NazfM2IeElBfVsKojPGtPM CqqV7IMZC3IjS7ur+i3oYeOMsfzJ7e3Ew+Q9lVD9hO6V/m+fwCmeV+GRLzecJQf94ufL dxIggWyVhf+ayr+LMWNkIBk99y0v9N0XSnstnwULiECvPdNgX9nx1VbmCJxXY40zDZgW ORu1XjUP/4k1zbfw3JjlGj73YW2MNL2ddYjZI3XiFs5qIHdz9hQSLXUX+LeaVJ6joYOw wumw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@amazonses.com header.s=ug7nbtf4gccmlpwj322ax3p6ow6yfsug header.b=PfolZphx; 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 i62si8365983pfc.17.2018.12.20.22.28.50; Thu, 20 Dec 2018 22:29:06 -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=PfolZphx; 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 S2389471AbeLTTWe (ORCPT + 99 others); Thu, 20 Dec 2018 14:22:34 -0500 Received: from a9-32.smtp-out.amazonses.com ([54.240.9.32]:38054 "EHLO a9-32.smtp-out.amazonses.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389335AbeLTTWB (ORCPT ); Thu, 20 Dec 2018 14:22:01 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/simple; s=ug7nbtf4gccmlpwj322ax3p6ow6yfsug; d=amazonses.com; t=1545333720; 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=HPynk5ie8DqlrwTSrcpoX8ICqEk/Juei7kWbVieJc3U=; b=PfolZphxIyAKtwwsB+etH1iPIkc5vgB18IIUZeZFp+eNrdEkSPSxmjzp2/HrWYBD 6jNi+e3ZPWy1bh34NwFCLIQXbD4VJEqXD6sowCDjyMi/oR/JGbPKLJ78ZjXGhVt4Prf +vNus1fbj5+deIsZuLLB5qaBnqanDwkpGAKDAHOo= Message-ID: <01000167cd1143e3-1533fccc-7036-4a4e-97ea-5be8b347bbf0-000000@email.amazonses.com> User-Agent: quilt/0.65 Date: Thu, 20 Dec 2018 19:22:00 +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 4/7] slub: Sort slab cache list and establish maximum objects for defrag slabs References: <20181220192145.023162076@linux.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline; filename=sort_and_max X-SES-Outgoing: 2018.12.20-54.240.9.32 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 It is advantageous to have all defragmentable slabs together at the beginning of the list of slabs so that there is no need to scan the complete list. Put defragmentable caches first when adding a slab cache and others last. Determine the maximum number of objects in defragmentable slabs. This allows the sizing of the array holding refs to objects in a slab later. Signed-off-by: Christoph Lameter --- mm/slub.c | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) Index: linux/mm/slub.c =================================================================== --- linux.orig/mm/slub.c +++ linux/mm/slub.c @@ -196,6 +196,9 @@ static inline bool kmem_cache_has_cpu_pa /* Use cmpxchg_double */ #define __CMPXCHG_DOUBLE ((slab_flags_t __force)0x40000000U) +/* Maximum objects in defragmentable slabs */ +static unsigned int max_defrag_slab_objects; + /* * Tracking user of a slab. */ @@ -4310,22 +4313,45 @@ int __kmem_cache_create(struct kmem_cach return err; } +/* + * Allocate a slab scratch space that is sufficient to keep at least + * max_defrag_slab_objects pointers to individual objects and also a bitmap + * for max_defrag_slab_objects. + */ +static inline void *alloc_scratch(void) +{ + return kmalloc(max_defrag_slab_objects * sizeof(void *) + + BITS_TO_LONGS(max_defrag_slab_objects) * sizeof(unsigned long), + GFP_KERNEL); +} + void kmem_cache_setup_mobility(struct kmem_cache *s, kmem_isolate_func isolate, kmem_migrate_func migrate) { + int max_objects = oo_objects(s->max); + /* * Defragmentable slabs must have a ctor otherwise objects may be * in an undetermined state after they are allocated. */ BUG_ON(!s->ctor); + + mutex_lock(&slab_mutex); + s->isolate = isolate; s->migrate = migrate; + /* * Sadly serialization requirements currently mean that we have * to disable fast cmpxchg based processing. */ s->flags &= ~__CMPXCHG_DOUBLE; + list_move(&s->list, &slab_caches); /* Move to top */ + if (max_objects > max_defrag_slab_objects) + max_defrag_slab_objects = max_objects; + + mutex_unlock(&slab_mutex); } EXPORT_SYMBOL(kmem_cache_setup_mobility); Index: linux/mm/slab_common.c =================================================================== --- linux.orig/mm/slab_common.c +++ linux/mm/slab_common.c @@ -393,7 +393,7 @@ static struct kmem_cache *create_cache(c goto out_free_cache; s->refcount = 1; - list_add(&s->list, &slab_caches); + list_add_tail(&s->list, &slab_caches); memcg_link_cache(s); out: if (err)