vmalloc for zlib workspace
Hi
In the jffs2_zlib_init() function of fs/jffs2/comr_zlib.c. workspace is aquired by vmalloc.
But it could be allocated by static variable, like;
static char dbuf[WORKSPACESIZE];
int __init jffs2_zlib_init(void)
{
def_strm.workspace = dbuf;Care should be taken as to the workspace size, but it is old refined library and it would hardly be changed. It would reduce TLB load and improve performance (a little).
BR.
Matsunaga.
P.S.
GC thread BUG() (inode wrap around) seems to be fixed. Thanks.
P.S.2fs/jffs2/gc.c
line 139
struct jffs2_inode_cache *ic;
seems not necessary or the name should be changed.
__________________________________________________
Do You Yahoo!?
Yahoo! BB is Broadband by Yahoo! http://bb.yahoo.co.jp/
Quoted 5 lines · matsunaga
In the
jffs2_zlib_init()function offs/jffs2/comr_zlib.c. workspace is aquired by vmalloc.
But it could be allocated by static variable, like;static char dbuf[WORKSPACESIZE];
Hmm. That's a useful idea. Care to benchmark it an show how _much_ it improves performance in practice? Although I suppose there's no downside to it so we might as well change it.
Quoted 5 lines
P.S.2
fs/jffs2/gc.c
line 139struct jffs2_inode_cache *ic;seems not necessary or the name should be changed.
Fixed; thanks.
Signature · 1 line
dwmw2
Quoted 6 lines · matsunaga
In the
jffs2_zlib_init()function offs/jffs2/comr_zlib.c. workspace is aquired by vmalloc.But it could be allocated by static variable, like;
Quoted 8 lines
static char dbuf[WORKSPACESIZE];
int
__initjffs2_zlib_init(void){ def_strm.workspace = dbuf;Care should be taken as to the workspace size, but it is old refined library and it would hardly be changed. It would reduce TLB load and improve performance (a little).
Great idea!
How about:
static void deflate_workspace[WORKSPACESIZE];
static void inflate_workspace[WORKSPACESIZE];
int __init jffs2_zlib_init(void)
{
if (WORKSPACESIZE < zlib_deflate_workspacesize())
BUG();
if (WORKSPACESIZE < zlib_inflate_workspacesize())
BUG();
return 0;
}In a second patch, it would be possible to fold those two workspaces into one and save a little memory as well.
Jörn
Signature · 3 lines
They laughed at Galileo. They laughed at Copernicus. They laughed at Columbus. But remember, they also laughed at Bozo the Clown. -- unknown
Quoted 4 lines · Jörn Engel
How about:
[code that works with 2.4.20]
Oh, crud! Maybe I should work more with mtd cvs, even though it is a pain. Sorry for the noise.
Quoted 2 lines
In a second patch, it would be possible to fold those two workspaces into one and save a little memory as well.
But this is still possible and should be almost orthogonal to your proposal.
Jörn
Signature · 3 lines
Fantasy is more important than knowlegde. Knowlegde is limited, while fantasy embraces the whole world. -- Albert Einstein
----- Original Message -----
From: "David Woodhouse" <[email protected]>
To: "matsunaga" <[email protected]>
Cc: <[email protected]>
Sent: Friday, May 23, 2003 3:01 AM
Subject: Re: vmalloc for zlib workspace
Quoted 3 lines
Hmm. That's a useful idea. Care to benchmark it an show how _much_ it improves performance in practice? Although I suppose there's no downside to it so we might as well change it.
I haven't tested it yet, I will check later... I think it could be effective to multitask environment.
Matsunaga
__________________________________________________
Do You Yahoo!?
Yahoo! BB is Broadband by Yahoo! http://bb.yahoo.co.jp/
----- Original Message -----
From: "Jörn Engel" <[email protected]>
To: "matsunaga" <[email protected]>
Cc: <[email protected]>
Sent: Friday, May 23, 2003 4:57 AM
Subject: Re: vmalloc for zlib workspace
Quoted 7 lines
Great idea!
How about:
static void deflate_workspace[WORKSPACESIZE];
static void inflate_workspace[WORKSPACESIZE];
Quoted 8 lines
int
__initjffs2_zlib_init(void)
{
if (WORKSPACESIZE <zlib_deflate_workspacesize())BUG();
if (WORKSPACESIZE <zlib_inflate_workspacesize())BUG();
return 0;
}
That's great idea too ;-)
We only have to check the size in init routine.
Quoted 2 lines
In a second patch, it would be possible to fold those two workspaces into one and save a little memory as well.
I think it is better.
Matsunaga
__________________________________________________
Do You Yahoo!?
Yahoo! BB is Broadband by Yahoo! http://bb.yahoo.co.jp/
Quoted 11 lines · matsunaga
Quoted 9 lines
int
__initjffs2_zlib_init(void)
{
if (WORKSPACESIZE <zlib_deflate_workspacesize())BUG();
if (WORKSPACESIZE <zlib_inflate_workspacesize())BUG();
return 0;
}That's great idea too ;-)
Thanks!
Quoted 1 line
We only have to check the size in init routine.
Actually, we could even go a bit further. zlib itself could have a single workspace and a mutex. Then we would add the following code to zlib_deflateInit2_():
if (strm->workspace)
mem = (deflate_workspace *) strm->workspace;
else {
down(&zlib_workspace_sem);
mem = zlib_workspace;
}And this little feller to zlib_deflateEnd():
up (&zlib_workspace_sem);
The same for inflate, of course, both using the same workspace and semaphore.
Now every subsystem using zlib can reuse the same workspace, jffs2 anole would save one, a big fat system (TM) with jffs2, cramfs, ppp and additional patches would save quite a bit more. And those systems do exist, no kidding.
And users that want to scale to 64 CPUs and use zlib concurrently on all of them can still provide their own workspace.
Comments?
Jörn
Signature · 2 lines
A victorious army first wins and then seeks battle. -- Sun Tzu
Quoted 13 lines · Jörn Engel
Actually, we could even go a bit further. zlib itself could have a single workspace and a mutex. Then we would add the following code to
zlib_deflateInit2_():if (strm->workspace) mem = (deflate_workspace *) strm->workspace; else { down(&zlib_workspace_sem); mem = zlib_workspace; }And this little feller to
zlib_deflateEnd():up (&zlib_workspace_sem);
Quoted 7 lines
The same for inflate, of course, both using the same workspace and semaphore.
Now every subsystem using zlib can reuse the same workspace, jffs2 anole would save one, a big fat system (TM) with jffs2, cramfs, ppp and additional patches would save quite a bit more. And those systems do exist, no kidding.
Would be cute -- we need to ensure that it doesn't deadlock. In what context does PPP do its decompression? I have a feeling it does it in BH or softirq context, hence isn't allowed to attempt to obtain a semaphore. cramfs and jffs2 could almost certainly share though.
Signature · 1 line
dwmw2
Quoted 11 lines · David Woodhouse
Quoted 5 lines · Jörn Engel
Now every subsystem using zlib can reuse the same workspace, jffs2 anole would save one, a big fat system (TM) with jffs2, cramfs, ppp and additional patches would save quite a bit more. And those systems do exist, no kidding.
Would be cute -- we need to ensure that it doesn't deadlock. In what context does PPP do its decompression? I have a feeling it does it in BH or softirq context, hence isn't allowed to attempt to obtain a semaphore. cramfs and jffs2 could almost certainly share though.
Not sure right now, the ppp code doesn't make that clear at first glance. But if it calls zlib from softirq context, that should be changed as well. It would shorten the buffers a little and process accounting should be a bit more accurate.
Jörn
Signature · 2 lines
And spam is a useful source of entropy for /dev/random too! -- Jasmine Strong
A workmate of mine had another good point. The mutex and workspace could be two arrays instead, with one member per CPU. That way, we don't need a CONFIG_TINY option and the code scales automatically from small embedded to multi-gigabyte SMP.
I'll work on a patch...
Jörn
Signature · 2 lines
It's just what we asked for, but not what we want! -- anonymous
Quoted 4 lines · Jörn Engel
A workmate of mine had another good point. The mutex and workspace could be two arrays instead, with one member per CPU. That way, we don't need a
CONFIG_TINYoption and the code scales automatically from small embedded to multi-gigabyte SMP.
Assuming you add a preempt_disable()... in one of the pieces of code which was one of the main culprits for non-voluntary scheduling anyway.
Signature · 1 line
dwmw2
Quoted 8 lines · David Woodhouse
Quoted 4 lines · Jörn Engel
A workmate of mine had another good point. The mutex and workspace could be two arrays instead, with one member per CPU. That way, we don't need a
CONFIG_TINYoption and the code scales automatically from small embedded to multi-gigabyte SMP.Assuming you add a
preempt_disable()... in one of the pieces of code which was one of the main culprits for non-voluntary scheduling anyway.
Good point!
preempt_disable();down();
//long processing timeup();preempt_enable();
That way, preemption will be turned of on all CPUs for a long time, doesn't sound too inviting. But until preemption is able to be (en|dis)abled for the current CPU only, I will ignore that problem.
Jörn
Signature · 2 lines
Sometimes, asking the right question is already the answer. -- Unknown
Quoted 7 lines · Jörn Engel
Quoted 6 lines · David Woodhouse
Quoted 4 lines · Jörn Engel
A workmate of mine had another good point. The mutex and workspace could be two arrays instead, with one member per CPU. That way, we don't need a
CONFIG_TINYoption and the code scales automatically from small embedded to multi-gigabyte SMP.
Quoted 7 lines
Quoted 2 lines
Assuming you add a
preempt_disable()... in one of the pieces of code which was one of the main culprits for non-voluntary scheduling anyway.Good point!
preempt_disable();down();
// which causes BUG() due to scheduling with preemption disabled.
Quoted 5 lines
//long processing time
up();preempt_enable();That way, preemption will be turned of on all CPUs for a long time,
Is that true? I thought not.
Signature · 1 line
dwmw2
Quoted 6 lines · David Woodhouse
Quoted 5 lines · Jörn Engel
Quoted 3 lines · David Woodhouse
Assuming you add a
preempt_disable()... in one of the pieces of code which was one of the main culprits for non-voluntary scheduling anyway.
Quoted 6 lines
Quoted 4 lines
Good point!
preempt_disable();down();// which causes
BUG()due to scheduling with preemption disabled.
Correct. Anddown();preemp_disable();
is a race we don't always win.
Quoted 7 lines
Quoted 5 lines
//long processing time
up();preempt_enable();That way, preemption will be turned of on all CPUs for a long time,
Is that true? I thought not.
How about the following:
static int workspace_pid[some];
static void *workspace[some];DECLARE_MUTEX(workspace_sem);
zlib_deflateInit2_() {
...
again:
down(&workspace_sem);
for (i=0; i<some; i++) {
if (workspace_pid[i])
continue;
workspace_pid[i] = current_pid;
}
if (i == some) { /* no workspaces left */
up(&workspace_sem)
schedule();
goto again;
}
...
}zlib_deflate() {
...
for (i=0; i<some; i++) {
if (likely(workspace_pid[i] == current_pid))
break;
}
mem = (deflate_workspace *) workspace[i]
...
}zlib_deflateEnd() {
...
for (i=0; i<some; i++) {
if (likely(workspace_pid[i] != current_pid))
break;
}
workspace_pid[i] = 0;
...
}"some" can be any number up to (and possible even beyond) the number of CPUs in the system. I take wishes, but my default would be smp_num_cpus.
This way, the workspace is not owned by the CPU, but by the process and will be migrated across CPUs on schedule(), preempt, etc. Much nicer than the original idea. The search for the right workspace is cheap on low loads (zero or one workspace used) and may cost one pileline stall on higher loads. For uniprocessor (embedded), gcc should optimize the SMP complexity out completely. At least, I don't see why it shouldn't.
Comments?
Jörn
Signature · 2 lines
Everything should be made as simple as possible, but not simpler. -- Albert Einstein
Quoted 5 lines · David Woodhouse
Quoted 2 lines
preempt_disable();down();// which causes
BUG()due to scheduling with preemption disabled.
Quoted 7 lines
Quoted 5 lines
//long processing time
up();preempt_enable();That way, preemption will be turned of on all CPUs for a long time,
Is that true? I thought not.
No, it isn't. Sometimes I tend to misread things. But still, the new design appears to be better, imho.
Jörn
Signature · 4 lines
The competent programmer is fully aware of the strictly limited size of his own skull; therefore he approaches the programming task in full humility, and among other things he avoids clever tricks like the plague. -- Edsger W. Dijkstra
Quoted 9 lines · Jörn Engel
How about the following:
static int workspace_pid[some]; ... for (i=0; i<some; i++) { if (likely(workspace_pid[i] == current_pid)) break; }
Why do I always have to produce 90% crap before the other 10% come out? Ok, ok, don't tell me! ;)
The information, which workspace belongs to which process can be put into the z_stream. That removes the ugly code above. The information, which workspaces are still free can now be put into bit-array, aka long and the loop be replaces with fls().
This design should perform as good as the current one in the worst case and a lot better for SMP and several parallel zlib processes currently on the same semaphore.
Maybe this time, the design is complete. Any comments before the patch is finished and benchmarks prove me right or wrong?
Jörn
Signature · 2 lines
Those who come seeking peace without a treaty are plotting. -- Sun Tzu