From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-177.mta0.migadu.com (out-177.mta0.migadu.com [91.218.175.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5B24E33F588 for ; Fri, 22 May 2026 06:28:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.177 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779431300; cv=none; b=KXAMEvm+MFn2gtXDLsfj7I1Q+eiY3Yg3PALEUCVIHZAyfVyegJd3Z45CdDNq4soWKkBsTLOkMBdxuw2cGqPJKheG9amdqIlglGxlXO+ms4bd5IinrOWEkWd9RA/DLt+ZJ3IpQ1Fwk1QaBntMcZ9m/5uZmNTBvU4p9FAxNaQzqkw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779431300; c=relaxed/simple; bh=fP00X4k8MmjG+IguaSew3taRAL1FxN+RIEhfaao2zVk=; h=Content-Type:Mime-Version:Subject:From:In-Reply-To:Date:Cc: Message-Id:References:To; b=K6M4NRPPAiZDra8pLR996UBLoOhZfmwRm/EvKvba5MGI8T6hWr8/TcMt7AC/VYzbyUq1rxLrGqxa/YCiiQdXmQ58w/gxEXlGcWuTwWI3m7FcrWAUhsKCYIhtCnKi7R92/sokf410oWnGg42tZ3+F6DoNLpuF/fNEwNterqbge0g= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=lq5o7TK2; arc=none smtp.client-ip=91.218.175.177 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="lq5o7TK2" Content-Type: text/plain; charset=us-ascii DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1779431296; 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=1V7UQqNrZ9uHp5/iZSBaT8tXf5HPRHPJw5/0rwYb3Qg=; b=lq5o7TK2C5sv98lfHMgrVSITzYSD4jMhnl/rsr/dC1xxmIz0sAkB+EhOF0dpwqD3qNx7mU fVVse2Kyo3f0wbrnIqtoqtozvQ7vnbeV50hNaOr+qgBkq6S3Dz/D/Bau2JLNPmFuJW+96s 9IUeMwSqGmlMZ7T/XGOprzFHUl5XRxY= Precedence: bulk X-Mailing-List: cgroups@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3864.600.51.1.1\)) Subject: Re: [PATCH v2 2/4] memcg: uint16_t for nr_bytes in obj_stock_pcp X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Muchun Song In-Reply-To: <20260522011908.1669332-3-shakeel.butt@linux.dev> Date: Fri, 22 May 2026 14:27:41 +0800 Cc: Andrew Morton , Johannes Weiner , Michal Hocko , Roman Gushchin , Qi Zheng , Alexandre Ghiti , Joshua Hahn , Harry Yoo , Meta kernel team , linux-mm@kvack.org, cgroups@vger.kernel.org, linux-kernel@vger.kernel.org, kernel test robot Content-Transfer-Encoding: quoted-printable Message-Id: References: <20260522011908.1669332-1-shakeel.butt@linux.dev> <20260522011908.1669332-3-shakeel.butt@linux.dev> To: Shakeel Butt X-Migadu-Flow: FLOW_OUT > On May 22, 2026, at 09:19, Shakeel Butt = wrote: >=20 > Currently struct obj_stock_pcp stores nr_bytes in an 'unsigned int' > which is 4 bytes on 64-bit machines. Switch the field to uint16_t to > shrink the per-CPU cache. >=20 > The kernel supports PAGE_SIZE_4KB, _8KB, _16KB, _32KB, _64KB and > _256KB (see HAVE_PAGE_SIZE_* in arch/Kconfig). After the > PAGE_SIZE-aligned flush in __refill_obj_stock(), the sub-page > remainder fits in uint16_t up through 64KiB pages where PAGE_SIZE - 1 > =3D=3D U16_MAX, but on 256KiB pages PAGE_SIZE - 1 =3D=3D 0x3FFFF = exceeds > U16_MAX. The accumulator also needs to stay within uint16_t between > page-aligned flushes on 64KiB pages where PAGE_SIZE itself is > U16_MAX + 1. >=20 > Accumulate the new total in an 'unsigned int' local, then: >=20 > 1. Flush whenever the accumulator would hit U16_MAX. Together with > the existing allow_uncharge flush at PAGE_SIZE, this keeps the > uint16_t safe on PAGE_SIZE <=3D 64KiB. >=20 > 2. On configs with PAGE_SHIFT > 16 (PAGE_SIZE_256KB on hexagon and > powerpc 44x), push any sub-page remainder above U16_MAX into > objcg->nr_charged_bytes via atomic_add before storing back, so > the store cannot silently truncate. The PAGE_SHIFT > 16 guard > folds the branch out at compile time on smaller page sizes. >=20 > Fixes: 01b9da291c49 ("mm: memcontrol: convert objcg to be per-memcg = per-node type") > Tested-by: kernel test robot > Signed-off-by: Shakeel Butt > Reviewed-by: Harry Yoo (Oracle) Acked-by: Muchun Song Thanks.