Received: by 2002:a25:c593:0:0:0:0:0 with SMTP id v141csp4358111ybe; Mon, 9 Sep 2019 08:11:31 -0700 (PDT) X-Google-Smtp-Source: APXvYqyH46UdNr1/eycc6r/1bDgX9tVTMtg24KnYhqH9pHMc06nr4KI57qJUrmYmC6q/6XhaFrXm X-Received: by 2002:a17:906:5391:: with SMTP id g17mr20304859ejo.79.1568041891800; Mon, 09 Sep 2019 08:11:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1568041891; cv=none; d=google.com; s=arc-20160816; b=R4TobNOiP+nfxL5dBvVmOZZXovjVxkUSISpLRNVCp6uqJO96/zUHR+4g99yMPh/e0q imwcwhQjIam8T4e7ZV1WNtGFowbu/kuXkVoxwktxoZP9m5xU+0r6wTEDLaSKEgcKyR+A 3BkIn94DL/8URL3NeXXNLUvXwx7bbfIbMNhHoCkYE9/0zXOvUzhH7DaZapL8IGzJyvUO QqIRq/hfywjtvYfXbwW3V4WQGjM6XQ9G/VgjkjXOZT4I+6f/naw2rJMWbWsxPP9oeh5t 5kegkY5fbabkYW1K1lY3Tmdl0yb3+z9WJzRZI8C+9YtR4CSGXTBi5kJwpAD0q42ZCjGN jbvg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=4SKyZYA96ZSRssF5bkYvn8/ZaoQgr/75nnF3v6r+aa4=; b=cVeWHCh8ejUzPAQes2qZoGf5XjA2luNl8ZzcUM0R78JHPed1oji/UPymjqIO8NVTZt o4LQ33RVpb2yQS4PdoNlqpUybTSCFU/Xs3PkSE99MBogLiHW5POnzKkjJ/vaVCtBJl6d NpjtW37zUEtZxe3WOB3h0kW8+hlJ6h6AIWZXdxzFbeBzV8CeUJNsjvT42A5NqRS2YcYz AEb/5ZmZkTxhCjWlvfGdwhLlrJbmk4GfLrm7fXQwSmMUsGtx8LU3HbjizzqN1HATbPfw C5lFUCLhVkrp7GmSKy2FA4DGAkxPQfFGN6GiqzQzkp1LDD1chPSZYlI4XpNz8tiKKwyV 63vA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@shutemov-name.20150623.gappssmtp.com header.s=20150623 header.b=v8w3omLd; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z7si9377389edb.160.2019.09.09.08.11.06; Mon, 09 Sep 2019 08:11:31 -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; dkim=pass header.i=@shutemov-name.20150623.gappssmtp.com header.s=20150623 header.b=v8w3omLd; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389585AbfIIJHG (ORCPT + 99 others); Mon, 9 Sep 2019 05:07:06 -0400 Received: from mail-ed1-f67.google.com ([209.85.208.67]:32992 "EHLO mail-ed1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727674AbfIIJHG (ORCPT ); Mon, 9 Sep 2019 05:07:06 -0400 Received: by mail-ed1-f67.google.com with SMTP id o9so12297560edq.0 for ; Mon, 09 Sep 2019 02:07:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=shutemov-name.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=4SKyZYA96ZSRssF5bkYvn8/ZaoQgr/75nnF3v6r+aa4=; b=v8w3omLdQptz1DFzG6nBTgRTann5rTwOgCIpzFAUG6tuIXQysQUnfXsX6/y/3pY3P9 uuS7yln7izn8sa95u0TM8CxgbGe80u+X7t+BlonTv/Ols4bkZ2vzfkF1DV9YLxLMbFWT xMTJREdPJWH3jVZBD9E+ZKhbm9fxBa7VvxrMdRD31hii4MCogV1JmJclv2q1d2hOR8mU ZmP3pZ6SwqNXdDC1we1lskq5l3t193Mkb/3/NHR7WEDq49Askf9VlLY7UIB/Uu8JTBTS Nb6KVgXuECh0+jAIrDzxGYdOgJP/buaC0u2KcFllDTZyMTRwGgl/GCSf7CPvpXRD1ygX 8PnA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=4SKyZYA96ZSRssF5bkYvn8/ZaoQgr/75nnF3v6r+aa4=; b=d0BpUymTU7y0ByrVL5mOoDd8h13LZEqUyzcpB3AIFY1rKmQ3Dz1+zza/MjY2QGdVoL vu4stewUeIXJSqJc+dPSxIt4mzdGA3luTEsGVEWnGl9Tt0+TB6/xw86DNesTPnuQ5Aff bS4m0S3Uhtjawi3iVuLV1gACZbPYCj1mANjJd2X/NHfEqOvqxdebYnJbOgOKS+b3VePR bH8ulaHkaxv0D5rXk9YFnfIPipp/OCdKlDF/QouFtMTZy7E0eHs2e3e8vB2oTIz2PU4x C8uJ2tzi2e76+QWExXNE3cus2cnI2czYaj3VsT1de8ElClzucp22q1d4R3Rqnh0SvA9D IDpA== X-Gm-Message-State: APjAAAXzXP2c70rZYG7xOvqO2DJdJS1OXB5KVV20bUI4EfRAZtWnSzsX 2NiSB+bxRyOEvLWq5K0rpo+Tog== X-Received: by 2002:a17:906:af98:: with SMTP id mj24mr18377781ejb.199.1568020023846; Mon, 09 Sep 2019 02:07:03 -0700 (PDT) Received: from box.localdomain ([86.57.175.117]) by smtp.gmail.com with ESMTPSA id t21sm1658127ejs.37.2019.09.09.02.07.02 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 09 Sep 2019 02:07:03 -0700 (PDT) Received: by box.localdomain (Postfix, from userid 1000) id 94FB410022D; Mon, 9 Sep 2019 12:07:01 +0300 (+03) Date: Mon, 9 Sep 2019 12:07:01 +0300 From: "Kirill A. Shutemov" To: 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, alexander.h.duyck@linux.intel.com, kirill.shutemov@linux.intel.com Subject: Re: [PATCH v9 1/8] mm: Add per-cpu logic to page shuffling Message-ID: <20190909090701.7ebz4foxyu3rxzvc@box> References: <20190907172225.10910.34302.stgit@localhost.localdomain> <20190907172512.10910.74435.stgit@localhost.localdomain> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190907172512.10910.74435.stgit@localhost.localdomain> User-Agent: NeoMutt/20180716 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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; > } > > -- Kirill A. Shutemov