Received: by 2002:a05:6358:489b:b0:bb:da1:e618 with SMTP id x27csp209968rwn; Wed, 7 Sep 2022 15:18:03 -0700 (PDT) X-Google-Smtp-Source: AA6agR4gClly+vVG870QxrwVArVXUdFw6xGa0vNeOd6NqGWNEAWuLPLwBuJ1fyIr5Ve3/yMowAM0 X-Received: by 2002:a05:6402:b45:b0:44e:a071:2b3b with SMTP id bx5-20020a0564020b4500b0044ea0712b3bmr4789441edb.95.1662589083360; Wed, 07 Sep 2022 15:18:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662589083; cv=none; d=google.com; s=arc-20160816; b=ROLTtWWqXoQwFH6cmUqeSC9b4B4nTQIRHV+tbcy9ybsjh4/GT0i+MN68XPRkNrgBON 4uoBLULH4k6w1TT++xeE0Af5Q/sPehFtp23KUnr3LQkO6N6XG1uBnCHgDGrHBSHq0yRf e1Oxg68bf3z9fQLr8H5souWgTrs+SJqmOuT3qPkzV/1OGZeEJoApONAvJcXIsZY1Toei L+6CjV0VE2w4DWbSAFO8TVxlf4cjLResWpUAysvPdvwDYMu3vrPne+IJwRsL8QZ1oA4D PtkHMSCyzunGh1D26ErrmaLjqgngCsv1fY4nI+BwhCQag4jdqnCYvrjxZMp/RWapuWZX EMzA== 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 :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=27K80smNAv5aUF9gk8jWKD6E9xQPMeNUJzT3V7IQsCw=; b=viPu1uO3d+br3aJXyMsTEvEE4UUa3fVjjkPp3jF1EOudKQH5ky8vhZvHIib33WsxNw thuteHnmuse2ztlXy5/yMl+VsbOzSVAHmKjBGmojcIL6T9ezNoVpdZwvDdo3KeW1Zbfb OAQV62IO6kWKHiD/i9PLqoDiAFf7eKmsFyNVrzw73NIayDUYikeoOMPmm5EuR4u28GJF 3yVJN2zKN84+7Kp2c1EXTOrnzN1uykjYkbXAEivadyCftt5E9NvuYr6ABDaAEKIu0g/I OTChr0xcQgqAfB7SRgR1n/TdaghTJj4c4FA5HMCM54kfrh7+H/zPC0Upeco95WyZvoAy M6Fg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=korg header.b=lWhoM2fw; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i16-20020a170906699000b0073ddec832bcsi386496ejr.721.2022.09.07.15.17.37; Wed, 07 Sep 2022 15:18:03 -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; dkim=pass header.i=@linux-foundation.org header.s=korg header.b=lWhoM2fw; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230163AbiIGVed (ORCPT + 99 others); Wed, 7 Sep 2022 17:34:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39908 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229982AbiIGVea (ORCPT ); Wed, 7 Sep 2022 17:34:30 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 56238E0BB for ; Wed, 7 Sep 2022 14:34:29 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id E29396194E for ; Wed, 7 Sep 2022 21:34:28 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B7E25C433D6; Wed, 7 Sep 2022 21:34:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1662586468; bh=UgoD/NLQ0MqihZ87VFspXN0wI9uOU/Esj7gHe+uAoqo=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=lWhoM2fwKkQ0+S3jLkEBCouMBZXU7I4Tg04RzM5+IrYRYOobXKSOVdFVr4tcHdWjO EVP9+WRSEW+9l1GV5Qoh9gWaWoXbY3LYcfo1RxrZrWB2jqQx06huNTu0MnL/0ynzEG zKHib011BQJcyBAO1tyDumbf/8nTVs+l35cI4WvM= Date: Wed, 7 Sep 2022 14:34:27 -0700 From: Andrew Morton To: Tim Chen Cc: Jiebin Sun , vasily.averin@linux.dev, shakeelb@google.com, dennis@kernel.org, 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: <20220907143427.0ce54bbf096943ffca197fee@linux-foundation.org> In-Reply-To: References: <20220907172516.1210842-1-jiebin.sun@intel.com> X-Mailer: Sylpheed 3.7.0 (GTK+ 2.24.33; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-11.3 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham 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 On Wed, 07 Sep 2022 09:01:53 -0700 Tim Chen wrote: > On Thu, 2022-09-08 at 01:25 +0800, Jiebin Sun wrote: > > The msg_bytes and msg_hdrs atomic counters are frequently > > updated when IPC msg queue is in heavy use, causing heavy > > cache bounce and overhead. Change them to percpu_counter > > greatly improve the performance. Since there is one percpu > > struct per namespace, additional memory cost is minimal. > > Reading of the count done in msgctl call, which is infrequent. > > So the need to sum up the counts in each CPU is infrequent. > > > > > > Apply the patch and test the pts/stress-ng-1.4.0 > > -- system v message passing (160 threads). > > > > Score gain: 3.17x > > > > > ... > > > > +/* large batch size could reduce the times to sum up percpu counter */ > > +#define MSG_PERCPU_COUNTER_BATCH 1024 > > + > > Jiebin, > > 1024 is a small size (1/4 page). > The local per cpu counter could overflow to the gloabal count quickly > if it is limited to this size, since our count tracks msg size. > > I'll suggest something larger, say 8*1024*1024, about > 8MB to accommodate about 2 large page worth of data. Maybe that > will further improve throughput on stress-ng by reducing contention > on adding to the global count. > I think this concept of a percpu_counter_add() which is massively biased to the write side and with very rare reading is a legitimate use-case. Perhaps it should become an addition to the formal interface. Something like /* * comment goes here */ static inline void percpu_counter_add_local(struct percpu_counter *fbc, s64 amount) { percpu_counter_add_batch(fbc, amount, INT_MAX); } and percpu_counter_sub_local(), I guess. The only instance I can see is block/blk-cgroup-rwstat.h:blkg_rwstat_add() which is using INT_MAX/2 because it always uses percpu_counter_sum_positive() on the read side. But that makes two!