From patchwork Thu Aug 10 10:38:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guo Hui X-Patchwork-Id: 13349220 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 0CC3EC04A94 for ; Thu, 10 Aug 2023 10:38:55 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9DFF26B0071; Thu, 10 Aug 2023 06:38:54 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 98FE76B0074; Thu, 10 Aug 2023 06:38:54 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 87FA16B0078; Thu, 10 Aug 2023 06:38:54 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 797956B0071 for ; Thu, 10 Aug 2023 06:38:54 -0400 (EDT) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 4652D1A1098 for ; Thu, 10 Aug 2023 10:38:54 +0000 (UTC) X-FDA: 81107846988.07.EA46256 Received: from smtpbguseast3.qq.com (smtpbguseast3.qq.com [54.243.244.52]) by imf29.hostedemail.com (Postfix) with ESMTP id 073DA120010 for ; Thu, 10 Aug 2023 10:38:50 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=none; spf=pass (imf29.hostedemail.com: domain of guohui@uniontech.com designates 54.243.244.52 as permitted sender) smtp.mailfrom=guohui@uniontech.com; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1691663932; 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-transfer-encoding:content-transfer-encoding: in-reply-to:references; bh=Z8aI6bKafnmSg+4V6qBtJYAWH5AHQHBuTM2xx5xohOQ=; b=wiF02RHuznwN7GZJGS1GlY2SjyfXGZ+CCZ4aIBfuz9ywo9XqeEqRJy60UJPNp30ufwAgO4 l3AdMlHUxJquI800XZ9mek9zmcqlmnCwuSczONwjUoYYygbtJTI/xOA5QKJbIIqbArn+RI IdqbW7CUiuZ4pgSXzFOCk5qZ6sZNkYA= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=none; spf=pass (imf29.hostedemail.com: domain of guohui@uniontech.com designates 54.243.244.52 as permitted sender) smtp.mailfrom=guohui@uniontech.com; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1691663932; a=rsa-sha256; cv=none; b=OIgfJDGfkR5NjQ3+wEloiAqcwXy48niLU4ykUHRX2j5QE2P+SYsQFmr+uGRh2K7WjaEVri qIA7jVv2x7d77nE8gRCST2PwwIeyrueWqEWLmn1Jlx46RucTgIeppW+G0hEPXy5LYsDf+W rlCNyO96sQsXig1RP3YRDm8gFg0uwJ8= X-QQ-mid: bizesmtp77t1691663913tp2sr55s Received: from localhost.localdomain ( [113.200.76.118]) by bizesmtp.qq.com (ESMTP) with id ; Thu, 10 Aug 2023 18:38:32 +0800 (CST) X-QQ-SSF: 01400000000000D0H000000A0000020 X-QQ-FEAT: EjS+9Gu1+/UrE7hGA5CptrTNK+BVaN/fKXfuwuxO7DWBNoWhtYKZzaeLbi2HD E2qrMVbHXLTLplJyyyYCUKI/F8XtN0jyGjfSdp4mf2SRutbdPYrT3Cfh35TXKAV1FIAVrC8 E/v7wmVkyZtjJENYQZAiGiKf4pvEbt4WtL98ybmxuHuslp6nWKw1TS/EjSARpZRcdFi3qb5 DfDFu8smMjorO1rQ8/wKjxG0ZM2t9YC0mQceN1LTgAxxF3jT2jOuDEUBZ7w5QWaQCY6LxgZ w8ejmKdFcaPfFbsHfNNok6/velvO/Mg+OKGhpGDurxHmLTIMgp4U6hGU4A61VTmvxjeT9CA QmuWGEQmHWEFicz8c0hdVNid4hSj8UEORzWTCj8emD5URHjJ74= X-QQ-GoodBg: 2 X-BIZMAIL-ID: 4023864530373408811 From: Guo Hui To: akpm@linux-foundation.org, linux-mm@kvack.org Cc: wangxiaohua@uniontech.com, Guo Hui Subject: [PATCH] mm: sparse: shift operation instead of division operation for root index Date: Thu, 10 Aug 2023 18:38:29 +0800 Message-Id: <20230810103829.10007-1-guohui@uniontech.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:uniontech.com:qybglogicsvrsz:qybglogicsvrsz4a-0 X-Rspamd-Queue-Id: 073DA120010 X-Rspam-User: X-Stat-Signature: hoe5g6neys1rb6ofrqkntczzqtu8ries X-Rspamd-Server: rspam01 X-HE-Tag: 1691663930-140478 X-HE-Meta: U2FsdGVkX1+fatZsbPE4ws7JhJkIsIUcDi/8pQT+1XDNIoarfKG23LpifOzgQm/8XwoJaF8m32iXjne8kvdPdnX0JIk4lJdaaZB4kCGfzmG4rL6sD8bo2aVGLLLrKqAffO9SAnAgUbEfN8/KZ1lLPMEiSLiOz5xX/YSrs0eA28Qr0VSurWl9DTsiLmHEs74O+7zUp/vFNxF+qJoWvS4IxfswQaiQuDfFb8ze9gRJHbxttqhV9VXkm9EL/JXxBNOC6ipUtcz983bSu1fegL4ZeVUBIabKoAj8+hFGjDdMhHeN8Y6K2qSZ1FAuiP9WJh1DpVkbsosMnAjs4wpoUifiJDcd4RQY59ZECo0jN/uojBp7C9rCa6d7ZkNVhqXwFOmA9QdM/DtewWb/T5UH22rwIbmOEFKrao1hEYXX3ULcjIfmRQbSIzEoLVHAvgYt57FbmlhALy7FZhGmWJw1v6dgRyYEyRHn3jcfTVqOPQiVHvf004HJWIRYXryS2GqrxwDQBrCX8YcNsGNVa0FC+BYl/oXbwpXNsMLdczkgmuQ/tgJT7rHPkAmghd+KI+5H8EWeoBY9Jjk5CpCz8hLDMh0AOTAjfpHD0CbRwgFk/kIAUEGXgJBOWgMpq+xS122e/DbIp5Hu3hAWysi8uoOG5d0v3V8mYh7gStFY3OBngSYZpr1r1XS0Xq4LRYYnuH/aYOz+FjfkWLNAz9v+IHME0uoehJdM1Wxvj2WOriSmWbs0Vd6tJpTFHvG+M5kUpqG23DvrWz3wPQZau2bnLnLSSqON7VudV5oVSGbGD+48hDYFXEjPFVoCi3lwuAJCjchOoM414Ijcn9DklCBngCO5W1rfieYwZQuOCRkeGoFAEzWmso4xLDntkXugzJnqtVmOaKS5SPU/ngbi1cSVwpUj953Xuk5mFCdiuNqILp1mvr/UsAIMJSMVVKLINTf4hs3JyHoyPuGMyKENhcCDEfFd23q P2AS/GdZ tHMiIPvBWm02j4AfXjiKBAmkhZ4lfRzKTgpSabu10YL3YZg7N3toAUmoWryjo+dTGqdlY779QeLjrzOFW68aIUdhGsKkqeRd2zrEHgxdQQw/ECtrK0jjMPIwKwAInXqE0sd9bkkFJtESCK+sCla6lchDl/IONGLLjzvZphqkx8j5yHtrfHeFCbcesUA== 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: In the function __nr_to_section, Use shift operation instead of division operation in order to improve the performance of memory management. There are no functional changes. Some performance data is as follows: Machine configuration: Hygon 128 cores, 256M memory Stream single core: with patch without patch promote Copy 23376.7731 23907.1532 -1.27% Scale 12580.2913 11679.7852 +7.71% Add 11922.9562 11461.8669 +4.02% Triad 12549.2735 11491.9798 +9.20% Signed-off-by: Guo Hui --- include/linux/mmzone.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h index 5e50b78d58ea..8dde6fb56109 100644 --- a/include/linux/mmzone.h +++ b/include/linux/mmzone.h @@ -1818,7 +1818,8 @@ struct mem_section { #define SECTIONS_PER_ROOT 1 #endif -#define SECTION_NR_TO_ROOT(sec) ((sec) / SECTIONS_PER_ROOT) +#define SECTION_ROOT_SHIFT (__builtin_popcount(SECTIONS_PER_ROOT - 1)) +#define SECTION_NR_TO_ROOT(sec) ((sec) >> SECTION_ROOT_SHIFT) #define NR_SECTION_ROOTS DIV_ROUND_UP(NR_MEM_SECTIONS, SECTIONS_PER_ROOT) #define SECTION_ROOT_MASK (SECTIONS_PER_ROOT - 1)