Received: by 2002:a89:48b:0:b0:1f5:f2ab:c469 with SMTP id a11csp201724lqd; Tue, 23 Apr 2024 22:12:12 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVtY2stQRzE2Lbr1pyGYfIIKfLMtuMDUTJDiV35ipLdiMJnSZoqeIHDEanDpPIE7Uh0Q3uj/NsCEPvSkGJqoDnczjIpjQjZ+khBK8aZcQ== X-Google-Smtp-Source: AGHT+IE/xfQOOM/ZA6ihIdhVOuEoSD5oTQMrzCSEzdz1SajGHaTw6MFzWzPCzTFVhMfRzOhBTJ2q X-Received: by 2002:a2e:2ac5:0:b0:2de:9408:e74f with SMTP id q188-20020a2e2ac5000000b002de9408e74fmr135288ljq.42.1713935532264; Tue, 23 Apr 2024 22:12:12 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713935532; cv=pass; d=google.com; s=arc-20160816; b=A4kUbS9AIbXjtfsUZEs5z4dZNYVt7W01ckE2q/elQdypOhKk7nTDhgO8V6lyWXlInL KT5mbJZpnAYr7Whxmg87ZfUqTArDoLUwV5U5qqxmDW4bORUMJ7eAEVtK/jDMiW/LtHHz 6eYL0JRg9HZUvefPkBE9BvKiEGVPbhP2DmZ3AneTea435N23443rPMtrk+oP8oWvEci1 p35opuCWEbWyQ1OO1NFY5Zu+1inJKwtGZOKe+5ExBVegi9bRVL9pDIkk7tCSHXnwUfM0 FPDd/segTuJazjxBwqMtQP+4Vopc29hYDtMSo/rTS/D0niyGeVD/j3Fq5WLy/86fgWjQ WnPA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date; bh=kDsmPvXYsnOtt5Kv84eWPCrAOOb+S3KIJ6SkIHs9ZVU=; fh=mMF16b9kzVHr6Qszc/hut0p/8YfAvwier+7dzelOf/k=; b=q0v/7ZH3WdUvXVzEPqx2HWlkJ9wVdTurRuQkfMS3L6vt5jcwdju1bZ4CaYNZBxf9Ah zNk0KVHfQdTWaJ+PYVcqwmgnzBNMUfzGNl/VFqk6dxOpVjZ6PGyxuUi6o/7gK7jTuNNf cSPGaOZHoMWk03SpMBYSEKjl5PKyeqq1V7Wkaqo6vYZjlVqfkMPCdbzterX5iK0NBkY5 KsXR5QedHQtxHfng2iXHow8ZGB+3VJXkqNgamiRiHFFiY53d35BHvQPdwnBvWIPK5Jon 7upMcw1OCpUvIHmeib7Edu85PlUX8iokYsmEdnpAyZF02OS1xhuRRvlkyYoypCxQgsEe CPaw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-156290-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-156290-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id a22-20020a05640213d600b005701ec0c6e9si1117461edx.463.2024.04.23.22.12.12 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Apr 2024 22:12:12 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-156290-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; arc=pass (i=1 spf=pass spfdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-156290-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-156290-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org 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 F2EAF1F21388 for ; Wed, 24 Apr 2024 05:12:11 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1AA33154BFC; Wed, 24 Apr 2024 05:12:06 +0000 (UTC) Received: from mail-pl1-f172.google.com (mail-pl1-f172.google.com [209.85.214.172]) (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 50CF315445E for ; Wed, 24 Apr 2024 05:12:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713935525; cv=none; b=WLqzhh+cl37Gtd8eiwHu9m/Ix86zV1HNME9bjqfpSktKOigspvBo9ODNgFNSwC7Wk+RGOYzFkIUTIhv/PPa8+Ki+n9XVvTEb5umCAxz+AcMABNBfHG085U4VbwTbkKONGUi1v0vg1/bjvIqkeSRIw2PLOy7KDLLOiFDtyx6aLYw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713935525; c=relaxed/simple; bh=R2VJh8WiIXUQUQbuDawRD/f7e6jb55B4s0cBMzFgifw=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=F6sqVq1LV/HX8qrT/lmxKYMHaT/Tyg1QQ8tbBxaX7amcv2kkX41QfBYgOb2nefz/Qf0GOme4ii+Ca7DSkoLrseqBTU+Q/+qU7VGVfNNZgiyRP/js7tGnRMC5brO7eOPDbgZ17S/atklqFVYxjSuGIs3/a+fzKy1AkLxDA7CZpdM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.214.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pl1-f172.google.com with SMTP id d9443c01a7336-1e834159f40so48222445ad.2 for ; Tue, 23 Apr 2024 22:12:04 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713935524; x=1714540324; 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=kDsmPvXYsnOtt5Kv84eWPCrAOOb+S3KIJ6SkIHs9ZVU=; b=tAXBbgAjA5s+lf3eN6IdPT7Lv5jyjrETJt7ZDmcA9IPdsCw1L5uXfIRm4qZlhCf7Op Kk5lACc+FLY9R8tWyqCkHgCl92EoAG9LJ2EzFLC7jQzcb69h0XQ1bl9mGWFVDo8xMYd+ xCfg0zNNgwa+EMiairSoLma9FCDHrbbj3vyCS7OfmVppKkopm3iBwjlAZWBpoKlNecwq ctlzeEnYgv48Djsenn6NA8RuSMF0gz2WI0/v6o4ScYBkxpxmjiLKI0ZS13A6IuescHZ8 z0h9RUaUGnBwq98YodPHczh9sRTreCueDAkAxvtgenCI5Fquy45MVe9vo0G+tdL1Vw2j 4Uvw== X-Gm-Message-State: AOJu0Ywan9SQbVP1UTtq0uWFBkudAPm7QuclqGQYFXSJHbvb374ESPIz Cf6TlyaZYlIVxPKPANwsPiutYSuxZ+uITeeNsvfuhadhsGrk3L1rzqkE6Vja X-Received: by 2002:a17:902:f551:b0:1e4:3321:21e9 with SMTP id h17-20020a170902f55100b001e4332121e9mr1509243plf.48.1713935523628; Tue, 23 Apr 2024 22:12:03 -0700 (PDT) Received: from snowbird ([136.25.84.117]) by smtp.gmail.com with ESMTPSA id ku13-20020a170903288d00b001e403970ec0sm10891540plb.277.2024.04.23.22.12.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Apr 2024 22:12:03 -0700 (PDT) Date: Tue, 23 Apr 2024 22:12:00 -0700 From: Dennis Zhou To: Yuntao Wang Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, Dennis Zhou , Tejun Heo , Christoph Lameter , Andrew Morton Subject: Re: [PATCH] percpu: simplify the logic of pcpu_alloc_first_chunk() Message-ID: References: <20240423135525.36872-1-ytcoode@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240423135525.36872-1-ytcoode@gmail.com> Hi Yuntao, On Tue, Apr 23, 2024 at 09:55:25PM +0800, Yuntao Wang wrote: > 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; Generally I think this makes sense, but I'm less inclined to mix the start_offset variable name in here. A helper function might make this cleaner, consolidating the start_offset and end_offset logic. static void pcpu_chunk_hide_region(chunk, bit_off, bits); Thanks, Dennis > + > + 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 >