From mboxrd@z Thu Jan 1 00:00:00 1970 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 32D81C433F5 for ; Sun, 17 Apr 2022 06:17:21 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4856B6B0072; Sun, 17 Apr 2022 02:17:20 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4346C6B0073; Sun, 17 Apr 2022 02:17:20 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2D58F6B0074; Sun, 17 Apr 2022 02:17:20 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.hostedemail.com [64.99.140.25]) by kanga.kvack.org (Postfix) with ESMTP id 199676B0072 for ; Sun, 17 Apr 2022 02:17:20 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id C7C95240F2 for ; Sun, 17 Apr 2022 06:17:19 +0000 (UTC) X-FDA: 79365363798.19.C0682B8 Received: from mail-yb1-f170.google.com (mail-yb1-f170.google.com [209.85.219.170]) by imf22.hostedemail.com (Postfix) with ESMTP id 0EDD4C0006 for ; Sun, 17 Apr 2022 06:17:18 +0000 (UTC) Received: by mail-yb1-f170.google.com with SMTP id m132so20928877ybm.4 for ; Sat, 16 Apr 2022 23:17:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=leDgynV+ujUVCmP8gHEBiaj8szQTU9a+b8YdxSYSrEo=; b=hXjmP63NBnxBsIZ9pGc9BjrZ5ijRcBF7UGZ7Wsu8qrJ5IcFnIcJvbhIpceZBmgRi31 U32ucpUmUbSKMU9ePwS0fA/cIaxNSjfh45lziYMjuiJ+hDIBRKV3l+Cqu38FNggLp9+h EjIHBgSB2PQs9UmfRP/rQuURxK5DYSP+5vOizFPynjcTf54MwJf8pu+okKWRu647ERQI 3iRSP+YGexv34Utxid0DV0Z6S4Clw02tVv3VJ2npH2BCAn4xBsl+TJISSDqoTm4+dnnL rAjCoxo7wP3JpNWpk4qslKfQCCEwkq9N0VzyZiwrIbPHDlCzPuKkvpNwntJtL+M1QjQ0 SkQw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=leDgynV+ujUVCmP8gHEBiaj8szQTU9a+b8YdxSYSrEo=; b=1c7p8WkgPimVur1gJz1E8+uQwd+IsnNWd/++ZtxU2N1QDsbgTN5bKc9ElIAAeTNswQ ssF1sRavUJ/UmyshGecvvX6NLI4GeHA73Vlhb12umh7lN1ko2g7BDIROupK7MAKoSk8d bHGB85tlmu0jM7iDzTAqrKi7APX9vpXU36l2BVQSmseP825KfCF9UjO1kIbtoGDh+P9w MYzvOZ7ghFuRe2AaX0oZGrAxScbh5b/+5O0PnPWgwR0hVa+19hH2cMHkyYhfDohfmJwV kxESrhLceOkIYQtW8+DhPXv4NTg5qc1+JTlRUmbp7LF8R22jMONH8q8goookrQGZNVG4 IU1w== X-Gm-Message-State: AOAM531JzWRnGElMyG+stFaP93hcPZaZM21/Xr1OoZXE+BtDGo/iF5Gf mwnG9oD/8wotCS1cywsvBxRd0zKxr5fZuoL6IEs= X-Google-Smtp-Source: ABdhPJzEC4LcSFDCovop6KxhhoZtj8dXg9HDWbdjPGdEgB77k3cvqSoPhXZe4LjFA2/gdG7PNu1LV1fT+jmcXp5AK8E= X-Received: by 2002:a25:7b41:0:b0:641:26a9:9be3 with SMTP id w62-20020a257b41000000b0064126a99be3mr5169454ybc.163.1650176238278; Sat, 16 Apr 2022 23:17:18 -0700 (PDT) MIME-Version: 1.0 References: <20220416074059.526970-1-vvghjk1234@gmail.com> In-Reply-To: From: Wonhyuk Yang Date: Sun, 17 Apr 2022 15:17:07 +0900 Message-ID: Subject: Re: [PATCH v2] mm/slub: Remove repeated action in calculate_order() To: Hyeonggon Yoo <42.hyeyoo@gmail.com> Cc: Christoph Lameter , Pekka Enberg , David Rientjes , Joonsoo Kim , Andrew Morton , Vlastimil Babka , Roman Gushchin , Ohhoon Kwon , JaeSang Yoo , Jiyoup Kim , Donghyeok Kim , linux-mm@kvack.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=hXjmP63N; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf22.hostedemail.com: domain of vvghjk1234@gmail.com designates 209.85.219.170 as permitted sender) smtp.mailfrom=vvghjk1234@gmail.com X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 0EDD4C0006 X-Stat-Signature: cf77r54g9bt6ymfm9x9etkkt6m96r3wq X-HE-Tag: 1650176238-42626 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: On Sun, Apr 17, 2022 at 10:43 AM Hyeonggon Yoo <42.hyeyoo@gmail.com> wrote: > > On Sat, Apr 16, 2022 at 04:40:59PM +0900, Wonhyuk Yang wrote: > > 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 > > Maybe you mean when min_object reached 1. Yes, That comment need to be updated... > > > 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 > > --- > > 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: > > You don't need to cast value of get_order(size). max_t() does cast both operands. That's a good point, I will delete it. > > > if (order < MAX_ORDER) > > return order; > > return -ENOSYS; > > For the correctness of the patch, I don't see any problem about the > code. > > But to be honest I'm a bit skeptical about saving some cycles in > calculating slab order. It's done only when creating caches (usually in boot > process). >