From: Dave Hansen Subject: Re: [RFC][PATCH 4/9] create aggregate kvm_total_used_mmu_pages value Date: Wed, 16 Jun 2010 09:55:00 -0700 Message-ID: <1276707300.6437.17429.camel@nimitz> References: <20100615135518.BC244431@kernel.beaverton.ibm.com> <20100615135523.25D24A73@kernel.beaverton.ibm.com> <4C188FC0.3050306@redhat.com> Mime-Version: 1.0 Content-Type: text/plain Content-Transfer-Encoding: 7bit Cc: linux-kernel@vger.kernel.org, kvm@vger.kernel.org To: Avi Kivity Return-path: In-Reply-To: <4C188FC0.3050306@redhat.com> Sender: linux-kernel-owner@vger.kernel.org List-Id: kvm.vger.kernel.org On Wed, 2010-06-16 at 11:48 +0300, Avi Kivity wrote: > > +static inline void kvm_mod_used_mmu_pages(struct kvm *kvm, int nr) > > +{ > > + kvm->arch.n_used_mmu_pages += nr; > > + kvm_total_used_mmu_pages += nr; > > > > Needs an atomic operation, since there's no global lock here. To avoid > bouncing this cacheline around, make the variable percpu and make > readers take a sum across all cpus. Side benefit is that you no longer > need an atomic but a local_t, which is considerably cheaper. We do have the stuff in: include/linux/percpu_counter.h the downside being that they're not precise and they're *HUGE* according to the comment. :) It's actually fairly difficult to do a counter which is precise, scalable, and works well for small CPU counts when NR_CPUS is large. Do you mind if we just stick with a plain atomic_t for now? -- Dave