Received: by 2002:a05:6358:489b:b0:bb:da1:e618 with SMTP id x27csp862413rwn; Thu, 8 Sep 2022 09:45:05 -0700 (PDT) X-Google-Smtp-Source: AA6agR4nhqSZEjpZ/jVl5vT1967xaAlRv3gUa5G4irLh94Vhz7TR0UgaGQB8/Cca+68xjA9IhF6Y X-Received: by 2002:a05:6512:1110:b0:494:73fe:f960 with SMTP id l16-20020a056512111000b0049473fef960mr3390033lfg.453.1662655505439; Thu, 08 Sep 2022 09:45:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662655505; cv=none; d=google.com; s=arc-20160816; b=WxUzJRee20Ak8Uh0MwUAD7D3IXi43JP3ypnP8CHXdp1cIJZxHQs03Euspv80LAHyrg UNjUAOeaOTdqukTrsbH0ZNFF2pswVvsxWhRNw4tU/Jfvbr/er8yLDUewNbJSpvUK+5q7 mdmSv50wqUkKjkqZmo6tnsHbzl7UmwI6/5Yg4v5aHVXP0YFnPGIFNZfesLIpg3CG/lJV c3kSgh5eBfcX43S52ADG7ZXEuK8YVvNPx4nCT/1iadaF3E61z6KFYwvzd0WcioJAPO2k xdaaPafKESwtOoAbwQgYDxRQ/ErnZqWYqNPTpGveZ1thvsWUiBLfL61lpIgrJykrlGfJ eRyQ== 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; bh=WRizZ/elGsKzYrgR6wHhu5mQCbmwoq7lJMsQ4A5WuXk=; b=Sr3EWRtEcpg9q9cz3hxl9JPkp6a78VbXc3Z+Ygft8VwJD1Y0iZY2qk0Om6B0rV78it XVF9kPDYT0u7m4buB5bn8wd9W1mFRTESTAUJALPAifnN+FlEnIMwUwZVxxpHh/6wnX6Y UZ9WchN8R7vkzTZdFqANT/FtigyDcn5uE5T728/CUGChuUxX/W/v6fA73HBVvIfTelx6 pUL6B0+0TPFn3ukKM+jH1u+q1rT2sm474n+5fihe1JmCbroOI3wMLgvQ0AEkv7B8nTct OGGBn+W4K9D8qVIQXD56FZt8KUBR2SpRNOiMGVEWAhl0KryBmspFtB2woLK+iVocPyda WLZA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x38-20020a056512132600b00492cbb262f4si8479374lfu.573.2022.09.08.09.44.35; Thu, 08 Sep 2022 09:45:05 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232149AbiIHQQd (ORCPT + 99 others); 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-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> X-Spam-Status: No, score=-1.4 required=5.0 tests=BAYES_00, FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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