UBIFS: save a bit of RAM
Subsystems (2)
PATCH 1/6 UBIFS: allocate dump buffer on demand
In reply to Artem BityutskiyFrom: Artem Bityutskiy <[email protected]>
Instead of using pre-allocated 'c->dbg->buf' buffer in 'dbg_dump_leb()', 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.
--- fs/ubifs/debug.c | 15 +++++++++++++-- 1 files changed, 13 insertions(+), 2 deletions(-)
fs/ubifs/debug.c +13 -2
@@ -810,16 +810,24 @@ void dbg_dump_leb(const struct ubifs_info *c, int lnum) {struct ubifs_scan_leb *sleb;struct ubifs_scan_node *snod; +void *buf;if (dbg_failure_mode)return ;printk (KERN_DEBUG "(pid %d) start dumping LEB %d\n" , current->pid, lnum); - sleb =ubifs_scan (c, lnum,0 , c->dbg->buf,0 ); + + buf =__vmalloc (c->leb_size,GFP_KERNEL |GFP_NOFS ,PAGE_KERNEL ); +if (!buf) { +ubifs_err ("cannot allocate memory for dumping LEB %d" , lnum); +return ; + } + + sleb =ubifs_scan (c, lnum,0 , buf,0 );if (IS_ERR (sleb)) {ubifs_err ("scan error %d" , (int )PTR_ERR (sleb)); -return ; + goto out; } printk(KERN_DEBUG "LEB %d has %d nodes ending at %d\n", lnum,
@@ -835,6 +843,9 @@ void dbg_dump_leb(const struct ubifs_info *c, int lnum)printk (KERN_DEBUG "(pid %d) finish dumping LEB %d\n" , current->pid, lnum);ubifs_scan_destroy (sleb); + +out: +vfree (buf);return ; }
Signature · 1 line
1.7.2.3
PATCH 5/6 UBIFS: allocate orphans scan buffer on demand
In reply to Artem BityutskiyFrom: Artem Bityutskiy <[email protected]>
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.
--- fs/ubifs/orphan.c | 10 +++++++++- 1 files changed, 9 insertions(+), 1 deletions(-)
fs/ubifs/orphan.c +9 -1
@@ -892,15 +892,22 @@ static int dbg_read_orphans(struct check_info *ci, struct ubifs_scan_leb *sleb)static int dbg_scan_orphans (struct ubifs_info *c,struct check_info *ci) {int lnum, err =0 ; +void *buf;/* Check no-orphans flag and skip this if no orphans */ if (c->no_orphs)return 0 ; + buf =__vmalloc (c->leb_size,GFP_KERNEL |GFP_NOFS ,PAGE_KERNEL ); +if (!buf) { +ubifs_err ("cannot allocate memory to check orphans" ); +return 0 ; + } +for (lnum = c->orph_first; lnum <= c->orph_last; lnum++) {struct ubifs_scan_leb *sleb; - sleb =ubifs_scan (c, lnum,0 , c->dbg->buf,0 ); + sleb =ubifs_scan (c, lnum,0 , buf,0 );if (IS_ERR (sleb)) { err =PTR_ERR (sleb);break ;
@@ -912,6 +919,7 @@ static int dbg_scan_orphans(struct ubifs_info *c, struct check_info *ci)break ; } +vfree (buf);return err; }
Signature · 1 line
1.7.2.3
cover UBIFS: save a bit of RAM
Hi,
this is a simple patch series which makes UBIFS use a bit less RAM. It gets rid of a debugging buffer of PEB size, which is in most cases 128KiB, but can be larger as well.
When UBIFS is compiled with debugging support (most typical setup I believe), UBIFS allocate a PEB size buffer for miscellaneous purposes. But mostly it uses the buffer in various self-checks.
However, most people never enable the self-checks, so the RAM is wasted. This patch series makes UBIFS always allocate the RAM when it is needed, and free it afterwords.
Artem.
PATCH 2/6 UBIFS: allocate scanning buffer on demand
From: Artem Bityutskiy <[email protected]>
Instead of using pre-allocated 'c->dbg->buf' buffer in 'scan_check_cb()', 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.
--- fs/ubifs/lprops.c | 26 ++++++++++++++++++++------ 1 files changed, 20 insertions(+), 6 deletions(-)
fs/ubifs/lprops.c +20 -6
@@ -1035,7 +1035,8 @@ static int scan_check_cb(struct ubifs_info *c,struct ubifs_scan_leb *sleb;struct ubifs_scan_node *snod;struct ubifs_lp_stats *lst = &data->lst; -int cat, lnum = lp->lnum, is_idx =0 , used =0 , free, dirty; +int cat, lnum = lp->lnum, is_idx =0 , used =0 , free, dirty, ret; +void *buf =NULL ; cat = lp->flags &LPROPS_CAT_MASK ;if (cat !=LPROPS_UNCAT ) {
@@ -1093,7 +1094,13 @@ static int scan_check_cb(struct ubifs_info *c, } } - sleb =ubifs_scan (c, lnum,0 , c->dbg->buf,0 ); + buf =__vmalloc (c->leb_size,GFP_KERNEL |GFP_NOFS ,PAGE_KERNEL ); +if (!buf) { +ubifs_err ("cannot allocate memory to scan LEB %d" , lnum); + goto out; + } + + sleb =ubifs_scan (c, lnum,0 , buf,0 );if (IS_ERR (sleb)) {/* * After an unclean unmount, empty and freeable LEBs
@@ -1105,7 +1112,8 @@ static int scan_check_cb(struct ubifs_info *c, lst->empty_lebs +=1 ; lst->total_free += c->leb_size; lst->total_dark +=ubifs_calc_dark (c, c->leb_size); -return LPT_SCAN_CONTINUE ; + ret =LPT_SCAN_CONTINUE ; + goto exit; } if (lp->free + lp->dirty == c->leb_size &&
@@ -1115,10 +1123,12 @@ static int scan_check_cb(struct ubifs_info *c, lst->total_free += lp->free; lst->total_dirty += lp->dirty; lst->total_dark +=ubifs_calc_dark (c, c->leb_size); -return LPT_SCAN_CONTINUE ; + ret =LPT_SCAN_CONTINUE ; + goto exit; } data->err =PTR_ERR (sleb); -return LPT_SCAN_STOP ; + ret =LPT_SCAN_STOP ; + goto exit; } is_idx =-1 ;
@@ -1236,7 +1246,10 @@ static int scan_check_cb(struct ubifs_info *c, }ubifs_scan_destroy (sleb); -return LPT_SCAN_CONTINUE ; + ret =LPT_SCAN_CONTINUE ; +exit: +vfree (buf); +return ret; out_print: ubifs_err("bad accounting of LEB %d: free %d, dirty %d flags %#x, "
@@ -1246,6 +1259,7 @@ out_print: out_destroy:ubifs_scan_destroy (sleb); out: +vfree (buf); data->err = -EINVAL ;return LPT_SCAN_STOP ; }
Signature · 1 line
1.7.2.3
PATCH 4/6 UBIFS: allocate lpt dump buffer on demand
In reply to Artem BityutskiyFrom: Artem Bityutskiy <[email protected]>
Instead of using pre-allocated 'c->dbg->buf' buffer in 'dump_lpt_leb()', 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.
--- fs/ubifs/lpt_commit.c | 27 ++++++++++++++++++--------- 1 files changed, 18 insertions(+), 9 deletions(-)
fs/ubifs/lpt_commit.c +18 -9
@@ -1881,25 +1881,31 @@ int dbg_chk_lpt_sz(struct ubifs_info *c, int action, int len)static void dump_lpt_leb (const struct ubifs_info *c,int lnum) {int err, len = c->leb_size, node_type, node_num, node_len, offs; -void *buf = c->dbg->buf; +void *buf, *p;printk (KERN_DEBUG "(pid %d) start dumping LEB %d\n" , current->pid, lnum); + buf = p =__vmalloc (c->leb_size,GFP_KERNEL |GFP_NOFS ,PAGE_KERNEL ); +if (!buf) { +ubifs_err ("cannot allocate memory to dump LPT" ); +return ; + } + err =ubi_read (c->ubi, lnum, buf,0 , c->leb_size);if (err) {ubifs_err ("cannot read LEB %d, error %d" , lnum, err); -return ; + goto out; }while (1 ) { offs = c->leb_size - len; -if (!is_a_node (c, buf, len)) { +if (!is_a_node (c, p, len)) {int pad_len; - pad_len =get_pad_len (c, buf, len); + pad_len =get_pad_len (c, p, len);if (pad_len) {printk (KERN_DEBUG "LEB %d:%d, pad %d bytes\n" , lnum, offs, pad_len); - buf += pad_len; + p += pad_len; len -= pad_len;continue ; }
@@ -1909,7 +1915,7 @@ static void dump_lpt_leb(const struct ubifs_info *c, int lnum)break ; } - node_type =get_lpt_node_type (c, buf, &node_num); + node_type =get_lpt_node_type (c, p, &node_num);switch (node_type) {case UBIFS_LPT_PNODE : {
@@ -1934,7 +1940,7 @@ static void dump_lpt_leb(const struct ubifs_info *c, int lnum)else printk (KERN_DEBUG "LEB %d:%d, nnode, " , lnum, offs); - err =ubifs_unpack_nnode (c, buf, &nnode); + err =ubifs_unpack_nnode (c, p, &nnode);for (i =0 ; i <UBIFS_LPT_FANOUT ; i++) {printk (KERN_CONT "%d:%d" , nnode.nbranch[i].lnum, nnode.nbranch[i].offs);
@@ -1955,15 +1961,18 @@ static void dump_lpt_leb(const struct ubifs_info *c, int lnum)break ;default :ubifs_err ("LPT node type %d not recognized" , node_type); -return ; + goto out; } - buf += node_len; + p += node_len; len -= node_len; }printk (KERN_DEBUG "(pid %d) finish dumping LEB %d\n" , current->pid, lnum); +out: +vfree (buf); +return ; }/**
Signature · 1 line
1.7.2.3
PATCH 3/6 UBIFS: allocate ltab checking buffer on demand
In reply to Artem BityutskiyFrom: Artem Bityutskiy <[email protected]>
Instead of using pre-allocated 'c->dbg->buf' buffer in 'dbg_check_ltab_lnum()', 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.
--- fs/ubifs/lpt_commit.c | 29 ++++++++++++++++++++--------- 1 files changed, 20 insertions(+), 9 deletions(-)
fs/ubifs/lpt_commit.c +20 -9
@@ -1628,29 +1628,35 @@ static int dbg_check_ltab_lnum(struct ubifs_info *c, int lnum) {int err, len = c->leb_size, dirty =0 , node_type, node_num, node_len;int ret; -void *buf = c->dbg->buf; +void *buf, *p;if (!(ubifs_chk_flags &UBIFS_CHK_LPROPS ))return 0 ; + buf = p =__vmalloc (c->leb_size,GFP_KERNEL |GFP_NOFS ,PAGE_KERNEL ); +if (!buf) { +ubifs_err ("cannot allocate memory for ltab checking" ); +return 0 ; + } +dbg_lp ("LEB %d" , lnum); err =ubi_read (c->ubi, lnum, buf,0 , c->leb_size);if (err) {dbg_msg ("ubi_read failed, LEB %d, error %d" , lnum, err); -return err; + goto out; }while (1 ) { -if (!is_a_node (c, buf, len)) { +if (!is_a_node (c, p, len)) {int i, pad_len; - pad_len =get_pad_len (c, buf, len); + pad_len =get_pad_len (c, p, len);if (pad_len) { - buf += pad_len; + p += pad_len; len -= pad_len; dirty += pad_len;continue ; } -if (!dbg_is_all_ff (buf, len)) { +if (!dbg_is_all_ff (p, len)) {dbg_msg ("invalid empty space in LEB %d at %d" , lnum, c->leb_size - len); err = -EINVAL ;
@@ -1668,16 +1674,21 @@ static int dbg_check_ltab_lnum(struct ubifs_info *c, int lnum) lnum, dirty, c->ltab[i].dirty); err = -EINVAL ; } -return err; + goto out; } - node_type =get_lpt_node_type (c, buf, &node_num); + node_type =get_lpt_node_type (c, p, &node_num); node_len =get_lpt_node_len (c, node_type); ret =dbg_is_node_dirty (c, node_type, lnum, c->leb_size - len);if (ret ==1 ) dirty += node_len; - buf += node_len; + p += node_len; len -= node_len; } + + err =0 ; +out: +vfree (buf); +return err; }/**
Signature · 1 line
1.7.2.3
PATCH 6/6 UBIFS: save 128KiB or more RAM
In reply to Artem BityutskiyFrom: Artem Bityutskiy <[email protected]>
When debugging is enabled, we allocate a buffer of PEB size for various debugging purposes. However, now all users of this buffer are gone and we can safely remove it and save 128KiB or more RAM.
--- fs/ubifs/debug.c | 9 --------- fs/ubifs/debug.h | 2 -- 2 files changed, 0 insertions(+), 11 deletions(-)
fs/ubifs/debug.c +0 -9
@@ -2701,16 +2701,8 @@ int ubifs_debugging_init(struct ubifs_info *c)if (!c->dbg)return -ENOMEM ; - c->dbg->buf =vmalloc (c->leb_size); -if (!c->dbg->buf) - goto out; -failure_mode_init (c);return 0 ; - -out: -kfree (c->dbg); -return -ENOMEM ; }/**
@@ -2720,7 +2712,6 @@ out:void ubifs_debugging_exit (struct ubifs_info *c) {failure_mode_exit (c); -vfree (c->dbg->buf);kfree (c->dbg); }
fs/ubifs/debug.h +0 -2
@@ -27,7 +27,6 @@/** * ubifs_debug_info - per-FS debugging information. -* @buf: a buffer of LEB size, used for various purposes * @old_zroot: old index root - used by 'dbg_check_old_index()' * @old_zroot_level: old index root level - used by 'dbg_check_old_index()' * @old_zroot_sqnum: old index root sqnum - used by 'dbg_check_old_index()'
@@ -54,7 +53,6 @@* dfs_dump_tnc: "dump TNC" debugfs knob */ struct ubifs_debug_info { -void *buf;struct ubifs_zbranch old_zroot;int old_zroot_level;unsigned long long old_zroot_sqnum;
Signature · 1 line
1.7.2.3