Received: by 2002:ab2:6203:0:b0:1f5:f2ab:c469 with SMTP id o3csp2960607lqt; Tue, 23 Apr 2024 06:58:11 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXl45n8vE+ar0k1bp0m22wH8wcxaQZOmxfLQbgDJaRv4rBx/PuNOfrARouxl/OAUEDlQW2R1HxxA8JroMyWzvz72iegGfe+RibBOaucLg== X-Google-Smtp-Source: AGHT+IGnttr8AeZQEKNHNbsnAL/BJwGJaE/dJs3tjtTJlQTfZbEtZmvh2WWQTXc6mjOfjkYjRaam X-Received: by 2002:a17:907:7288:b0:a54:e183:6248 with SMTP id dt8-20020a170907728800b00a54e1836248mr12288820ejc.0.1713880691756; Tue, 23 Apr 2024 06:58:11 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713880691; cv=pass; d=google.com; s=arc-20160816; b=iUriS3mZdSVwrA9+HMaGiTGlvnfujQLH+Dd0WVneymfjrYcMJ+zXEF2oBQnMQOYghI +sC3e4nyNUhX5X0SMgfSmHGH+TJT3ZydaHBU/CQYvy13hegoVzxdao9u0PhIcZGvwhQx rHFGOCUDTopP5rU648f2Ph428AMd5+qgBnyYEwblq8gHTQLzqHLioVQZVeJXkQK8wTML IWg57MYPAJXXCvTaCzWzk7SZFWKmbdkyoam23QYM6Y63klVwvxWJ1WgXNJetE+8fkHho Pgaaty9Awa1Sq53Grzci+Y37HDg6Re7XWCNPn9Zot/Y3kP6byXWBqDUsAOqL6a1Tg5mt DsIw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=kQk5FyVP0lAkjPXrseFZ4aW2TL7nmZurojICLrE1sJU=; fh=XydXde5dLR54X7nJZwGU4Z1kFmE0b5onnv+0szv4U4w=; b=AWkLOIleQTR4UyVT+0tkokHsCyfYVIMUHR2mE3+Yy5knGznSMzVqgaJK0Eq2M/1unp 08TBogyC2HehfAp5Qe+IW2reaUHs9KnL/VjAKkp8Q4YNU9au3Bno0/fO1+KuWzTJ01ce jSINaB700FckvQcEKxmdLChPQaqYNNvWdC1xxZ5nk1Kl+Y85nkaBF5OYAG+yPi9iupMF kcI4Q6taN/xTDU7/WrDvRt078VhqEkj6xvRdxidO01rY2ILKpmck+H0hazwhbk84O8To KL8pyF53ZZQk1K6XBU4uMq7E8ksyPMXFxIzHWfUMW0EpnfzyOPBDIrzXZbBk+V+dVnjM e27Q==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=C3QL1llP; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-155317-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-155317-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id bo4-20020a170906d04400b00a55b57713d6si2590097ejb.588.2024.04.23.06.58.11 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Apr 2024 06:58:11 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-155317-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=C3QL1llP; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-155317-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-155317-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 5BE7A1F21FF3 for ; Tue, 23 Apr 2024 13:56:50 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2C03B136E22; Tue, 23 Apr 2024 13:56:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="C3QL1llP" Received: from mail-pg1-f176.google.com (mail-pg1-f176.google.com [209.85.215.176]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2534F135414 for ; Tue, 23 Apr 2024 13:56:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.176 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713880604; cv=none; b=tEJzEYyeXa9v3xWfXCw7W70X1HsfUR1IR7aD2bG8fCcbss4H8RXlP3JDO4naCa61Ee4V5Wy3thWKINK5pYifoE5fX9NKzSjIElsh7G1puyQPwqQeE9ijjEuu5lM02zCIkpNMCl/62xH3gRRcycl0URTKMBZW/pgh5g9RnvbYYvc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713880604; c=relaxed/simple; bh=eIDuK7Btp+udf2fVv94JzYZMy4NbqqbriW7Pgan3wkg=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=NDh+COAu7jkMWHueFxwktezpctvgOpMagDhoklBd5cIfhT7PkuhLk1Wp7NlFryirijQ1av8xIbZSh9EmNb+BbAJv6v0SAFXp+LG102rTTBVgeR8+0ENzXsbQr8xudors5kYRpOZC1nqHNoR9wvRi4dvkMjiw0J34tdH53S+35N0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=C3QL1llP; arc=none smtp.client-ip=209.85.215.176 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pg1-f176.google.com with SMTP id 41be03b00d2f7-5d3912c9a83so3898254a12.3 for ; Tue, 23 Apr 2024 06:56:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1713880602; x=1714485402; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=kQk5FyVP0lAkjPXrseFZ4aW2TL7nmZurojICLrE1sJU=; b=C3QL1llPHVNesFaFRxCoejLZbYYnNlXsJw6zcDDr0h/cVhyyUeSAHp66gG8LxgikrB 4ZKnx+vdAWpTBXGH6EB67O3bll9Q7XFRp5fSag3kNNhDW9NbMQwhrhbxiRBV9hrQZnyK VhJyBp9M0r38XYgZyIr57QRnLva3qtsu4H8z2OUTHD4Cu/UhorzZ47rwpQ6GM/iXCl1I CVdXlHfxfsUqm3OrtIV4L5wY3SgPLrnItEK/t/h/cjLdXp/w/PwBBZj3MCdhy/KPKLAd bSCepC7XSJhwSZzmU3WDRKxwGHeEn43cPFGhhhWmzsZVh1Gv6Zh6wnsUTfmqNpRgApJh wyog== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713880602; x=1714485402; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=kQk5FyVP0lAkjPXrseFZ4aW2TL7nmZurojICLrE1sJU=; b=YE48RjqBy5gov0hP8bg4MYD3C0J8pfQDGptlV4aVKGTHL1NlPvZeULTPR2zEV/1vkD g+zREKCiH2/auIy+36JNmzBwIvz206B+MW9ep2MTvd4GMKHvT8BHcN53uTpwSkydTRXp Q0C0baz+euHdKDSuLogYajHdv0MMNXZwqZX3gwgV84PooqWvnXJHnVCkCRUg004VwAUI EWalN5WW+RXNCTIMDDSy3VV0gc8jQzY0yLnerRSQZwEMIhb/2kDO2EiU3XRbUh/VzWUC rCxoWAgn4hnw49n2Rl1JI0CMgL77K/oq+fLKu/lAVavP1dTfiq8ei++KgJSvxxk7BH26 Dzsw== X-Gm-Message-State: AOJu0Yyv7eeAKph+2AOvP/jNVxA0WJCW6KbocvlmzilwfoiEX8kMXbqA RBy9UJdCxYbtfSUDF7fax03Gjf0IAX3wB9v3DTlVMlEPR3hPRe+TJNwJh6s1 X-Received: by 2002:a05:6a21:9102:b0:1a7:8a55:b070 with SMTP id tn2-20020a056a21910200b001a78a55b070mr17991393pzb.37.1713880602157; Tue, 23 Apr 2024 06:56:42 -0700 (PDT) Received: from code.. ([144.202.108.46]) by smtp.gmail.com with ESMTPSA id fa19-20020a056a002d1300b006e57247f4e5sm9623570pfb.8.2024.04.23.06.56.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Apr 2024 06:56:22 -0700 (PDT) From: Yuntao Wang To: linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: Dennis Zhou , Tejun Heo , Christoph Lameter , Andrew Morton , Yuntao Wang Subject: [PATCH] percpu: simplify the logic of pcpu_alloc_first_chunk() Date: Tue, 23 Apr 2024 21:55:25 +0800 Message-ID: <20240423135525.36872-1-ytcoode@gmail.com> X-Mailer: git-send-email 2.44.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit In the logic for hiding the end of the bitmap, there are several places where the same value 'region_bits - offset_bits' is calculated over and over again using different methods. Eliminate these redundant calculations to improve code readability. Signed-off-by: Yuntao Wang --- mm/percpu.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/mm/percpu.c b/mm/percpu.c index 4e11fc1e6def..2a051f00f68d 100644 --- a/mm/percpu.c +++ b/mm/percpu.c @@ -1421,15 +1421,13 @@ static struct pcpu_chunk * __init pcpu_alloc_first_chunk(unsigned long tmp_addr, if (chunk->end_offset) { /* hide the end of the bitmap */ offset_bits = chunk->end_offset / PCPU_MIN_ALLOC_SIZE; - bitmap_set(chunk->alloc_map, - pcpu_chunk_map_bits(chunk) - offset_bits, - offset_bits); - set_bit((start_offset + map_size) / PCPU_MIN_ALLOC_SIZE, - chunk->bound_map); + start_offset = region_bits - offset_bits; + + bitmap_set(chunk->alloc_map, start_offset, offset_bits); + set_bit(start_offset, chunk->bound_map); set_bit(region_bits, chunk->bound_map); - pcpu_block_update_hint_alloc(chunk, pcpu_chunk_map_bits(chunk) - - offset_bits, offset_bits); + pcpu_block_update_hint_alloc(chunk, start_offset, offset_bits); } return chunk; -- 2.44.0