Skip to content

Commit 8bdc81c

Browse files
dedekindAl Viro
authored andcommitted
jffs2: get rid of jffs2_sync_super
Currently JFFS2 file-system maps the VFS "superblock" abstraction to the write-buffer. Namely, it uses VFS services to synchronize the write-buffer periodically. The whole "superblock write-out" VFS infrastructure is served by the 'sync_supers()' kernel thread, which wakes up every 5 (by default) seconds and writes out all dirty superblock using the '->write_super()' call-back. But the problem with this thread is that it wastes power by waking up the system every 5 seconds no matter what. So we want to kill it completely and thus, we need to make file-systems to stop using the '->write_super' VFS service, and then remove it together with the kernel thread. This patch switches the JFFS2 write-buffer management from '->write_super()'/'->s_dirt' to a delayed work. Instead of setting the 's_dirt' flag we just schedule a delayed work for synchronizing the write-buffer. Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
1 parent 0668890 commit 8bdc81c

4 files changed

Lines changed: 58 additions & 21 deletions

File tree

‎fs/jffs2/jffs2_fs_sb.h‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,10 @@ struct jffs2_sb_info {
126126
struct jffs2_inodirty *wbuf_inodes;
127127
struct rw_semaphore wbuf_sem; /* Protects the write buffer */
128128

129+
struct delayed_work wbuf_dwork; /* write-buffer write-out work */
130+
int wbuf_queued; /* non-zero delayed work is queued */
131+
spinlock_t wbuf_dwork_lock; /* protects wbuf_dwork and and wbuf_queued */
132+
129133
unsigned char *oobbuf;
130134
int oobavail; /* How many bytes are available for JFFS2 in OOB */
131135
#endif

‎fs/jffs2/os-linux.h‎

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ static inline void jffs2_init_inode_info(struct jffs2_inode_info *f)
9595
#define jffs2_ubivol(c) (0)
9696
#define jffs2_ubivol_setup(c) (0)
9797
#define jffs2_ubivol_cleanup(c) do {} while (0)
98+
#define jffs2_dirty_trigger(c) do {} while (0)
9899

99100
#else /* NAND and/or ECC'd NOR support present */
100101

@@ -135,14 +136,10 @@ void jffs2_ubivol_cleanup(struct jffs2_sb_info *c);
135136
#define jffs2_nor_wbuf_flash(c) (c->mtd->type == MTD_NORFLASH && ! (c->mtd->flags & MTD_BIT_WRITEABLE))
136137
int jffs2_nor_wbuf_flash_setup(struct jffs2_sb_info *c);
137138
void jffs2_nor_wbuf_flash_cleanup(struct jffs2_sb_info *c);
139+
void jffs2_dirty_trigger(struct jffs2_sb_info *c);
138140

139141
#endif /* WRITEBUFFER */
140142

141-
static inline void jffs2_dirty_trigger(struct jffs2_sb_info *c)
142-
{
143-
OFNI_BS_2SFFJ(c)->s_dirt = 1;
144-
}
145-
146143
/* background.c */
147144
int jffs2_start_garbage_collect_thread(struct jffs2_sb_info *c);
148145
void jffs2_stop_garbage_collect_thread(struct jffs2_sb_info *c);

‎fs/jffs2/super.c‎

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -63,18 +63,6 @@ static void jffs2_i_init_once(void *foo)
6363
inode_init_once(&f->vfs_inode);
6464
}
6565

