Skip to contentSkip to conversation

Xarray object migration V1

RFC In review Christoph Lameter 7 participants 24 messages Dec 27, 2017 – Jan 2, 2018

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

cover Xarray object migration V1

This is a patchset on top of Matthew Wilcox Xarray code and implements object migration of xarray nodes. The migration is integrated into the defragmetation and shrinking logic of the slab allocator.

Defragmentation will ensure that all xarray slab pages have less objects available than specified by the slab defrag ratio.

Slab shrinking will create a slab cache with optimal object density. Only one slab page will have available objects per node.

To test apply this patchset on top of Matthew Wilcox Xarray code from Dec 11th (See infradead github).

Then go to

/sys/kernel/slab/radix_tree

Inspect the number of partial slab pages

cat partial

And then perform a cache shrink operation

echo 1 >shrink

This is just a barebones approach using a special mode of the slab migration patchset that does not require refcounts.

If this is acceptable then additional functionality can be added:

1. Migration of objects to a specific node

2. Dispersion of objects across all nodes (MPOL_INTERLEAVE)

3. Subsystems can request to move an object to a specific node.

4. Tying into the page migration and page defragmentation logic so that so far unmovable pages that are in the way of creating a contiguous block of memory will become movable.

This is only possible for xarray for now but it would be worthwhile to extend this to dentries and inodes.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#1 lore raw

RFC 2/8 slub: Add defrag_ratio field and sysfs support

"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.

---
 Documentation/ABI/testing/sysfs-kernel-slab |   13 +++++++++++++
 include/linux/slub_def.h                    |    6 ++++++
 mm/slub.c                                   |   23 +++++++++++++++++++++++
 3 files changed, 42 insertions(+)
mm/slub.c +23 -0
Index: linux/mm/slub.c
===================================================================
@@ -3613,6 +3613,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
@@ -5078,6 +5079,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)
 {
@@ -5402,6 +5424,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,
Documentation/ABI/testing/sysfs-kernel-slab +13 -0
Index: 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 2017
+KernelVersion:	4.16
+Contact:	Christoph Lameter <[email protected]>
+		Pekka Enberg <[email protected]>,
+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
include/linux/slub_def.h +6 -0
Index: linux/include/linux/slub_def.h
===================================================================
@@ -104,6 +104,12 @@ struct kmem_cache {
 	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;

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

maintainer
#2 lore raw

Re: [RFC 2/8] slub: Add defrag_ratio field and sysfs support

Quoted 11 lines · Christoph Lameter

+++ linux/Documentation/ABI/testing/sysfs-kernel-slab

Documentation/ABI/testing/sysfs-kernel-slab +6 -0
@@ -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 2017
+KernelVersion:	4.16
+Contact:	Christoph Lameter <[email protected]>
+		Pekka Enberg <[email protected]>,
+Description:

Documentation/ABI/testing/sysfs-kernel-slab Description: · line 198

Quoted 10 lines
Documentation/ABI/testing/sysfs-kernel-slab +7 -0
+		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

Should this documentation mention it's SLUB-only?

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#3 lore raw

Re: [RFC 2/8] slub: Add defrag_ratio field and sysfs support

Quoted 5 lines · Matthew Wilcox
Quoted 3 lines

What: /sys/kernel/slab/cache/deactivate_to_tail
Date: February 2008
KernelVersion: 2.6.25

Should this documentation mention it's SLUB-only?

It could but /sys/kernel/slab is only supported for SLUB at this point. Sysfs handling should move into slab_common.c though long terms so that it works for any allocator.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#4 lore raw

RFC 3/8 slub: Add isolate() and migrate() methods

In reply to Christoph Lameter

Add the two methods needed for moving objects and enable the display of the callbacks via the /sys/kernel/slab interface.

Add documentation explaining the use of these methods and the prototypes for slab.h. Add functions to setup the callbacks method for a slab cache.

Add empty functions for SLAB/SLOB. The API is generic so it could be theoretically implemented for these allocators as well.

---
 include/linux/slab.h     |   50 +++++++++++++++++++++++++++++++++++++++++++++++
 include/linux/slub_def.h |    3 ++
 mm/slub.c                |   29 ++++++++++++++++++++++++++-
 3 files changed, 81 insertions(+), 1 deletion(-)
include/linux/slub_def.h +3 -0
Index: linux/include/linux/slub_def.h
===================================================================
@@ -98,6 +98,9 @@ struct kmem_cache {
 	gfp_t allocflags;	/* gfp flags to use on each alloc */
 	int refcount;		/* Refcount for slab cache destroy */
 	void (*ctor)(void *);
+	kmem_isolate_func *isolate;
+	kmem_migrate_func *migrate;
+
 	int inuse;		/* Offset to metadata */
 	int align;		/* Alignment */
 	int reserved;		/* Reserved bytes at the end of slabs */
mm/slub.c +33 -1
Index: linux/mm/slub.c
===================================================================
@@ -3479,7 +3479,6 @@ static int calculate_sizes(struct kmem_c
 	else
 		s->flags &= ~__OBJECT_POISON;
 
-
 	/*
 	 * If we are Redzoning then check if there is some space between the
 	 * end of the object and the free pointer. If not then add an
@@ -4275,6 +4274,25 @@ int __kmem_cache_create(struct kmem_cach
 	return err;
 }
 
+void kmem_cache_setup_mobility(struct kmem_cache *s,
+	kmem_isolate_func isolate, kmem_migrate_func migrate)
+{
+	/*
+	 * Defragmentable slabs must have a ctor otherwise objects may be
+	 * in an undetermined state after they are allocated.
+	 */
+	BUG_ON(!s->ctor);
+	s->isolate = isolate;
+	s->migrate = migrate;
+	/*
+	 * Sadly serialization requirements currently mean that we have
+	 * to disable fast cmpxchg based processing.
+	 */
+	s->flags &= ~__CMPXCHG_DOUBLE;
+
+}
+EXPORT_SYMBOL(kmem_cache_setup_mobility);
+
 void *__kmalloc_track_caller(size_t size, gfp_t gfpflags, unsigned long caller)
 {
 	struct kmem_cache *s;
@@ -4969,6 +4987,20 @@ static ssize_t ops_show(struct kmem_cach
 
 	if (s->ctor)
 		x += sprintf(buf + x, "ctor : %pS\n", s->ctor);
+
+	if (s->isolate) {
+		x += sprintf(buf + x, "isolate : ");
+		x += sprint_symbol(buf + x,
+				(unsigned long)s->isolate);
+		x += sprintf(buf + x, "\n");
+	}
+
+	if (s->migrate) {
+		x += sprintf(buf + x, "migrate : ");
+		x += sprint_symbol(buf + x,
+				(unsigned long)s->migrate);
+		x += sprintf(buf + x, "\n");
+	}
 	return x;
 }
 SLAB_ATTR_RO(ops);
include/linux/slab.h +62 -0

68 lines not on this page · raw message

mm/slab_common.c +1 -1
Index: linux/mm/slab_common.c
===================================================================
@@ -278,7 +278,7 @@ int slab_unmergeable(struct kmem_cache *
 	if (!is_root_cache(s))
 		return 1;
 
-	if (s->ctor)
+	if (s->ctor || s->isolate || s->migrate)
 		return 1;
 
 	/*

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

maintainer
#5 lore raw

Re: [RFC 3/8] slub: Add isolate() and migrate() methods

Quoted 10 lines · Christoph Lameter
include/linux/slub_def.h +3 -0
@@ -98,6 +98,9 @@ struct kmem_cache {
 	gfp_t allocflags;	/* gfp flags to use on each alloc */
 	int refcount;		/* Refcount for slab cache destroy */
 	void (*ctor)(void *);
+	kmem_isolate_func *isolate;
+	kmem_migrate_func *migrate;
+
 	int inuse;		/* Offset to metadata */
 	int align;		/* Alignment */
 	int reserved;		/* Reserved bytes at the end of slabs */

[...]

include/linux/slab.h void memcg_deactivate_kmem_caches(struct · line 205

Quoted 10 lines
include/linux/slab.h +10 -0
+/*
+ * kmem_cache_setup_mobility() is used to setup callbacks for a slab cache.
+ */
+#ifdef CONFIG_SLUB
+void kmem_cache_setup_mobility(struct kmem_cache *, kmem_isolate_func,
+						kmem_migrate_func);
+#else
+static inline void kmem_cache_setup_mobility(struct kmem_cache *s,
+	kmem_isolate_func isolate, kmem_migrate_func migrate) {}
+#endif

Is this the right approach? I could imagine there being more ops in the future. I suspect we should bite the bullet now and do:

struct kmem_cache_operations {
	void (*ctor)(void *);
	void *(*isolate)(struct kmem_cache *, void **objs, int nr);
	void (*migrate)(struct kmem_cache *, void **objs, int nr, int node,
			void *private);
};

Not sure how best to convert the existing constructor users to this scheme. Perhaps cheat ...

- void (*ctor)(void *);
+ union {
+ void (*ctor)(void *);
+ const struct kmem_cache_operations *ops;
+ };

and use a slab flag to tell you which to use.

mm/slub.c static ssize_t ops_show(struct kmem_cach · line 4996

Quoted 11 lines
mm/slub.c +7 -0
@@ -4969,6 +4987,20 @@ static ssize_t ops_show(struct kmem_cach
 
 	if (s->ctor)
 		x += sprintf(buf + x, "ctor : %pS\n", s->ctor);
+
+	if (s->isolate) {
+		x += sprintf(buf + x, "isolate : ");
+		x += sprint_symbol(buf + x,
+				(unsigned long)s->isolate);
+		x += sprintf(buf + x, "\n");
+	}

Here you could print the symbol of the ops vector instead of the function pointer ...

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

maintainer
#6 lore raw

Re: [RFC 3/8] slub: Add isolate() and migrate() methods

Quoted 2 lines · Matthew Wilcox

Is this the right approach? I could imagine there being more ops in the future. I suspect we should bite the bullet now and do:

I thought of a cute additional slab operation we could define, print(). We could do something like this ...

        struct page *page = virt_to_head_page(ptr);
        if (!PageSlab(page))
                return false;
        slab = page->slab_cache;
        if (!(slab->flags & SLAB_FLAGS_OPS) || !slab->ops->print)
                return false;
        slab->ops->print(ptr);
        return true;

and get nice debugging output like we have for VM_BUG_ON_PAGE, only for any type that's implemented a slab operations vec. Of course, this won't replace VM_BUG_ON_PAGE because struct pages aren't slab-allocated (but could we pretend they are?)

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#7 lore raw

Re: [RFC 3/8] slub: Add isolate() and migrate() methods

Quoted 12 lines · Matthew Wilcox

I thought of a cute additional slab operation we could define, print(). We could do something like this ...

        struct page *page = virt_to_head_page(ptr);
        if (!PageSlab(page))
                return false;
        slab = page->slab_cache;
        if (!(slab->flags & SLAB_FLAGS_OPS) || !slab->ops->print)
                return false;
        slab->ops->print(ptr);
        return true;
Quoted 4 lines

and get nice debugging output like we have for VM_BUG_ON_PAGE, only for any type that's implemented a slab operations vec. Of course, this won't replace VM_BUG_ON_PAGE because struct pages aren't slab-allocated (but could we pretend they are?)

Cute...

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#8 lore raw

Re: [RFC 3/8] slub: Add isolate() and migrate() methods

In reply to Matthew Wilcox
Quoted 9 lines · Matthew Wilcox

Is this the right approach? I could imagine there being more ops in the future. I suspect we should bite the bullet now and do:

struct kmem_cache_operations {
	void (*ctor)(void *);
	void *(*isolate)(struct kmem_cache *, void **objs, int nr);
	void (*migrate)(struct kmem_cache *, void **objs, int nr, int node,
			void *private);
};

Well yes but that would mean converting the existing call sites.

Quoted 2 lines

Not sure how best to convert the existing constructor users to this scheme. Perhaps cheat ...

One of the prior releases of slab defragmentation did this. We could do it at some point. For now the approach avoids changing the API.

Quoted 14 lines

mm/slub.c static ssize_t ops_show(struct kmem_cach · line 4996

Quoted 11 lines
mm/slub.c +7 -0
@@ -4969,6 +4987,20 @@ static ssize_t ops_show(struct kmem_cach
 
 	if (s->ctor)
 		x += sprintf(buf + x, "ctor : %pS\n", s->ctor);
+
+	if (s->isolate) {
+		x += sprintf(buf + x, "isolate : ");
+		x += sprint_symbol(buf + x,
+				(unsigned long)s->isolate);
+		x += sprintf(buf + x, "\n");
+	}

Here you could print the symbol of the ops vector instead of the function pointer ...

Well yes if we had it and thne we could avoid printing individual fields.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#9 lore raw

RFC 4/8 slub: Sort slab cache list and establish maximum objects for defrag slabs

In reply to Christoph Lameter

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.

---
 mm/slub.c |   26 ++++++++++++++++++++++++--
 1 file changed, 24 insertions(+), 2 deletions(-)
mm/slub.c +26 -0
Index: linux/mm/slub.c
===================================================================
@@ -197,6 +197,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.
  */
@@ -4274,22 +4278,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);
 
mm/slab_common.c +1 -1
Index: linux/mm/slab_common.c
===================================================================
@@ -392,7 +392,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)

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#10 lore raw

RFC 5/8 slub: Slab defrag core

In reply to Christoph Lameter

Slab defragmentation may occur:

1. Unconditionally when kmem_cache_shrink is called on a slab cache by the kernel calling kmem_cache_shrink.

2. Through the use of the slabinfo command.

3. Per node defrag conditionally when kmem_cache_defrag(<node>) is called (can be called from reclaim code with a later patch).

Defragmentation is only performed if the fragmentation of the slab is lower than the specified percentage. Fragmentation ratios are measured by calculating the percentage of objects in use compared to the total number of objects that the slab page can accomodate.

The scanning of slab caches is optimized because the defragmentable slabs come first on the list. Thus we can terminate scans on the first slab encountered that does not support defragmentation.

kmem_cache_defrag() takes a node parameter. This can either be -1 if defragmentation should be performed on all nodes, or a node number.

A couple of functions must be setup via a call to kmem_cache_setup_defrag() in order for a slabcache to support defragmentation. These are

kmem_defrag_isolate_func (void *isolate(struct kmem_cache *s, void **objects, int nr))

Must stabilize that the objects and ensure that they will not be freed until the migration function is complete. SLUB guarantees that
the objects are still allocated. However, other threads may be blocked in slab_free() attempting to free objects in the slab. These may succeed as soon as isolate() returns to the slab allocator. The function must be able to detect such situations and void the attempts to free such objects (by for example voiding the corresponding entry in the objects array).

No slab operations may be performed in isolate(). Interrupts are disabled. What can be done is very limited. The slab lock for the page that contains the object is taken. Any attempt to perform a slab operation may lead to a deadlock.

kmem_defrag_isolate_func returns a private pointer that is passed to kmem_defrag_kick_func(). Should we be unable to obtain all references then that pointer may indicate to the kick() function that it should not attempt any object removal or move but simply undo the measure that were used to stabilize the object.

kmem_defrag_migrate_func (void migrate(struct kmem_cache *, void **objects, int nr,
int node, void *get_result))

After SLUB has stabilzed the objects in a
slab it will then drop all locks and use migrate() to move objects out of the slab. The existence of the object is guaranteed by virtue of the earlier obtained references via kmem_defrag_get_func(). The callback may perform any slab operation since no locks are held at the time of call.

The callback should remove the object from the slab in some way. This may be accomplished by reclaiming the object and then running kmem_cache_free() or reallocating it and then running kmem_cache_free(). Reallocation is advantageous because the partial slabs were just sorted to have the partial slabs with the most objects first. Reallocation is likely to result in filling up a slab in addition to freeing up one slab. A filled up slab can also be removed from the partial list. So there could be a double effect.

kmem_defrag_migrate_func() does not return a result. SLUB will check the number of remaining objects in the slab. If all objects were removed then the slab is freed and we have reduced the overall fragmentation of the slab cache.

---
 include/linux/slab.h |    3 
 mm/slub.c            |  265 ++++++++++++++++++++++++++++++++++++++++-----------
 2 files changed, 215 insertions(+), 53 deletions(-)
mm/slub.c +264 -75
Index: linux/mm/slub.c
===================================================================
@@ -353,6 +353,12 @@ static __always_inline void slab_lock(st
 	bit_spin_lock(PG_locked, &page->flags);
 }
 
+static __always_inline int slab_trylock(struct page *page)
+{
+	VM_BUG_ON_PAGE(PageTail(page), page);
+	return bit_spin_trylock(PG_locked, &page->flags);
+}
+
 static __always_inline void slab_unlock(struct page *page)
 {
 	VM_BUG_ON_PAGE(PageTail(page), page);
@@ -3903,79 +3909,6 @@ void kfree(const void *x)
 }
 EXPORT_SYMBOL(kfree);
 
-#define SHRINK_PROMOTE_MAX 32
-
-/*
- * kmem_cache_shrink discards empty slabs and promotes the slabs filled
- * up most to the head of the partial lists. New allocations will then
- * fill those up and thus they can be removed from the partial lists.
- *
- * The slabs with the least items are placed last. This results in them
- * being allocated from last increasing the chance that the last objects
- * are freed in them.
- */
-int __kmem_cache_shrink(struct kmem_cache *s)
-{
-	int node;
-	int i;
-	struct kmem_cache_node *n;
-	struct page *page;
-	struct page *t;
-	struct list_head discard;
-	struct list_head promote[SHRINK_PROMOTE_MAX];
-	unsigned long flags;
-	int ret = 0;
-
-	flush_all(s);
-	for_each_kmem_cache_node(s, node, n) {
-		INIT_LIST_HEAD(&discard);
-		for (i = 0; i < SHRINK_PROMOTE_MAX; i++)
-			INIT_LIST_HEAD(promote + i);
-
-		spin_lock_irqsave(&n->list_lock, flags);
-
-		/*
-		 * Build lists of slabs to discard or promote.
-		 *
-		 * Note that concurrent frees may occur while we hold the
-		 * list_lock. page->inuse here is the upper limit.
-		 */
-		list_for_each_entry_safe(page, t, &n->partial, lru) {
-			int free = page->objects - page->inuse;
-
-			/* Do not reread page->inuse */
-			barrier();
-
-			/* We do not keep full slabs on the list */
-			BUG_ON(free <= 0);
-
-			if (free == page->objects) {
-				list_move(&page->lru, &discard);
-				n->nr_partial--;
-			} else if (free <= SHRINK_PROMOTE_MAX)
-				list_move(&page->lru, promote + free - 1);
-		}
-
-		/*
-		 * Promote the slabs filled up most to the head of the
-		 * partial list.
-		 */
-		for (i = SHRINK_PROMOTE_MAX - 1; i >= 0; i--)
-			list_splice(promote + i, &n->partial);
-
-		spin_unlock_irqrestore(&n->list_lock, flags);
-
-		/* Release empty slabs */
-		list_for_each_entry_safe(page, t, &discard, lru)
-			discard_slab(s, page);
-
-		if (slabs_node(s, node))
-			ret = 1;
-	}
-
-	return ret;
-}
-
 #ifdef CONFIG_MEMCG
 static void kmemcg_cache_deact_after_rcu(struct kmem_cache *s)
 {
@@ -4289,14 +4222,270 @@ static inline void *alloc_scratch(void)
 		GFP_KERNEL);
 }
 
+/*
+ * Move all objects in the given slab.
+ *
+ * If the target node is the current node then the object is moved else
+ * where on the same node. Which is an effective way of defragmentation
+ * since the current slab page with its object is exempt from allocation.
+ *
+ * The scratch area passed to list function is sufficient to hold
+ * struct listhead times objects per slab. We use it to hold void ** times
+ * objects per slab plus a bitmap for each object.
+ */
+static void kmem_cache_move(struct page *page, void *scratch, int node)
+{
+	void **vector = scratch;
+	void *p;
+	void *addr = page_address(page);
+	struct kmem_cache *s;
+	unsigned long *map;
+	int count;
+	void *private;
+	unsigned long flags;
+	unsigned long objects;
+
+	local_irq_save(flags);
+	slab_lock(page);
+
+	BUG_ON(!PageSlab(page));	/* Must be s slab page */
+	BUG_ON(!page->frozen);	/* Slab must have been frozen earlier */
+
+	s = page->slab_cache;
+	objects = page->objects;
+	map = scratch + objects * sizeof(void **);
+
+	/* Determine used objects */
+	bitmap_fill(map, objects);
+	for (p = page->freelist; p; p = get_freepointer(s, p))
+		__clear_bit(slab_index(p, s, addr), map);
+
+	/* Build vector of pointers to objects */
+	count = 0;
+	memset(vector, 0, objects * sizeof(void **));
+	for_each_object(p, s, addr, objects)
+		if (test_bit(slab_index(p, s, addr), map))
+			vector[count++] = p;
+
+	if (s->isolate)
+		private = s->isolate(s, vector, count);
+	else
+		/*
+		 * Objects do not need to be isolated.
+		 */
+		private = NULL;
+
+	/*
+	 * Pinned the objects. Now we can drop the slab lock. The slab
+	 * is frozen so it cannot vanish from under us nor will
+	 * allocations be performed on the slab. However, unlocking the
+	 * slab will allow concurrent slab_frees to proceed. So
+	 * the subsystem must have a way to tell from the content
+	 * of the object that it was freed.
+	 *
+	 * If neither RCU nor ctor is being used then the object
+	 * may be modified by the allocator after being freed
+	 * which may disrupt the ability of the migrate function
+	 * to tell if the object is free or not.
+	 */
+	slab_unlock(page);
+	local_irq_restore(flags);
+
+	/*
+	 * Perform callbacks to move the objects.
+	 */
+	s->migrate(s, vector, count, node, private);
+}
+
+/*
+ * Move slab objects on a particular node of the cache.
+ * Release slabs with zero objects and tryg to call the move function for
+ * slabs with less than the configured percentage of objects allocated.
+ *
+ * Returns the number of slabs left on the node after the operation.
+ */
+static unsigned long __move(struct kmem_cache *s, int node,
+		int target_node, int ratio)
+{
+	unsigned long flags;
+	struct page *page, *page2;
+	LIST_HEAD(move_list);
+	struct kmem_cache_node *n = get_node(s, node);
+
+	if (node == target_node && n->nr_partial <= 1)
+		/*
+		 * Trying to reduce fragmentataion on a node but there is
+		 * only a single or no partial slab page. This is already
+		 * the optimal object density that we can reach
+		 */
+		goto out;
+
+	spin_lock_irqsave(&n->list_lock, flags);
+	list_for_each_entry_safe(page, page2, &n->partial, lru) {
+		if (!slab_trylock(page))
+			/* Busy slab. Get out of the way */
+			continue;
+
+		if (page->inuse) {
+			if (page->inuse > ratio * page->objects / 100) {
+				slab_unlock(page);
+				/*
+				 * Skip slab because the object density
+				 * in the slab page is high enough
+				*/
+				continue;
+			}
+
+			list_move(&page->lru, &move_list);
+			if (s->migrate) {
+				/* Remove page from being considered for allocations */
+				n->nr_partial--;
+				page->frozen = 1;
+			}
+			slab_unlock(page);
+		} else {
+			/* Empty slab page */
+			list_del(&page->lru);
+			n->nr_partial--;
+			slab_unlock(page);
+			discard_slab(s, page);
+		}
+	}
+
+	if (!s->migrate)
+		/*
+		 * No defrag method. By simply putting the zaplist at the
+		 * end of the partial list we can let them simmer longer
+		 * and thus increase the chance of all objects being
+		 * reclaimed.
+		 *
+		 * We have effectively sorted the partial list and put
+		 * the slabs with more objects first. As soon as they
+		 * are allocated they are going to be removed from the
+		 * partial list.
+		 */
+		list_splice(&move_list, n->partial.prev);
+
+
+	spin_unlock_irqrestore(&n->list_lock, flags);
+
+	if (s->migrate && !list_empty(&move_list)) {
+		void **scratch = alloc_scratch();
+		struct page *page;
+		struct page *page2;
+
+		if (scratch) {
+			/* Try to remove / move the objects left */
+			list_for_each_entry(page, &move_list, lru) {
+				if (page->inuse)
+					kmem_cache_move(page, scratch, target_node);
+			}
+			kfree(scratch);
+		}
+
+		/* Inspect results and dispose of pages */
+		spin_lock_irqsave(&n->list_lock, flags);
+		list_for_each_entry_safe(page, page2, &move_list, lru) {
+			slab_lock(page);
+			page->frozen = 0;
+
+			if (page->inuse) {
+				/*
+				 * Objects left in slab page move it to
+				 * the tail of the partial list to
+				 * increase the change that the freeing
+				 * of the remaining objects will
+				 * free the slab page
+				 */
+				n->nr_partial++;
+				list_add_tail(&n->partial, &page->lru);
+				slab_unlock(page);
+
+			} else {
+				slab_unlock(page);
+				discard_slab(s, page);
+			}
+		}
+		spin_unlock_irqrestore(&n->list_lock, flags);
+	}
+out:
+	return atomic_long_read(&n->nr_slabs);
+}
+
+/*
+ * Defrag slabs conditional on the amount of fragmentation in a page.
+ */
+int kmem_cache_defrag(int node)
+{
+	struct kmem_cache *s;
+	unsigned long left = 0;
+
+	/*
+	 * kmem_cache_defrag may be called from the reclaim path which may be
+	 * called for any page allocator alloc. So there is the danger that we
+	 * get called in a situation where slub already acquired the slub_lock
+	 * for other purposes.
+	 */
+	if (!mutex_trylock(&slab_mutex))
+		return 0;
+
+	list_for_each_entry(s, &slab_caches, list) {
+		/*
+		 * Defragmentable caches come first. If the slab cache is not
+		 * defragmentable then we can stop traversing the list.
+		 */
+		if (!s->migrate)
+			break;
+
+		if (node == -1) {
+			int nid;
+
+			for_each_node_state(nid, N_NORMAL_MEMORY)
+				if (s->node[nid]->nr_partial > MAX_PARTIAL)
+					left += __move(s, nid, nid, s->defrag_ratio);
+		} else
+			left  += __move(s, node, node, 100);
+
+	}
+	mutex_unlock(&slab_mutex);
+	return left;
+}
+EXPORT_SYMBOL(kmem_cache_defrag);
+
+/*
+ * kmem_cache_shrink reduces the memory footprint of a slab cache
+ * by as much as possible. This works by removing empty slabs from
+ * the partial list, migrating slab objects to denser slab pages
+ * (if the slab cache supports that) or reorganizing the partial
+ * list so that denser slab pages come first and less dense
+ * allocated slab pages are at the end.
+ */
+int __kmem_cache_shrink(struct kmem_cache *s)
+{
+	int node;
+	int left = 0;
+
+	flush_all(s);
+	for_each_node_state(node, N_NORMAL_MEMORY)
+		left += __move(s, node, node, 100);
+
+	return 0;
+}
+EXPORT_SYMBOL(__kmem_cache_shrink);
+
 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.
+	 * Mobile objects must have a ctor otherwise the
+	 * object may be in an undefined state on allocation.
+	 *
+	 * Since the object may need to be inspected by the
+	 * migration function at any time after allocation we
+	 * musdt ensure that the object always has a defined
+	 * state.
 	 */
 	BUG_ON(!s->ctor);
 

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#11 lore raw

RFC 6/8 slub: Extend slabinfo to support -D and -F options

In reply to Christoph Lameter

-F lists caches that support moving and defragmentation

-C lists caches that use a ctor.

Change field names for defrag_ratio and remote_node_defrag_ratio.

Add determination of the allocation ratio for a slab. The allocation ratio is the percentage of available slots for objects in use.

---
 Documentation/vm/slabinfo.c |   48 +++++++++++++++++++++++++++++++++++++++-----
 1 file changed, 43 insertions(+), 5 deletions(-)
tools/vm/slabinfo.c +43 -5
Index: linux/tools/vm/slabinfo.c
===================================================================
@@ -33,6 +33,8 @@ struct slabinfo {
 	int hwcache_align, object_size, objs_per_slab;
 	int sanity_checks, slab_size, store_user, trace;
 	int order, poison, reclaim_account, red_zone;
+	int movable, ctor;
+	int defrag_ratio, remote_node_defrag_ratio;
 	unsigned long partial, objects, slabs, objects_partial, objects_total;
 	unsigned long alloc_fastpath, alloc_slowpath;
 	unsigned long free_fastpath, free_slowpath;
@@ -67,6 +69,8 @@ int show_report;
 int show_alias;
 int show_slab;
 int skip_zero = 1;
+int show_movable;
+int show_ctor;
 int show_numa;
 int show_track;
 int show_first_alias;
@@ -109,14 +113,16 @@ static void fatal(const char *x, ...)
 
 static void usage(void)
 {
-	printf("slabinfo 4/15/2011. (c) 2007 sgi/(c) 2011 Linux Foundation.\n\n"
-		"slabinfo [-ahnpvtsz] [-d debugopts] [slab-regexp]\n"
+	printf("slabinfo 4/15/2017. (c) 2007 sgi/(c) 2011 Linux Foundation/(c) 2017 Jump Trading LLC.\n\n"
+		"slabinfo [-aCdDefFhnpvtsz] [-d debugopts] [slab-regexp]\n"
 		"-a|--aliases           Show aliases\n"
 		"-A|--activity          Most active slabs first\n"
 		"-d<options>|--debug=<options> Set/Clear Debug options\n"
+		"-C|--ctor              Show slabs with ctors\n"
 		"-D|--display-active    Switch line format to activity\n"
 		"-e|--empty             Show empty slabs\n"
 		"-f|--first-alias       Show first alias\n"
+		"-F|--movable           Show caches that support movable objects\n"
 		"-h|--help              Show usage information\n"
 		"-i|--inverted          Inverted list\n"
 		"-l|--slabs             Show slabs\n"
@@ -369,7 +375,7 @@ static void slab_numa(struct slabinfo *s
 		return;
 
 	if (!line) {
-		printf("\n%-21s:", mode ? "NUMA nodes" : "Slab");
+		printf("\n%-21s: Rto ", mode ? "NUMA nodes" : "Slab");
 		for(node = 0; node <= highest_node; node++)
 			printf(" %4d", node);
 		printf("\n----------------------");
@@ -378,6 +384,7 @@ static void slab_numa(struct slabinfo *s
 		printf("\n");
 	}
 	printf("%-21s ", mode ? "All slabs" : s->name);
+	printf("%3d ", s->remote_node_defrag_ratio);
 	for(node = 0; node <= highest_node; node++) {
 		char b[20];
 
@@ -535,6 +542,8 @@ static void report(struct slabinfo *s)
 		printf("** Slabs are destroyed via RCU\n");
 	if (s->reclaim_account)
 		printf("** Reclaim accounting active\n");
+	if (s->movable)
+		printf("** Defragmentation at %d%%\n", s->defrag_ratio);
 
 	printf("\nSizes (bytes)     Slabs              Debug                Memory\n");
 	printf("------------------------------------------------------------------------\n");
@@ -585,6 +594,12 @@ static void slabcache(struct slabinfo *s
 	if (show_empty && s->slabs)
 		return;
 
+	if (show_movable && !s->movable)
+		return;
+
+	if (show_ctor && !s->ctor)
+		return;
+
 	if (sort_loss == 0)
 		store_size(size_str, slab_size(s));
 	else
@@ -599,6 +614,10 @@ static void slabcache(struct slabinfo *s
 		*p++ = '*';
 	if (s->cache_dma)
 		*p++ = 'd';
+	if (s->movable)
+		*p++ = 'F';
+	if (s->ctor)
+		*p++ = 'C';
 	if (s->hwcache_align)
 		*p++ = 'A';
 	if (s->poison)
@@ -633,7 +652,8 @@ static void slabcache(struct slabinfo *s
 		printf("%-21s %8ld %7d %15s %14s %4d %1d %3ld %3ld %s\n",
 			s->name, s->objects, s->object_size, size_str, dist_str,
 			s->objs_per_slab, s->order,
-			s->slabs ? (s->partial * 100) / s->slabs : 100,
+			s->slabs ? (s->partial * 100) /
+					(s->slabs * s->objs_per_slab) : 100,
 			s->slabs ? (s->objects * s->object_size * 100) /
 				(s->slabs * (page_size << s->order)) : 100,
 			flags);
@@ -1252,7 +1272,17 @@ static void read_slab_dir(void)
 			slab->cpu_partial_free = get_obj("cpu_partial_free");
 			slab->alloc_node_mismatch = get_obj("alloc_node_mismatch");
 			slab->deactivate_bypass = get_obj("deactivate_bypass");
+			slab->defrag_ratio = get_obj("defrag_ratio");
+			slab->remote_node_defrag_ratio =
+					get_obj("remote_node_defrag_ratio");
 			chdir("..");
+			if (read_slab_obj(slab, "ops")) {
+				if (strstr(buffer, "ctor :"))
+					slab->ctor = 1;
+				if (strstr(buffer, "migrate :"))
+					slab->movable = 1;
+			}
+
 			if (slab->name[0] == ':')
 				alias_targets++;
 			slab++;
@@ -1329,6 +1359,8 @@ static void xtotals(void)
 }
 
 struct option opts[] = {
+	{ "ctor", no_argument, NULL, 'C' },
+	{ "movable", no_argument, NULL, 'F' },
 	{ "aliases", no_argument, NULL, 'a' },
 	{ "activity", no_argument, NULL, 'A' },
 	{ "debug", optional_argument, NULL, 'd' },
@@ -1364,7 +1396,7 @@ int main(int argc, char *argv[])
 
 	page_size = getpagesize();
 
-	while ((c = getopt_long(argc, argv, "aAd::Defhil1noprstvzTSN:LXBU",
+	while ((c = getopt_long(argc, argv, "aACd::DefFhil1noprstvzTSN:LXBU",
 						opts, NULL)) != -1)
 		switch (c) {
 		case '1':
@@ -1420,6 +1452,12 @@ int main(int argc, char *argv[])
 		case 'z':
 			skip_zero = 0;
 			break;
+		case 'C':
+			show_ctor = 1;
+			break;
+		case 'F':
+			show_movable = 1;
+			break;
 		case 'T':
 			show_totals = 1;
 			break;

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#12 lore raw

RFC 7/8 xarray: Implement migration function for objects

In reply to Christoph Lameter

Implement functions to migrate objects. This is based on initial code by Matthew Wilcox and was modified to work with slab object migration.

lib/radix-tree.c +15 -0
Index: linux/lib/radix-tree.c
===================================================================
@@ -1754,6 +1754,18 @@ static int radix_tree_cpu_dead(unsigned
 	return 0;
 }
 
+
+extern void xa_object_migrate(void *tree_node, int numa_node);
+
+static void radix_tree_migrate(struct kmem_cache *s, void **objects, int nr,
+		int node, void *private)
+{
+	int i;
+
+	for (i=0; i<nr; i++)
+		xa_object_migrate(objects[i], node);
+}
+
 void __init radix_tree_init(void)
 {
 	int ret;
@@ -1766,4 +1778,7 @@ void __init radix_tree_init(void)
 	ret = cpuhp_setup_state_nocalls(CPUHP_RADIX_DEAD, "lib/radix:dead",
 					NULL, radix_tree_cpu_dead);
 	WARN_ON(ret < 0);
+	kmem_cache_setup_mobility(radix_tree_node_cachep,
+					NULL,
+					radix_tree_migrate);
 }
include/linux/xarray.h +2 -0
Index: linux/include/linux/xarray.h
===================================================================
@@ -62,6 +62,8 @@ struct xarray {
 
 void __xa_init(struct xarray *, gfp_t flags);
 
+#define XA_FREE ((struct xarray *)1)
+
 /**
  * xa_init() - Initialise an empty XArray.
  * @xa: XArray.
lib/xarray.c +46 -0

58 lines not on this page · raw message

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#13 lore raw

RFC 8/8 Add debugging output

In reply to Christoph Lameter

Useful to see whats going on.

lib/xarray.c +3 -0
Index: linux/lib/xarray.c
===================================================================
@@ -1583,11 +1583,13 @@ void xa_object_migrate(struct xa_node *n
 
 	new_node = kmem_cache_alloc_node(radix_tree_node_cachep, GFP_KERNEL, numa_node);
 
+	printk(KERN_INFO "xa_object_migrate(%px, %d)\n", node, numa_node);
 	xa_lock_irq(xa);
 
 	/* Check again..... */
 	if (xa != node->array || !list_empty(&node->private_list)) {
 		node = new_node;
+		printk(KERN_ERR "Skip temporary object\n");
 		goto unlock;
 	}
 
@@ -1606,6 +1608,7 @@ void xa_object_migrate(struct xa_node *n
 	else
 		slot = &xa_parent_locked(xa, new_node)->slots[new_node->offset];
 	rcu_assign_pointer(*slot, xa_mk_node(new_node));
+	printk(KERN_ERR "Success\n");
 
 unlock:
 	xa_unlock_irq(xa);
mm/slub.c +25 -2
Index: linux/mm/slub.c
===================================================================
@@ -4245,6 +4245,7 @@ static void kmem_cache_move(struct page
 	unsigned long flags;
 	unsigned long objects;
 
+	printk(KERN_ERR "kmem_cache_move in: page=%px inuse=%d\n", page, page->inuse);
 	local_irq_save(flags);
 	slab_lock(page);
 
@@ -4267,6 +4268,7 @@ static void kmem_cache_move(struct page
 		if (test_bit(slab_index(p, s, addr), map))
 			vector[count++] = p;
 
+	printk(KERN_ERR "Vector of %d items\n", count);
 	if (s->isolate)
 		private = s->isolate(s, vector, count);
 	else
@@ -4295,6 +4297,7 @@ static void kmem_cache_move(struct page
 	 * Perform callbacks to move the objects.
 	 */
 	s->migrate(s, vector, count, node, private);
+	printk(KERN_ERR "kmem_cache_move out: page=%px inuse=%d\n", page, page->inuse);
 }
 
 /*
@@ -4312,6 +4315,7 @@ static unsigned long __move(struct kmem_
 	LIST_HEAD(move_list);
 	struct kmem_cache_node *n = get_node(s, node);
 
+	printk(KERN_ERR "__move(%s, %d, %d, %d) migrate=%px\n", s->name, node, target_node, ratio, s->migrate);
 	if (node == target_node && n->nr_partial <= 1)
 		/*
 		 * Trying to reduce fragmentataion on a node but there is
@@ -4322,9 +4326,16 @@ static unsigned long __move(struct kmem_
 
 	spin_lock_irqsave(&n->list_lock, flags);
 	list_for_each_entry_safe(page, page2, &n->partial, lru) {
-		if (!slab_trylock(page))
+		printk(KERN_ERR "Slab page %px inuse=%d ", page, page->inuse);
+		if (page->inuse > 1000) {
+			printk("Page->inuse too high....\n");
+			break;
+		}
+		if (!slab_trylock(page)) {
+			printk("Locked\n");
 			/* Busy slab. Get out of the way */
 			continue;
+		}
 
 		if (page->inuse) {
 			if (page->inuse > ratio * page->objects / 100) {
@@ -4333,10 +4344,13 @@ static unsigned long __move(struct kmem_
 				 * Skip slab because the object density
 				 * in the slab page is high enough
 				*/
+				printk("Below ratio. Skipping\n");
 				continue;
 			}
 
 			list_move(&page->lru, &move_list);
+			printk("Added to list to move\n");
+
 			if (s->migrate) {
 				/* Remove page from being considered for allocations */
 				n->nr_partial--;
@@ -4345,6 +4359,7 @@ static unsigned long __move(struct kmem_
 			slab_unlock(page);
 		} else {
 			/* Empty slab page */
+			printk("Empty\n");
 			list_del(&page->lru);
 			n->nr_partial--;
 			slab_unlock(page);
@@ -4374,11 +4389,17 @@ static unsigned long __move(struct kmem_
 		struct page *page;
 		struct page *page2;
 
+		printk(KERN_ERR "Beginning to migrate pages\n");
 		if (scratch) {
 			/* Try to remove / move the objects left */
 			list_for_each_entry(page, &move_list, lru) {
-				if (page->inuse)
+				if (page->inuse) {
 					kmem_cache_move(page, scratch, target_node);
+					if (page->inuse > 1000) {
+						printk(KERN_ERR "Page corrupted. Abort\n");
+						break;
+					}
+				}
 			}
 			kfree(scratch);
 		}
@@ -4404,9 +4425,11 @@ static unsigned long __move(struct kmem_
 			} else {
 				slab_unlock(page);
 				discard_slab(s, page);
+				printk(KERN_ERR "Freed one page %px\n", page);
 			}
 		}
 		spin_unlock_irqrestore(&n->list_lock, flags);
+		printk(KERN_ERR "Finished migrating slab objects\n");
 	}
 out:
 	return atomic_long_read(&n->nr_slabs);

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#14 lore raw
In reply to Christoph Lameter
Quoted 4 lines · Christoph Lameter

This is a patchset on top of Matthew Wilcox Xarray code and implements object migration of xarray nodes. The migration is integrated into the defragmetation and shrinking logic of the slab allocator.

Quoted 8 lines

Defragmentation will ensure that all xarray slab pages have less objects available than specified by the slab defrag ratio.

Slab shrinking will create a slab cache with optimal object density. Only one slab page will have available objects per node.

To test apply this patchset on top of Matthew Wilcox Xarray code from Dec 11th (See infradead github).

linux-mm archive is missing patch 1/8 and so am I.

https://marc.info/?l=linux-mm

Signature · 7 lines
~Randy

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#15 lore raw
Quoted 6 lines · Randy Dunlap
Quoted 2 lines

To test apply this patchset on top of Matthew Wilcox Xarray code from Dec 11th (See infradead github).

linux-mm archive is missing patch 1/8 and so am I.

https://marc.info/?l=linux-mm

Duh. How can you troubleshoot that one?

First patch:

Subject: slub: Replace ctor field with ops field in /sys/slab/*

Create an ops field in /sys/slab/*/ops to contain all the callback operations defined for a slab cache. This will be used to display the additional callbacks that will be defined soon to enable defragmentation.

Display the existing ctor callback in the ops fields contents.

---
 mm/slub.c |   16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)
mm/slub.c +9 -4
Index: linux/mm/slub.c
===================================================================
@@ -4959,13 +4959,18 @@ static ssize_t cpu_partial_store(struct
 }
 SLAB_ATTR(cpu_partial);
 
-static ssize_t ctor_show(struct kmem_cache *s, char *buf)
+static ssize_t ops_show(struct kmem_cache *s, char *buf)
 {
+	int x = 0;
+
 	if (!s->ctor)
 		return 0;
-	return sprintf(buf, "%pS\n", s->ctor);
+
+	if (s->ctor)
+		x += sprintf(buf + x, "ctor : %pS\n", s->ctor);
+	return x;
 }
-SLAB_ATTR_RO(ctor);
+SLAB_ATTR_RO(ops);
 
 static ssize_t aliases_show(struct kmem_cache *s, char *buf)
 {
@@ -5377,7 +5382,7 @@ static struct attribute *slab_attrs[] =
 	&objects_partial_attr.attr,
 	&partial_attr.attr,
 	&cpu_slabs_attr.attr,
-	&ctor_attr.attr,
+	&ops_attr.attr,
 	&aliases_attr.attr,
 	&align_attr.attr,
 	&hwcache_align_attr.attr,

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#16 lore raw
Quoted 4 lines · Christopher Lameter
Quoted 2 lines · Randy Dunlap
Quoted 2 lines
Quoted 8 lines
Quoted 6 lines
Quoted 2 lines

To test apply this patchset on top of Matthew Wilcox Xarray code from Dec 11th (See infradead github).

linux-mm archive is missing patch 1/8 and so am I.

https://marc.info/?l=linux-mm

Duh. How can you troubleshoot that one?

Well you can ask for expert help. A The mm list also ate one of my bug reports (although the followup made it). A This is the lost email:

From: James Bottomley <[email protected]>
To: Linux Memory Management List <[email protected]>
Subject: Hang with v4.15-rc trying to swap back in
Date: Wed, 27 Dec 2017 10:12:20 -0800
Message-Id: <[email protected]>

This is the accepting MTA line from postfix:

Dec 27 10:12:23 bedivere postfix/smtp[15670]: CFB7E8EE190: to=<[email protected]>, relay=aspmx.l.google.com[74.125.28.26]:25, delay=1.2, delays=0.09/0.03/0.6/0.42, dsn=2.0.0, status=sent (250 2.0.0 OK 1514398342 z21si24644492plo.126 - gsmtp)

The one that made it is:

Message-Id: <[email protected]>

I've cc'd Ben because I think the list is still on his systems.

James

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#17 lore raw

On Thu, Dec 28, 2017 at 09:18:53AM -0800, James Bottomley wrote:
...

Quoted 8 lines

Well you can ask for expert help. The mm list also ate one of my bug reports (although the followup made it). This is the lost email:

From: James Bottomley <[email protected]>
To: Linux Memory Management List <[email protected]>
Subject: Hang with v4.15-rc trying to swap back in
Date: Wed, 27 Dec 2017 10:12:20 -0800
Message-Id: <[email protected]>

...

Quoted 1 line

I've cc'd Ben because I think the list is still on his systems.

...

Looks like Google's anti-spam service filtered it, so my system never even saw it. Not much I can do when that happens other than try to manually track it down.

-ben

Signature · 7 lines
"Thought is the essence of where you are now."

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#18 lore raw
Quoted 13 lines · Benjamin LaHaise

On Thu, Dec 28, 2017 at 09:18:53AM -0800, James Bottomley wrote:
...

Quoted 11 lines

Well you can ask for expert help. A The mm list also ate one of my bug reports (although the followup made it). A This is the lost email:

From: James Bottomley <[email protected]

Quoted 1 line

To: Linux Memory Management List <[email protected]>
Subject: Hang with v4.15-rc trying to swap back in
Date: Wed, 27 Dec 2017 10:12:20 -0800
Message-Id: <[email protected]>

Quoted 8 lines

...

Quoted 2 lines

I've cc'd Ben because I think the list is still on his systems.

...

Looks like Google's anti-spam service filtered it, so my system never even saw it.A A Not much I can do when that happens other than try to manually track it down.

I honestly don't think it's safe to host a public email list on google:
their "spam" filter is eccentric to say the least and is far too willing to generate false positives for reasons no-one seems to be able to fix. A What about moving the list to reliable infrastructure, like vger?

James

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#19 lore raw
Quoted 23 lines · James Bottomley
Quoted 13 lines · Benjamin LaHaise

On Thu, Dec 28, 2017 at 09:18:53AM -0800, James Bottomley wrote:
...

Quoted 11 lines

Well you can ask for expert help. The mm list also ate one of my bug reports (although the followup made it). This is the lost email:

From: James Bottomley <[email protected]

Quoted 1 line

To: Linux Memory Management List <[email protected]>
Subject: Hang with v4.15-rc trying to swap back in
Date: Wed, 27 Dec 2017 10:12:20 -0800
Message-Id: <[email protected]>

Quoted 8 lines

...

Quoted 2 lines

I've cc'd Ben because I think the list is still on his systems.

...

Looks like Google's anti-spam service filtered it, so my system never even saw it. Not much I can do when that happens other than try to manually track it down.

Quoted 5 lines

I honestly don't think it's safe to host a public email list on google:
their "spam" filter is eccentric to say the least and is far too willing to generate false positives for reasons no-one seems to be able to fix. What about moving the list to reliable infrastructure, like vger?

The list is not hosted on Google - Google's anti-spam service is only used for ingress filtering. Spamassassin is not a "Good Enough" option these days given the volume and nature of spam that comes into kvack.org. If you can point me at a better anti-spam solution that actually works (and is not RBL based), I'd be happy to try it since the Google service is absolutely awful with pretty much no way to get a human to fix obviously broken things.

-ben

Quoted 3 lines

James

Signature · 7 lines
"Thought is the essence of where you are now."

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#20 lore raw
Quoted 31 lines · Benjamin LaHaise
Quoted 30 lines · James Bottomley
Quoted 27 lines · Benjamin LaHaise

On Thu, Dec 28, 2017 at 09:18:53AM -0800, James Bottomley wrote:
...

Quoted 15 lines

Well you can ask for expert help. A The mm list also ate one of my bug reports (although the followup made it). A This is the lost email:

From: James Bottomley <James.Bottomley@HansenPartnership
.com

Quoted 2 lines

To: Linux Memory Management List <[email protected]>
Subject: Hang with v4.15-rc trying to swap back in
Date: Wed, 27 Dec 2017 10:12:20 -0800
Message-Id: <1514398340.3986.10.camel@HansenPartnership.
com>

...

Quoted 3 lines

I've cc'd Ben because I think the list is still on his systems.

...

Looks like Google's anti-spam service filtered it, so my system never even saw it.A A Not much I can do when that happens other than try to manually track it down.

Quoted 8 lines
Quoted 5 lines

I honestly don't think it's safe to host a public email list on
google: their "spam" filter is eccentric to say the least and is far too willing to generate false positives for reasons no-one seems to be able to fix. A What about moving the list to reliable infrastructure, like vger?

The list is not hosted on Google - Google's anti-spam service is only used for ingress filtering.

OK, but that is the problem: you're relying on google infrastructure for a service it does incredibly poorly.

Quoted 6 lines

Spamassassin is not a "Good Enough" option these days given the volume and nature of spam that comes into kvack.org.A A If you can point me at a better anti-spam solution that actually works (and is not RBL based), I'd be happy to try it since the Google service is absolutely awful with pretty much no way to get a human to fix obviously broken things.

Well, to be honest, I find spamassassin to be incredibly useful (it's what I use), especially being rules and points based instead of absolute (meaning I can use the RBL but not rely on it). A It hasn't given me a false positive on anything for over a year and its false negative rate is about 2% with my current configuration.

However, I think the best solution is to use vger ... it already has an efficient ingress filter and it doesn't rely on google, so it doesn't suffer the arbitrary mail loss problem of google.

James

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#21 lore raw

On Thu, Dec 28, 2017 at 12:00:58PM -0800, James Bottomley wrote:
...

Quoted 5 lines
Quoted 2 lines

The list is not hosted on Google - Google's anti-spam service is only used for ingress filtering.

OK, but that is the problem: you're relying on google infrastructure for a service it does incredibly poorly.

I did say that I am open to changing how spam filtering is done.

Quoted 7 lines
Quoted 6 lines

Spamassassin is not a "Good Enough" option these days given the volume and nature of spam that comes into kvack.org. If you can point me at a better anti-spam solution that actually works (and is not RBL based), I'd be happy to try it since the Google service is absolutely awful with pretty much no way to get a human to fix obviously broken things.

Quoted 5 lines

Well, to be honest, I find spamassassin to be incredibly useful (it's what I use), especially being rules and points based instead of absolute (meaning I can use the RBL but not rely on it). It hasn't given me a false positive on anything for over a year and its false negative rate is about 2% with my current configuration.

False negative rate last time I used spam assassin was way more than 10-15%, and it mostly failed to filter out the phishing scams which tend to be the bigger problem of late. That isn't so much of a mailing list concern, but it is a significant issue for user accounts.

Quoted 3 lines

However, I think the best solution is to use vger ... it already has an efficient ingress filter and it doesn't rely on google, so it doesn't suffer the arbitrary mail loss problem of google.

This is the first time anyone has complained to me about messages being filtered in a number of years, and I have added whitelists for people over the years that had problems ending up on various blacklists. I don't have time these days to actively scan mailing lists for issues, so reporting them on-list without directly Cc'ing me will not get my attention. I'll look into options over the next few days and see if there are any better solutions available now than the last time I looked at the spam problem. Please give me at least a little a bit of time to look into possible fixes before going nuclear.

-ben

Quoted 3 lines

James

Signature · 7 lines
"Thought is the essence of where you are now."

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#22 lore raw
In reply to Christoph Lameter
Quoted 3 lines · Christoph Lameter

This is a patchset on top of Matthew Wilcox Xarray code and implements object migration of xarray nodes. The migration is integrated into the defragmetation and shrinking logic of the slab allocator.

.....

Quoted 2 lines

This is only possible for xarray for now but it would be worthwhile to extend this to dentries and inodes.

Christoph, you keep saying this is the goal, but I'm yet to see a solution proposed for the atomic replacement of all the pointers to an inode from external objects. An inode that has no active references still has an awful lot of passive and internal references that need to be dealt with.

e.g. racing page operations accessing mapping->host, the inode in various lists (e.g. superblock inode list, writeback lists, etc), the inode lookup cache(s), backpointers from LSMs, fsnotify marks, crypto information, internal filesystem pointers (e.g. log items, journal handles, buffer references, etc) and so on. And each filesystem has a different set of passive references, too.

Oh, and I haven't even mentioned deadlocks yet, either. :P

IOWs, just saying "it would be worthwhile to extend this to dentries and inodes" completely misrepresents the sheer complexity of doing so. We've known that atomic replacement is the big problem for defragging inodes and dentries since this work was started, what, more than 10 years? And while there's been many revisions of the core defrag code since then, there has been no credible solution presented for atomic replacement of objects with complex external references. This is a show-stopper for inode/dentry slab defrag, and I don't see that this new patchset is any different...

Cheers,

Dave.

Signature · 8 lines
Dave Chinner
[email protected]

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#23 lore raw
Quoted 9 lines · Dave Chinner

IOWs, just saying "it would be worthwhile to extend this to dentries and inodes" completely misrepresents the sheer complexity of doing so. We've known that atomic replacement is the big problem for defragging inodes and dentries since this work was started, what, more than 10 years? And while there's been many revisions of the core defrag code since then, there has been no credible solution presented for atomic replacement of objects with complex external references. This is a show-stopper for inode/dentry slab defrag, and I don't see that this new patchset is any different...

Well this is a chance here to start an implementation since the radix tree is being reworked anyways. This is not dealing with dentries and inodes but it brings in the basic infrastructure into the slab allocators that can then be used to add other slab caches. Same warnings were given to me when we did page migration and it languished for 5 years.

I have not had time to really focus on memory management issues since I left SGI about 9 years ago but it seems that I may now have the chance in 2018 to put a significant amount of time into making some progress.

Large memory in servers has become a significant problem for my employer and the ability to allocate and manage contiguous memory blocks is essential to preserve performance and avoid constant reboot. So I will be looking for ways to address these issues. Maybe with a couple of approaches.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>