Re: [PATCH 3/3 v4] mm/vmalloc: Cache the vmalloc memory info

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



* Ingo Molnar <mingo@xxxxxxxxxx> wrote:

> +/*
> + * Return a consistent snapshot of the current vmalloc allocation
> + * statistics, for /proc/meminfo:
> + */
> +void get_vmalloc_info(struct vmalloc_info *vmi)
> +{
> +	int gen = READ_ONCE(vmap_info_gen);
> +
> +	/*
> +	 * If the generation counter of the cache matches that of
> +	 * the vmalloc generation counter then return the cache:
> +	 */
> +	if (READ_ONCE(vmap_info_cache_gen) == gen) {
> +		int gen_after;
> +
> +		/*
> +		 * The two read barriers make sure that we read
> +		 * 'gen', 'vmap_info_cache' and 'gen_after' in
> +		 * precisely that order:
> +		 */
> +		smp_rmb();
> +		*vmi = vmap_info_cache;
> +
> +		smp_rmb();
> +		gen_after = READ_ONCE(vmap_info_gen);
> +
> +		/* The cache is still valid: */
> +		if (gen == gen_after)
> +			return;
> +
> +		/* Ok, the cache got invalidated just now, regenerate it */
> +		gen = gen_after;
> +	}

One more detail: I just realized that with the read barriers, the READ_ONCE() 
accesses are not needed anymore - the barriers and the control dependencies are 
enough.

This will further simplify the code.

Thanks,

	Ingo

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@xxxxxxxxx.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@xxxxxxxxx";> email@xxxxxxxxx </a>



[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [ECOS]     [Asterisk Internet PBX]     [Linux API]