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 50ACCEB64DD for ; Fri, 21 Jul 2023 21:01:40 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E02078D0002; Fri, 21 Jul 2023 17:01:39 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id DB2638D0001; Fri, 21 Jul 2023 17:01:39 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C7A998D0002; Fri, 21 Jul 2023 17:01:39 -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 B473B8D0001 for ; Fri, 21 Jul 2023 17:01:39 -0400 (EDT) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 6C454B1635 for ; Fri, 21 Jul 2023 21:01:39 +0000 (UTC) X-FDA: 81036840318.06.6E305CA Received: from mail-io1-f54.google.com (mail-io1-f54.google.com [209.85.166.54]) by imf14.hostedemail.com (Postfix) with ESMTP id 71FCB100033 for ; Fri, 21 Jul 2023 21:01:36 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=none; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" header.from=kernel.org (policy=none); spf=pass (imf14.hostedemail.com: domain of dennisszhou@gmail.com designates 209.85.166.54 as permitted sender) smtp.mailfrom=dennisszhou@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1689973297; 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-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=yM+Mlo3/qdURDyU/jOXBjf2mTfeeu/j5kwoCIZNPzV4=; b=1XDtkSK3/A7MLAURu2xpDZTlL1Xfu5GkJ8Wh9GcCF9Ow4UVWQ510s4WC0UNR8xw9a0UJnY 6vfmg9kOyUuxhRKHT1y3j0irQKjlN9v57aMkF2LitBnmRfmuXrnZEiTX6dOUHjdcW2tmIs Q3PFDVl3PfV/RoQlzjggL/SiGS8Q6XE= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=none; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" header.from=kernel.org (policy=none); spf=pass (imf14.hostedemail.com: domain of dennisszhou@gmail.com designates 209.85.166.54 as permitted sender) smtp.mailfrom=dennisszhou@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1689973297; a=rsa-sha256; cv=none; b=ifc8hl0Q8xroyAH/nmzkE/Kx3lq10PmecAHm/ZFY1w7cRPM8k1ySwZnu51B962O3kzmSpz 2WzSj49pgw389Boys+twh9jkxoKMFho5Z6PNLLy0sxB2WN1Oi6txAsBWevzY3QObXoGAKW R19f53Cpcwgngjng54Z9nCGokgNC7pY= Received: by mail-io1-f54.google.com with SMTP id ca18e2360f4ac-7835971026fso108243239f.3 for ; Fri, 21 Jul 2023 14:01:36 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689973296; x=1690578096; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=yM+Mlo3/qdURDyU/jOXBjf2mTfeeu/j5kwoCIZNPzV4=; b=TyI0tbNUBWa/2amBDjhhAePn1pmUYGJbJg0Q+I++QhDExBtuRoVcYOXe3IGzM/Nd5y dkr2ffsHLCRtvGo0AUl6qM14M1UTeWeyryK1PMSqTTM/6i09wmTT4sg0LzHt+KgcbFiO 1PZPBM92Fjt1s0sCE8fV4iUb+B3Gny+uTPo3AGnBKVIbYD5RG8cEBIaV4IfBJop2rS1S w/qZWYc4N2D4ysdikp0ux1HH6C24hu8J5LTiOM/zGE7HJrrBaVJVJXooUa1gG91CinbT N0di/Kr48kx5igpO/+WaZwX7PKAE22gxYwZgT+ZPn+C6+9CBXgc0v7od8tGiD8WQ0JKd SyDQ== X-Gm-Message-State: ABy/qLbqhrJ+ySn34rjcKX5SOYC6yVq3+m4bQ2ScXsEQPASzhrSrzd8w HanKlgI3EgAIKmTrjChzuJw= X-Google-Smtp-Source: APBJJlEkNbiIvlo9GdVjs7O3HS7p2Fincaq3SVX/f/JJcykDQH0nGgIFUG1fZgJmhjt9Ga2CfRUS3g== X-Received: by 2002:a05:6602:151:b0:787:5ca:d4f with SMTP id v17-20020a056602015100b0078705ca0d4fmr913746iot.8.1689973296198; Fri, 21 Jul 2023 14:01:36 -0700 (PDT) Received: from snowbird ([2601:282:1800:1f50::d356]) by smtp.gmail.com with ESMTPSA id c11-20020a6bfd0b000000b0076ffebfc9fasm1297464ioi.47.2023.07.21.14.01.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Jul 2023 14:01:35 -0700 (PDT) Date: Fri, 21 Jul 2023 14:01:34 -0700 From: Dennis Zhou To: Baoquan He Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, akpm@linux-foundation.org, tj@kernel.org, cl@linux.com, mawupeng1@huawei.com Subject: Re: [PATCH 2/3] mm/percpu.c: optimize the code in pcpu_setup_first_chunk() a little bit Message-ID: References: <20230721131800.20003-1-bhe@redhat.com> <20230721131800.20003-3-bhe@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230721131800.20003-3-bhe@redhat.com> X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 71FCB100033 X-Stat-Signature: 337xhwrdan7q1smctdczuboautp46k55 X-Rspam-User: X-HE-Tag: 1689973296-884208 X-HE-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QZlwAX7PGBedotp8M/nnqjylqfilj+rtVHZd3aVaSzHLjwMK4KyVEukK0aSrZseqM8lFtEjxmXiiN08UULpGb5sP7qvbmt+UbW1AQhbxfh759+KjGqo1gbHCf2dS4NF9bIAAeMlZ+PtyTCCWqOZo4vJefc2vep1iYOrp6SZa78HB4vdLi5AI87nwyzTEDJrdelQcvYgEXvCpQAm0l5GyhocJTOAThzSXlAZPuh3eZN19uNmFTesHshE7NLdoChwH4so48liSnN1eTw64AJwlBsTPIrRK3FN1tRsqwa1h7IjvpThJnkHA2ivsZsjUPakbpfDhsTa6kGQv0+D98X+evyBiElC3ETTvqq8bNyuYBcqz2b7MGlgfPBmXOrTin9RIlie4XiK/raOoQ66QzIdDVuL++jLuzW5hepYp/isOJAVhesQXawXrPZItr3bDIw0q8bXMjgPyUfQ/Zw9oCu2nbbUrKReRBOsgKvG70xQO8xCI= 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: Hello, On Fri, Jul 21, 2023 at 09:17:59PM +0800, Baoquan He wrote: > This removes the need of local varibale 'chunk', and optimize the code > calling pcpu_alloc_first_chunk() to initialize reserved chunk and > dynamic chunk to make it simpler. > > Signed-off-by: Baoquan He > --- > mm/percpu.c | 32 +++++++++++++------------------- > 1 file changed, 13 insertions(+), 19 deletions(-) > > diff --git a/mm/percpu.c b/mm/percpu.c > index 1480bf283d11..c25b058a46ad 100644 > --- a/mm/percpu.c > +++ b/mm/percpu.c > @@ -2581,7 +2581,6 @@ void __init pcpu_setup_first_chunk(const struct pcpu_alloc_info *ai, > { > size_t size_sum = ai->static_size + ai->reserved_size + ai->dyn_size; > size_t static_size, dyn_size; > - struct pcpu_chunk *chunk; > unsigned long *group_offsets; > size_t *group_sizes; > unsigned long *unit_off; > @@ -2697,7 +2696,7 @@ void __init pcpu_setup_first_chunk(const struct pcpu_alloc_info *ai, > pcpu_unit_pages = ai->unit_size >> PAGE_SHIFT; > pcpu_unit_size = pcpu_unit_pages << PAGE_SHIFT; > pcpu_atom_size = ai->atom_size; > - pcpu_chunk_struct_size = struct_size(chunk, populated, > + pcpu_chunk_struct_size = struct_size((struct pcpu_chunk *)0, populated, > BITS_TO_LONGS(pcpu_unit_pages)); > > pcpu_stats_save_ai(ai); > @@ -2735,28 +2734,23 @@ void __init pcpu_setup_first_chunk(const struct pcpu_alloc_info *ai, > > /* > * Initialize first chunk. > - * If the reserved_size is non-zero, this initializes the reserved > - * chunk. If the reserved_size is zero, the reserved chunk is NULL > - * and the dynamic region is initialized here. The first chunk, > - * pcpu_first_chunk, will always point to the chunk that serves > - * the dynamic region. > + * If the reserved_size is non-zero, initializes the reserved chunk ^initialize > + * firstly. If the reserved_size is zero, the reserved chunk is NULL ^ can remove firstly. > + * and the dynamic region is initialized directly. The first chunk, > + * pcpu_first_chunk, will always point to the chunk that serves the > + * dynamic region. Reading this, I'll probably reword this comment to explain the reserved chunk better. > */ > tmp_addr = (unsigned long)base_addr + static_size; > - map_size = ai->reserved_size ?: dyn_size; > - chunk = pcpu_alloc_first_chunk(tmp_addr, map_size); > - > - /* init dynamic chunk if necessary */ > if (ai->reserved_size) { > - pcpu_reserved_chunk = chunk; > - > - tmp_addr = (unsigned long)base_addr + static_size + > - ai->reserved_size; > - map_size = dyn_size; > - chunk = pcpu_alloc_first_chunk(tmp_addr, map_size); > + map_size = ai->reserved_size; > + pcpu_reserved_chunk = pcpu_alloc_first_chunk(tmp_addr, map_size); > } > > - /* link the first chunk in */ > - pcpu_first_chunk = chunk; > + /* init dynamic chunk if necessary */ > + tmp_addr += (unsigned long)ai->reserved_size; I'm not a big fan of += the tmp_addr as I personally find it easier to read if it's just laid out explicitly. > + map_size = dyn_size; > + pcpu_first_chunk = pcpu_alloc_first_chunk(tmp_addr, map_size); > + > pcpu_nr_empty_pop_pages = pcpu_first_chunk->nr_empty_pop_pages; > pcpu_chunk_relocate(pcpu_first_chunk, -1); > > -- > 2.34.1 > Overall, I think this is good, but I'd go 1 step further and get rid of map_size. Regarding tmp_addr, I'd prefer if we kept all the math together. Thanks, Dennis