Reducing of JFFS2 mounting time
Subsystems (4)
Hi all,
Some time ago, we faced a problem with a long mounting of high filled JFFS2 filesystem. On 16Mb FLASH partition, the scanning (and mount, respectively) tooks about 4-5 seconds. To reduce this time, after looking around of possible ways to improve JFFS2 perfomance in this area, we decided to move flash scanning process itself into start of garbage collecting thread. While scanning will not be done, no any access from user-space is allowed, of course, and we reach it by blocking filesystem with semaphore and counter of already scanned flash blocks. Since scanning is executing in different kernel thread, user-space 'mount' released relatively fast.
After scan completion, block counter will be equal total number of blocks and completion semaphore will be released, giving applications right to access filesystem.
In original driver's version, when a filesystem mounted in 'read-only mode', a garbage collection thread doesn't started; in out modified version, we start this thread anyway, but after scanning completes, we check with what flags a mounting has been requested. And if we mounts 'read-only', thread is terminated as usual.
Attached patch have been tested with MontaVista' MVLCEE 2.4.20 Linux kernel. On 16Mb, 100% filled JFFS2 flash partition, a mounting tooks about 800ms.
Guys, if anybody have a time, please take a look at attached work. What do you think about it? Your opinions?
Thanks,
Ruslan Satlykov
Documentation/Configure.help +23 -0
@@ -16640,6 +16640,29 @@ If reporting bugs, please try to have available a full dump of the messages at debug level 1 while the misbehaviour was occurring. +JFFS2 Fast mounting +CONFIG_JFFS2_FAST_MOUNT + This option allows to skip entire FLASH media scanning by moving this + phase into different kernel thread (at the start of the garbage + collector thread). Also, this add new option to the user-level + 'mount' command, 'mfast'. + + NOTE: This is _VERY_ experimental, and _NOT_ OFFICIAL add-on to + well-known filesystem. + + It's good to say 'N' here if you don't understand which was saying above. +JFFS2 scanned inodes caching +CONFIG_JFFS2_CACHED_NODES + On the first mounting phase, physical FLASH media scanning, scanned + inodes info can be cached, which will prevent it's repeately readings + on the latter accesses to file system (if the file has not been changed, + of course). It will slightly improve filesystem perfomance. + + NOTE: This is _EXPERIMENTAL_, and _NOT_ official add-on to + well-known filesystem. + + It's good to say 'N' here if you don't understand which was saying above. + JFFS stats available in /proc filesystem CONFIG_JFFS_PROC_FS Enabling this option will cause statistics from mounted JFFS file systems
fs/Config.in +2 -0
@@ -46,6 +46,8 @@ dep_tristate 'Journalling Flash File System v2 (JFFS2) support' CONFIG_JFFS2_FS $CONFIG_MTD if [ "$CONFIG_JFFS2_FS" = "y" -o "$CONFIG_JFFS2_FS" = "m" ] ; then int 'JFFS2 debugging verbosity (0 = quiet, 2 = noisy)' CONFIG_JFFS2_FS_DEBUG 0 + bool 'Fast mounting (EXPERIMENTAL)' CONFIG_JFFS2_FAST_MOUNT $CONFIG_EXPERIMENTAL + bool 'Cache inodes on scanning (EXPERIMENTA)' CONFIG_JFFS2_CACHED_NODES $CONFIG_EXPERIMENTAL fi tristate 'Compressed ROM file system support' CONFIG_CRAMFS dep_mbool ' Use linear addressing for cramfs' CONFIG_CRAMFS_LINEAR $CONFIG_CRAMFS
fs/jffs2/background.c +34 -5
@@ -2,6 +2,7 @@* JFFS2 -- Journalling Flash File System, Version 2. * * Copyright (C) 2001, 2002 Red Hat, Inc. +* Copyright (C) 2003 MontaVista Software <[email protected]>. * * Created by David Woodhouse <[email protected]> *
@@ -22,6 +23,7 @@#include <linux/unistd.h> #include "nodelist.h" +extern int jffs2_build_filesystem (struct jffs2_sb_info *c);static int jffs2_garbage_collect_thread (void *);static int thread_should_wake (struct jffs2_sb_info *c);
@@ -42,10 +44,10 @@if (c->gc_task)BUG (); - +init_MUTEX_LOCKED (&c->gc_thread_start);init_completion (&c->gc_thread_exit); - + pid =kernel_thread (jffs2_garbage_collect_thread, c,CLONE_FS |CLONE_FILES );if (pid <0 ) {printk (KERN_WARNING "fork failed for JFFS2 garbage collect thread: %d\n" , -pid);
@@ -81,7 +83,9 @@static int jffs2_garbage_collect_thread (void *_c) {struct jffs2_sb_info *c = _c; - +#ifdef CONFIG_JFFS2_FAST_MOUNT +int ret =0 ; +#endif daemonize (); c->gc_task = current;
@@ -89,8 +93,33 @@sprintf (current->comm,"jffs2_gcd_mtd%d" , c->mtd->index); -set_user_nice (current,10 ); - +#ifdef CONFIG_JFFS2_FAST_MOUNT +if (!jffs2_is_complete (c)) { + +struct super_block *sb; + +set_user_nice (current,0 ); + + ret =jffs2_do_mount_fs (c); +/* +if (ret) { +complete(&c->scan_complete); +goto c_a_e; +} +*/ + sb =OFNI_BS_2SFFJ (c); + +if ((sb->s_flags &MS_RDONLY ) || ret) { +spin_lock_bh (&c->erase_completion_lock); + c->gc_task =NULL ; +spin_unlock_bh (&c->erase_completion_lock); +complete_and_exit (&c->gc_thread_exit, ret); + } + } +done: +#endif +set_user_nice (current,10 ); +for (;;) {spin_lock_irq (¤t_sig_lock);siginitsetinv (¤t->blocked,sigmask (SIGHUP ) |sigmask (SIGKILL ) |sigmask (SIGSTOP ) |sigmask (SIGCONT ));
fs/jffs2/build.c +38 -11
117 lines not on this page · raw message
fs/jffs2/dir.c +17 -3
@@ -2,6 +2,7 @@* JFFS2 -- Journalling Flash File System, Version 2. * * Copyright (C) 2001, 2002 Red Hat, Inc. +* Copyright (C) 2003 MontaVista Software <[email protected]>. * * Created by David Woodhouse <[email protected]> *
@@ -73,14 +74,19 @@struct jffs2_full_dirent *fd =NULL , *fd_list;uint32_t ino =0 ;struct inode *inode =NULL ; - +D1 (printk (KERN_DEBUG "jffs2_lookup()\n" )); dir_f =JFFS2_INODE_INFO (dir_i); c =JFFS2_SB_INFO (dir_i->i_sb); +#ifdef CONFIG_JFFS2_FAST_MOUNT +jffs2_waiting_for_scan (c); +jffs2_read_inode (dir_i); +#endif +down (&dir_f->sem); - +/* NB: The 2.2 backport will need to explicitly check for '.' and '..' here */ for (fd_list = dir_f->dents; fd_list && fd_list->nhash <= target->d_name.hash; fd_list = fd_list->next) { if (fd_list->nhash == target->d_name.hash &&
@@ -92,6 +98,7 @@ }if (fd) ino = fd->ino; +up (&dir_f->sem);if (ino) { inode =iget (dir_i->i_sb, ino);
@@ -116,12 +123,16 @@struct inode *inode = filp->f_dentry->d_inode;struct jffs2_full_dirent *fd;unsigned long offset, curofs; - +D1 (printk (KERN_DEBUG "jffs2_readdir() for dir_i #%lu\n" , filp->f_dentry->d_inode->i_ino)); f =JFFS2_INODE_INFO (inode); c =JFFS2_SB_INFO (inode->i_sb); +#ifdef CONFIG_JFFS2_FAST_MOUNT +jffs2_waiting_for_scan (c); +jffs2_read_inode (inode); +#endif offset = filp->f_pos;if (offset ==0 ) {
@@ -140,9 +151,12 @@ curofs=1 ;down (&f->sem); + +for (fd = f->dents; fd; fd = fd->next) { curofs++; +/* First loop: curofs = 2; offset = 2 */ if (curofs < offset) { D2(printk(KERN_DEBUG "Skipping dirent: \"%s\", ino #%u, type %d, because curofs %ld < offset %ld\n",
fs/jffs2/file.c +4 -1
@@ -269,7 +269,10 @@ {struct jffs2_inode_info *f =JFFS2_INODE_INFO (pg->mapping->host);int ret; - + +#ifdef CONFIG_JFFS2_FAST_MOUNT +jffs2_waiting_for_scan (JFFS2_SB_INFO (pg->mapping->host->i_sb)); +#endif down (&f->sem); ret =jffs2_do_readpage_unlock (pg->mapping->host, pg);up (&f->sem);
fs/jffs2/fs.c +35 -13
112 lines not on this page · raw message
fs/jffs2/nodelist.c +25 -10
@@ -2,6 +2,7 @@* JFFS2 -- Journalling Flash File System, Version 2. * * Copyright (C) 2001, 2002 Red Hat, Inc. +* Copyright (C) 2003 MontaVista Software <[email protected]>. * * Created by David Woodhouse <[email protected]> *
@@ -103,27 +104,29 @@struct jffs2_raw_node_ref *ref = f->inocache->nodes;struct jffs2_tmp_dnode_info *tn, *ret_tn =NULL ;struct jffs2_full_dirent *fd, *ret_fd =NULL ; - +union jffs2_node_union node;size_t retlen;int err; *mctime_ver =0 ; -D1 (printk (KERN_DEBUG "jffs2_get_inode_nodes(): ino #%lu\n" , ino)); +D1 (printk ("jffs2_get_inode_nodes(): ino #%lu\n" , ino));if (!f->inocache->nodes) {printk (KERN_WARNING "Eep. no nodes for ino #%lu\n" , ino); } - +spin_lock_bh (&c->erase_completion_lock); +for (ref = f->inocache->nodes; ref && ref->next_in_ino; ref = ref->next_in_ino) {/* Work out whether it's a data node or a dirent node */ if (ref_obsolete (ref)) {/* FIXME: On NAND flash we may need to read these */ -D1 (printk (KERN_DEBUG "node at 0x%08x is obsoleted. Ignoring.\n" ,ref_offset (ref))); +printk ("node at 0x%08x is obsoleted. Ignoring.\n" ,ref_offset (ref));continue ; } +/* We can hold a pointer to a non-obsolete node without the spinlock, but _obsolete_ nodes may disappear at any time, if the block they're in gets erased */
@@ -131,17 +134,29 @@cond_resched (); +#ifdef CONFIG_JFFS2_CACHED_NODES +if (je16_to_cpu (ref->v.u.magic) ==JFFS2_MAGIC_BITMASK &&je16_to_cpu (ref->v.u.nodetype) ==JFFS2_NODETYPE_INODE ) { +D2 (printk (KERN_DEBUG "inode at 0x%08X cached\n" ,ref_offset (ref))); + err =0 ; + retlen =/*ref->totlen*/ sizeof (node.i); +//memcpy (&node.i, ref->v.ri, sizeof (ref->v.ri)); + node.u.magic = ref->v.ri.magic; + node.u.totlen = ref->v.ri.totlen; + node.u.nodetype = ref->v.ri.nodetype; +memcpy (&node.i, &ref->v.ri,sizeof (node.i)); + } else +#endif /* FIXME: point() */ err =jffs2_flash_read (c, (ref_offset (ref)),min (ref->totlen,sizeof (node)), &retlen, (void *)&node);if (err) {printk (KERN_WARNING "error %d reading node at 0x%08x in get_inode_nodes()\n" , err,ref_offset (ref)); goto free_out; } - - +/* Check we've managed to read at least the common node header */ if (retlen <min (ref->totlen,sizeof (node.u))) { -printk (KERN_WARNING "short read in get_inode_nodes()\n" ); +printk (KERN_WARNING "short read in get_inode_nodes(): ref_offset(ref) = 0x%08X, retlen = %d, ref->totlen = %d, sizeof(node.u) = %lu\n" , +ref_offset (ref), retlen, ref->totlen,sizeof (node.u)); err = -EIO ; goto free_out; }
@@ -154,7 +169,7 @@BUG (); }if (retlen <sizeof (node.d)) { -printk (KERN_WARNING "short read in get_inode_nodes()\n" ); +printk (KERN_WARNING "short read in get_inode_nodes() for dirent\n" ); err = -EIO ; goto free_out; }
@@ -219,14 +234,14 @@case JFFS2_NODETYPE_INODE :D1 (printk (KERN_DEBUG "Node at %08x (%d) is a data node\n" ,ref_offset (ref),ref_flags (ref)));if (retlen <sizeof (node.i)) { -printk (KERN_WARNING "read too short for dnode\n" ); +printk (KERN_WARNING "read too short for dnode; retlen = %ld, sizeof(node.i) = %ld\n" , retlen,sizeof (node.i)); err = -EIO ; goto free_out; }if (je32_to_cpu (node.i.version) > *highest_version) *highest_version =je32_to_cpu (node.i.version);D1 (printk (KERN_DEBUG "version %d, highest_version now %d\n" ,je32_to_cpu (node.i.version), *highest_version)); - +if (ref_obsolete (ref)) {/* Obsoleted. This cannot happen, surely? dwmw2 20020308 */ printk(KERN_ERR "Inode node at 0x%08x became obsolete while we weren't looking\n",
fs/jffs2/nodelist.h +32 -1
@@ -39,6 +39,14 @@#define D2 (x)#endif +#ifdef CONFIG_JFFS2_CACHED_NODES +struct jffs2_raw_nodes_vtbl +{ +struct jffs2_unknown_node u; +struct jffs2_raw_inode ri; +struct jffs2_raw_dirent *rd; +}; +#endif /* This is all we need to keep in-core for each raw node during normal operation. As and when we do read_inode on a particular inode, we can
@@ -55,7 +63,9 @@struct jffs2_raw_node_ref *next_phys;uint32_t flash_offset;uint32_t totlen; - +#ifdef CONFIG_JFFS2_CACHED_NODES +struct jffs2_raw_nodes_vtbl v; +#endif /* flash_offset & 3 always has to be zero, because nodes are always aligned at 4 bytes. So we have a couple of extra bits to play with. So we set the least significant bit to 1 to
@@ -246,6 +256,27 @@#define PAD (x) (((x)+3)&~3) +#ifdef CONFIG_JFFS2_FAST_MOUNT +static inline int jffs2_is_complete (struct jffs2_sb_info *c) +{ +int ret =0 ; +struct completion *x = &c->scan_complete; + +spin_lock_irq (&x->wait.lock); + +if (x->done) + ret =1 ; + +spin_unlock_irq (&x->wait.lock); + +return ret; +} +#define jffs2_waiting_for_scan (c) wait_for_completion(&c->scan_complete); \ + complete(&c->scan_complete); +#else +#define jffs2_waiting_for_scan (c) { ; } +#endif +static inline int jffs2_raw_ref_to_inum (struct jffs2_raw_node_ref *raw) {while (raw->next_in_ino) {
fs/jffs2/scan.c +62 -4
122 lines not on this page · raw message
fs/jffs2/super-v24.c +8 -1
@@ -2,6 +2,7 @@* JFFS2 -- Journalling Flash File System, Version 2. * * Copyright (C) 2001, 2002 Red Hat, Inc. +* Copyright (C) 2003 MontaVista Software <[email protected]>. * * Created by David Woodhouse <[email protected]> *
@@ -29,6 +30,12 @@#define MTD_BLOCK_MAJOR 31#endif +#ifndef CONFIG_JFFS2_FAST_MOUNT +#define JFFS2NAM "JFFS2 version 2.1. (C) 2001, 2002 Red Hat, Inc., designed by Axis Communications AB.\n" +#else +#define JFFS2NAM "JFFS2 version 2.1 (with Fast-Mounting option). (C) 2001, 2002 Red Hat, Inc., designed by Axis Communications AB.\n" +#endif +void jffs2_put_super (struct super_block *); static struct super_operations jffs2_super_operations =
@@ -106,7 +113,7 @@ {int ret; -printk (KERN_NOTICE "JFFS2 version 2.1. (C) 2001, 2002 Red Hat, Inc., designed by Axis Communications AB.\n" ); +printk (KERN_NOTICE "%s" ,JFFS2NAM );#ifdef JFFS2_OUT_OF_KERNEL /* sanity checks. Could we do these at compile time? */
include/linux/jffs2_fs_sb.h +8 -0
@@ -13,6 +13,8 @@#define JFFS2_SB_FLAG_RO 1#define JFFS2_SB_FLAG_MOUNTING 2 +#define CHECKPOINT_BLOCK (c) (c->nr_blocks / 16) +/* A struct for the overall file system control. Pointers to jffs2_sb_info structs are named `c' in the source code. Nee jffs_control
@@ -51,6 +53,7 @@uint32_t nr_erasing_blocks;uint32_t nr_blocks; +struct jffs2_eraseblock *blocks;/* The whole array of blocks. Used for getting blocks * from the offset (blocks[ofs / sector_size]) */ struct jffs2_eraseblock *nextblock;/* The block we're currently filling */
@@ -75,6 +78,11 @@struct jffs2_inode_cache **inocache_list;spinlock_t inocache_lock; + +#ifdef CONFIG_JFFS2_FAST_MOUNT +struct completion scan_complete; +atomic_t scan_count; +#endif /* CONFIG_JFFS2_FAST_MOUNT */ /* Sem to allow jffs2_garbage_collect_deletion_dirent to drop the erase_completion_lock while it's holding a pointer