Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754018AbbHXHrT (ORCPT ); Mon, 24 Aug 2015 03:47:19 -0400 Received: from mail-wi0-f179.google.com ([209.85.212.179]:38901 "EHLO mail-wi0-f179.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751696AbbHXHrS (ORCPT ); Mon, 24 Aug 2015 03:47:18 -0400 Date: Mon, 24 Aug 2015 09:47:14 +0200 From: Ingo Molnar To: George Spelvin Cc: dave@sr71.net, linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux@rasmusvillemoes.dk, peterz@infradead.org, riel@redhat.com, rientjes@google.com, torvalds@linux-foundation.org Subject: Re: [PATCH 3/3 v4] mm/vmalloc: Cache the vmalloc memory info Message-ID: <20150824074714.GA20106@gmail.com> References: <20150823081750.GA28349@gmail.com> <20150824010403.27903.qmail@ns.horizon.com> <20150824073422.GC13082@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20150824073422.GC13082@gmail.com> User-Agent: Mutt/1.5.23 (2014-03-12) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1379 Lines: 51 * Ingo Molnar 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 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/