From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 9DB3138C2C2; Tue, 3 Mar 2026 09:34:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772530464; cv=none; b=rco+cIamP2giKOX/lRt0i/q90la0lqbKijEfnAuwAcZTeDVXJRKe0jLasjRIZbKss7p47nnF/1Y4mrry7PVVhrrdTOG8CtQ6XIQCsyrip9Vnvjbx/+EB4u1knhZAIYCJ3tGl1vymDV0DzmGZs2bCFG6428cNzrHSEd9ZuVae+aI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772530464; c=relaxed/simple; bh=aF0geMfZfg7K36R3UA50A5lGdrThrnCyNqDKuaHXlUU=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=oNSaUV4iVliLJhnp+V/pU3u5YKT5rlYBsNSUGfL/8kW/Euo38eWsjWROnN11TR/8C064cCV5hz6kugUU2cWhfnbQf6kYSk77w/8kusGCLgjPL5ZyPmugCGmEztEbOkBQJqg1ChjXPyIAAGY5+KEcjxdZQiT3Scy7ZCwPUGuJah0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=TrgZIT4+; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="TrgZIT4+" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D9E94C116C6; Tue, 3 Mar 2026 09:34:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1772530464; bh=aF0geMfZfg7K36R3UA50A5lGdrThrnCyNqDKuaHXlUU=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=TrgZIT4+ZXZ5Ij0Pckh4JcvO6r3FTtQqoX3igL1DYRgXGSlUB2kmvsCk2EWI3KSOD onrlbftUWavPQo3y3shH+1g15Lr3BxFMVeJsqyZhGmTL+Hi569qcQBiA+c0+nBRiU/ U16dsnQKo6xoeAX5L2v4GQ/tjadQ1c/ddea9YUAXMMdyIov7FAaogWAnGnhuRzsy+c R/4BJT/0udRLDF2MjHIcVxziOE3GLDi7v2dH7cg6Ws7zBMYALep8TU7+o8tqygQYQo hNtH2kzCuJIIUJyJ7FSnrGzIG2lLUna0yfybyDh5aMZVdC0IpopPBjIZQTVKjfzaMa pTJrRFC3GzrmA== Message-ID: <8580309c-7166-4475-80de-fb2a11a8a1e8@kernel.org> Date: Tue, 3 Mar 2026 10:34:19 +0100 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 2/5] mm: memcg: simplify objcg charge size and stock remainder math Content-Language: en-US To: Johannes Weiner , Andrew Morton Cc: Hao Li , Michal Hocko , Roman Gushchin , Shakeel Butt , Vlastimil Babka , Harry Yoo , linux-mm@kvack.org, cgroups@vger.kernel.org, linux-kernel@vger.kernel.org, Johannes Weiner References: <20260302195305.620713-1-hannes@cmpxchg.org> <20260302195305.620713-3-hannes@cmpxchg.org> From: "Vlastimil Babka (SUSE)" In-Reply-To: <20260302195305.620713-3-hannes@cmpxchg.org> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit On 3/2/26 20:50, Johannes Weiner wrote: > From: Johannes Weiner > > Use PAGE_ALIGN() and a more natural cache remainder calculation. > > Signed-off-by: Johannes Weiner Reviewed-by: Vlastimil Babka (SUSE) > --- > mm/memcontrol.c | 16 ++++++---------- > 1 file changed, 6 insertions(+), 10 deletions(-) > > diff --git a/mm/memcontrol.c b/mm/memcontrol.c > index a975ab3aee10..0d0a77fedb00 100644 > --- a/mm/memcontrol.c > +++ b/mm/memcontrol.c > @@ -3417,7 +3417,7 @@ static void refill_obj_stock(struct obj_cgroup *objcg, unsigned int nr_bytes, > static int obj_cgroup_charge_account(struct obj_cgroup *objcg, gfp_t gfp, size_t size, > struct pglist_data *pgdat, enum node_stat_item idx) > { > - unsigned int nr_pages, nr_bytes; > + size_t charge_size, remainder; > int ret; > > if (likely(consume_obj_stock(objcg, size, pgdat, idx))) > @@ -3446,16 +3446,12 @@ static int obj_cgroup_charge_account(struct obj_cgroup *objcg, gfp_t gfp, size_t > * bytes is (sizeof(object) + PAGE_SIZE - 2) if there is no data > * race. > */ > - nr_pages = size >> PAGE_SHIFT; > - nr_bytes = size & (PAGE_SIZE - 1); > + charge_size = PAGE_ALIGN(size); > + remainder = charge_size - size; > > - if (nr_bytes) > - nr_pages += 1; > - > - ret = obj_cgroup_charge_pages(objcg, gfp, nr_pages); > - if (!ret && (nr_bytes || pgdat)) > - refill_obj_stock(objcg, nr_bytes ? PAGE_SIZE - nr_bytes : 0, > - false, size, pgdat, idx); > + ret = obj_cgroup_charge_pages(objcg, gfp, charge_size >> PAGE_SHIFT); > + if (!ret && (remainder || pgdat)) > + refill_obj_stock(objcg, remainder, false, size, pgdat, idx); > > return ret; > }