UBI: reduce memory consumption
Remove the pre-allocated 'peb_buf2' buffer because we do not really need it. The only reason UBI has it is to check that the data were written correctly. But we do not have to have 2 buffers for this and waste RAM - we can just compare CRC checksums instead. This reduces UBI memory consumption. Artem bityutskiy: massaged the patch and commit message Signed-off-by: Josselin Costanzi <josselin.costanzi@mobile-devices.fr> Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
This commit is contained in:
parent
7eb3aa6585
commit
43b043e78b
|
@ -949,10 +949,6 @@ int ubi_attach_mtd_dev(struct mtd_info *mtd, int ubi_num, int vid_hdr_offset)
|
||||||
if (!ubi->peb_buf1)
|
if (!ubi->peb_buf1)
|
||||||
goto out_free;
|
goto out_free;
|
||||||
|
|
||||||
ubi->peb_buf2 = vmalloc(ubi->peb_size);
|
|
||||||
if (!ubi->peb_buf2)
|
|
||||||
goto out_free;
|
|
||||||
|
|
||||||
err = ubi_debugging_init_dev(ubi);
|
err = ubi_debugging_init_dev(ubi);
|
||||||
if (err)
|
if (err)
|
||||||
goto out_free;
|
goto out_free;
|
||||||
|
@ -1030,7 +1026,6 @@ out_debugging:
|
||||||
ubi_debugging_exit_dev(ubi);
|
ubi_debugging_exit_dev(ubi);
|
||||||
out_free:
|
out_free:
|
||||||
vfree(ubi->peb_buf1);
|
vfree(ubi->peb_buf1);
|
||||||
vfree(ubi->peb_buf2);
|
|
||||||
if (ref)
|
if (ref)
|
||||||
put_device(&ubi->dev);
|
put_device(&ubi->dev);
|
||||||
else
|
else
|
||||||
|
@ -1102,7 +1097,6 @@ int ubi_detach_mtd_dev(int ubi_num, int anyway)
|
||||||
put_mtd_device(ubi->mtd);
|
put_mtd_device(ubi->mtd);
|
||||||
ubi_debugging_exit_dev(ubi);
|
ubi_debugging_exit_dev(ubi);
|
||||||
vfree(ubi->peb_buf1);
|
vfree(ubi->peb_buf1);
|
||||||
vfree(ubi->peb_buf2);
|
|
||||||
ubi_msg("mtd%d is detached from ubi%d", ubi->mtd->index, ubi->ubi_num);
|
ubi_msg("mtd%d is detached from ubi%d", ubi->mtd->index, ubi->ubi_num);
|
||||||
put_device(&ubi->dev);
|
put_device(&ubi->dev);
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -1134,8 +1134,8 @@ int ubi_eba_copy_leb(struct ubi_device *ubi, int from, int to,
|
||||||
* We've written the data and are going to read it back to make
|
* We've written the data and are going to read it back to make
|
||||||
* sure it was written correctly.
|
* sure it was written correctly.
|
||||||
*/
|
*/
|
||||||
|
memset(ubi->peb_buf1, 0xFF, aldata_size);
|
||||||
err = ubi_io_read_data(ubi, ubi->peb_buf2, to, 0, aldata_size);
|
err = ubi_io_read_data(ubi, ubi->peb_buf1, to, 0, aldata_size);
|
||||||
if (err) {
|
if (err) {
|
||||||
if (err != UBI_IO_BITFLIPS) {
|
if (err != UBI_IO_BITFLIPS) {
|
||||||
ubi_warn("error %d while reading data back "
|
ubi_warn("error %d while reading data back "
|
||||||
|
@ -1149,7 +1149,7 @@ int ubi_eba_copy_leb(struct ubi_device *ubi, int from, int to,
|
||||||
|
|
||||||
cond_resched();
|
cond_resched();
|
||||||
|
|
||||||
if (memcmp(ubi->peb_buf1, ubi->peb_buf2, aldata_size)) {
|
if (crc != crc32(UBI_CRC32_INIT, ubi->peb_buf1, data_size)) {
|
||||||
ubi_warn("read data back from PEB %d and it is "
|
ubi_warn("read data back from PEB %d and it is "
|
||||||
"different", to);
|
"different", to);
|
||||||
err = -EINVAL;
|
err = -EINVAL;
|
||||||
|
|
|
@ -388,8 +388,7 @@ struct ubi_wl_entry;
|
||||||
* @mtd: MTD device descriptor
|
* @mtd: MTD device descriptor
|
||||||
*
|
*
|
||||||
* @peb_buf1: a buffer of PEB size used for different purposes
|
* @peb_buf1: a buffer of PEB size used for different purposes
|
||||||
* @peb_buf2: another buffer of PEB size used for different purposes
|
* @buf_mutex: protects @peb_buf1
|
||||||
* @buf_mutex: protects @peb_buf1 and @peb_buf2
|
|
||||||
* @ckvol_mutex: serializes static volume checking when opening
|
* @ckvol_mutex: serializes static volume checking when opening
|
||||||
*
|
*
|
||||||
* @dbg: debugging information for this UBI device
|
* @dbg: debugging information for this UBI device
|
||||||
|
@ -472,7 +471,6 @@ struct ubi_device {
|
||||||
struct mtd_info *mtd;
|
struct mtd_info *mtd;
|
||||||
|
|
||||||
void *peb_buf1;
|
void *peb_buf1;
|
||||||
void *peb_buf2;
|
|
||||||
struct mutex buf_mutex;
|
struct mutex buf_mutex;
|
||||||
struct mutex ckvol_mutex;
|
struct mutex ckvol_mutex;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue