Received: by 2002:a25:c593:0:0:0:0:0 with SMTP id v141csp5317431ybe; Tue, 10 Sep 2019 01:39:35 -0700 (PDT) X-Google-Smtp-Source: APXvYqwG0j1W0T3SmAdaR4fpFc0GE4VQdReOY5p4Ja/d4TqyEbkpuhYkdJVHGDoLPG1VSYpEpv/2 X-Received: by 2002:a17:906:c359:: with SMTP id ci25mr23154033ejb.205.1568104775457; Tue, 10 Sep 2019 01:39:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1568104775; cv=none; d=google.com; s=arc-20160816; b=uhBPJmeh+nuEtvgjZ3EplyUiw/USbT9VyYBsjO7Xdd16tFKouFpbcGE3jABxohfGZC 6ozX3x+grRJaZM1UNkbNY76F42RIr51/nSf7IRstzOXUJy9zzFcX+HOurklWgcwSyhJo sqmaqUO+AiA+l0vcK7r4yswI0SIFerPCyIqgqdBhLKzXnp1C4IARtI5OubLNS3IBvTWu zuB5PaNxKU/zW+mojxXYnKkI8lfOGfNmYYcv/US5UPgQ0jDtnr2E0qu0cJ5HxoAYwZeU 03b0rE4VBu+iTAvMjvP5drMGz0jkkmlzb79PrIvUsVthDZXTOF6OwceQzvzp6nTIHLaF MDwQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:date:cc:to:from:subject :message-id; bh=2H+PalwS3wUR0x8vqm9N+bn6x0BRKjmjDPXc9uZjaR0=; b=JTiGyTnt1M14n7CweaiPlIrf2aFxHagdWoiAzzq/wvFQn8JWZPFpZLRxudbzieJizS UjMXDSQ4lslyqTqvzVg/WVhc+rvVo8GRVD6Jv/mP5frSm1ONxEpD+Nt5AhrHiJZiphFh NaXVqlXDx6UeaQ5CdDDrfW+Q1AlFXrHOiHEeE8NqOp+MLaEJ5y+EsGvtIIQ845UA1CQi c0XWrRzwiukcpS6DJIfMcAroczE3q+vjLdjk34Lr1c2tATgf36r2P6STjFceis5rZGWp 5UARU6iQxG0qe8HosmgnNQGuCxryliT/auE0NtzcpDzstH+kMkMBIJyxmMV2/or9Ce/j jZbQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d1si2421374ejk.376.2019.09.10.01.39.10; Tue, 10 Sep 2019 01:39:35 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388099AbfIIPMO (ORCPT + 99 others); Mon, 9 Sep 2019 11:12:14 -0400 Received: from mga06.intel.com ([134.134.136.31]:38457 "EHLO mga06.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726587AbfIIPMO (ORCPT ); Mon, 9 Sep 2019 11:12:14 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga004.jf.intel.com ([10.7.209.38]) by orsmga104.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 09 Sep 2019 08:12:12 -0700 X-IronPort-AV: E=Sophos;i="5.64,486,1559545200"; d="scan'208";a="335622307" Received: from ahduyck-desk1.jf.intel.com ([10.7.198.76]) by orsmga004-auth.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 09 Sep 2019 08:12:12 -0700 Message-ID: Subject: Re: [PATCH v9 1/8] mm: Add per-cpu logic to page shuffling From: Alexander Duyck To: "Kirill A. Shutemov" , Alexander Duyck Cc: virtio-dev@lists.oasis-open.org, kvm@vger.kernel.org, mst@redhat.com, catalin.marinas@arm.com, david@redhat.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, 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, kirill.shutemov@linux.intel.com Date: Mon, 09 Sep 2019 08:12:12 -0700 In-Reply-To: <20190909090701.7ebz4foxyu3rxzvc@box> References: <20190907172225.10910.34302.stgit@localhost.localdomain> <20190907172512.10910.74435.stgit@localhost.localdomain> <20190909090701.7ebz4foxyu3rxzvc@box> Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.30.5 (3.30.5-1.fc29) MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, 2019-09-09 at 12:07 +0300, Kirill A. Shutemov wrote: > On Sat, Sep 07, 2019 at 10:25:12AM -0700, Alexander Duyck wrote: > > From: Alexander Duyck > > > > Change the logic used to generate randomness in the suffle path so that we > > Typo. > > > 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. > > > > 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)) > > Maybe something like this would be more readble: > > if (entropy & BIT(position)) > > > add_to_free_area(page, area, migratetype); > > else > > add_to_free_area_tail(page, area, migratetype); > > - rand_bits--; > > - rand >>= 1; > > } > > > > Thanks for the review. I will update these two items for v10. - Alex