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 D1F5EC433EF for ; Sun, 17 Apr 2022 06:21:20 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 36E8B6B0072; Sun, 17 Apr 2022 02:21:20 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 31E5E6B0073; Sun, 17 Apr 2022 02:21:20 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 20CEA6B0074; Sun, 17 Apr 2022 02:21:20 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.hostedemail.com [64.99.140.28]) by kanga.kvack.org (Postfix) with ESMTP id 1124F6B0072 for ; Sun, 17 Apr 2022 02:21:20 -0400 (EDT) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay11.hostedemail.com (Postfix) with ESMTP id DA52481A26 for ; Sun, 17 Apr 2022 06:21:19 +0000 (UTC) X-FDA: 79365373878.22.8EEE930 Received: from mail-yb1-f181.google.com (mail-yb1-f181.google.com [209.85.219.181]) by imf13.hostedemail.com (Postfix) with ESMTP id 7C43720008 for ; Sun, 17 Apr 2022 06:21:19 +0000 (UTC) Received: by mail-yb1-f181.google.com with SMTP id j2so21007810ybu.0 for ; Sat, 16 Apr 2022 23:21:19 -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=UYimQXzjWqzb40fO/1C9OZnRSRr/Zk7PyszpEA08vvI=; b=K3UEB8+S1XcuLnW9dHmFz0IzQjCs8XSMr5L5LRen7i093XYkd88sO31b1MeHOUktVG Loo1UiIhSQQKly1d30UOmKJ6w3uVj1c2bDNQO2fzBVF5MoQADTjX4s4zCTCawBJemDn7 pn5z4QvAUvcBcZf6Qyj56ptjMv28EAXsNxAPDdhK0/6fCL455YIIMHlevAHdTYRUhQRp kzVNUDFwwNPZecaAPBq5XiXhY/lVSrAfr4tyRkMy2deHMlKDezX0IWqTMlzL3KZESeMf IGaI0wXMcHXlW4lCcIquuATEFGhMwtU5w5Xg/HO8dYtCzp7gTkvnCeOVv+w+mGv7HEEa 0DKg== 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=UYimQXzjWqzb40fO/1C9OZnRSRr/Zk7PyszpEA08vvI=; b=n+uW+SuQ640xL57UqTFJ3yJ0ZM1Pu7upm6rrQVpM8FJw3dAAqYqvXkD7j08Li0V8v1 seIRXx64W5FhwLxndaZ6bNZPPjho86o4whcJldGeXdNxdOQKNd4mMxFOkosD5lSblDR3 hUX1JSbqaeWkvf+yPX3V/oHBF+FFwvYv44aR2BzMlNBesMLAr/+3goTyQfepkwaTxBLN JtaRYqDDk8B3dX3W9sKGQg0PHFxGBcT3/kWC5DUjDk2pG3jp2kABsAkQieZ0JOSatbSm d2Oo4TRPoIrmIBrn1QBUhwxq7260SHz6iVI8KpyVY7nlb/7+cQHp9gpFL5nyTYMbGAXS 4MHg== X-Gm-Message-State: AOAM531vfao+BVuC/oZwkeRbAv4AYtHyOMSvTguroTNZxArqLVKg3EFy 7dAY3wW0w3Zr8A1y3wjjCKk655M8tuc9hXccDeM= X-Google-Smtp-Source: ABdhPJyrMjI6snmoZNuw5XepVTzgpUZZl9dLfKD5fCNuvTzSIu1PSHCyJnMH2nCMbdEvMYI+2drWwha4I5VBRFxuD2Q= X-Received: by 2002:a5b:ac9:0:b0:641:8ac2:aa5e with SMTP id a9-20020a5b0ac9000000b006418ac2aa5emr5457447ybr.50.1650176478789; Sat, 16 Apr 2022 23:21: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:21: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" X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: 7C43720008 X-Stat-Signature: 8fyftx31yc4p8z4syxrsgtjwyzth3kfd Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=K3UEB8+S; spf=pass (imf13.hostedemail.com: domain of vvghjk1234@gmail.com designates 209.85.219.181 as permitted sender) smtp.mailfrom=vvghjk1234@gmail.com; dmarc=pass (policy=none) header.from=gmail.com X-Rspam-User: X-HE-Tag: 1650176479-971878 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000003, 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 11:07 AM Hyeonggon Yoo <42.hyeyoo@gmail.com> wrote: > > On Sun, Apr 17, 2022 at 10:43:20AM +0900, Hyeonggon Yoo 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. > > > > > 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. > > > > > 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). > > But yeah, maybe it's worth for better maintenance of code. > > So after considering my comments, feel free to add: > Reviewed-by: Hyeonggon Yoo <42.hyeyoo@gmail.com> > > Thanks! > Thanks for taking the time to review Hyeonggon!