Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
L
linux
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
linux
Commits
de941536
Commit
de941536
authored
Mar 04, 2002
by
David Woodhouse
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Preallocate JFFS2 zlib workspaces at init time, using vmalloc for deflate workspace, cos
it's too big for kmalloc.
parent
ecf72cc2
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
65 additions
and
57 deletions
+65
-57
fs/jffs2/compr_zlib.c
fs/jffs2/compr_zlib.c
+53
-57
fs/jffs2/nodelist.h
fs/jffs2/nodelist.h
+5
-0
fs/jffs2/super.c
fs/jffs2/super.c
+7
-0
No files found.
fs/jffs2/compr_zlib.c
View file @
de941536
/*
/*
* JFFS2 -- Journalling Flash File System, Version 2.
* JFFS2 -- Journalling Flash File System, Version 2.
*
*
* Copyright (C) 2001 Red Hat, Inc.
* Copyright (C) 2001
, 2002
Red Hat, Inc.
*
*
* Created by David Woodhouse <dwmw2@cambridge.redhat.com>
* Created by David Woodhouse <dwmw2@cambridge.redhat.com>
*
*
...
@@ -31,36 +31,22 @@
...
@@ -31,36 +31,22 @@
* provisions above, a recipient may use your version of this file
* provisions above, a recipient may use your version of this file
* under either the RHEPL or the GPL.
* under either the RHEPL or the GPL.
*
*
* $Id: compr_zlib.c,v 1.
8 2001/09/20 15:28:31
dwmw2 Exp $
* $Id: compr_zlib.c,v 1.
15 2002/03/04 09:35:48
dwmw2 Exp $
*
*
*/
*/
#ifdef __KERNEL__
#ifndef __KERNEL__
#include <linux/zlib.h>
#error "The userspace support got too messy and was removed. Update your mkfs.jffs2"
#else
#include "zlib.h"
#endif
#endif
#i
fdef __KERNEL__
#i
nclude <linux/config.h>
#include <linux/kernel.h>
#include <linux/kernel.h>
#include <linux/mtd/compatmac.h>
/* for min() */
#include <linux/mtd/compatmac.h>
/* for min() */
#include <linux/slab.h>
#include <linux/slab.h>
#include <linux/jffs2.h>
#include <linux/jffs2.h>
#include <linux/zlib.h>
#include "nodelist.h"
#include "nodelist.h"
#else
#define min(x,y) ((x)<(y)?(x):(y))
#ifndef D1
#define D1(x)
#endif
#define KERN_DEBUG
#define KERN_NOTICE
#define KERN_WARNING
#define printk printf
#include <stdio.h>
#include <asm/types.h>
#endif
/* Plan: call deflate() with avail_in == *sourcelen,
/* Plan: call deflate() with avail_in == *sourcelen,
avail_out = *dstlen - 12 and flush == Z_FINISH.
avail_out = *dstlen - 12 and flush == Z_FINISH.
If it doesn't manage to finish, call it again with
If it doesn't manage to finish, call it again with
...
@@ -70,8 +56,37 @@
...
@@ -70,8 +56,37 @@
*/
*/
#define STREAM_END_SPACE 12
#define STREAM_END_SPACE 12
static
DECLARE_MUTEX
(
deflate_sem
);
static
DECLARE_MUTEX
(
inflate_sem
);
static
void
*
deflate_workspace
;
static
void
*
inflate_workspace
;
int
__init
jffs2_zlib_init
(
void
)
{
deflate_workspace
=
vmalloc
(
zlib_deflate_workspacesize
());
if
(
!
deflate_workspace
)
{
printk
(
"Failed to allocate %d bytes for deflate workspace
\n
"
,
zlib_deflate_workspacesize
());
return
-
ENOMEM
;
}
D1
(
printk
(
"Allocated %d bytes for deflate workspace
\n
"
,
zlib_deflate_workspacesize
()));
inflate_workspace
=
vmalloc
(
zlib_inflate_workspacesize
());
if
(
!
inflate_workspace
)
{
printk
(
"Failed to allocate %d bytes for inflate workspace
\n
"
,
zlib_inflate_workspacesize
());
vfree
(
deflate_workspace
);
return
-
ENOMEM
;
}
D1
(
printk
(
"Allocated %d bytes for inflate workspace
\n
"
,
zlib_inflate_workspacesize
()));
return
0
;
}
void
__exit
jffs2_zlib_exit
(
void
)
{
vfree
(
deflate_workspace
);
vfree
(
inflate_workspace
);
}
int
zlib_compress
(
unsigned
char
*
data_in
,
unsigned
char
*
cpage_out
,
int
zlib_compress
(
unsigned
char
*
data_in
,
unsigned
char
*
cpage_out
,
__u32
*
sourcelen
,
__u32
*
dstlen
)
uint32_t
*
sourcelen
,
uint32_t
*
dstlen
)
{
{
z_stream
strm
;
z_stream
strm
;
int
ret
;
int
ret
;
...
@@ -79,22 +94,15 @@ int zlib_compress(unsigned char *data_in, unsigned char *cpage_out,
...
@@ -79,22 +94,15 @@ int zlib_compress(unsigned char *data_in, unsigned char *cpage_out,
if
(
*
dstlen
<=
STREAM_END_SPACE
)
if
(
*
dstlen
<=
STREAM_END_SPACE
)
return
-
1
;
return
-
1
;
#ifdef __KERNEL__
down
(
&
deflate_sem
);
strm
.
workspace
=
kmalloc
(
zlib_deflate_workspacesize
(),
strm
.
workspace
=
deflate_workspace
;
GFP_KERNEL
);
if
(
strm
.
workspace
==
NULL
)
{
printk
(
KERN_WARNING
"deflateInit alloc of workspace failed
\n
"
);
return
-
1
;
}
#else
strm
.
zalloc
=
(
void
*
)
0
;
strm
.
zfree
=
(
void
*
)
0
;
#endif
if
(
Z_OK
!=
zlib_deflateInit
(
&
strm
,
3
))
{
if
(
Z_OK
!=
zlib_deflateInit
(
&
strm
,
3
))
{
printk
(
KERN_WARNING
"deflateInit failed
\n
"
);
printk
(
KERN_WARNING
"deflateInit failed
\n
"
);
up
(
&
deflate_sem
);
return
-
1
;
return
-
1
;
}
}
strm
.
next_in
=
data_in
;
strm
.
next_in
=
data_in
;
strm
.
total_in
=
0
;
strm
.
total_in
=
0
;
...
@@ -111,56 +119,44 @@ int zlib_compress(unsigned char *data_in, unsigned char *cpage_out,
...
@@ -111,56 +119,44 @@ int zlib_compress(unsigned char *data_in, unsigned char *cpage_out,
strm
.
avail_in
,
strm
.
avail_out
,
strm
.
total_in
,
strm
.
total_out
));
strm
.
avail_in
,
strm
.
avail_out
,
strm
.
total_in
,
strm
.
total_out
));
if
(
ret
!=
Z_OK
)
{
if
(
ret
!=
Z_OK
)
{
D1
(
printk
(
KERN_DEBUG
"deflate in loop returned %d
\n
"
,
ret
));
D1
(
printk
(
KERN_DEBUG
"deflate in loop returned %d
\n
"
,
ret
));
goto
out_err
;
zlib_deflateEnd
(
&
strm
);
up
(
&
deflate_sem
);
return
-
1
;
}
}
}
}
strm
.
avail_out
+=
STREAM_END_SPACE
;
strm
.
avail_out
+=
STREAM_END_SPACE
;
strm
.
avail_in
=
0
;
strm
.
avail_in
=
0
;
ret
=
zlib_deflate
(
&
strm
,
Z_FINISH
);
ret
=
zlib_deflate
(
&
strm
,
Z_FINISH
);
zlib_deflateEnd
(
&
strm
);
up
(
&
deflate_sem
);
if
(
ret
!=
Z_STREAM_END
)
{
if
(
ret
!=
Z_STREAM_END
)
{
D1
(
printk
(
KERN_DEBUG
"final deflate returned %d
\n
"
,
ret
));
D1
(
printk
(
KERN_DEBUG
"final deflate returned %d
\n
"
,
ret
));
goto
out_err
;
return
-
1
;
}
}
zlib_deflateEnd
(
&
strm
);
kfree
(
strm
.
workspace
);
D1
(
printk
(
KERN_DEBUG
"zlib compressed %ld bytes into %ld
\n
"
,
strm
.
total_in
,
strm
.
total_out
));
D1
(
printk
(
KERN_DEBUG
"zlib compressed %ld bytes into %ld
\n
"
,
strm
.
total_in
,
strm
.
total_out
));
if
(
strm
.
total_out
>=
strm
.
total_in
)
if
(
strm
.
total_out
>=
strm
.
total_in
)
return
-
1
;
return
-
1
;
*
dstlen
=
strm
.
total_out
;
*
dstlen
=
strm
.
total_out
;
*
sourcelen
=
strm
.
total_in
;
*
sourcelen
=
strm
.
total_in
;
return
0
;
return
0
;
out_err:
zlib_deflateEnd
(
&
strm
);
kfree
(
strm
.
workspace
);
return
-
1
;
}
}
void
zlib_decompress
(
unsigned
char
*
data_in
,
unsigned
char
*
cpage_out
,
void
zlib_decompress
(
unsigned
char
*
data_in
,
unsigned
char
*
cpage_out
,
__u32
srclen
,
__u32
destlen
)
uint32_t
srclen
,
uint32_t
destlen
)
{
{
z_stream
strm
;
z_stream
strm
;
int
ret
;
int
ret
;
#ifdef __KERNEL__
down
(
&
inflate_sem
);
strm
.
workspace
=
kmalloc
(
zlib_inflate_workspacesize
(),
strm
.
workspace
=
inflate_workspace
;
GFP_KERNEL
);
if
(
strm
.
workspace
==
NULL
)
{
printk
(
KERN_WARNING
"inflateInit alloc of workspace failed
\n
"
);
return
;
}
#else
strm
.
zalloc
=
(
void
*
)
0
;
strm
.
zfree
=
(
void
*
)
0
;
#endif
if
(
Z_OK
!=
zlib_inflateInit
(
&
strm
))
{
if
(
Z_OK
!=
zlib_inflateInit
(
&
strm
))
{
printk
(
KERN_WARNING
"inflateInit failed
\n
"
);
printk
(
KERN_WARNING
"inflateInit failed
\n
"
);
up
(
&
inflate_sem
);
return
;
return
;
}
}
strm
.
next_in
=
data_in
;
strm
.
next_in
=
data_in
;
...
@@ -177,5 +173,5 @@ void zlib_decompress(unsigned char *data_in, unsigned char *cpage_out,
...
@@ -177,5 +173,5 @@ void zlib_decompress(unsigned char *data_in, unsigned char *cpage_out,
printk
(
KERN_NOTICE
"inflate returned %d
\n
"
,
ret
);
printk
(
KERN_NOTICE
"inflate returned %d
\n
"
,
ret
);
}
}
zlib_inflateEnd
(
&
strm
);
zlib_inflateEnd
(
&
strm
);
kfree
(
strm
.
workspace
);
up
(
&
inflate_sem
);
}
}
fs/jffs2/nodelist.h
View file @
de941536
...
@@ -32,6 +32,7 @@
...
@@ -32,6 +32,7 @@
* under either the RHEPL or the GPL.
* under either the RHEPL or the GPL.
*
*
* $Id: nodelist.h,v 1.46.2.1 2002/02/23 14:04:44 dwmw2 Exp $
* $Id: nodelist.h,v 1.46.2.1 2002/02/23 14:04:44 dwmw2 Exp $
* + zlib_init calls from v1.65
*
*
*/
*/
...
@@ -349,3 +350,7 @@ void jffs2_erase_block(struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb);
...
@@ -349,3 +350,7 @@ void jffs2_erase_block(struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb);
void
jffs2_erase_pending_blocks
(
struct
jffs2_sb_info
*
c
);
void
jffs2_erase_pending_blocks
(
struct
jffs2_sb_info
*
c
);
void
jffs2_mark_erased_blocks
(
struct
jffs2_sb_info
*
c
);
void
jffs2_mark_erased_blocks
(
struct
jffs2_sb_info
*
c
);
void
jffs2_erase_pending_trigger
(
struct
jffs2_sb_info
*
c
);
void
jffs2_erase_pending_trigger
(
struct
jffs2_sb_info
*
c
);
/* compr_zlib.c */
int
jffs2_zlib_init
(
void
);
void
jffs2_zlib_exit
(
void
);
fs/jffs2/super.c
View file @
de941536
...
@@ -32,6 +32,7 @@
...
@@ -32,6 +32,7 @@
* under either the RHEPL or the GPL.
* under either the RHEPL or the GPL.
*
*
* $Id: super.c,v 1.48.2.1 2002/02/23 14:13:34 dwmw2 Exp $
* $Id: super.c,v 1.48.2.1 2002/02/23 14:13:34 dwmw2 Exp $
* + zlib_init calls from v1.56
*
*
*/
*/
...
@@ -373,6 +374,11 @@ static int __init init_jffs2_fs(void)
...
@@ -373,6 +374,11 @@ static int __init init_jffs2_fs(void)
}
}
#endif
#endif
ret
=
jffs2_zlib_init
();
if
(
ret
)
{
printk
(
KERN_ERR
"JFFS2 error: Failed to initialise zlib workspaces
\n
"
);
return
ret
;
}
ret
=
jffs2_create_slab_caches
();
ret
=
jffs2_create_slab_caches
();
if
(
ret
)
{
if
(
ret
)
{
printk
(
KERN_ERR
"JFFS2 error: Failed to initialise slab caches
\n
"
);
printk
(
KERN_ERR
"JFFS2 error: Failed to initialise slab caches
\n
"
);
...
@@ -389,6 +395,7 @@ static int __init init_jffs2_fs(void)
...
@@ -389,6 +395,7 @@ static int __init init_jffs2_fs(void)
static
void
__exit
exit_jffs2_fs
(
void
)
static
void
__exit
exit_jffs2_fs
(
void
)
{
{
jffs2_destroy_slab_caches
();
jffs2_destroy_slab_caches
();
jffs2_zlib_exit
();
unregister_filesystem
(
&
jffs2_fs_type
);
unregister_filesystem
(
&
jffs2_fs_type
);
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment