|
16 | 16 | * used to save error information organized in a lock-less list. |
17 | 17 | * |
18 | 18 | * This memory pool is only to be used to save MCE records in MCE context. |
19 | | - * MCE events are rare, so a fixed size memory pool should be enough. Use |
20 | | - * 2 pages to save MCE events for now (~80 MCE records at most). |
| 19 | + * MCE events are rare, so a fixed size memory pool should be enough. |
| 20 | + * Allocate on a sliding scale based on number of CPUs. |
21 | 21 | */ |
22 | | -#define MCE_POOLSZ (2 * PAGE_SIZE) |
| 22 | +#define MCE_MIN_ENTRIES (unsigned int)80 |
| 23 | +#define MCE_PER_CPU 2 |
23 | 24 |
|
24 | 25 | static struct gen_pool *mce_evt_pool; |
25 | 26 | static LLIST_HEAD(mce_event_llist); |
26 | | -static char gen_pool_buf[MCE_POOLSZ]; |
27 | 27 |
|
28 | 28 | /* |
29 | 29 | * Compare the record "t" with each of the records on list "l" to see if |
@@ -118,22 +118,32 @@ int mce_gen_pool_add(struct mce *mce) |
118 | 118 |
|
119 | 119 | static int mce_gen_pool_create(void) |
120 | 120 | { |
121 | | - struct gen_pool *tmpp; |
| 121 | + int mce_numrecords, mce_poolsz, order; |
| 122 | + struct gen_pool *gpool; |
122 | 123 | int ret = -ENOMEM; |
123 | | - |
124 | | - tmpp = gen_pool_create(ilog2(sizeof(struct mce_evt_llist)), -1); |
125 | | - if (!tmpp) |
126 | | - goto out; |
127 | | - |
128 | | - ret = gen_pool_add(tmpp, (unsigned long)gen_pool_buf, MCE_POOLSZ, -1); |
| 124 | + void *mce_pool; |
| 125 | + |
| 126 | + order = order_base_2(sizeof(struct mce_evt_llist)); |
| 127 | + gpool = gen_pool_create(order, -1); |
| 128 | + if (!gpool) |
| 129 | + return ret; |
| 130 | + |
| 131 | + mce_numrecords = max(MCE_MIN_ENTRIES, num_possible_cpus() * MCE_PER_CPU); |
| 132 | + mce_poolsz = mce_numrecords * (1 << order); |
| 133 | + mce_pool = kmalloc(mce_poolsz, GFP_KERNEL); |
| 134 | + if (!mce_pool) { |
| 135 | + gen_pool_destroy(gpool); |
| 136 | + return ret; |
| 137 | + } |
| 138 | + ret = gen_pool_add(gpool, (unsigned long)mce_pool, mce_poolsz, -1); |
129 | 139 | if (ret) { |
130 | | - gen_pool_destroy(tmpp); |
131 | | - goto out; |
| 140 | + gen_pool_destroy(gpool); |
| 141 | + kfree(mce_pool); |
| 142 | + return ret; |
132 | 143 | } |
133 | 144 |
|
134 | | - mce_evt_pool = tmpp; |
| 145 | + mce_evt_pool = gpool; |
135 | 146 |
|
136 | | -out: |
137 | 147 | return ret; |
138 | 148 | } |
139 | 149 |
|
|
0 commit comments