Re: [patch] lockless, scalable get_pid(), for_each_process()

Ingo Molnar (mingo@elte.hu)
Wed, 18 Sep 2002 18:46:03 +0200 (CEST)


On Wed, 18 Sep 2002, Linus Torvalds wrote:

> Yeah. It increases memory pressure for the _complex_ and _slow_
> algorithms. Agreed.

what complex and slow algorithms? Take a look at the alloc_pid() and
free_pid() fastpaths:

void free_pid(unsigned long pid)
{
pidmap_t *map = pidmap_array + pid / BITS_PER_PAGE;
int offset = pid & BITS_PER_PAGE_MASK;

atomic_inc(&map->nr_free);
test_and_clear_bit(offset, map->page));
}

it's all bitshifts.

int alloc_pid(void)
{
pid = last_pid + 1;
if (pid >= pid_max)
pid = RESERVED_PIDS;

offset = pid & BITS_PER_PAGE_MASK;
map = pidmap_array + pid / BITS_PER_PAGE;

if (likely(map->page && !test_and_set_bit(offset, map->page))) {
atomic_dec(&map->nr_free);
last_pid = pid;
return pid;
[...]
}

> See my two-liner suggestion (which is admittedly not even compiled, so
> the one disadvantage it might have is that it might need to be debugged.
> But it's only two lines and doesn't actually change any fundamental part
> of any existing algorithms, so debugging shouldn't be a big problem.

it solves the PID-space-squeeze problem, but it does not solve the
fundamental problem: possibly thousands of consecutive PIDs allocated.

Ingo

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/