Received: by 2002:a05:6a10:17d3:0:0:0:0 with SMTP id hz19csp1083638pxb; Thu, 15 Apr 2021 13:38:56 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy31cIReVx+/XZFNtsgpxoHqDbxDJRa28vnheMBFjLeHTn11XAxW4NSVyiyAFBjR+32sLar X-Received: by 2002:a17:907:7745:: with SMTP id kx5mr5288853ejc.3.1618519135944; Thu, 15 Apr 2021 13:38:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618519135; cv=none; d=google.com; s=arc-20160816; b=egk0Q3MPrzX99ZCqQ1Spmt6Dc+nId/JqSW8GDi1RZQgfvQ62iFDNLhTY9jjvMLwHh3 YPXxK69oTt1Ng7qteJCJf6MSHjwcmQENKhMrJh/fZUUXArfzQopSzWe1T4/DuprlLzVK USnhJ8EOhhSSuSHnhejwjZ196zSPLAXXCV4OQ4vDjdOCphYJMQKhnkykf454WSPgUtoX OixNJhVxxNnyDen7u7+Seq+egWhnKqZ+KvaDBPdDQSv6OXFTY7zlgCmV1ZAmPYrnM3Cq JZquI5cblO1th1TNDhT2pi2zsmcQk/kfkUVNwkYBl9xHovkEW1xq5rowpz6m2f3YEM/7 17oQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=hD3bQIY2ucYvZVOUSWo6vopC1VOcxVsnFm0zvmFOg+E=; b=dJCoJhY3qlCgTqkfXJfPXzE/PEmDfNFA95PqUhrJdhcpZBww7HPM+M1prG40snToT3 nbYm6LaFRCQkYIrxj7CFKE4LQLUQyplxDsmNiyGDI5eW4MISUJbjH8ysyPRBWblPdMgF sJ3I3pDz7wOuFYHGnZb8FlnHAynKpCdNB7ke6qbnhHE1I2ZDHrf986q+nlKV73IxXIT1 6+G4GI+0J+JUARTYnGEOFvTASLc+VvLOU750LiaHk9FFbwinX8sx5p/q6R7ElUpaODv2 se1RRpV5J+yCoFXtgJObtp628EKQlQheGTXXJy6O43jWwQ1Ok0pyxe+pie3bgdCwJFaW ZZLQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@cmpxchg-org.20150623.gappssmtp.com header.s=20150623 header.b=ncE49eeS; 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=fail (p=NONE sp=NONE dis=NONE) header.from=cmpxchg.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id zm17si3496198ejb.350.2021.04.15.13.38.31; Thu, 15 Apr 2021 13:38:55 -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=@cmpxchg-org.20150623.gappssmtp.com header.s=20150623 header.b=ncE49eeS; 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=fail (p=NONE sp=NONE dis=NONE) header.from=cmpxchg.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235257AbhDOUTm (ORCPT + 99 others); Thu, 15 Apr 2021 16:19:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58782 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235169AbhDOUTj (ORCPT ); Thu, 15 Apr 2021 16:19:39 -0400 Received: from mail-qk1-x72c.google.com (mail-qk1-x72c.google.com [IPv6:2607:f8b0:4864:20::72c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CF8B0C061574 for ; Thu, 15 Apr 2021 13:19:15 -0700 (PDT) Received: by mail-qk1-x72c.google.com with SMTP id x11so26567094qkp.11 for ; Thu, 15 Apr 2021 13:19:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cmpxchg-org.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=hD3bQIY2ucYvZVOUSWo6vopC1VOcxVsnFm0zvmFOg+E=; b=ncE49eeSu4d9JPAV9lE+/q2xl8LS+vgcjxBrrC1YbpgbOEdDASvGHJSbLbPwFvkpVd G3FDAN50vmifSNPyI/+iFoCnMeJuHzWS9JePPFYvKAncH1z/O1/khvTw2ESGPrEVx/EX Ml8HScotQVh5QAaoX1NaKvt/TdkCYlK/uKcva06UWtHgDWwstlIDYXclXcrPiUbL9QJ2 fu7+7zlr+hxzXe6hq6LC5vTCg9H5b/3dHncRSN9i7CBH2gZXaewKzpSS0g3SYZCvvlBh uDp0AeuH+jAUDLoCanhLTeoi4x8WzLnDdkSU3xfu41oXZPBPNF+wWndl1QWgWuiaCEeO 9jAg== 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; bh=hD3bQIY2ucYvZVOUSWo6vopC1VOcxVsnFm0zvmFOg+E=; b=ll7OG/fLiYRokEeAVRPtpi9LhdcK5qFszJPz1KhqBWtqP4zfN5ejaA7OBGIxkIvbcG cODdLOC1M7Zog5zGvbiucli/ZuKkO3Xi/lgAaE0ITATlhW9aWPAjaGZnOnznNj0BkkIS bh6rgtSFFRNfB9jK/mdbS98lwmVMSVAUQLEgfGI9+bXS2pOeAScHuZWuha1+DwhVZxdh 1yJR+w1FEWzAufLH94HypBUMrABjIGcKgt8owRxZoRikj/BJGXc6Njk7apEsT1MFMGna HoCmdqJS48G7GIjK5ceB6I0n8NWB1g4tkxeNse0/VMUN811XVZjPPkkFnWkyENHMVCqh Dw3Q== X-Gm-Message-State: AOAM532C+2Zu3l1TOYpvX4uPS/1sW84qY6Pyh356rOs8cq6JDPYDRorP DhpiwEyEamFJuXESgpr0pngjBQ== X-Received: by 2002:a37:9604:: with SMTP id y4mr5219490qkd.345.1618517954908; Thu, 15 Apr 2021 13:19:14 -0700 (PDT) Received: from localhost (70.44.39.90.res-cmts.bus.ptd.net. [70.44.39.90]) by smtp.gmail.com with ESMTPSA id l16sm2814015qke.117.2021.04.15.13.19.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Apr 2021 13:19:14 -0700 (PDT) Date: Thu, 15 Apr 2021 16:19:13 -0400 From: Johannes Weiner To: Waiman Long Cc: Michal Hocko , Vladimir Davydov , Andrew Morton , Tejun Heo , Christoph Lameter , Pekka Enberg , David Rientjes , Joonsoo Kim , Vlastimil Babka , Roman Gushchin , linux-kernel@vger.kernel.org, cgroups@vger.kernel.org, linux-mm@kvack.org, Shakeel Butt , Muchun Song , Alex Shi , Chris Down , Yafang Shao , Wei Yang , Masayoshi Mizuma , Xing Zhengjun Subject: Re: [PATCH v3 2/5] mm/memcg: Introduce obj_cgroup_uncharge_mod_state() Message-ID: References: <20210414012027.5352-1-longman@redhat.com> <20210414012027.5352-3-longman@redhat.com> <1c85e8f6-e8b9-33e1-e29b-81fbadff959f@redhat.com> <8a104fd5-64c7-3f41-981c-9cfa977c78a6@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Apr 15, 2021 at 03:44:56PM -0400, Waiman Long wrote: > On 4/15/21 3:40 PM, Johannes Weiner wrote: > > On Thu, Apr 15, 2021 at 02:47:31PM -0400, Waiman Long wrote: > > > On 4/15/21 2:10 PM, Johannes Weiner wrote: > > > > On Thu, Apr 15, 2021 at 12:35:45PM -0400, Waiman Long wrote: > > > > > On 4/15/21 12:30 PM, Johannes Weiner wrote: > > > > > > On Tue, Apr 13, 2021 at 09:20:24PM -0400, Waiman Long wrote: > > > > > > > In memcg_slab_free_hook()/pcpu_memcg_free_hook(), obj_cgroup_uncharge() > > > > > > > is followed by mod_objcg_state()/mod_memcg_state(). Each of these > > > > > > > function call goes through a separate irq_save/irq_restore cycle. That > > > > > > > is inefficient. Introduce a new function obj_cgroup_uncharge_mod_state() > > > > > > > that combines them with a single irq_save/irq_restore cycle. > > > > > > > > > > > > > > @@ -3292,6 +3296,25 @@ void obj_cgroup_uncharge(struct obj_cgroup *objcg, size_t size) > > > > > > > refill_obj_stock(objcg, size); > > > > > > > } > > > > > > > +void obj_cgroup_uncharge_mod_state(struct obj_cgroup *objcg, size_t size, > > > > > > > + struct pglist_data *pgdat, int idx) > > > > > > The optimization makes sense. > > > > > > > > > > > > But please don't combine independent operations like this into a > > > > > > single function. It makes for an unclear parameter list, it's a pain > > > > > > in the behind to change the constituent operations later on, and it > > > > > > has a habit of attracting more random bools over time. E.g. what if > > > > > > the caller already has irqs disabled? What if it KNOWS that irqs are > > > > > > enabled and it could use local_irq_disable() instead of save? > > > > > > > > > > > > Just provide an __obj_cgroup_uncharge() that assumes irqs are > > > > > > disabled, combine with the existing __mod_memcg_lruvec_state(), and > > > > > > bubble the irq handling up to those callsites which know better. > > > > > > > > > > > That will also work. However, the reason I did that was because of patch 5 > > > > > in the series. I could put the get_obj_stock() and put_obj_stock() code in > > > > > slab.h and allowed them to be used directly in various places, but hiding in > > > > > one function is easier. > > > > Yeah it's more obvious after getting to patch 5. > > > > > > > > But with the irq disabling gone entirely, is there still an incentive > > > > to combine the atomic section at all? Disabling preemption is pretty > > > > cheap, so it wouldn't matter to just do it twice. > > > > > > > > I.e. couldn't the final sequence in slab code simply be > > > > > > > > objcg_uncharge() > > > > mod_objcg_state() > > > > > > > > again and each function disables preemption (and in the rare case > > > > irqs) as it sees fit? > > > > > > > > You lose the irqsoff batching in the cold path, but as you say, hit > > > > rates are pretty good, and it doesn't seem worth complicating the code > > > > for the cold path. > > > > > > > That does make sense, though a little bit of performance may be lost. I will > > > try that out to see how it work out performance wise. > > Thanks. > > > > Even if we still end up doing it, it's great to have that cost > > isolated, so we know how much extra code complexity corresponds to how > > much performance gain. It seems the task/irq split could otherwise be > > a pretty localized change with no API implications. > > > I still want to move mod_objcg_state() function to memcontrol.c though as I > don't want to put any obj_stock stuff in mm/slab.h. No objection from me! That's actually a nice cleanup, IMO. Not sure why it was separated from the rest of the objcg interface implementation to begin with.