Return-Path: virtio-dev-return-6078-cohuck=redhat.com@lists.oasis-open.org Sender: List-Post: List-Help: List-Unsubscribe: List-Subscribe: Received: from lists.oasis-open.org (oasis-open.org [10.110.1.242]) by lists.oasis-open.org (Postfix) with ESMTP id 0B2AD98431C for ; Mon, 9 Sep 2019 08:14:41 +0000 (UTC) References: <20190907172225.10910.34302.stgit@localhost.localdomain> <20190907172512.10910.74435.stgit@localhost.localdomain> From: David Hildenbrand Message-ID: <0df2e5d0-af92-04b4-aa7d-891387874039@redhat.com> Date: Mon, 9 Sep 2019 10:14:24 +0200 MIME-Version: 1.0 In-Reply-To: <20190907172512.10910.74435.stgit@localhost.localdomain> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Subject: [virtio-dev] Re: [PATCH v9 1/8] mm: Add per-cpu logic to page shuffling To: Alexander Duyck , virtio-dev@lists.oasis-open.org, kvm@vger.kernel.org, mst@redhat.com, catalin.marinas@arm.com, dave.hansen@intel.com, linux-kernel@vger.kernel.org, willy@infradead.org, mhocko@kernel.org, linux-mm@kvack.org, akpm@linux-foundation.org, will@kernel.org, linux-arm-kernel@lists.infradead.org, osalvador@suse.de Cc: yang.zhang.wz@gmail.com, pagupta@redhat.com, konrad.wilk@oracle.com, nitesh@redhat.com, riel@surriel.com, lcapitulino@redhat.com, wei.w.wang@intel.com, aarcange@redhat.com, ying.huang@intel.com, pbonzini@redhat.com, dan.j.williams@intel.com, fengguang.wu@intel.com, alexander.h.duyck@linux.intel.com, kirill.shutemov@linux.intel.com List-ID: On 07.09.19 19:25, Alexander Duyck wrote: > From: Alexander Duyck > > Change the logic used to generate randomness in the suffle path so that we > can avoid cache line bouncing. The previous logic was sharing the offset > and entropy word between all CPUs. As such this can result in cache line > bouncing and will ultimately hurt performance when enabled. So, usually we perform such changes if there is real evidence. Do you have any such performance numbers to back your claims? > > To resolve this I have moved to a per-cpu logic for maintaining a unsigned > long containing some amount of bits, and an offset value for which bit we > can use for entropy with each call. > > Reviewed-by: Dan Williams > Signed-off-by: Alexander Duyck > --- > mm/shuffle.c | 33 +++++++++++++++++++++++---------- > 1 file changed, 23 insertions(+), 10 deletions(-) > > diff --git a/mm/shuffle.c b/mm/shuffle.c > index 3ce12481b1dc..9ba542ecf335 100644 > --- a/mm/shuffle.c > +++ b/mm/shuffle.c > @@ -183,25 +183,38 @@ void __meminit __shuffle_free_memory(pg_data_t *pgdat) > shuffle_zone(z); > } > > +struct batched_bit_entropy { > + unsigned long entropy_bool; > + int position; > +}; > + > +static DEFINE_PER_CPU(struct batched_bit_entropy, batched_entropy_bool); > + > void add_to_free_area_random(struct page *page, struct free_area *area, > int migratetype) > { > - static u64 rand; > - static u8 rand_bits; > + struct batched_bit_entropy *batch; > + unsigned long entropy; > + int position; > > /* > - * The lack of locking is deliberate. If 2 threads race to > - * update the rand state it just adds to the entropy. > + * We shouldn't need to disable IRQs as the only caller is > + * __free_one_page and it should only be called with the zone lock > + * held and either from IRQ context or with local IRQs disabled. > */ > - if (rand_bits == 0) { > - rand_bits = 64; > - rand = get_random_u64(); > + batch = raw_cpu_ptr(&batched_entropy_bool); > + position = batch->position; > + > + if (--position < 0) { > + batch->entropy_bool = get_random_long(); > + position = BITS_PER_LONG - 1; > } > > - if (rand & 1) > + batch->position = position; > + entropy = batch->entropy_bool; > + > + if (1ul & (entropy >> position)) > add_to_free_area(page, area, migratetype); > else > add_to_free_area_tail(page, area, migratetype); > - rand_bits--; > - rand >>= 1; > } > > -- Thanks, David / dhildenb --------------------------------------------------------------------- To unsubscribe, e-mail: virtio-dev-unsubscribe@lists.oasis-open.org For additional commands, e-mail: virtio-dev-help@lists.oasis-open.org