vmalloc for zlib workspace

Jörn Engel joern at wohnheim.fh-wedel.de
Mon May 26 10:33:24 EDT 2003


On Mon, 26 May 2003 14:57:49 +0100, David Woodhouse wrote:
> On Mon, 2003-05-26 at 14:48, Jörn Engel wrote:
> > On Mon, 26 May 2003 14:38:28 +0100, David Woodhouse wrote:
> > > 
> > > 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.

Correct.  And
down();
preemp_disable();

is a race we don't always win.

> > //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

-- 
Everything should be made as simple as possible, but not simpler.
-- Albert Einstein



More information about the linux-mtd mailing list