From patchwork Fri Jul 21 13:17:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baoquan He X-Patchwork-Id: 13321976 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 1BAB6EB64DD for ; Fri, 21 Jul 2023 13:18:25 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A93B58D0003; Fri, 21 Jul 2023 09:18:24 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A1B718D0002; Fri, 21 Jul 2023 09:18:24 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 895588D0003; Fri, 21 Jul 2023 09:18:24 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 76CC08D0002 for ; Fri, 21 Jul 2023 09:18:24 -0400 (EDT) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 469B7B13EC for ; Fri, 21 Jul 2023 13:18:24 +0000 (UTC) X-FDA: 81035672928.01.27BC00E Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf03.hostedemail.com (Postfix) with ESMTP id 52FA72001D for ; Fri, 21 Jul 2023 13:18:22 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=TRZPfvZM; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf03.hostedemail.com: domain of bhe@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=bhe@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1689945502; 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:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=LHVCmyopA5Gpa/p3+Tf6DYpT7yyPaihL3mV5AOHJdCk=; b=CkbNTdBagNrc7D75TsNn5HG5k1bJulUtV3visD1ea35ZJ7j9+HxJ/UicCcMU1EoMhsOmbI 1RXhnvdkbQTTIePud9S0tyB6RREayYYmlevQZ29me0VmSvbNB6xFrXXHPSZfE5meLSJR4S 2hCtcVTXqWp6V2dVbx5UnejcSARQ1qo= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=TRZPfvZM; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf03.hostedemail.com: domain of bhe@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=bhe@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1689945502; a=rsa-sha256; cv=none; b=5NXGqYWeqEecg9EwQgyTVcEPQ8sXEwUFe/ol9w2NH8Ij+LlVGrNq5p7HjU5BHu2niwEbjN m9w2zglmAqCK+CJzb7ZBrOdIgVTwTU5AbAuohrwrZzJHVrXAy7WuDlraph5iImWGCTPzfJ emm5xlwES9CU7w3FJHrzsMlbf+ZmH0A= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1689945501; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=LHVCmyopA5Gpa/p3+Tf6DYpT7yyPaihL3mV5AOHJdCk=; b=TRZPfvZMl60v1FUXjAXQsiyd9NcPn7L/NZJutjHBFZ2bCU7/WLMlSNlDTpj1ne26Ilb9YT 5AyT1g57AQ0jCDi+/5RRpLg0E0Tws3bE7bniOGOr33TM2XI2pTJXAYT7pyZ+EuUl+YDs+5 DvEK67uCNSiixb5VDSMUx5RV1ZUpD4E= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-46-gPqUh22iP5KQ72sCd8VWSA-1; Fri, 21 Jul 2023 09:18:18 -0400 X-MC-Unique: gPqUh22iP5KQ72sCd8VWSA-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 7C41080123E; Fri, 21 Jul 2023 13:18:17 +0000 (UTC) Received: from MiWiFi-R3L-srv.redhat.com (ovpn-12-18.pek2.redhat.com [10.72.12.18]) by smtp.corp.redhat.com (Postfix) with ESMTP id 771C540C2071; Fri, 21 Jul 2023 13:18:13 +0000 (UTC) From: Baoquan He To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, akpm@linux-foundation.org, dennis@kernel.org, tj@kernel.org, cl@linux.com, mawupeng1@huawei.com, Baoquan He Subject: [PATCH 2/3] mm/percpu.c: optimize the code in pcpu_setup_first_chunk() a little bit Date: Fri, 21 Jul 2023 21:17:59 +0800 Message-Id: <20230721131800.20003-3-bhe@redhat.com> In-Reply-To: <20230721131800.20003-1-bhe@redhat.com> References: <20230721131800.20003-1-bhe@redhat.com> MIME-Version: 1.0 Content-type: text/plain X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 52FA72001D X-Stat-Signature: 1k6a9kwxbqoujaamncdf8nj718wijbct X-HE-Tag: 1689945502-806869 X-HE-Meta: U2FsdGVkX19Zvo6pP5577aHWL4OuMSpbr0aIY1IEF3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rmcbQweOJ5J46YnQ3n7rNdX2sEmin40wHGwe1gfRnM7oDqzSAa1dwfbi0AWoGCZkTaCBk/ZM5PzKAg1IGKOnbMQ== 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: 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 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 + * firstly. If the reserved_size is zero, the reserved chunk is NULL + * and the dynamic region is initialized directly. The first chunk, + * pcpu_first_chunk, will always point 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); + 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; + 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);