[PATCH] JFFS2 symlink cache
Artem B. Bityuckiy
dedekind at infradead.org
Thu Feb 17 09:25:01 EST 2005
Hello,
here is the JFFS2 patch which adds the symlink caching. In practice, the
patch speeds up the processes startup.
--
Best Regards,
Artem B. Bityuckiy,
St.-Petersburg, Russia.
-------------- next part --------------
diff --exclude=CVS -auNr mtd-pristine/fs/jffs2/dir.c mtd-symlink/fs/jffs2/dir.c
--- mtd-pristine/fs/jffs2/dir.c 2005-02-16 10:35:07.000000000 +0300
+++ mtd-symlink/fs/jffs2/dir.c 2005-02-15 12:45:02.000000000 +0300
@@ -296,11 +296,11 @@
struct jffs2_full_dirent *fd;
int namelen;
uint32_t alloclen, phys_ofs;
- int ret;
+ int ret, targetlen = strlen(target);
/* FIXME: If you care. We'd need to use frags for the target
if it grows much more than this */
- if (strlen(target) > 254)
+ if (targetlen > 254)
return -EINVAL;
ri = jffs2_alloc_raw_inode();
@@ -314,7 +314,7 @@
* Just the node will do for now, though
*/
namelen = dentry->d_name.len;
- ret = jffs2_reserve_space(c, sizeof(*ri) + strlen(target), &phys_ofs, &alloclen, ALLOC_NORMAL);
+ ret = jffs2_reserve_space(c, sizeof(*ri) + targetlen, &phys_ofs, &alloclen, ALLOC_NORMAL);
if (ret) {
jffs2_free_raw_inode(ri);
@@ -333,16 +333,16 @@
f = JFFS2_INODE_INFO(inode);
- inode->i_size = strlen(target);
+ inode->i_size = targetlen;
ri->isize = ri->dsize = ri->csize = cpu_to_je32(inode->i_size);
ri->totlen = cpu_to_je32(sizeof(*ri) + inode->i_size);
ri->hdr_crc = cpu_to_je32(crc32(0, ri, sizeof(struct jffs2_unknown_node)-4));
ri->compr = JFFS2_COMPR_NONE;
- ri->data_crc = cpu_to_je32(crc32(0, target, strlen(target)));
+ ri->data_crc = cpu_to_je32(crc32(0, target, targetlen));
ri->node_crc = cpu_to_je32(crc32(0, ri, sizeof(*ri)-8));
- fn = jffs2_write_dnode(c, f, ri, target, strlen(target), phys_ofs, ALLOC_NORMAL);
+ fn = jffs2_write_dnode(c, f, ri, target, targetlen, phys_ofs, ALLOC_NORMAL);
jffs2_free_raw_inode(ri);
@@ -353,6 +353,20 @@
jffs2_clear_inode(inode);
return PTR_ERR(fn);
}
+
+ /* We use f->dents field to store the target path. */
+ f->dents = kmalloc(targetlen + 1, GFP_KERNEL);
+ if (!f->dents) {
+ printk(KERN_WARNING "Can't allocate %d bytes of memory\n", targetlen + 1);
+ up(&f->sem);
+ jffs2_complete_reservation(c);
+ jffs2_clear_inode(inode);
+ return -ENOMEM;
+ }
+
+ memcpy(f->dents, target, targetlen + 1);
+ D1(printk(KERN_DEBUG "jffs2_symlink: symlink's target '%s' cached\n", (char *)f->dents));
+
/* No data here. Only a metadata node, which will be
obsoleted by the first data write
*/
diff --exclude=CVS -auNr mtd-pristine/fs/jffs2/read.c mtd-symlink/fs/jffs2/read.c
--- mtd-pristine/fs/jffs2/read.c 2005-02-16 10:35:08.000000000 +0300
+++ mtd-symlink/fs/jffs2/read.c 2005-02-15 13:23:05.000000000 +0300
@@ -218,7 +218,6 @@
char *jffs2_getlink(struct jffs2_sb_info *c, struct jffs2_inode_info *f)
{
char *buf;
- int ret;
down(&f->sem);
@@ -232,15 +231,12 @@
up(&f->sem);
return ERR_PTR(-ENOMEM);
}
- buf[f->metadata->size]=0;
- ret = jffs2_read_dnode(c, f, f->metadata, buf, 0, f->metadata->size);
+ memcpy(buf, f->dents, f->metadata->size+1);
+
+ D1(printk(KERN_DEBUG "jffs2_getlink(): target path is '%s'\n", buf));
up(&f->sem);
- if (ret) {
- kfree(buf);
- return ERR_PTR(ret);
- }
return buf;
}
diff --exclude=CVS -auNr mtd-pristine/fs/jffs2/readinode.c mtd-symlink/fs/jffs2/readinode.c
--- mtd-pristine/fs/jffs2/readinode.c 2005-02-16 10:35:07.000000000 +0300
+++ mtd-symlink/fs/jffs2/readinode.c 2005-02-17 17:18:01.629635056 +0300
@@ -4,7 +4,10 @@
* Copyright (C) 2001-2003 Red Hat, Inc.
*
* Created by David Woodhouse <dwmw2 at infradead.org>
- *
+ *
+ * 2005-02-16, Artem B. Bityuckiy, <dedekind at infradead.org>
+ * add symlink target caching support
+ *
* For licensing information, see the file 'LICENCE' in this directory.
*
* $Id: readinode.c,v 1.117 2004/11/20 18:06:54 dwmw2 Exp $
@@ -623,6 +626,40 @@
case. */
if (!je32_to_cpu(latest_node->isize))
latest_node->isize = latest_node->dsize;
+
+ if (f->inocache->state != INO_STATE_CHECKING) {
+ /* Symlink's inode data is the target path. Read it and
+ * keep in RAM to facilitate quick follow symlink operation.
+ * We use f->dents field to store the target path, which
+ * is somewhat ugly. */
+ f->dents = kmalloc(je32_to_cpu(latest_node->csize) + 1, GFP_KERNEL);
+ if (!f->dents) {
+ printk(KERN_WARNING "Can't allocate %d bytes of memory "
+ "for the symlink target path cache\n",
+ je32_to_cpu(latest_node->csize));
+ up(&f->sem);
+ jffs2_do_clear_inode(c, f);
+ return -ENOMEM;
+ }
+
+ ret = jffs2_flash_read(c, ref_offset(fn->raw) + sizeof(*latest_node),
+ je32_to_cpu(latest_node->csize), &retlen, (char *)f->dents);
+
+ if (ret || retlen != je32_to_cpu(latest_node->csize)) {
+ if (retlen != je32_to_cpu(latest_node->csize))
+ ret = -EIO;
+ kfree(f->dents);
+ f->dents = NULL;
+ up(&f->sem);
+ jffs2_do_clear_inode(c, f);
+ return -ret;
+ }
+
+ ((char *)f->dents)[je32_to_cpu(latest_node->csize)] = '\0';
+ D1(printk(KERN_DEBUG "jffs2_do_read_inode(): symlink's target '%s' cached\n",
+ (char *)f->dents));
+ }
+
/* fall through... */
case S_IFBLK:
@@ -680,12 +717,20 @@
jffs2_kill_fragtree(&f->fragtree, deleted?c:NULL);
- fds = f->dents;
+ /* For symlink inodes we utilize f->dents to store the target path name */
+ if ((OFNI_EDONI_2SFFJ(f)->i_mode & S_IFMT) == S_IFLNK) {
+ if (f->dents) {
+ kfree(f->dents);
+ f->dents = NULL;
+ }
+ } else {
+ fds = f->dents;
- while(fds) {
- fd = fds;
- fds = fd->next;
- jffs2_free_full_dirent(fd);
+ while(fds) {
+ fd = fds;
+ fds = fd->next;
+ jffs2_free_full_dirent(fd);
+ }
}
if (f->inocache && f->inocache->state != INO_STATE_CHECKING)
More information about the linux-mtd
mailing list