From patchwork Sat Apr 30 00:25:55 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wonhyuk Yang X-Patchwork-Id: 12833010 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 545FAC433EF for ; Sat, 30 Apr 2022 00:26:06 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8EF6C6B0071; Fri, 29 Apr 2022 20:26:05 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8AA716B0072; Fri, 29 Apr 2022 20:26:05 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 741CC6B0073; Fri, 29 Apr 2022 20:26:05 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.a.hostedemail.com [64.99.140.24]) by kanga.kvack.org (Postfix) with ESMTP id 650976B0071 for ; Fri, 29 Apr 2022 20:26:05 -0400 (EDT) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 38F0D28CDE for ; Sat, 30 Apr 2022 00:26:05 +0000 (UTC) X-FDA: 79411653090.28.E4DE045 Received: from mail-pj1-f53.google.com (mail-pj1-f53.google.com [209.85.216.53]) by imf21.hostedemail.com (Postfix) with ESMTP id ABAC01C006E for ; Sat, 30 Apr 2022 00:26:00 +0000 (UTC) Received: by mail-pj1-f53.google.com with SMTP id r9so8363537pjo.5 for ; Fri, 29 Apr 2022 17:26:04 -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=wj0GCAwyvudPRmGRRgsX12+MeUaxxTPPMDMQ7+QSvNg=; b=l+jK1iji/9TzBj7wkgUFu/NItPRwk6FZVFT2XJAwgjLa7CgwjRFyTekvMZlCecijWr Rt+D6gKOqH/P69hDamtFwIfI6eu1sOM319CwQF0hbH+l5aYNTatIGAsZJXxJ+xT0DdHr eHvzW17qMHRMQSmyfKli/H+Wh/zCToKvFPDZNiHmG6FkZH6gE7Rp+JIY/zAAFsrRJvdq 5OKUiZDl62LVYIEs3Z0zCu+f/XqJ77zb1EWE6jj2Z5/Iz+yFG0O9EhK72C8Dbe8uln+B L/XaS/44KYb+2TvpdnAvY3wrU9/4t/BoYR9bYSKw5yz2JnLTIVPmuVnEnGfqd5BrqZ1E S4Ag== 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=wj0GCAwyvudPRmGRRgsX12+MeUaxxTPPMDMQ7+QSvNg=; b=gZEEQr6x6CgLDwr3S6vm7U41uqoDL1EGL/veCZMra+5xUoiqQjzFyRUXWsDkrkjiIK L0KCa1U/M+LlOrhgaYE53h3ks7pzyprXZt5MhoUPVY/AL3NgO09EnRFu1IcOhur1YkAT rugZLmPYahShD0MfqCOuRsWWM9GpZe8aP+PORNFwxWEm9AlNlED8v4sr5+0pEGs6DH4N +rAxLNW0o3kY+MkDffgXFYcfaX/mY+y7VpTBpYZ4cXOpfGw/XW6LsaEnjEpSuuQ9gWsd YHhbaQOqdODcQflP1FpnNAxUKY1W912VxkD0AN5qRK59GdG8iW4KelOVDnwDvfDLn6cD 65Ug== X-Gm-Message-State: AOAM5302p+FhyOXfiBND3kfI8pf6BsalYGRhD7AU6u/lA96NV3P6m+s/ Y5lrzFxqXHv7vaGfOlQvDyo= X-Google-Smtp-Source: ABdhPJwbC29ym+34xajMXMcVDFqWB0hl6bj7vlrp2zq9ZwucXZYdNW6X1oLcnNgIex9U5/T1FF2XEw== X-Received: by 2002:a17:902:82c9:b0:15d:3a76:936f with SMTP id u9-20020a17090282c900b0015d3a76936fmr1733796plz.139.1651278363471; Fri, 29 Apr 2022 17:26:03 -0700 (PDT) Received: from localhost.localdomain ([125.131.156.123]) by smtp.gmail.com with ESMTPSA id u12-20020a170902e80c00b0015e8d4eb25fsm181271plg.169.2022.04.29.17.26.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Apr 2022 17:26:02 -0700 (PDT) From: Wonhyuk Yang To: Christoph Lameter , Pekka Enberg , David Rientjes , Joonsoo Kim , Andrew Morton , Vlastimil Babka , Roman Gushchin Cc: Wonhyuk Yang , Hyeonggon Yoo <42.hyeyoo@gmail.com>, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [Patch v3] mm/slub: Remove repeated action in calculate_order() Date: Sat, 30 Apr 2022 09:25:55 +0900 Message-Id: <20220430002555.3881-1-vvghjk1234@gmail.com> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: ABAC01C006E Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=l+jK1iji; spf=pass (imf21.hostedemail.com: domain of vvghjk1234@gmail.com designates 209.85.216.53 as permitted sender) smtp.mailfrom=vvghjk1234@gmail.com; dmarc=pass (policy=none) header.from=gmail.com X-Rspam-User: X-Stat-Signature: zikgg3tce15wcnbmnb97d1xj56yo19ik X-HE-Tag: 1651278360-135820 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 1, 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> --- mm/slub.c | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/mm/slub.c b/mm/slub.c index ed5c2c03a47a..1fe4d62b72b8 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, get_order(size)); +out: if (order < MAX_ORDER) return order; return -ENOSYS;