|
31 | 31 | #include <sys/wait.h> |
32 | 32 | #include <linux/slab.h> |
33 | 33 | #include <linux/swap.h> |
| 34 | +#include <linux/percpu_compat.h> |
34 | 35 | #include <linux/prefetch.h> |
35 | 36 |
|
36 | 37 | /* |
@@ -948,6 +949,13 @@ spl_kmem_cache_create(char *name, size_t size, size_t align, |
948 | 949 | skc->skc_obj_emergency = 0; |
949 | 950 | skc->skc_obj_emergency_max = 0; |
950 | 951 |
|
| 952 | + rc = percpu_counter_init_common(&skc->skc_linux_alloc, 0, |
| 953 | + GFP_KERNEL); |
| 954 | + if (rc != 0) { |
| 955 | + kfree(skc); |
| 956 | + return (NULL); |
| 957 | + } |
| 958 | + |
951 | 959 | /* |
952 | 960 | * Verify the requested alignment restriction is sane. |
953 | 961 | */ |
@@ -1047,6 +1055,7 @@ spl_kmem_cache_create(char *name, size_t size, size_t align, |
1047 | 1055 | return (skc); |
1048 | 1056 | out: |
1049 | 1057 | kfree(skc->skc_name); |
| 1058 | + percpu_counter_destroy(&skc->skc_linux_alloc); |
1050 | 1059 | kfree(skc); |
1051 | 1060 | return (NULL); |
1052 | 1061 | } |
@@ -1117,6 +1126,9 @@ spl_kmem_cache_destroy(spl_kmem_cache_t *skc) |
1117 | 1126 | ASSERT3U(skc->skc_obj_emergency, ==, 0); |
1118 | 1127 | ASSERT(list_empty(&skc->skc_complete_list)); |
1119 | 1128 |
|
| 1129 | + ASSERT3U(percpu_counter_sum(&skc->skc_linux_alloc), ==, 0); |
| 1130 | + percpu_counter_destroy(&skc->skc_linux_alloc); |
| 1131 | + |
1120 | 1132 | spin_unlock(&skc->skc_lock); |
1121 | 1133 |
|
1122 | 1134 | kfree(skc->skc_name); |
@@ -1473,9 +1485,7 @@ spl_kmem_cache_alloc(spl_kmem_cache_t *skc, int flags) |
1473 | 1485 | * how many objects we've allocated in it for |
1474 | 1486 | * better debuggability. |
1475 | 1487 | */ |
1476 | | - spin_lock(&skc->skc_lock); |
1477 | | - skc->skc_obj_alloc++; |
1478 | | - spin_unlock(&skc->skc_lock); |
| 1488 | + percpu_counter_inc(&skc->skc_linux_alloc); |
1479 | 1489 | } |
1480 | 1490 | goto ret; |
1481 | 1491 | } |
@@ -1550,9 +1560,7 @@ spl_kmem_cache_free(spl_kmem_cache_t *skc, void *obj) |
1550 | 1560 | */ |
1551 | 1561 | if (skc->skc_flags & KMC_SLAB) { |
1552 | 1562 | kmem_cache_free(skc->skc_linux_cache, obj); |
1553 | | - spin_lock(&skc->skc_lock); |
1554 | | - skc->skc_obj_alloc--; |
1555 | | - spin_unlock(&skc->skc_lock); |
| 1563 | + percpu_counter_dec(&skc->skc_linux_alloc); |
1556 | 1564 | return; |
1557 | 1565 | } |
1558 | 1566 |
|
|
0 commit comments