From patchwork Fri Apr 12 09:24:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peng Zhang X-Patchwork-Id: 13627431 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 16BA8C4345F for ; Fri, 12 Apr 2024 09:24:58 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6CC756B0082; Fri, 12 Apr 2024 05:24:57 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 678216B0088; Fri, 12 Apr 2024 05:24:57 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4F23B6B0087; Fri, 12 Apr 2024 05:24:57 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 30BFB6B007B for ; Fri, 12 Apr 2024 05:24:57 -0400 (EDT) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id D12531C118A for ; Fri, 12 Apr 2024 09:24:56 +0000 (UTC) X-FDA: 82000345392.10.7BF0DD4 Received: from szxga06-in.huawei.com (szxga06-in.huawei.com [45.249.212.32]) by imf10.hostedemail.com (Postfix) with ESMTP id 6E623C0005 for ; Fri, 12 Apr 2024 09:24:54 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=none; spf=pass (imf10.hostedemail.com: domain of zhangpeng362@huawei.com designates 45.249.212.32 as permitted sender) smtp.mailfrom=zhangpeng362@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1712913895; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding:in-reply-to: references; bh=dH9Zu0qT1FzivdEVNb10nKpxtih3+dNhqFlXxLHhzYw=; b=OJIk+XKw4Q72Vza92jBGyEMPknqB7kWUMNkHY2SqrnqrkE7/lfVW7jXUknb4GqlpXWnskx AzAZMKXqYJx8cnfDXlx7tQAnm+bd3hkQql0xqQoa6o95oL37zkF7MH9mMN0pu/vqw4yS5p RYhzQI41e4W1Ogqi3kDkQPrzyUJ8sYk= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1712913895; a=rsa-sha256; cv=none; b=vJXHrLph3YcyV1A/XHiHrZHn0X2mLV0X3YjanJXYCFKh2cXU1CwEWgrO7rFu1OimlPSnal zvcbhQGg1nyuIVhsGRtRQS6IvGDz4S36B6m/5LlW8+AV5XV8R/ixknnO0ca7qgtr5PwH4f Rbu2u2L8lInEiqyQazo2CVWjo2fa6zA= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=none; spf=pass (imf10.hostedemail.com: domain of zhangpeng362@huawei.com designates 45.249.212.32 as permitted sender) smtp.mailfrom=zhangpeng362@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com Received: from mail.maildlp.com (unknown [172.19.162.112]) by szxga06-in.huawei.com (SkyGuard) with ESMTP id 4VGB2d3X4jz1wrPX; Fri, 12 Apr 2024 17:23:53 +0800 (CST) Received: from kwepemm600020.china.huawei.com (unknown [7.193.23.147]) by mail.maildlp.com (Postfix) with ESMTPS id BE13D140156; Fri, 12 Apr 2024 17:24:49 +0800 (CST) Received: from localhost.localdomain (10.175.112.125) by kwepemm600020.china.huawei.com (7.193.23.147) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.35; Fri, 12 Apr 2024 17:24:48 +0800 From: Peng Zhang To: , CC: , , , , , , , , , , , , Subject: [RFC PATCH 0/3] mm: convert mm's rss stats into lazy_percpu_counter Date: Fri, 12 Apr 2024 17:24:38 +0800 Message-ID: <20240412092441.3112481-1-zhangpeng362@huawei.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-Originating-IP: [10.175.112.125] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To kwepemm600020.china.huawei.com (7.193.23.147) X-Stat-Signature: xsktxbqftetdm9ipxjgueoxfz3kx3zzq X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: 6E623C0005 X-Rspam-User: X-HE-Tag: 1712913894-38307 X-HE-Meta: U2FsdGVkX1+VPaaHwClGI6YBBNIniP8inU1WZr3khlMcOnZsZkB8IxRP/ibXvtYmmIlv+AnQAMVOaXmmX9FoOB2RnXq5FrPxtsFrECTtT8UT+AFtZ3/ATBQO5bXOQYwhHwzAYEB/d5Cdcrj6xVAm0kTYxfVRO39u/PO/c84I7PoQVWKpliKRdOask+RAFVqWOct0oPH7j55GWJVI/7vZp7pLr3SOa5bMVki9n7XEHs6RZf0q10p4QxRz+Eo6ks2qq8us/1+2iC2Lry0hrElwrcNYDHixwipRq1n0AAykF35zyVfF+tW4e9tfJaFv3O/wbnh6j6f8+/A/oye3YUkti/mlo3yuN85rbD6AyY/oxOI7dsAki8lyOzrciMoB0snKTGiqx1Hu8WWf90CX9PUGZYOcY0os56VeokhzF5WiUenIB0expOfR8Hv5WUJ04dwj9SggRi+PSyJ3hCKNzzoZxWPldUPivzlIEgG1wgbNEcA06MdyyszWxBZnsp89GXfWEBVFbgUf4QWHPFQtvgxjJ1FRzzEfbNaBcXt/yVomJeJI03fa1UBCzNut2xbd6BWKuIISF0tzu90OYMw/plVhgnuKR+Xosv0lqtzP1m72KqfCygVzFEsilLyFDXAcgi6R9lffDNHVU47h5D0tWEId0t0F6/9HPm9zfM8YE9ZD/SU/dFRF/FEL2loBvHnhP6gmNvkebLw+lSSQXu9ZRhoD8bWRe9b4KLA9LBWvahpetZpmNMLCFYDu0JeJces0tWy8dzuH/se0IEYPNp9pT+BhJlMC/AnVgIuZ/Axm70L2ihzZcEyavT9l+oDZJB83Zo9tOApd5AbnQJgVVr02UIIJKKeFCaDVD19U7aLDi9tqMgrDWTHsBjlCcHzeR6OMnld1x9Zxaoa81MWyNI3bSlzf/RHDgTnnLheh1oVAxVwF30L7XFwBrEOCbc5ubPLoB2ZHOb2PlyYqom1DHHN5bE7 TOG0fN8T bd/XO65j+0Qt6uCJkf1VwjOqENgAWtp77BHmGubo346nOBE70To7DERR80IghlK32ofZwn8+YZB44eiDwi35ZiCZEDTc02uwZoDwuqZNLizUT7kDu/+Z0Mdx0vCnPrLHNNHStReGQfql1qi13QTZ4ZipsNVQNsidc1pFU0Rb8Ulf9NxauyiXB2oBRGXmloJQJfF3DoPC97pxW082Lr9XYViKWzC5DrcWyZiIWPsLtIjplbAjt5VirEk0XmkAfrcwySjAouLtzJPBjq/Q= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: From: ZhangPeng Since commit f1a7941243c1 ("mm: convert mm's rss stats into percpu_counter"), the rss_stats have converted into percpu_counter, which convert the error margin from (nr_threads * 64) to approximately (nr_cpus ^ 2). However, the new percpu allocation in mm_init() causes a performance regression on fork/exec/shell. Even after commit 14ef95be6f55 ("kernel/fork: group allocation/free of per-cpu counters for mm struct"), the performance of fork/exec/shell is still poor compared to previous kernel versions. To mitigate performance regression, we use lazy_percpu_counter[1] to delay the allocation of percpu memory for rss_stats. After lmbench test, we will get 3% ~ 6% performance improvement for lmbench fork_proc/exec_proc/shell_proc after conversion. The test results are as follows: base base+revert base+lazy_percpu_counter fork_proc 427.4ms 394.1ms (7.8%) 413.9ms (3.2%) exec_proc 2205.1ms 2042.2ms (7.4%) 2072.0ms (6.0%) shell_proc 3180.9ms 2963.7ms (6.8%) 3010.7ms (5.4%) This solution has not been fully evaluated and tested. The main idea of this RFC patch series is to get the community's opinion on this approach. [1] https://lore.kernel.org/linux-iommu/20230501165450.15352-8-surenb@google.com/ Kent Overstreet (1): Lazy percpu counters ZhangPeng (2): lazy_percpu_counter: include struct percpu_counter in struct lazy_percpu_counter mm: convert mm's rss stats into lazy_percpu_counter include/linux/lazy-percpu-counter.h | 88 +++++++++++++++++++ include/linux/mm.h | 8 +- include/linux/mm_types.h | 4 +- include/trace/events/kmem.h | 4 +- kernel/fork.c | 12 +-- lib/Makefile | 2 +- lib/lazy-percpu-counter.c | 131 ++++++++++++++++++++++++++++ 7 files changed, 232 insertions(+), 17 deletions(-) create mode 100644 include/linux/lazy-percpu-counter.h create mode 100644 lib/lazy-percpu-counter.c