Skip to content

Commit f5cf319

Browse files
Artem BityutskiyArtem Bityutskiy
authored andcommitted
UBIFS: allocate orphans scan buffer on demand
Instead of using pre-allocated 'c->dbg->buf' buffer in 'dbg_scan_orphans()', dynamically allocate it when needed. The intend is to get rid of the pre-allocated 'c->dbg->buf' buffer and save 128KiB of RAM (or more if PEB size is larger). Indeed, currently we allocate this memory even if the user never enables any self-check, which is wasteful. Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
1 parent cab95d4 commit f5cf319

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

‎fs/ubifs/orphan.c‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -892,15 +892,22 @@ static int dbg_read_orphans(struct check_info *ci, struct ubifs_scan_leb *sleb)
892892
static int dbg_scan_orphans(struct ubifs_info *c, struct check_info *ci)
893893
{
894894
int lnum, err = 0;
895+
void *buf;
895896

896897
/* Check no-orphans flag and skip this if no orphans */
897898
if (c->no_orphs)
898899
return 0;
899900

901+
buf = __vmalloc(c->leb_size, GFP_KERNEL | GFP_NOFS, PAGE_KERNEL);
902+
if (!buf) {
903+
ubifs_err("cannot allocate memory to check orphans");
904+
return 0;
905+
}
906+
900907
for (lnum = c->orph_first; lnum <= c->orph_last; lnum++) {
901908
struct ubifs_scan_leb *sleb;
902909

903-
sleb = ubifs_scan(c, lnum, 0, c->dbg->buf, 0);
910+
sleb = ubifs_scan(c, lnum, 0, buf, 0);
904911
if (IS_ERR(sleb)) {
905912
err = PTR_ERR(sleb);
906913
break;
@@ -912,6 +919,7 @@ static int dbg_scan_orphans(struct ubifs_info *c, struct check_info *ci)
912919
break;
913920
}
914921

922+
vfree(buf);
915923
return err;
916924
}
917925

0 commit comments

Comments
 (0)