From patchwork Thu Mar 16 01:25:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gou Hao X-Patchwork-Id: 13176905 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 AD060C6FD1D for ; Thu, 16 Mar 2023 01:26:16 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0AFB86B0071; Wed, 15 Mar 2023 21:26:16 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 039026B0072; Wed, 15 Mar 2023 21:26:15 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E1DA36B0075; Wed, 15 Mar 2023 21:26:15 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id D3F1B6B0071 for ; Wed, 15 Mar 2023 21:26:15 -0400 (EDT) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 9E949121294 for ; Thu, 16 Mar 2023 01:26:15 +0000 (UTC) X-FDA: 80573020710.18.4F884E5 Received: from smtpbgeu1.qq.com (smtpbgeu1.qq.com [52.59.177.22]) by imf23.hostedemail.com (Postfix) with ESMTP id D850714000C for ; Thu, 16 Mar 2023 01:26:12 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf23.hostedemail.com: domain of gouhao@uniontech.com designates 52.59.177.22 as permitted sender) smtp.mailfrom=gouhao@uniontech.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1678929974; 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=Yy/Bied8pfGqz5GNKCEXUADg8ofe4kj1LDJ+7SJOgic=; b=B8metgE73oys856m87Iq7zZh9/vIezdovC7EfbHvzkT1ys64ZGFo4FV5xm+itTy/owUgjJ PE4gtbv0L/ohc9Xe/A1PhMxFQyJSI3DFRsjWNM3p82nCL05VXqaWuaCRBDBBFuCwRIOcLy s/9/47rym/YGLg4Rz6d8GbTPCrEDo0w= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf23.hostedemail.com: domain of gouhao@uniontech.com designates 52.59.177.22 as permitted sender) smtp.mailfrom=gouhao@uniontech.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1678929974; a=rsa-sha256; cv=none; b=NSY7k72d5IsQ/kiu4td/2EZ214o9GaZLO/d8XkLi90DS/VXpYBvJRcrxZV3Ml4cs6fP5Vt u+V0f/ljZWYHqTlSiyHjRxEY9Oc6PFbonGPwHmb2FG+qSnUbe2b9zBHHL9ygxfZCnAWZpv KDrx1POYdP6w2z8/LJe3s20UzXHiITY= X-QQ-mid: bizesmtp88t1678929921t8u0hujh Received: from localhost.localdomain ( [113.200.76.118]) by bizesmtp.qq.com (ESMTP) with id ; Thu, 16 Mar 2023 09:25:19 +0800 (CST) X-QQ-SSF: 01400000000000B0E000000A0000000 X-QQ-FEAT: XBN7tc9DADInawRw6jdAUZ44VnwO3c57Fz7vH9MBathCjMyDHzQi1aWRllgAo +VYrJn9XLcUhtaJgBYmMVdpgGheSmFrXnnG/7OKViMNtH3gI+MHcfiBL/VNCvqvzI/wPwFp No8RbJN35NWOemsO0nim5X2cy+mjgn8EHq3c1a1ZoocchtaYgXRLPluEC1KQ/AIZCVKaC8M n1BDBMAbnmWqUP6QxzAB1uwePYG5z0P0pbIUvpRpTIYmu8CJ7QxUnpgX7rbcxSuQGFEk0Z1 2LV4OPlhzN4P7bdvuTk/FY/Y6FnH8dvkK1Zkc/HUwJrX0EivMzCWjv/BgBrdKaobXl+WUew /G4GDNka4JSOxm3qscgyLBeGRtndwXnaCm6cb7XJyvwmw3BsnLVIM0vXXJkb4faYil37mj/ X-QQ-GoodBg: 1 From: gouhao@uniontech.com To: cl@linux.com, penberg@kernel.org, rientjes@google.com, iamjoonsoo.kim@lge.com, akpm@linux-foundation.org, vbabka@suse.cz, roman.gushchin@linux.dev, 42.hyeyoo@gmail.com, keescook@chromium.org Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org Subject: [PATCH] mm/slub: reduce the calculation times of 'MAX_OBJS_PER_PAGE' Date: Thu, 16 Mar 2023 09:25:17 +0800 Message-Id: <20230316012517.10479-1-gouhao@uniontech.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:uniontech.com:qybglogicsvr:qybglogicsvr7 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: D850714000C X-Rspam-User: X-Stat-Signature: 1ge68zwcaz57o9tt3omfdnx17cfjrbg6 X-HE-Tag: 1678929972-886302 X-HE-Meta: U2FsdGVkX1/kRkQV76g/kLfr2RX41QS1LpUTSwagl9jsyc+Hr+jJ/vAyyRAtA95p4GBnf03KfbrCZaBjz5QwBLUcJviumojpTHaSIq2e565fhzhIoU0qNvqobRA7B2IarTr2P9A5ZxPtf+JYetCjje1AOq8oYrd3Ys1Z43DgvZwVRAjo2RAjkgN1nnRsL/6br3gpS1FoZbqgdKHGL7PHEz75tiEJBAKDgL1iFMzlthhTjkrmS89jrFZA/oCoXcGCI5J1v60n4dhW8iDYx+VbL0gnvmtXaMXFoSpZ+9A03f6ZAvzMBBiYA0RK5chMZRCfCejxrTm83WnpxnqUieWlPkb/kkHyTZD0XP3iLPiI9BAmAaU2cCM3zT3R1/EpnytorYibZI/nu3cpa1cI1GGeMLIid/FX1UxnCGpcnASehtBhrvHq4yuAMZvT2teS1d/yd8OJnHLeVjpI5OR/1C2TrVNTW5ZyoihfCIT2ouz1zeVF0JsfsLH9tCG47FgtjVuXslQb/Oxj/wqC9hRkXx7mj0OoaMtccOdbpV6Cpg8Gw0nyj4zeYbSfP4HndWqtXhnPH6WXRV862A6R58lpgzzV/bNsyVCJ1jIdpyv7f2heQ/o0knG+j/u7+Pfmgd4uhAYH6WGezA+zJgyjzV8NE6cKQkfWABrdhVGlAlY1nwlmZ3AU2DAB90pOBu4bCW5QBkwO/P8pYjtNksTCvuhI22Hn22jT+AOiWcVssVh4stoltQt1r3cENebcuUbkzPx0RVi7x9OKgT5FtsfWLm4a9eyKYyQg1AciyQrpMAFgo0ApqmzUsFLFoWZoSfMZ5ohFKgPjp91AWK/fBB3lT321xPtgfEN9FQJ362Og0mXKJJhmbmnUOfJtVcsLDnOv0Gi/r6obcjnDncZEIGz0GTDqbvcQ4hPm8GCGebX5xFRW9Ir3zAx/WIvtLcIjncAGP9UpPvWYFmLtPJXoxzdSorRW39Z +eCrhwmL 7H2rkLlbeFNLozZyTQe+DDPk/B6UWiG3IgfoM2UE42AkGaD90Y+bOIHFup8goJ11gVN50oTWn3mdajrhUgF+COkCeR1XJWz9hgyWpckGnbNPajcEbEeGiiUxYrCGjlp+hS8iAQvpAWhU0uDO2xtnNTZIuN3VpAqG+MjEJYPW2OwKdSYyO34h3m1wkrg+i/KFzBAUwtnHtWVeow+xZycVJx61+CXbAp+vy/ve2uCi+NkvyD03SAM2oAuykcsfW1ypVaOrRN5TUmYCBy7iAXuPZSShSwbhj5Y4e92Nn9uG5rlL5IdCQ22bbKw9G+VLKbQyppfDqgV4oIYgm0ToFMucIXAzz7rXNIJci6qLcI6QiHfatAm4/Vtmm3U241lDJ6uMlYzjl 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: From: Gou Hao when calling calc_slab_order(), 'slub_min_order' and 'size' are fixed values, if the condition of 'MAX_OBJS_PER_PAGE' is true, it will be returned from here every time. So we can calculate the condition of 'MAX_OBJS_PER_PAGE' before calling calculate_order(). Signed-off-by: Gou Hao --- mm/slub.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/mm/slub.c b/mm/slub.c index 39327e98fce3..ed6d797a5cd8 100644 --- a/mm/slub.c +++ b/mm/slub.c @@ -4094,9 +4094,6 @@ static inline unsigned int calc_slab_order(unsigned int size, unsigned int min_order = slub_min_order; unsigned int order; - if (order_objects(min_order, size) > MAX_OBJS_PER_PAGE) - return get_order(size * MAX_OBJS_PER_PAGE) - 1; - for (order = max(min_order, (unsigned int)get_order(min_objects * size)); order <= max_order; order++) { @@ -4457,9 +4454,14 @@ static int calculate_sizes(struct kmem_cache *s) size = ALIGN(size, s->align); s->size = size; s->reciprocal_size = reciprocal_value(size); - order = calculate_order(size); - if ((int)order < 0) + + if (order_objects(slub_min_order, size) > MAX_OBJS_PER_PAGE) + order = get_order(size * MAX_OBJS_PER_PAGE) - 1; + else + order = calculate_order(size); + + if ((int)order < 0 || order > slub_max_order) return 0; s->allocflags = 0;