From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id EC4F2C6FA90 for ; Thu, 8 Sep 2022 16:16:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232160AbiIHQQd (ORCPT ); Thu, 8 Sep 2022 12:16:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41732 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232034AbiIHQPq (ORCPT ); Thu, 8 Sep 2022 12:15:46 -0400 Received: from mail-pl1-f172.google.com (mail-pl1-f172.google.com [209.85.214.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CBE25B1BA7 for ; Thu, 8 Sep 2022 09:15:42 -0700 (PDT) Received: by mail-pl1-f172.google.com with SMTP id v1so5039284plo.9 for ; Thu, 08 Sep 2022 09:15:42 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date; bh=WRizZ/elGsKzYrgR6wHhu5mQCbmwoq7lJMsQ4A5WuXk=; b=vwfy5U6ErUToEm2JuxFc9hLjVPxVoke67KGDmgkoQSDqpmc7aXYryqFBgwxYEpoBV/ vrbiC7yWnICk9GDxa8nmmAv6tyaaaSdp6D/6nTaXnza/Lux5kDMh5gsAKT7nOLkWmOTu RCDmr/97dYtOQpmzslpQEXxAYNyvBgR8yISWQHujMtt15md3Ep1/278NUd+rFsMwqUUd AmFH9Moqda6R+S9SYOxso5PtaBjnQLi1xNbIGx+gg4nB0TYfmbPnwg3WY5E7hFRadSuc DfVL8Te1nKoc2vGLfrMO4ifmgeAD1sQD2NsO5G0wDd2MlVH8nclGFchBJCJEm2xUn2wn 4I1A== X-Gm-Message-State: ACgBeo1IJIgiOSqm0bKs3YkHgJ9GSp8oV9f2EB15pfvmDLFL3Kb+lFpR V9f5CLov0E6Pkxwuq0gvwL4= X-Google-Smtp-Source: AA6agR6KpN7x7XlsPo6Q7kge66cDmDp3fSYTyoziPQRe/m8ELeYmKS1qH7kGqoQP3k0HhEr/Ng0tpQ== X-Received: by 2002:a17:90b:1a91:b0:1ff:f703:ccad with SMTP id ng17-20020a17090b1a9100b001fff703ccadmr5061311pjb.154.1662653741656; Thu, 08 Sep 2022 09:15:41 -0700 (PDT) Received: from fedora (136-24-99-118.cab.webpass.net. [136.24.99.118]) by smtp.gmail.com with ESMTPSA id r20-20020a634414000000b00421841943dfsm12633501pga.12.2022.09.08.09.15.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Sep 2022 09:15:41 -0700 (PDT) Date: Thu, 8 Sep 2022 09:15:37 -0700 From: Dennis Zhou To: Andrew Morton Cc: "Sun, Jiebin" , Tim Chen , vasily.averin@linux.dev, shakeelb@google.com, tj@kernel.org, cl@linux.com, ebiederm@xmission.com, legion@kernel.org, manfred@colorfullife.com, alexander.mikhalitsyn@virtuozzo.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, tim.c.chen@intel.com, feng.tang@intel.com, ying.huang@intel.com, tianyou.li@intel.com, wangyang.guo@intel.com Subject: Re: [PATCH v4] ipc/msg: mitigate the lock contention with percpu counter Message-ID: References: <20220907172516.1210842-1-jiebin.sun@intel.com> <20220907143427.0ce54bbf096943ffca197fee@linux-foundation.org> <20220908083859.24c989f08d62ddbd031005de@linux-foundation.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220908083859.24c989f08d62ddbd031005de@linux-foundation.org> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hello, On Thu, Sep 08, 2022 at 08:38:59AM -0700, Andrew Morton wrote: > On Thu, 8 Sep 2022 16:25:47 +0800 "Sun, Jiebin" wrote: > > > In our case, if the local > > percpu counter is near to INT_MAX and there comes a big msgsz, the > > overflow issue could happen. > > percpu_counter_add_batch() handles this - your big message > won't overflow an s64. > > > Lookng at percpu_counter_add_batch(), is this tweak right? > > - don't need to update *fbc->counters inside the lock > - that __this_cpu_sub() is an obscure way of zeroing the thing > > --- a/lib/percpu_counter.c~a > +++ a/lib/percpu_counter.c > @@ -89,8 +89,8 @@ void percpu_counter_add_batch(struct per > unsigned long flags; > raw_spin_lock_irqsave(&fbc->lock, flags); > fbc->count += count; > - __this_cpu_sub(*fbc->counters, count - amount); > raw_spin_unlock_irqrestore(&fbc->lock, flags); > + __this_cpu_write(*fbc->counters, 0); I don't think this is irq safe. It'd be best to leave it inside the spinlock as then we can use __this_cpu_write() to 0 in there. > } else { > this_cpu_add(*fbc->counters, amount); > } > _ > Thanks, Dennis