Re: [PATCH] mm/util.c: Make kvfree() safe for calling while holding spinlocks

From: Matthew Wilcox
Date: Sat Dec 25 2021 - 17:58:48 EST


On Sat, Dec 25, 2021 at 07:54:12PM +0100, Uladzislau Rezki wrote:
> +static void drain_vmap_area(struct work_struct *work)
> +{
> + if (mutex_trylock(&vmap_purge_lock)) {
> + __purge_vmap_area_lazy(ULONG_MAX, 0);
> + mutex_unlock(&vmap_purge_lock);
> + }
> +}
> +
> +static DECLARE_WORK(drain_vmap_area_work, drain_vmap_area);

Presuambly if the worker fails to get the mutex, it should reschedule
itself? And should it even trylock or just always lock?

This kind of ties into something I've been wondering about -- we have
a number of places in the kernel which cache 'freed' vmalloc allocations
in order to speed up future allocations of the same size. Kind of like
slab. Would we be better off trying to cache frequent allocations
inside vmalloc instead of always purging them?