diff options
| author | Wei Yang <richard.weiyang@gmail.com> | 2017-07-06 18:36:34 -0400 |
|---|---|---|
| committer | Linus Torvalds <torvalds@linux-foundation.org> | 2017-07-06 19:24:30 -0400 |
| commit | e6d0e1dcf5f07fb04704b87ffab749589d29cb02 (patch) | |
| tree | 73c8033b1e0e8d539d0a132591ab8234834beb37 | |
| parent | a93cf07bc3fb4e7bc924d33c387dabc85086ea38 (diff) | |
mm/slub.c: wrap kmem_cache->cpu_partial in config CONFIG_SLUB_CPU_PARTIAL
kmem_cache->cpu_partial is just used when CONFIG_SLUB_CPU_PARTIAL is
set, so wrap it with config CONFIG_SLUB_CPU_PARTIAL will save some space
on 32bit arch.
This patch wraps kmem_cache->cpu_partial in config CONFIG_SLUB_CPU_PARTIAL
and wraps its sysfs too.
Link: http://lkml.kernel.org/r/20170502144533.10729-4-richard.weiyang@gmail.com
Signed-off-by: Wei Yang <richard.weiyang@gmail.com>
Cc: Christoph Lameter <cl@linux.com>
Cc: Pekka Enberg <penberg@kernel.org>
Cc: David Rientjes <rientjes@google.com>
Cc: Joonsoo Kim <iamjoonsoo.kim@lge.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
| -rw-r--r-- | include/linux/slub_def.h | 13 | ||||
| -rw-r--r-- | mm/slub.c | 69 |
2 files changed, 51 insertions, 31 deletions
diff --git a/include/linux/slub_def.h b/include/linux/slub_def.h index a3e9492fed02..cc0faf3a90be 100644 --- a/include/linux/slub_def.h +++ b/include/linux/slub_def.h | |||
| @@ -86,7 +86,9 @@ struct kmem_cache { | |||
| 86 | int size; /* The size of an object including meta data */ | 86 | int size; /* The size of an object including meta data */ |
| 87 | int object_size; /* The size of an object without meta data */ | 87 | int object_size; /* The size of an object without meta data */ |
| 88 | int offset; /* Free pointer offset. */ | 88 | int offset; /* Free pointer offset. */ |
| 89 | #ifdef CONFIG_SLUB_CPU_PARTIAL | ||
| 89 | int cpu_partial; /* Number of per cpu partial objects to keep around */ | 90 | int cpu_partial; /* Number of per cpu partial objects to keep around */ |
| 91 | #endif | ||
| 90 | struct kmem_cache_order_objects oo; | 92 | struct kmem_cache_order_objects oo; |
| 91 | 93 | ||
| 92 | /* Allocation and freeing of slabs */ | 94 | /* Allocation and freeing of slabs */ |
| @@ -131,6 +133,17 @@ struct kmem_cache { | |||
| 131 | struct kmem_cache_node *node[MAX_NUMNODES]; | 133 | struct kmem_cache_node *node[MAX_NUMNODES]; |
| 132 | }; | 134 | }; |
| 133 | 135 | ||
| 136 | #ifdef CONFIG_SLUB_CPU_PARTIAL | ||
| 137 | #define slub_cpu_partial(s) ((s)->cpu_partial) | ||
| 138 | #define slub_set_cpu_partial(s, n) \ | ||
| 139 | ({ \ | ||
| 140 | slub_cpu_partial(s) = (n); \ | ||
| 141 | }) | ||
| 142 | #else | ||
| 143 | #define slub_cpu_partial(s) (0) | ||
| 144 | #define slub_set_cpu_partial(s, n) | ||
| 145 | #endif // CONFIG_SLUB_CPU_PARTIAL | ||
| 146 | |||
| 134 | #ifdef CONFIG_SYSFS | 147 | #ifdef CONFIG_SYSFS |
| 135 | #define SLAB_SUPPORTS_SYSFS | 148 | #define SLAB_SUPPORTS_SYSFS |
| 136 | void sysfs_slab_release(struct kmem_cache *); | 149 | void sysfs_slab_release(struct kmem_cache *); |
| @@ -1829,7 +1829,7 @@ static void *get_partial_node(struct kmem_cache *s, struct kmem_cache_node *n, | |||
| 1829 | stat(s, CPU_PARTIAL_NODE); | 1829 | stat(s, CPU_PARTIAL_NODE); |
| 1830 | } | 1830 | } |
| 1831 | if (!kmem_cache_has_cpu_partial(s) | 1831 | if (!kmem_cache_has_cpu_partial(s) |
| 1832 | || available > s->cpu_partial / 2) | 1832 | || available > slub_cpu_partial(s) / 2) |
| 1833 | break; | 1833 | break; |
| 1834 | 1834 | ||
| 1835 | } | 1835 | } |
| @@ -3404,6 +3404,39 @@ static void set_min_partial(struct kmem_cache *s, unsigned long min) | |||
| 3404 | s->min_partial = min; | 3404 | s->min_partial = min; |
| 3405 | } | 3405 | } |
| 3406 | 3406 | ||
| 3407 | static void set_cpu_partial(struct kmem_cache *s) | ||
| 3408 | { | ||
| 3409 | #ifdef CONFIG_SLUB_CPU_PARTIAL | ||
| 3410 | /* | ||
| 3411 | * cpu_partial determined the maximum number of objects kept in the | ||
| 3412 | * per cpu partial lists of a processor. | ||
| 3413 | * | ||
| 3414 | * Per cpu partial lists mainly contain slabs that just have one | ||
| 3415 | * object freed. If they are used for allocation then they can be | ||
| 3416 | * filled up again with minimal effort. The slab will never hit the | ||
| 3417 | * per node partial lists and therefore no locking will be required. | ||
| 3418 | * | ||
| 3419 | * This setting also determines | ||
| 3420 | * | ||
| 3421 | * A) The number of objects from per cpu partial slabs dumped to the | ||
| 3422 | * per node list when we reach the limit. | ||
| 3423 | * B) The number of objects in cpu partial slabs to extract from the | ||
| 3424 | * per node list when we run out of per cpu objects. We only fetch | ||
| 3425 | * 50% to keep some capacity around for frees. | ||
| 3426 | */ | ||
| 3427 | if (!kmem_cache_has_cpu_partial(s)) | ||
| 3428 | s->cpu_partial = 0; | ||
| 3429 | else if (s->size >= PAGE_SIZE) | ||
| 3430 | s->cpu_partial = 2; | ||
| 3431 | else if (s->size >= 1024) | ||
| 3432 | s->cpu_partial = 6; | ||
| 3433 | else if (s->size >= 256) | ||
| 3434 | s->cpu_partial = 13; | ||
| 3435 | else | ||
| 3436 | s->cpu_partial = 30; | ||
| 3437 | #endif | ||
| 3438 | } | ||
| 3439 | |||
| 3407 | /* | 3440 | /* |
| 3408 | * calculate_sizes() determines the order and the distribution of data within | 3441 | * calculate_sizes() determines the order and the distribution of data within |
| 3409 | * a slab object. | 3442 | * a slab object. |
| @@ -3562,33 +3595,7 @@ static int kmem_cache_open(struct kmem_cache *s, unsigned long flags) | |||
| 3562 | */ | 3595 | */ |
| 3563 | set_min_partial(s, ilog2(s->size) / 2); | 3596 | set_min_partial(s, ilog2(s->size) / 2); |
| 3564 | 3597 | ||
| 3565 | /* | 3598 | set_cpu_partial(s); |
| 3566 | * cpu_partial determined the maximum number of objects kept in the | ||
| 3567 | * per cpu partial lists of a processor. | ||
| 3568 | * | ||
| 3569 | * Per cpu partial lists mainly contain slabs that just have one | ||
| 3570 | * object freed. If they are used for allocation then they can be | ||
| 3571 | * filled up again with minimal effort. The slab will never hit the | ||
| 3572 | * per node partial lists and therefore no locking will be required. | ||
| 3573 | * | ||
| 3574 | * This setting also determines | ||
| 3575 | * | ||
| 3576 | * A) The number of objects from per cpu partial slabs dumped to the | ||
| 3577 | * per node list when we reach the limit. | ||
| 3578 | * B) The number of objects in cpu partial slabs to extract from the | ||
| 3579 | * per node list when we run out of per cpu objects. We only fetch | ||
| 3580 | * 50% to keep some capacity around for frees. | ||
| 3581 | */ | ||
| 3582 | if (!kmem_cache_has_cpu_partial(s)) | ||
| 3583 | s->cpu_partial = 0; | ||
| 3584 | else if (s->size >= PAGE_SIZE) | ||
| 3585 | s->cpu_partial = 2; | ||
| 3586 | else if (s->size >= 1024) | ||
| 3587 | s->cpu_partial = 6; | ||
| 3588 | else if (s->size >= 256) | ||
| 3589 | s->cpu_partial = 13; | ||
| 3590 | else | ||
| 3591 | s->cpu_partial = 30; | ||
| 3592 | 3599 | ||
| 3593 | #ifdef CONFIG_NUMA | 3600 | #ifdef CONFIG_NUMA |
| 3594 | s->remote_node_defrag_ratio = 1000; | 3601 | s->remote_node_defrag_ratio = 1000; |
| @@ -3975,7 +3982,7 @@ void __kmemcg_cache_deactivate(struct kmem_cache *s) | |||
| 3975 | * Disable empty slabs caching. Used to avoid pinning offline | 3982 | * Disable empty slabs caching. Used to avoid pinning offline |
| 3976 | * memory cgroups by kmem pages that can be freed. | 3983 | * memory cgroups by kmem pages that can be freed. |
| 3977 | */ | 3984 | */ |
| 3978 | s->cpu_partial = 0; | 3985 | slub_set_cpu_partial(s, 0); |
| 3979 | s->min_partial = 0; | 3986 | s->min_partial = 0; |
| 3980 | 3987 | ||
| 3981 | /* | 3988 | /* |
| @@ -4915,7 +4922,7 @@ SLAB_ATTR(min_partial); | |||
| 4915 | 4922 | ||
| 4916 | static ssize_t cpu_partial_show(struct kmem_cache *s, char *buf) | 4923 | static ssize_t cpu_partial_show(struct kmem_cache *s, char *buf) |
| 4917 | { | 4924 | { |
| 4918 | return sprintf(buf, "%u\n", s->cpu_partial); | 4925 | return sprintf(buf, "%u\n", slub_cpu_partial(s)); |
| 4919 | } | 4926 | } |
| 4920 | 4927 | ||
| 4921 | static ssize_t cpu_partial_store(struct kmem_cache *s, const char *buf, | 4928 | static ssize_t cpu_partial_store(struct kmem_cache *s, const char *buf, |
| @@ -4930,7 +4937,7 @@ static ssize_t cpu_partial_store(struct kmem_cache *s, const char *buf, | |||
| 4930 | if (objects && !kmem_cache_has_cpu_partial(s)) | 4937 | if (objects && !kmem_cache_has_cpu_partial(s)) |
| 4931 | return -EINVAL; | 4938 | return -EINVAL; |
| 4932 | 4939 | ||
| 4933 | s->cpu_partial = objects; | 4940 | slub_set_cpu_partial(s, objects); |
| 4934 | flush_all(s); | 4941 | flush_all(s); |
| 4935 | return length; | 4942 | return length; |
| 4936 | } | 4943 | } |
