Skip to content

Commit cfe2790

Browse files
jognesspmladek
authored andcommitted
printk: move printk_info into separate array
The majority of the size of a descriptor is taken up by meta data, which is often not of interest to the ringbuffer (for example, when performing state checks). Since descriptors are often temporarily stored on the stack, keeping their size minimal will help reduce stack pressure. Rather than embedding the printk_info into the descriptor, create a separate printk_info array. The index of a descriptor in the descriptor array corresponds to the printk_info with the same index in the printk_info array. The rules for validity of a printk_info match the existing rules for the data blocks: the descriptor must be in a consistent state. Signed-off-by: John Ogness <john.ogness@linutronix.de> Reviewed-by: Petr Mladek <pmladek@suse.com> Signed-off-by: Petr Mladek <pmladek@suse.com> Link: https://lore.kernel.org/r/20200918223421.21621-2-john.ogness@linutronix.de
1 parent f5f022e commit cfe2790

3 files changed

Lines changed: 133 additions & 71 deletions

File tree

kernel/printk/printk.c

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -959,11 +959,11 @@ void log_buf_vmcoreinfo_setup(void)
959959
VMCOREINFO_STRUCT_SIZE(prb_desc_ring);
960960
VMCOREINFO_OFFSET(prb_desc_ring, count_bits);
961961
VMCOREINFO_OFFSET(prb_desc_ring, descs);
962+
VMCOREINFO_OFFSET(prb_desc_ring, infos);
962963
VMCOREINFO_OFFSET(prb_desc_ring, head_id);
963964
VMCOREINFO_OFFSET(prb_desc_ring, tail_id);
964965

965966
VMCOREINFO_STRUCT_SIZE(prb_desc);
966-
VMCOREINFO_OFFSET(prb_desc, info);
967967
VMCOREINFO_OFFSET(prb_desc, state_var);
968968
VMCOREINFO_OFFSET(prb_desc, text_blk_lpos);
969969
VMCOREINFO_OFFSET(prb_desc, dict_blk_lpos);
@@ -1097,11 +1097,13 @@ static char setup_dict_buf[CONSOLE_EXT_LOG_MAX] __initdata;
10971097

10981098
void __init setup_log_buf(int early)
10991099
{
1100+
struct printk_info *new_infos;
11001101
unsigned int new_descs_count;
11011102
struct prb_desc *new_descs;
11021103
struct printk_info info;
11031104
struct printk_record r;
11041105
size_t new_descs_size;
1106+
size_t new_infos_size;
11051107
unsigned long flags;
11061108
char *new_dict_buf;
11071109
char *new_log_buf;
@@ -1142,18 +1144,23 @@ void __init setup_log_buf(int early)
11421144
if (unlikely(!new_dict_buf)) {
11431145
pr_err("log_buf_len: %lu dict bytes not available\n",
11441146
new_log_buf_len);
1145-
memblock_free(__pa(new_log_buf), new_log_buf_len);
1146-
return;
1147+
goto err_free_log_buf;
11471148
}
11481149

11491150
new_descs_size = new_descs_count * sizeof(struct prb_desc);
11501151
new_descs = memblock_alloc(new_descs_size, LOG_ALIGN);
11511152
if (unlikely(!new_descs)) {
11521153
pr_err("log_buf_len: %zu desc bytes not available\n",
11531154
new_descs_size);
1154-
memblock_free(__pa(new_dict_buf), new_log_buf_len);
1155-
memblock_free(__pa(new_log_buf), new_log_buf_len);
1156-
return;
1155+
goto err_free_dict_buf;
1156+
}
1157+
1158+
new_infos_size = new_descs_count * sizeof(struct printk_info);
1159+
new_infos = memblock_alloc(new_infos_size, LOG_ALIGN);
1160+
if (unlikely(!new_infos)) {
1161+
pr_err("log_buf_len: %zu info bytes not available\n",
1162+
new_infos_size);
1163+
goto err_free_descs;
11571164
}
11581165

11591166
prb_rec_init_rd(&r, &info,
@@ -1163,7 +1170,8 @@ void __init setup_log_buf(int early)
11631170
prb_init(&printk_rb_dynamic,
11641171
new_log_buf, ilog2(new_log_buf_len),
11651172
new_dict_buf, ilog2(new_log_buf_len),
1166-
new_descs, ilog2(new_descs_count));
1173+
new_descs, ilog2(new_descs_count),
1174+
new_infos);
11671175

11681176
logbuf_lock_irqsave(flags);
11691177

@@ -1192,6 +1200,14 @@ void __init setup_log_buf(int early)
11921200
pr_info("log_buf_len: %u bytes\n", log_buf_len);
11931201
pr_info("early log buf free: %u(%u%%)\n",
11941202
free, (free * 100) / __LOG_BUF_LEN);
1203+
return;
1204+
1205+
err_free_descs:
1206+
memblock_free(__pa(new_descs), new_descs_size);
1207+
err_free_dict_buf:
1208+
memblock_free(__pa(new_dict_buf), new_log_buf_len);
1209+
err_free_log_buf:
1210+
memblock_free(__pa(new_log_buf), new_log_buf_len);
11951211
}
11961212

11971213
static bool __read_mostly ignore_loglevel;

0 commit comments

Comments
 (0)