No, my mistake. You should check whatever array you want.
> vfree() at a guess (I may be completely wrong on that one in which case I
> appologize!) can also sleep so that breaks that scheme.
Well, just get rid of the while loop then and use an if+goto for both
the vmalloc and the vfree case. At most we can loop NR_CPUS times.
char *newbuf = NULL;
int cpunum;
recheck:
cpunum = current_cpu();
if (unlikely(ntfs_compr_array[cpunum] == NULL)) {
newbuf = vmalloc(NTFS_DECOMPR_BUFFER_SIZE);
/*
* Re-check the buffer case we slept in vmalloc() and
* someone else already allocated a buffer for "this" CPU.
*/
if (likely(ntfs_compr_array[cpunum] == NULL)) {
ntfs_compr_array[cpunum] = newbuf;
newbuf = NULL;
}
goto recheck;
}
/* Hmm, we slept in vmalloc and we don't need the new buffer */
if (unlikely(newbuf != NULL)) {
vfree(newbuf);
goto recheck;
}
> But if doing something like that I might as well use the present
> approach and just allocate all buffers at once if they haven't been
> allocated yet and be done with it. Then no vfree()s are needed either and
> then it really does work. (-;
But then you may be allocating a lot of memory for CPUs that don't
even exist, which is the whole point of this exercise. Better to do
it on-demand and loop for the very few times needed.
Cheers, Andreas
-- Andreas Dilger http://www-mddsp.enel.ucalgary.ca/People/adilger/ http://sourceforge.net/projects/ext2resize/- 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/