From patchwork Sat Apr 16 07:40:59 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wonhyuk Yang X-Patchwork-Id: 12815708 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 28C04C433EF for ; Sat, 16 Apr 2022 07:41:38 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A9F886B0073; Sat, 16 Apr 2022 03:41:37 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A50BB6B0074; Sat, 16 Apr 2022 03:41:37 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 917986B0075; Sat, 16 Apr 2022 03:41:37 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.hostedemail.com [64.99.140.26]) by kanga.kvack.org (Postfix) with ESMTP id 858356B0073 for ; Sat, 16 Apr 2022 03:41:37 -0400 (EDT) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 655CC1387 for ; Sat, 16 Apr 2022 07:41:37 +0000 (UTC) X-FDA: 79361947434.23.7CE7204 Received: from mail-pg1-f176.google.com (mail-pg1-f176.google.com [209.85.215.176]) by imf23.hostedemail.com (Postfix) with ESMTP id D7BB7140008 for ; Sat, 16 Apr 2022 07:41:36 +0000 (UTC) Received: by mail-pg1-f176.google.com with SMTP id s137so10061803pgs.5 for ; Sat, 16 Apr 2022 00:41:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=YTmNGfrC+3pxkSIDNGI4Pu99E1WgWPC8IWfV/O/1jPo=; b=BuaJUevtcqJmCeqT9gjYj5JDfFjXqxpdLmSEYY3wyml2Ixmo/t7AumlMXEtfwsYnLz QT5QXdDnuywbvgo0TwQN9kjAZOnElhfXKh1CfYKSZpk2/hkTsJSJJyK2aS/mVm6T+dyP srFde8KDdu3+trIBgOq2ZPMXjYjG2aPkbEpDLe+tEQw1+ZnaU0NYCDEkPLvNn+qrN/vn DD3sp6tYHmSfb8HeauRdIoX3NYLHU5WCp65UVnrSxrf/p8clRN61C/5yg7Avdkobte1R Erf8GEEmFjF7N9IO+vB7BeHMAQ4mwTQqghPKnANEa5Nn3zaVbbGa15QqQ86t5Wz7yRxp Ob1g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=YTmNGfrC+3pxkSIDNGI4Pu99E1WgWPC8IWfV/O/1jPo=; b=qvKoe0k93hp/XlZUoBvL3jhQe52PNtExVOr/NHuEIUEF4JcmxVkjaf9245ZhpY8yrd hqp36Dpxx0s+ip+w6L5LesxleJnDtbHVsXYdcV4Pd+VtNpC0UzHO9nFf1kP8/oR+abnP M8prupo2gnnqG3E1WZAQRZeF9w994Wwhcf3R9bG91elhGioGT96kvE9ht69EUj72+O+k fsmVHvgjZRvYtNGmlRzhjAbcbxtudmyAEadHG6TDbZ5kzaCraH0HUnkBtTpltF3iu/6y bD15hdBlIddt78Y5gpPhnI+RUgiOKGjhC6oHyXtti6jMtBWG9JW8hGD9nIrENmeChScp 8tGg== X-Gm-Message-State: AOAM531bsEYloId8YCcSPbUuGxJ6sDD+qtgh/Secq8MJPyaoBtgRYzu9 F6rWjDsiFXVXffaJgAvCPbc= X-Google-Smtp-Source: ABdhPJx2jNKo3m5uktJcIeP3hTP5PFlKUvfSL5GX+AWVcLyenjLIBkBQzJADzIwtVmRfGoLRG8RyOg== X-Received: by 2002:a63:ad0c:0:b0:374:50b4:c955 with SMTP id g12-20020a63ad0c000000b0037450b4c955mr2037578pgf.530.1650094895773; Sat, 16 Apr 2022 00:41:35 -0700 (PDT) Received: from localhost.localdomain ([125.131.156.123]) by smtp.gmail.com with ESMTPSA id e6-20020a056a001a8600b004fac74c8382sm5078720pfv.47.2022.04.16.00.41.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 16 Apr 2022 00:41:35 -0700 (PDT) From: Wonhyuk Yang To: Christoph Lameter , Pekka Enberg , David Rientjes , Joonsoo Kim , Andrew Morton , Vlastimil Babka , Roman Gushchin Cc: Ohhoon Kwon , JaeSang Yoo , Wonhyuk Yang , Jiyoup Kim , Donghyeok Kim , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH v2] mm/slub: Remove repeated action in calculate_order() Date: Sat, 16 Apr 2022 16:40:59 +0900 Message-Id: <20220416074059.526970-1-vvghjk1234@gmail.com> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: D7BB7140008 X-Stat-Signature: wdaexia5k3re4dqq8qj31tcxfk1zyj5g Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=BuaJUevt; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf23.hostedemail.com: domain of vvghjk1234@gmail.com designates 209.85.215.176 as permitted sender) smtp.mailfrom=vvghjk1234@gmail.com X-HE-Tag: 1650094896-124973 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: To calculate order, calc_slab_order() is called repeatly changing the fract_leftover. Thus, the branch which is not dependent on fract_leftover is executed repeatly. So make it run only once. Plus, when min_object reached to 0, we set fract_leftover to 1. In this case, we can calculate order by max(slub_min_order, get_order(size)) instead of calling calc_slab_order(). No functional impact expected. Signed-off-by: Wonhyuk Yang Reviewed-by: Hyeonggon Yoo <42.hyeyoo@gmail.com> --- V1 -> V2: Fix typo miss in a commit message mm/slub.c | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/mm/slub.c b/mm/slub.c index ed5c2c03a47a..e7a394d7b75a 100644 --- a/mm/slub.c +++ b/mm/slub.c @@ -3795,9 +3795,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++) { @@ -3820,6 +3817,11 @@ static inline int calculate_order(unsigned int size) unsigned int max_objects; unsigned int nr_cpus; + if (unlikely(order_objects(slub_min_order, size) > MAX_OBJS_PER_PAGE)) { + order = get_order(size * MAX_OBJS_PER_PAGE) - 1; + goto out; + } + /* * Attempt to find best configuration for a slab. This * works by first attempting to generate a layout with @@ -3865,14 +3867,8 @@ static inline int calculate_order(unsigned int size) * We were unable to place multiple objects in a slab. Now * lets see if we can place a single object there. */ - order = calc_slab_order(size, 1, slub_max_order, 1); - if (order <= slub_max_order) - return order; - - /* - * Doh this slab cannot be placed using slub_max_order. - */ - order = calc_slab_order(size, 1, MAX_ORDER, 1); + order = max_t(unsigned int, slub_min_order, (unsigned int)get_order(size)); +out: if (order < MAX_ORDER) return order; return -ENOSYS;