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.

lib/freader: support reading more than 2 folios

freader_fetch currently reads from at most two folios. When a read spans
into a third folio, the overflow bytes are copied adjacent to the second
folio’s data instead of being handled as a separate folio.
This patch modifies fetch algorithm to support reading from many folios.

Signed-off-by: Mykyta Yatsenko <yatsenko@meta.com>
Reviewed-by: Andrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/r/20251026203853.135105-5-mykyta.yatsenko5@gmail.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>

authored by

Mykyta Yatsenko and committed by
Alexei Starovoitov
5a5fff60 76e4fed8

+13 -10
+13 -10
lib/buildid.c
··· 108 108 */ 109 109 folio_sz = folio_size(r->folio); 110 110 if (file_off + sz > r->folio_off + folio_sz) { 111 - int part_sz = r->folio_off + folio_sz - file_off; 111 + u64 part_sz = r->folio_off + folio_sz - file_off, off; 112 112 113 - /* copy the part that resides in the current folio */ 114 - memcpy(r->buf, r->addr + (file_off - r->folio_off), part_sz); 113 + memcpy(r->buf, r->addr + file_off - r->folio_off, part_sz); 114 + off = part_sz; 115 115 116 - /* fetch next folio */ 117 - r->err = freader_get_folio(r, r->folio_off + folio_sz); 118 - if (r->err) 119 - return NULL; 120 - 121 - /* copy the rest of requested data */ 122 - memcpy(r->buf + part_sz, r->addr, sz - part_sz); 116 + while (off < sz) { 117 + /* fetch next folio */ 118 + r->err = freader_get_folio(r, r->folio_off + folio_sz); 119 + if (r->err) 120 + return NULL; 121 + folio_sz = folio_size(r->folio); 122 + part_sz = min_t(u64, sz - off, folio_sz); 123 + memcpy(r->buf + off, r->addr, part_sz); 124 + off += part_sz; 125 + } 123 126 124 127 return r->buf; 125 128 }