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 6B7C5EB64DD for ; Sat, 22 Jul 2023 01:14:49 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C6BEE6B0071; Fri, 21 Jul 2023 21:14:48 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C1BB98D0001; Fri, 21 Jul 2023 21:14:48 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id ABC806B0074; Fri, 21 Jul 2023 21:14:48 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 98F686B0071 for ; Fri, 21 Jul 2023 21:14:48 -0400 (EDT) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 53A5AC0474 for ; Sat, 22 Jul 2023 01:14:48 +0000 (UTC) X-FDA: 81037478256.13.3D41239 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf24.hostedemail.com (Postfix) with ESMTP id 6EFB7180003 for ; Sat, 22 Jul 2023 01:14:45 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=iycTMBMf; spf=pass (imf24.hostedemail.com: domain of bhe@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=bhe@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1689988485; 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:dkim-signature; bh=b6R1QlipilZ8PvReJeTFJdQRGxlgRH9JHq1e33Yk320=; b=GvQst+2XuehCqMI7qL8Th1F3QrKg1vLoTpvasd/ZV3TB77yHKYXSKmBG7jSXCLpg3BKsV5 oyqAnye7LVTpOg6BMkst78Q78MNb0rdNT7l+cXaTXPBMFbr0VYhounuMjRjzFNVmdM8Hj9 Poc3ZmxwEx4k55xSmOqM5Y79bUh/rMg= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=iycTMBMf; spf=pass (imf24.hostedemail.com: domain of bhe@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=bhe@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1689988485; a=rsa-sha256; cv=none; b=a/82GHU2+s4pOFF4VKnURsftKDcQoQSBQOWw4Ymszd2XtITG+YNCSdZzJ8PUH7MnJc9zob iaqwmSuq0rG4O6k3X2pMd+w/mr62KlcuCgY8ii2igqRT5wt2dSvyKHUNpfGkVFdSL5GKMD rEVXVo/jhhy1TZQy1vGkW2UbYu30+h4= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1689988484; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=b6R1QlipilZ8PvReJeTFJdQRGxlgRH9JHq1e33Yk320=; b=iycTMBMfymZ/yZNfZJ6vYvDQGoSxtxe85Wqjs4GX3U2GDn9etHxtYk7YGQcO5LLTn6ftng +bGzFIdy2DwsbMEaqq5WioP6BiKkZSg5Mg0ibHy7cJMpzwDIaC9iNbYzLt6NvoLkr62uiV 28N3GOO/zHa7bNJN3kM492kzXidweAA= Received: from mimecast-mx02.redhat.com (66.187.233.73 [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-314-hhOyGdPgPGOUGHeqaxD95g-1; Fri, 21 Jul 2023 21:14:43 -0400 X-MC-Unique: hhOyGdPgPGOUGHeqaxD95g-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id B2CDB29AA2C2; Sat, 22 Jul 2023 01:14:42 +0000 (UTC) Received: from localhost (ovpn-12-31.pek2.redhat.com [10.72.12.31]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 534F9492C13; Sat, 22 Jul 2023 01:14:40 +0000 (UTC) Date: Sat, 22 Jul 2023 09:14:37 +0800 From: Baoquan He To: Dennis Zhou 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: X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 X-Rspamd-Queue-Id: 6EFB7180003 X-Rspam-User: X-Stat-Signature: xp5z8hhtif898bbgx9417g3qz1u8rcsr X-Rspamd-Server: rspam01 X-HE-Tag: 1689988485-643501 X-HE-Meta: U2FsdGVkX1+LDjM5YaEaVrwaLf6UDFa2SOW9VT8Bu6LmSgrCI4BT1TheXjwX/OnP3ylpUUTh5iudezTd4Y+Tj4CLG1z8wzsBT1ly1CcPkD7UyPaTKOSqa4hMXdTBnG2Yv8j+FCyggl3z0D2z4U7D8CJTfq1AVaeeiMRlOF3empSbL7PyfdgbFsA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osity: 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 07/21/23 at 02:01pm, Dennis Zhou wrote: > 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. Agree. The expression is a little messy and too colloquial. > > > */ > > 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. OK, will change. > > > + 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. Makes sense. Thanks a lot for your careful review and great suggestions. According to your comments, I made a draft v2. Please help check if I have got them correctly and if the new change is OK to you. >From 17832ce8a755d8327b853a18c6f1cc00c9f93e50 Mon Sep 17 00:00:00 2001 From: Baoquan He Date: Tue, 27 Jun 2023 09:33:28 +0800 Subject: [PATCH] mm/percpu.c: optimize the code in pcpu_setup_first_chunk() a little bit Content-type: text/plain 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 | 36 +++++++++++++----------------------- 1 file changed, 13 insertions(+), 23 deletions(-) diff --git a/mm/percpu.c b/mm/percpu.c index 1480bf283d11..83fc47206680 100644 --- a/mm/percpu.c +++ b/mm/percpu.c @@ -2581,14 +2581,12 @@ 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; unsigned int cpu; int *unit_map; int group, unit, i; - int map_size; unsigned long tmp_addr; size_t alloc_size; @@ -2697,7 +2695,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); @@ -2734,29 +2732,21 @@ void __init pcpu_setup_first_chunk(const struct pcpu_alloc_info *ai, dyn_size = ai->dyn_size - (static_size - ai->static_size); /* - * 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. + * Initialize first chunk: + * + * - If the reserved_size is non-zero, initialize the reserved + * chunk firstly. Otherwise, the reserved chunk is NULL. + * + * - The first chunk, pcpu_first_chunk, always points to the + * chunk that serves the dynamic region. */ 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); - } + if (ai->reserved_size) + pcpu_reserved_chunk = pcpu_alloc_first_chunk(tmp_addr, + ai->reserved_size); + tmp_addr = (unsigned long)base_addr + static_size + ai->reserved_size; + pcpu_first_chunk = pcpu_alloc_first_chunk(tmp_addr, dyn_size); - /* link the first chunk in */ - pcpu_first_chunk = chunk; pcpu_nr_empty_pop_pages = pcpu_first_chunk->nr_empty_pop_pages; pcpu_chunk_relocate(pcpu_first_chunk, -1); -- 2.34.1