From nobody Tue Mar 3 05:25:18 2026 Received: from mail-qv1-f44.google.com (mail-qv1-f44.google.com [209.85.219.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 755F2315D5B for ; Mon, 2 Mar 2026 19:53:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772481196; cv=none; b=X91XUIS5jAIZoK+Im9uEyILfIFo4doC6RdzDRkdjRl0hl51u+JQw6FVHS8JZbXz403MZZlZ2F7SJD4yLEopeHqGbPsHcbWvmR5yP346AFhD5Nwx1pgkkeEFuPmrpzBBKAEE2HFIJhCjh+ozb20zDRMmAIFrRQTIpW7HW/0H+W6I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772481196; c=relaxed/simple; bh=xMOOY+JO0QZspES/MoGCVCDt+stnCC4+6jDUOXw23q8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ZS7VJD9zGv4AQYWVl3Eff988H2WuC8u/FdyyBOOEMC975Uyo9C3ZdB0At1rZdoC7U4LNKDvoEhxDKpfBA8UYmc6a/1dxhWVyjoJnrfXz+SXFwcQ24erE0YuQxG3OaUzvu0EzzpSoQuS96QLD/+9STUdukhult+LXtI54P2laE2k= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=cmpxchg.org; spf=pass smtp.mailfrom=cmpxchg.org; dkim=pass (2048-bit key) header.d=cmpxchg.org header.i=@cmpxchg.org header.b=gdaDoVZb; arc=none smtp.client-ip=209.85.219.44 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=cmpxchg.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=cmpxchg.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=cmpxchg.org header.i=@cmpxchg.org header.b="gdaDoVZb" Received: by mail-qv1-f44.google.com with SMTP id 6a1803df08f44-896f4627dffso68352146d6.0 for ; Mon, 02 Mar 2026 11:53:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cmpxchg.org; s=google; t=1772481194; x=1773085994; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=MpE/M8Cc0DYeAdsX8W3VyabxBIuEQ5Zyn3nZkaA1QSY=; b=gdaDoVZb9pIB8DDyj2ANOlDdYNRy3Vd3zTkGDmF1KiR4/jJXxgC0lHuDfKOjo4TFyA pXnu7rzlpVfqilqxw1x1k0y58/Gma+E64DRUuwbWMGhXxR0kvYdQjHTp9sgLonbiV4Nn xkWd3X01YTQSyLcWp/of/ZWllniNv71xrxBXDRiCXUc7Uxx8a3T/S+/+Cn3B1mxoOftC jSKjM+LYrRaL5q2YOcnvv4KdezJfU21B8RB2/x4bSEOxXDEKKUzUXRkwF+lYOqpzIGbg uQxmPi8OXkuidyRvNNFP09wscQaFUv/hAbymk09pPAGv3HC8jb85hRryy2ZgdCup0ORi hl+w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1772481194; x=1773085994; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=MpE/M8Cc0DYeAdsX8W3VyabxBIuEQ5Zyn3nZkaA1QSY=; b=AbA92rDLYGAX5V5f9l/64p/qPxDnN9NvUJWE0tSmpAOEciTiQjEPJUloH9rQvfBWQk 7x9YCT2MF0hpm1GrmhUOj9CV8hwuZ7n2DPlY2aitU3St3WGZx22OnWWoOi2bcu9KXtUC v5IZKAePzSoMnC7QS23lnmoxIAmU1RUgDclV6MmWsv+18vdnGznyZwiOfPq93IFE1qcT ZtjjXMCvLb0SzmLQWSFuZ9Bc2FjHtlwS3Kr+UfDT57k2S+yleVhTgoAnTxa27pYFRnZI yi3sFHpUIvexx5nCcjQmoOgLe7U6taQd5RemmiKCGbQXkXxkVGkvmeTxWZ9OcWFh1Aro KqlA== X-Forwarded-Encrypted: i=1; AJvYcCVyNkAQKwK5RuRu9s4OQI0Kw5VyKLDLaE/w1fDwT/TQ6Vchu3bKK2IPHEeCGwipExrOjnCj4uovlfNrJ9o=@vger.kernel.org X-Gm-Message-State: AOJu0Yw4fB5v32H5kXVYZXew/lGhGdwL/Ci6FDfB9cBoOY/6uKfu4h5z 8nv4Y5aWsO2zTk7zbcY7DQxRpQHFjHESYgjsk6Ktx7S1G7dkT0bEYRGlEWHnRjCKmZc= X-Gm-Gg: ATEYQzxm1FOPxL85LB6ve1xxrZ9uepnwuYHMYu6VI9uo4IjrnJ9U4yH8n12eCJtjaWr +oTk1vdGMDBo8IXIBae3tSoES7r9gqO5PvWx0i+P4JNmvFCx3xap3JPf4ckGCozVRvf2lmJQKLW JWnBxK3e8rqYDIqgCYWuc6Pb+/6yz9gxLPlCK/r4FRwfF7SnlBIgK1/peA8Ill5gKxRWruFnKUe f5+Tk9YtYlQ6+9uhxzobEanL73AgXz7QU7HrULasVQKsPDu1MyxPoCDfGFIK5OWr5jDxsBlz3uA nrL3vNeulBdr2aYwULrs5vKO0Cmiq80dRTxAI/eWHM97AO4wOHsg4ibmltOW5HfC8BEI0rUoDWA 5l3SJkwjmaacNw1HXH6RDN/100glFM9LKcaY9lHaRSNXaUF22hls5sQFQP5FZQEPSkFwv/oVKkz 1KkdHyi/uJT7xARIaYQJ2BZQ== X-Received: by 2002:a05:6214:226c:b0:895:d97:a2ba with SMTP id 6a1803df08f44-899d1e9866cmr180883656d6.67.1772481194477; Mon, 02 Mar 2026 11:53:14 -0800 (PST) Received: from localhost ([2603:7000:c00:3a00:365a:60ff:fe62:ff29]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-899e53a0d04sm58618466d6.1.2026.03.02.11.53.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Mar 2026 11:53:13 -0800 (PST) From: Johannes Weiner To: 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 Subject: [PATCH 2/5] mm: memcg: simplify objcg charge size and stock remainder math Date: Mon, 2 Mar 2026 14:50:15 -0500 Message-ID: <20260302195305.620713-3-hannes@cmpxchg.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260302195305.620713-1-hannes@cmpxchg.org> References: <20260302195305.620713-1-hannes@cmpxchg.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Johannes Weiner Use PAGE_ALIGN() and a more natural cache remainder calculation. Signed-off-by: Johannes Weiner Acked-by: Shakeel Butt --- 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; =20 if (likely(consume_obj_stock(objcg, size, pgdat, idx))) @@ -3446,16 +3446,12 @@ static int obj_cgroup_charge_account(struct obj_cgr= oup *objcg, gfp_t gfp, size_t * bytes is (sizeof(object) + PAGE_SIZE - 2) if there is no data * race. */ - nr_pages =3D size >> PAGE_SHIFT; - nr_bytes =3D size & (PAGE_SIZE - 1); + charge_size =3D PAGE_ALIGN(size); + remainder =3D charge_size - size; =20 - if (nr_bytes) - nr_pages +=3D 1; - - ret =3D 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 =3D obj_cgroup_charge_pages(objcg, gfp, charge_size >> PAGE_SHIFT); + if (!ret && (remainder || pgdat)) + refill_obj_stock(objcg, remainder, false, size, pgdat, idx); =20 return ret; } --=20 2.53.0