From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wr1-f44.google.com (mail-wr1-f44.google.com [209.85.221.44]) (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 CFE90433BC5 for ; Wed, 15 Jul 2026 09:34:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.44 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784108098; cv=none; b=UA1XVbdFFvrt1lzsKOGeEmSbtgnhHX/akPEB5HMJGfPssDOl/W1Ni2gyqozptYeCAc/HhFCz2uwGYaKhBhGcZgc4c/29S2FwXTDwRUU2qRfpUTEyc8xYp0Qfxt3ZYWlyY8WSaw4ZTH23A6XX/7K9I69UzwltRegyLXxX3yngrv4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784108098; c=relaxed/simple; bh=YCZgjQYU/o7TX/Pqv1mNLAZnZAkpWALC7y4RvSF+pKQ=; h=Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=cjMUoW8L+ZiWYsGu8W2kKAfEcF1z5/t8NOWaamADcW5O+fOOVEhQD5RZZX+4alOcf3OShYblhYmct9+3ccvpETfS2LHeWvNyDU/J+Ofajqj32lUHLyAdPWZCfx9itQv7t8i/5xaowZrFyVZnYuTAlfxMU8ZuPo3maGYs+NuWAik= 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=pOzAUFgh; arc=none smtp.client-ip=209.85.221.44 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="pOzAUFgh" Received: by mail-wr1-f44.google.com with SMTP id ffacd0b85a97d-47ddf7b09aaso3558135f8f.3 for ; Wed, 15 Jul 2026 02:34:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1784108088; x=1784712888; darn=vger.kernel.org; h=content-transfer-encoding:content-type:mime-version:references :in-reply-to:message-id:subject:cc:to:from:date:from:to:cc:subject :date:message-id:reply-to:content-type; bh=In4RoSQy1KdCVouUHaMqPZfN9Q31yqvGm3xJhSceDCI=; b=pOzAUFghY/CceE5dD9hrxEPpH4dWHrGuyLk2q+eQGR/L/Mlwn3/mPfvAfwak6qF7Hs h/lFf0qHPLzqCqUQiJWWW0WCGvFICI2VZPUVhqIl5OahQ72oxMYmodO+wY0wEQlig1EN pmgyu0kQ1rRe5AnwdwQQJOx7QWjLSRwGYDs4fovexQc/uPTAIC2QeAF2aTPwiE1r08lo 7rdl7h+72pfTyCyTgBgLHzk/BEszS4Ka8CIhyiYvLiS1smEf9rvej3m48M4GUHD/oAtq S5xQqdFOLg0nM2FLf90p3hXvpE+QIV/SEUcbpAMvr47TFZUnqqkzSjBqAJAwjzwxMWpO EauA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784108088; x=1784712888; h=content-transfer-encoding:content-type:mime-version:references :in-reply-to:message-id:subject:cc:to:from:date:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=In4RoSQy1KdCVouUHaMqPZfN9Q31yqvGm3xJhSceDCI=; b=jA2QEphAFTnAS05seu5jdlAHIv+fZgHDfeG4XOZwqnnKG0FI2Dc3P6GTY2pYjk8Zfv TzB36aaqDow9WTYjYnXyorgs9u8ItmB+OhWpqueBdIWr9Imdn9YbbozwWJ/pTpafyckV WxL1HczOwjYcEgIQlL84SvfLjrUrDypunpQJs4PJ7ykrrfYb+3Rqr17zQ2uML+/jxcW2 miXrqQNWiNL0iwg4Svq+YblFc2MF2gEquY5oR1V7Q6Rn3ypTVfnxn/N4I4WrCMBM53dk 5z8Z/SjGIKXDRX7k1podjtmmORJKCz059X6o/pz30xZQOloUjZ/jeySpgtClor/rpzpM GPvg== X-Forwarded-Encrypted: i=1; AHgh+Rr81t3KpCxU7uEXLUpB03ATg9Qd5wtPSHaYbAK98x6KilcPqHqguQQ1L3GLZx8bYj5iUmKJDwtA0L7auvc=@vger.kernel.org X-Gm-Message-State: AOJu0Yzh+zX4zzGFqp5offWS1OCTwlzrr6m2w5LIDpWSCnabVPvwDJDq KY76uf/ZIa44k5sGCYywsikfzIypRhKrz74OdAtrAxucDi1c72fH4rbE X-Gm-Gg: AfdE7cmM4za+wrXTE/KoZ47jjQZZsw8Z/XKSUZ52HpOsvdlwTgMT2XJ2wp4tb0G0igg uvf3p4/Y5g2UsLxSR5u38mMaZh0SMNbotUh+m0sdM7ZRQqgKrnRUh6uq9VHKvZOFNJXAPzHhbQ/ 9Nxz8BEAHR06VaBXX5SdfP6BpixTnYNr77VEu4v5Hto0TvzfNkjiX62UH9EfYDEAI5/SZHlbfLr yHtFlKRnNe16BpjgPOodeeiNzfy3Oi9ImlphQh39akfwrJjjX5Q+61Lnscf6BGLg9KlNGnbYISy Ed+BclMdXknAwJQssDo5zfaqeHlP8jkcqjJDS/FbaIU6GTrRcnyxe6dvC5UcN5vnPoQ/dz4v4fD lik0o9H9OjPWYLiwR98tJ0iPvAN0uBSVjt0W51brJRN4NMDMu6y82xljXtG1wWLD6fvzv04ffya MrpaPqHU342VSVgU9eqQ1hn/xm261pMtdhJqDikTLgiZ/JJ9w83g== X-Received: by 2002:a05:6000:2481:b0:476:504f:7a1 with SMTP id ffacd0b85a97d-47f4632fd7dmr10068853f8f.7.1784108087710; Wed, 15 Jul 2026 02:34:47 -0700 (PDT) Received: from pumpkin (82-69-66-36.dsl.in-addr.zen.co.uk. [82.69.66.36]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-47f464bbb0esm15226542f8f.28.2026.07.15.02.34.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Jul 2026 02:34:47 -0700 (PDT) Date: Wed, 15 Jul 2026 10:34:45 +0100 From: David Laight To: Muchun Song Cc: Andrew Morton , Oscar Salvador , David Hildenbrand , linux-mm@kvack.org, Mike Rapoport , Vlastimil Babka , Lorenzo Stoakes , Michal Hocko , linux-kernel@vger.kernel.org, muchun.song@linux.dev Subject: Re: [PATCH 01/17] mm/sparse: drop power-of-2 size requirement for struct mem_section Message-ID: <20260715103445.31b2f727@pumpkin> In-Reply-To: <20260702093821.2740183-2-songmuchun@bytedance.com> References: <20260702093821.2740183-1-songmuchun@bytedance.com> <20260702093821.2740183-2-songmuchun@bytedance.com> X-Mailer: Claws Mail 4.1.1 (GTK 3.24.38; arm-unknown-linux-gnueabihf) 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-Transfer-Encoding: 7bit On Thu, 2 Jul 2026 17:38:05 +0800 Muchun Song wrote: > struct mem_section is currently forced to a power-of-2 size so the > section-to-root lookup can use a mask instead of a modulo. > > That requirement adds configuration-dependent padding, especially with > CONFIG_PAGE_EXTENSION, just to preserve the lookup scheme. > > Drop the constraint and use a plain modulo for the lookup instead. The > divisor is constant, so the generated code remains cheap while avoiding > the extra padding. It also removes an unnecessary layout constraint > from the type. This has a side effect of changing the size of the 'section' from PAGE_SIZE to something 'a bit smaller' when CONFIG_PAGE_EXTENSION is defined. I don't think it actually matters, the allocation is done by: static noinline struct mem_section __ref *sparse_index_alloc(int nid) { struct mem_section *section = NULL; unsigned long array_size = SECTIONS_PER_ROOT * sizeof(struct mem_section); if (slab_is_available()) { section = kzalloc_node(array_size, GFP_KERNEL, nid); } else { section = memblock_alloc_node(array_size, SMP_CACHE_BYTES, nid); so the size might get rounded up to PAGE_SIZE anyway. I also suspect that '% 24u' might be enough slower than '% 32u' to generate a measurable performance drop. (It doesn't matter whether you do '& 31' or '% 32u'.) David