yaffs: Keep checkpt rd/wr buffers
authorCharles Manning <cdhmanning@gmail.com>
Mon, 1 Jun 2015 21:52:23 +0000 (09:52 +1200)
committerCharles Manning <cdhmanning@gmail.com>
Mon, 1 Jun 2015 22:16:24 +0000 (10:16 +1200)
Continual malloc/free on some systemcs can cause fragmentation. Better
to just allocate the buffers once and hold unto them.

Signed-off-by: Charles Manning <cdhmanning@gmail.com>
yaffs_checkptrw.c
yaffs_guts.c

index e739fb4..4937291 100644 (file)
@@ -237,8 +237,9 @@ int yaffs2_checkpt_open(struct yaffs_dev *dev, int writing)
        dev->blocks_in_checkpt = 0;
        dev->checkpt_max_blocks =
            (dev->internal_end_block - dev->internal_start_block) / 16 + 2;
-       dev->checkpt_block_list =
-           kmalloc(sizeof(int) * dev->checkpt_max_blocks, GFP_NOFS);
+       if (!dev->checkpt_block_list)
+               dev->checkpt_block_list =
+                     kmalloc(sizeof(int) * dev->checkpt_max_blocks, GFP_NOFS);
 
        if (!dev->checkpt_block_list)
                return 0;
@@ -441,8 +442,6 @@ int yaffs_checkpt_close(struct yaffs_dev *dev)
                        if (bi && bi->block_state == YAFFS_BLOCK_STATE_EMPTY)
                                bi->block_state = YAFFS_BLOCK_STATE_CHECKPOINT;
                }
-               kfree(dev->checkpt_block_list);
-               dev->checkpt_block_list = NULL;
        }
 
        dev->n_free_chunks -=
@@ -452,14 +451,10 @@ int yaffs_checkpt_close(struct yaffs_dev *dev)
        yaffs_trace(YAFFS_TRACE_CHECKPOINT, "checkpoint byte count %d",
                dev->checkpt_byte_count);
 
-       if (dev->checkpt_buffer) {
-               /* free the buffer */
-               kfree(dev->checkpt_buffer);
-               dev->checkpt_buffer = NULL;
+       if (dev->checkpt_buffer)
                return 1;
-       } else {
+       else
                return 0;
-       }
 }
 
 int yaffs2_checkpt_invalidate_stream(struct yaffs_dev *dev)
index dd35e25..89fb2a9 100644 (file)
@@ -5019,8 +5019,15 @@ void yaffs_deinitialise(struct yaffs_dev *dev)
 
                kfree(dev->gc_cleanup_list);
 
-               for (i = 0; i < YAFFS_N_TEMP_BUFFERS; i++)
+               for (i = 0; i < YAFFS_N_TEMP_BUFFERS; i++) {
                        kfree(dev->temp_buffer[i].buffer);
+                       dev->temp_buffer[i].buffer = NULL;
+               }
+
+               kfree(dev->checkpt_buffer);
+               dev->checkpt_buffer = NULL;
+               kfree(dev->checkpt_block_list);
+               dev->checkpt_block_list = NULL;
 
                dev->is_mounted = 0;