The patch titled Subject: mm/slub.c: improve performance by skipping checked node in get_any_partial() has been removed from the -mm tree. Its filename was mm-slub-improve-performance-by-skipping-checked-node-in-get_any_partial.patch This patch was dropped because it is obsolete ------------------------------------------------------ From: Wei Yang <richard.weiyang@xxxxxxxxx> Subject: mm/slub.c: improve performance by skipping checked node in get_any_partial() 1. Background Current slub has three layers: * cpu_slab * percpu_partial * per node partial list Slub allocator tries to get an object from top to bottom. When it can't get an object from the upper two layers, it will search the per node partial list. The is done in get_partial(). The abstraction of get_partial() look like this: get_partial() get_partial_node() get_any_partial() for_each_zone_zonelist() The idea behind this is: first try a local node, then try other nodes if caller doesn't specify a node. 2. Room for Improvement When we look one step deeper in get_any_partial(), it tries to get a proper node by for_each_zone_zonelist(), which iterates on the node_zonelists. This behavior would introduce some redundant check on the same node. Because: * the local node is already checked in get_partial_node() * one node may have several zones on node_zonelists 3. Solution Proposed in Patch We could reduce these redundant check by record the last unsuccessful node and then skip it. 4. Tests & Result After some tests, the result shows this may improve the system a little, especially on a machine with only one node. 4.1 Test Description There are two cases for two system configurations. Test Cases: 1. counter comparison 2. kernel build test System Configuration: 1. One node machine with 4G 2. Four node machine with 8G 4.2 Result for Test 1 Test 1: counter comparison This is a test with hacked kernel to record times function get_any_partial() is invoked and times the inner loop iterates. By comparing the ratio of two counters, we get to know how many inner loops we skipped. Here is a snip of the test patch. --- static void *get_any_partial() { get_partial_count++; do { for_each_zone_zonelist() { get_partial_try_count++; } } while(); return NULL; } --- The result of (get_partial_count / get_partial_try_count): +----------+----------------+------------+-------------+ | | Base | Patched | Improvement| +----------+----------------+------------+-------------+ |One Node | 1:3 | 1:0 | - 100% | +----------+----------------+------------+-------------+ |Four Nodes| 1:5.8 | 1:2.5 | - 56% | +----------+----------------+------------+-------------+ 4.3 Result for Test 2 Test 2: kernel build Command used: > time make -j8 bzImage Each version/system configuration combination has four round kernel build tests. Take the average result of real to compare. +----------+----------------+------------+-------------+ | | Base | Patched | Improvement| +----------+----------------+------------+-------------+ |One Node | 4m41s | 4m32s | - 4.47% | +----------+----------------+------------+-------------+ |Four Nodes| 4m45s | 4m39s | - 2.92% | +----------+----------------+------------+-------------+ [akpm@xxxxxxxxxxxxxxxxxxxx: rename variable, tweak comment] Link: http://lkml.kernel.org/r/20181120033119.30013-1-richard.weiyang@xxxxxxxxx Signed-off-by: Wei Yang <richard.weiyang@xxxxxxxxx> Cc: Christoph Lameter <cl@xxxxxxxxx> Cc: Pekka Enberg <penberg@xxxxxxxxxx> Cc: David Rientjes <rientjes@xxxxxxxxxx> Cc: Joonsoo Kim <iamjoonsoo.kim@xxxxxxx> Signed-off-by: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx> --- mm/slub.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) --- a/mm/slub.c~mm-slub-improve-performance-by-skipping-checked-node-in-get_any_partial +++ a/mm/slub.c @@ -1877,7 +1877,7 @@ static void *get_partial_node(struct kme * Get a page from somewhere. Search in increasing NUMA distances. */ static void *get_any_partial(struct kmem_cache *s, gfp_t flags, - struct kmem_cache_cpu *c) + struct kmem_cache_cpu *c, int exclude_nid) { #ifdef CONFIG_NUMA struct zonelist *zonelist; @@ -1915,6 +1915,9 @@ static void *get_any_partial(struct kmem for_each_zone_zonelist(zone, z, zonelist, high_zoneidx) { struct kmem_cache_node *n; + if (exclude_nid == zone_to_nid(zone)) + continue; + n = get_node(s, zone_to_nid(zone)); if (n && cpuset_zone_allowed(zone, flags) && @@ -1931,6 +1934,14 @@ static void *get_any_partial(struct kmem return object; } } + /* + * Failed to get an object from this node, either + * because + * 1. Failure in the above if check + * 2. NULL return from get_partial_node() + * So skip this node next time. + */ + exclude_nid = zone_to_nid(zone); } } while (read_mems_allowed_retry(cpuset_mems_cookie)); #endif @@ -1955,7 +1966,7 @@ static void *get_partial(struct kmem_cac if (object || node != NUMA_NO_NODE) return object; - return get_any_partial(s, flags, c); + return get_any_partial(s, flags, c, searchnode); } #ifdef CONFIG_PREEMPT _ Patches currently in -mm which might be from richard.weiyang@xxxxxxxxx are mm-slub-remove-validation-on-cpu_slab-in-__flush_cpu_slab.patch mm-slub-page-is-always-non-null-for-node_match.patch mm-slub-record-final-state-of-slub-action-in-deactivate_slab.patch mm-remove-reset-of-pcp-counter-in-pageset_init.patch vmscan-return-node_reclaim_noscan-in-node_reclaim-when-config_numa-is-n.patch drivers-base-memoryc-remove-an-unnecessary-check-on-nr_mem_sections.patch mm-check-nr_initialised-with-pages_per_section-directly-in-defer_init.patch mm-sparse-drop-pgdat_resize_lock-in-sparse_add-remove_one_section.patch mm-sparse-drop-pgdat_resize_lock-in-sparse_add-remove_one_section-v4.patch mm-sparse-pass-nid-instead-of-pgdat-to-sparse_add_one_section.patch mm-hotplug-move-init_currently_empty_zone-under-zone_span_lock-protection.patch mm-show_mem-drop-pgdat_resize_lock-in-show_mem.patch mm-page_alloc-calculate-first_deferred_pfn-directly.patch memory_hotplug-remove-duplicate-declaration-of-offline_pages.patch mm-page_alloc-enable-pcpu_drain-with-zone-capability.patch mm-remove-unused-page-state-adjustment-macro.patch