66-
static void jffs2_write_super(struct super_block *sb)
67-
{
68-
struct jffs2_sb_info *c = JFFS2_SB_INFO(sb);
69-
70-
sb->s_dirt = 0;
71-
72-
if (!(sb->s_flags & MS_RDONLY)) {
73-
jffs2_dbg(1, "%s()\n", __func__);
74-
jffs2_flush_wbuf_gc(c, 0);
75-
}
76-
}
77-
7866
static const char *jffs2_compr_name(unsigned int compr)
7967
{
8068
switch (compr) {
@@ -246,7 +234,6 @@ static const struct super_operations jffs2_super_operations =
246234
.alloc_inode = jffs2_alloc_inode,
247235
.destroy_inode =jffs2_destroy_inode,
248236
.put_super = jffs2_put_super,
249-
.write_super = jffs2_write_super,
250237
.statfs = jffs2_statfs,
251238
.remount_fs = jffs2_remount_fs,
252239
.evict_inode = jffs2_evict_inode,

‎fs/jffs2/wbuf.c‎

Lines changed: 52 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include <linux/mtd/nand.h>
2121
#include <linux/jiffies.h>
2222
#include <linux/sched.h>
23+
#include <linux/writeback.h>
2324

2425
#include "nodelist.h"
2526

@@ -85,7 +86,7 @@ static void jffs2_wbuf_dirties_inode(struct jffs2_sb_info *c, uint32_t ino)
8586
{
8687
struct jffs2_inodirty *new;
8788

88-
/* Mark the superblock dirty so that kupdated will flush... */
89+
/* Schedule delayed write-buffer write-out */
8990
jffs2_dirty_trigger(c);
9091

9192
if (jffs2_wbuf_pending_for_ino(c, ino))
@@ -1148,6 +1149,47 @@ int jffs2_write_nand_badblock(struct jffs2_sb_info *c, struct jffs2_eraseblock *
11481149
return 1;
11491150
}
11501151

1152+
static struct jffs2_sb_info *work_to_sb(struct work_struct *work)
1153+
{
1154+
struct delayed_work *dwork;
1155+
1156+
dwork = container_of(work, struct delayed_work, work);
1157+
return container_of(dwork, struct jffs2_sb_info, wbuf_dwork);
1158+
}
1159+
1160+
static void delayed_wbuf_sync(struct work_struct *work)
1161+
{
1162+
struct jffs2_sb_info *c = work_to_sb(work);
1163+
struct super_block *sb = OFNI_BS_2SFFJ(c);
1164+
1165+
spin_lock(&c->wbuf_dwork_lock);
1166+
c->wbuf_queued = 0;
1167+
spin_unlock(&c->wbuf_dwork_lock);
1168+
1169+
if (!(sb->s_flags & MS_RDONLY)) {
1170+
jffs2_dbg(1, "%s()\n", __func__);
1171+
jffs2_flush_wbuf_gc(c, 0);
1172+
}
1173+
}
1174+
1175+
void jffs2_dirty_trigger(struct jffs2_sb_info *c)
1176+
{
1177+
struct super_block *sb = OFNI_BS_2SFFJ(c);
1178+
unsigned long delay;
1179+
1180+
if (sb->s_flags & MS_RDONLY)
1181+
return;
1182+
1183+
spin_lock(&c->wbuf_dwork_lock);
1184+
if (!c->wbuf_queued) {
1185+
jffs2_dbg(1, "%s()\n", __func__);
1186+
delay = msecs_to_jiffies(dirty_writeback_interval * 10);
1187+
queue_delayed_work(system_long_wq, &c->wbuf_dwork, delay);
1188+
c->wbuf_queued = 1;
1189+
}
1190+
spin_unlock(&c->wbuf_dwork_lock);
1191+
}
1192+
11511193
int jffs2_nand_flash_setup(struct jffs2_sb_info *c)
11521194
{
11531195
struct nand_ecclayout *oinfo = c->mtd->ecclayout;
@@ -1169,6 +1211,8 @@ int jffs2_nand_flash_setup(struct jffs2_sb_info *c)
11691211

11701212
/* Initialise write buffer */
11711213
init_rwsem(&c->wbuf_sem);
1214+
spin_lock_init(&c->wbuf_dwork_lock);
1215+
INIT_DELAYED_WORK(&c->wbuf_dwork, delayed_wbuf_sync);
11721216
c->wbuf_pagesize = c->mtd->writesize;
11731217
c->wbuf_ofs = 0xFFFFFFFF;
11741218

@@ -1207,8 +1251,8 @@ int jffs2_dataflash_setup(struct jffs2_sb_info *c) {
12071251

12081252
/* Initialize write buffer */
12091253
init_rwsem(&c->wbuf_sem);
1210-
1211-
1254+
spin_lock_init(&c->wbuf_dwork_lock);
1255+
INIT_DELAYED_WORK(&c->wbuf_dwork, delayed_wbuf_sync);
12121256
c->wbuf_pagesize = c->mtd->erasesize;
12131257

12141258
/* Find a suitable c->sector_size
@@ -1267,6 +1311,9 @@ int jffs2_nor_wbuf_flash_setup(struct jffs2_sb_info *c) {
12671311

12681312
/* Initialize write buffer */
12691313
init_rwsem(&c->wbuf_sem);
1314+
spin_lock_init(&c->wbuf_dwork_lock);
1315+
INIT_DELAYED_WORK(&c->wbuf_dwork, delayed_wbuf_sync);
1316+
12701317
c->wbuf_pagesize = c->mtd->writesize;
12711318
c->wbuf_ofs = 0xFFFFFFFF;
12721319

@@ -1299,6 +1346,8 @@ int jffs2_ubivol_setup(struct jffs2_sb_info *c) {
12991346
return 0;
13001347

13011348
init_rwsem(&c->wbuf_sem);
1349+
spin_lock_init(&c->wbuf_dwork_lock);
1350+
INIT_DELAYED_WORK(&c->wbuf_dwork, delayed_wbuf_sync);
13021351

13031352
c->wbuf_pagesize = c->mtd->writesize;
13041353
c->wbuf_ofs = 0xFFFFFFFF;

0 commit comments

Comments
 (0)