Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp1030509pxf; Thu, 8 Apr 2021 20:36:34 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxsoYFRT7VX+Lo0RtRE/poKsM93zdei5qPDKj8D9/OTlw2bEb8OHsdERGxAlmtfkvpH5NsP X-Received: by 2002:a05:6402:40c9:: with SMTP id z9mr15496558edb.24.1617939393981; Thu, 08 Apr 2021 20:36:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617939393; cv=none; d=google.com; s=arc-20160816; b=xjaJzHO3gUMA0HjKDunXgXUP9qwngpqsc17hwLeYavUEEdz42K3wZdKDB4TZ8MORNh ySl5Z8+giXZhh2mXQkh63VhsdM73pMERAQ2N/C3MLiqb23o+ETHCPZi4Heeh1sC678+v lpvqi2Bv0QGFxnMhifm+zknku6Z5Zb+jO9yyrw4eEP4wWMP0mTcQcJRO3dtVOdt0iK4j o7fHVe1Dd0Ad8bfRL3QE1DX4wbA274I/oV7Xw8rIOsMuwN4pbY3wS0eCx0P6V+Vb9chL NkLxO8LcwYh8uUUCQsyQ7ID4UnFDj0J40Y9xAo3Rr/uamWOm3dd9h9AJvf1Sw6ojRmSI x8kw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:organization:references:in-reply-to:date:cc:to:from :subject:message-id:dkim-signature; bh=6UuQfMQF3OUZ83yBXGwyDB/n7MYxlPyfj5Q62eMYOas=; b=apSgUmsDb//S0AQFs2GZ2HC4lbtOulzY27fjeK81glc5vymc8x5v8awMMMNmwc4g3p E9CZJkp3lPyQhlDai1rws6kXdS0E+Lwb5OpZN1+GTadjdR13x9UcYmsE14h15ZA+inQQ eSvC9Kn4uFhOB4EwjDvdAd81yt2KMViS1M8cLUVohecrgcEmZ6BRSidQ3h1AEoN7FZvb A7NiBu5PesniaF/G81f5qWDsGiRVyG+BgXafd1kswkJ8PvwFtiN4GcHbgCVfWFC7xVDl lle0f6mAaYqyO0bEMezVHBP3D6PTHh+o2+RQyUI4/V2k9zgayZVvLGofX89OCG61eKlB XcFA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=n0r36yzy; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id o17si1127077edv.601.2021.04.08.20.36.10; Thu, 08 Apr 2021 20:36:33 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=n0r36yzy; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233121AbhDIDbb (ORCPT + 99 others); Thu, 8 Apr 2021 23:31:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53436 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233087AbhDIDb2 (ORCPT ); Thu, 8 Apr 2021 23:31:28 -0400 Received: from mail-qt1-x831.google.com (mail-qt1-x831.google.com [IPv6:2607:f8b0:4864:20::831]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8F43BC061760 for ; Thu, 8 Apr 2021 20:31:11 -0700 (PDT) Received: by mail-qt1-x831.google.com with SMTP id h7so3239306qtx.3 for ; Thu, 08 Apr 2021 20:31:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:subject:from:to:cc:date:in-reply-to:references :organization:user-agent:mime-version:content-transfer-encoding; bh=6UuQfMQF3OUZ83yBXGwyDB/n7MYxlPyfj5Q62eMYOas=; b=n0r36yzy05cjaLySQ0nj0iZxl6wD3E4lQ6XjHXdBIqrfwkHyxefdW5OcIoLS2tZ0YI LuyoNJdit33LPL5CN0O8ValmYVvyaO8c1H+Pa32tCe2s8yw9vN7yKw9fTj6NWR0XXldQ V5tKvHEeVR2d9dLU2jf46yC3lTz7U8cNQodrDZ9+2IL3eouiIzbagu1a+kD4XLmG/fmB DqZaLi9IfpC9FkwNMHXzDryhD/kETBKmfmFHIDhpcxd2c7fQv0HhQxpeoAOZ0W3Pjals WS1UMVcOaWeFwSQjoWOQd6jesuDkXUHFz+exC2VxfQg+NpLMLeAuhdeXWeH7grZAbrdL yDdQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:subject:from:to:cc:date:in-reply-to :references:organization:user-agent:mime-version :content-transfer-encoding; bh=6UuQfMQF3OUZ83yBXGwyDB/n7MYxlPyfj5Q62eMYOas=; b=bXd4nc766l9potb8l0UV/2RkGt/0Cbu3XmCYE95tYB96O9hiu7TavpRClAOIPaoPN7 R4RO58/SMU60r9+negJt4gFdI6K2ATIxqREPhOJV4p11CbafedA4rqr00pAvHdR2LK/r 2DbAj96aKKbTWQyjr2cU/CC+GJo0vgTNHTpNhLlWLu9/Vxki6KTXKe8Zpo82QkBprKnA UyyU4v6VD4uJ+K1DGKFMHHSQ1OHeTBqyIcFb7NQ8oB+bczWZA7VjQr02Lmg3nBQLuCzv 0LGe60HHbGSxwcCtV8xJF4MfmIS06zbwj7ZvOcWyWdf8Uqj2USXS0/ofS+QiCI5sUGcm XyYw== X-Gm-Message-State: AOAM5329zq9+pF1tlSYNyFwzLUcoBHqSzvhcT+SGV3ezcKy4vQaz7CnB +VEIRwsK5l7Gl9LoX2j8eoo= X-Received: by 2002:ac8:6f2e:: with SMTP id i14mr10652056qtv.277.1617939070848; Thu, 08 Apr 2021 20:31:10 -0700 (PDT) Received: from li-908e0a4c-2250-11b2-a85c-f027e903211b.ibm.com ([2804:14c:482:7b04::1000]) by smtp.gmail.com with ESMTPSA id g11sm953629qkk.5.2021.04.08.20.31.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Apr 2021 20:31:10 -0700 (PDT) Message-ID: <418f044aab385389681529b0b6057e75825b0e5f.camel@gmail.com> Subject: Re: [PATCH 3/3] powerpc/mm/hash: Avoid multiple HPT resize-downs on memory hotunplug From: Leonardo Bras To: David Gibson Cc: Michael Ellerman , Benjamin Herrenschmidt , Paul Mackerras , Andrew Morton , Sandipan Das , "Aneesh Kumar K.V" , Logan Gunthorpe , Mike Rapoport , Bharata B Rao , Dan Williams , Nicholas Piggin , Nathan Lynch , David Hildenbrand , Laurent Dufour , Scott Cheloha , linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org Date: Fri, 09 Apr 2021 00:31:03 -0300 In-Reply-To: References: <20210312072940.598696-1-leobras.c@gmail.com> <20210312072940.598696-4-leobras.c@gmail.com> Organization: IBM Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.38.4 (3.38.4-1.fc33) MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hello David, thanks for commenting. On Tue, 2021-03-23 at 10:45 +1100, David Gibson wrote: > > @@ -805,6 +808,10 @@ static int resize_hpt_for_hotplug(unsigned long new_mem_size, bool shrinking) > >   if (shrinking) { > > > > + /* When batch removing entries, only resizes HPT at the end. */ > > + if (atomic_read_acquire(&hpt_resize_disable)) > > + return 0; > > + > > I'm not quite convinced by this locking. Couldn't hpt_resize_disable > be set after this point, but while you're still inside > resize_hpt_for_hotplug()? Probably better to use an explicit mutex > (and mutex_trylock()) to make the critical sections clearer. Sure, I can do that for v2. > Except... do we even need the fancy mechanics to suppress the resizes > in one place to do them elswhere. Couldn't we just replace the > existing resize calls with the batched ones? How do you think of having batched resizes-down in HPT? Other than the current approach, I could only think of a way that would touch a lot of generic code, and/or duplicate some functions, as dlpar_add_lmb() does a lot of other stuff. > > +void hash_memory_batch_shrink_end(void) > > +{ > > + unsigned long newsize; > > + > > + /* Re-enables HPT resize-down after hot-unplug */ > > + atomic_set_release(&hpt_resize_disable, 0); > > + > > + newsize = memblock_phys_mem_size(); > > + /* Resize to smallest SHIFT possible */ > > + while (resize_hpt_for_hotplug(newsize, true) == -ENOSPC) { > > + newsize *= 2; > > As noted earlier, doing this without an explicit cap on the new hpt > size (of the existing size) this makes me nervous.  > I can add a stop in v2. > Less so, but doing > the calculations on memory size, rather than explictly on HPT size / > HPT order also seems kinda clunky. Agree, but at this point, it would seem kind of a waste to find the shift from newsize, then calculate (1 << shift) for each retry of resize_hpt_for_hotplug() only to point that we are retrying the order value. But sure, if you think it looks better, I can change that. > > +void memory_batch_shrink_begin(void) > > +{ > > + if (!radix_enabled()) > > + hash_memory_batch_shrink_begin(); > > +} > > + > > +void memory_batch_shrink_end(void) > > +{ > > + if (!radix_enabled()) > > + hash_memory_batch_shrink_end(); > > +} > > Again, these wrappers don't seem particularly useful to me. Options would be add 'if (!radix_enabled())' to hotplug-memory.c functions or to hash* functions, which look kind of wrong. > > + memory_batch_shrink_end(); > > remove_by_index only removes a single LMB, so there's no real point to > batching here. Sure, will be fixed for v2. > > @@ -700,6 +712,7 @@ static int dlpar_memory_add_by_count(u32 lmbs_to_add) > >   if (lmbs_added != lmbs_to_add) { > >   pr_err("Memory hot-add failed, removing any added LMBs\n"); > > > > + memory_batch_shrink_begin(); > > > The effect of these on the memory grow path is far from clear. > On hotplug, HPT is resized-up before adding LMBs. On hotunplug, HPT is resized-down after removing LMBs. And each one has it's own mechanism to batch HPT resizes... I can't understand exactly how using it on hotplug fail path can be any different than using it on hotunplug. > Can you please help me understanding this? Best regards, Leonardo Bras