Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

printk_ringbuffer: don't needlessly wrap data blocks around

Previously, data blocks that perfectly fit the data ring buffer would
get wrapped around to the beginning for no reason since the calculated
offset of the next data block would belong to the next wrap. Since this
offset is not actually part of the data block, but rather the offset of
where the next data block is going to start, there is no reason to
include it when deciding whether the current block fits the buffer.

Signed-off-by: Daniil Tatianin <d-tatianin@yandex-team.ru>
Reviewed-by: Petr Mladek <pmladek@suse.com>
Tested-by: Petr Mladek <pmladek@suse.com>
Reviewed-by: John Ogness <john.ogness@linutronix.de>
Tested-by: John Ogness <john.ogness@linutronix.de>
Link: https://patch.msgid.link/20250905144152.9137-2-d-tatianin@yandex-team.ru
[pmladek@suse.com: Updated indentation.]
Signed-off-by: Petr Mladek <pmladek@suse.com>

authored by

Daniil Tatianin and committed by
Petr Mladek
67e1b005 48e3694a

+20 -8
+20 -8
kernel/printk/printk_ringbuffer.c
··· 999 999 return true; 1000 1000 } 1001 1001 1002 + static bool is_blk_wrapped(struct prb_data_ring *data_ring, 1003 + unsigned long begin_lpos, unsigned long next_lpos) 1004 + { 1005 + /* 1006 + * Subtract one from next_lpos since it's not actually part of this data 1007 + * block. This allows perfectly fitting records to not wrap. 1008 + */ 1009 + return DATA_WRAPS(data_ring, begin_lpos) != 1010 + DATA_WRAPS(data_ring, next_lpos - 1); 1011 + } 1012 + 1002 1013 /* Determine the end of a data block. */ 1003 1014 static unsigned long get_next_lpos(struct prb_data_ring *data_ring, 1004 1015 unsigned long lpos, unsigned int size) ··· 1021 1010 next_lpos = lpos + size; 1022 1011 1023 1012 /* First check if the data block does not wrap. */ 1024 - if (DATA_WRAPS(data_ring, begin_lpos) == DATA_WRAPS(data_ring, next_lpos)) 1013 + if (!is_blk_wrapped(data_ring, begin_lpos, next_lpos)) 1025 1014 return next_lpos; 1026 1015 1027 1016 /* Wrapping data blocks store their data at the beginning. */ ··· 1098 1087 blk = to_block(data_ring, begin_lpos); 1099 1088 blk->id = id; /* LMM(data_alloc:B) */ 1100 1089 1101 - if (DATA_WRAPS(data_ring, begin_lpos) != DATA_WRAPS(data_ring, next_lpos)) { 1090 + if (is_blk_wrapped(data_ring, begin_lpos, next_lpos)) { 1102 1091 /* Wrapping data blocks store their data at the beginning. */ 1103 1092 blk = to_block(data_ring, 0); 1104 1093 ··· 1142 1131 return NULL; 1143 1132 1144 1133 /* Keep track if @blk_lpos was a wrapping data block. */ 1145 - wrapped = (DATA_WRAPS(data_ring, blk_lpos->begin) != DATA_WRAPS(data_ring, blk_lpos->next)); 1134 + wrapped = is_blk_wrapped(data_ring, blk_lpos->begin, blk_lpos->next); 1146 1135 1147 1136 size = to_blk_size(size); 1148 1137 ··· 1178 1167 1179 1168 blk = to_block(data_ring, blk_lpos->begin); 1180 1169 1181 - if (DATA_WRAPS(data_ring, blk_lpos->begin) != DATA_WRAPS(data_ring, next_lpos)) { 1170 + if (is_blk_wrapped(data_ring, blk_lpos->begin, next_lpos)) { 1182 1171 struct prb_data_block *old_blk = blk; 1183 1172 1184 1173 /* Wrapping data blocks store their data at the beginning. */ ··· 1214 1203 if (BLK_DATALESS(blk_lpos)) 1215 1204 return 0; 1216 1205 1217 - if (DATA_WRAPS(data_ring, blk_lpos->begin) == DATA_WRAPS(data_ring, blk_lpos->next)) { 1206 + if (!is_blk_wrapped(data_ring, blk_lpos->begin, blk_lpos->next)) { 1218 1207 /* Data block does not wrap. */ 1219 1208 return (DATA_INDEX(data_ring, blk_lpos->next) - 1220 1209 DATA_INDEX(data_ring, blk_lpos->begin)); ··· 1261 1250 } 1262 1251 1263 1252 /* Regular data block: @begin less than @next and in same wrap. */ 1264 - if (DATA_WRAPS(data_ring, blk_lpos->begin) == DATA_WRAPS(data_ring, blk_lpos->next) && 1253 + if (!is_blk_wrapped(data_ring, blk_lpos->begin, blk_lpos->next) && 1265 1254 blk_lpos->begin < blk_lpos->next) { 1266 1255 db = to_block(data_ring, blk_lpos->begin); 1267 1256 *data_size = blk_lpos->next - blk_lpos->begin; 1268 1257 1269 1258 /* Wrapping data block: @begin is one wrap behind @next. */ 1270 - } else if (DATA_WRAPS(data_ring, blk_lpos->begin + DATA_SIZE(data_ring)) == 1271 - DATA_WRAPS(data_ring, blk_lpos->next)) { 1259 + } else if (!is_blk_wrapped(data_ring, 1260 + blk_lpos->begin + DATA_SIZE(data_ring), 1261 + blk_lpos->next)) { 1272 1262 db = to_block(data_ring, 0); 1273 1263 *data_size = DATA_INDEX(data_ring, blk_lpos->next); 1274 1264