Re: [PATCH V3] Fix Committed_AS underflow

From: KOSAKI Motohiro
Date: Mon Apr 20 2009 - 21:41:39 EST


> void vm_acct_memory(long pages)
> {
> long *local;
> long local_min = -ACCT_THRESHOLD;
> long local_max = ACCT_THRESHOLD;
> long local_goal = 0;
>
> preempt_disable();
> local = &__get_cpu_var(committed_space);
> *local += pages;
> if (*local > local_max || *local < local_min) {
> atomic_long_add(*local - local_goal, &vm_committed_space);
> *local = local_goal;
> }
> preempt_enable();
> }
>
> But now consider if we changed the local_* variables a bit:
>
> long local_min = -(ACCT_THRESHOLD*2);
> long local_max = 0
> long local_goal = -ACCT_THRESHOLD;
>
> We'll get some possibly *large* numbers in meminfo, but it will at least
> never underflow.

if *local == -(ACCT_THRESHOLD*2),
*local - local_goal = -(ACCT_THRESHOLD*2) + ACCT_THRESHOLD = -ACCT_THRESHOLD

Then, we still pass negative value to atomic_long_add().
IOW, vm_committed_space still can be negative value.

Am I missing anything?



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