From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-oo1-f42.google.com (mail-oo1-f42.google.com [209.85.161.42]) (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 5DAAA1D5146 for ; Fri, 5 Jun 2026 17:07:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.161.42 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780679267; cv=none; b=pW6lSAP9uhcyVIof3QY+7Z9neagYIDNeBErXI+9RKYx5G3mSFQmYf9hw2xRpLiCbjaDLFuUumsd6CJK0Yw35+xdYJNoVMZ5ya+6hYrLTptuaZ4k56aZWsnZWotVttnmpZMj/qOJFojDFLO6ZWZos3HSD66O2ZYqif+chjmyagOU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780679267; c=relaxed/simple; bh=zyAzjgNheCu5UzZcmkW2Vo/6l+PANb/K/lhIHU2Fsyk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=RiaCblNZl7oiMGR8xNQl5T0fstC04iFAAOXYMhYlB/THoO/dvQ5eCJYARi1qz+oH8Tr+6ZvbO96SlvFgI4eWYXB/VjM+UCGdxFDCbEkvoh5Ck0bOt9jd9TKN0hYYYiIMDVbwIS33QpZhXdqUYFenwILcuIzDy0rUH6wZsKEU1wo= 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=Y9vUBRrg; arc=none smtp.client-ip=209.85.161.42 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="Y9vUBRrg" Received: by mail-oo1-f42.google.com with SMTP id 006d021491bc7-69d7cdd3b8eso981978eaf.2 for ; Fri, 05 Jun 2026 10:07:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1780679265; x=1781284065; 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=wfdqaOn+smG9hY8rD85LL22KMJy+2AytX3mGNk8Tobs=; b=Y9vUBRrgcGTVJjtKm0Q0pV+ANQZAaQXVrqG6wPakXhH6CctBGkZTn+0Gwsu5Y5ZoYZ Wf1eJjE/Y2JCpkkhMizoRNAALjbrgDb5zSWCjrzSe5FKSGM7ofTzrsqqLpoE40hCKuiI v5JzBPP9h85Odx6rM0U2Xe6VbWk2M7E/6OdawDV9x6GIjO8F2K2nEhrNsWDtQJdlPK4t OZYQ1mkEbZNNOKEDBqhUqyV5TsfREWqCCqSpifdtCXHVNvPaKloYAaYm7kifg1wx00/T 8E/P0n2ET9+jRVoHkL8uPsx8LiCe6wB1R4AZKWKKXTKD/f21lSs4WGJYYGKfiOVxKS4u +dMg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780679265; x=1781284065; 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=wfdqaOn+smG9hY8rD85LL22KMJy+2AytX3mGNk8Tobs=; b=bMjEBp2bJQDRjq7BfiVR2kbXU8JlHcrT2egTzgU5IRM3/BeOdWDrRkXIlZ/TCvmAEV mmAiazR5kcpWiZ5ECmxhD3S7L53Ex5QgSnNVZwvSRPtC0JTQ56zwwPRQ5SJbcwnWeZG1 PPxdvcgb+XukHirCKoTXFdDpmio/8zUiL6P518NHexDwB/LJ/A1mJ0+i3IOHRHC6Aa2e OJxpabu7fcmatnUG8M0LbFHQnxGVaTAnXhMzoCZfUFwNf1asefbiuCUUXeN6asYw6FYq pUq2pawjMFlGdTIuChlYTO+con3Y7zI45DXC+OE0rGtv+t9wtTfDTYZt1vsToK6uq2Kc k4zg== X-Forwarded-Encrypted: i=1; AFNElJ9MvsnkIE8qgNNwiY6/tl4JnCgTEueHGwzsLPWTS47rc4ySjS304DU/LA4a7m7eAvrsZk9WGBPD5YPVWv8=@vger.kernel.org X-Gm-Message-State: AOJu0YxPuuBSwBGBz91qwKhQRltBBnS0JNZPHDp9pLqPvcMnRKEPIyxD XIU/RlhMmk5AYCKOcM1/wDFEF2RaQuxq9oRi5O7V2t2wNWoCSZ++BWaI X-Gm-Gg: Acq92OFBJ5i2xtdY+cEiJjHWInRcHy/zGIyTn89oKdfGh3gYSpxalV9eMVRVXuSbRUd Kba2ZjAeRxIrN0TltVOT7hlw7aY8NTXFY4YJZT51OckDzep84LRiNSMz0970iDpWoseiG2AcjEI czvv1iohN3fsegOLeICQjSPGKFvDzbTEchxvQAOPmUK5hLVKBe1kPWtOu0dc1oRYAMSTCWHOQQZ C+AZugg7YGo0v/MKYh2lmrEmhgRgesNi15NoheCU7eqXT3GZq5ZtmGkm9afLPbzJfC580D/ujuF KBYgJZApDhc5QeRK333DISEMMeWDRZnRpzSGPytG7qMG4w7QOhjZwBYDwDGQVIOH8GJg1vRu6FT 9qGtG+4/v4FwII9PEobAQt1hWRgJzXbS/HakqIWIPs2GB7WTP9aIiXNlxx/SCJPGk/oGoFYksH+ tIGOomMfVF+Sz1WNkDbvlH8onvugU8a6Scq/sYireD6an/d6AFA4P0IUrQLI4k8q/J X-Received: by 2002:a05:6820:4dcc:b0:69d:7a88:9ccb with SMTP id 006d021491bc7-69e68b94fe5mr2444413eaf.24.1780679265289; Fri, 05 Jun 2026 10:07:45 -0700 (PDT) Received: from localhost ([2a03:2880:10ff:53::]) by smtp.gmail.com with ESMTPSA id 586e51a60fabf-440d7c42c33sm7420128fac.6.2026.06.05.10.07.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Jun 2026 10:07:44 -0700 (PDT) From: Joshua Hahn To: Joshua Hahn , Johannes Weiner , Michal Hocko Cc: Roman Gushchin , Shakeel Butt , Muchun Song , Andrew Morton , David Hildenbrand , Lorenzo Stoakes , "Liam R . Howlett" , Vlastimil Babka , Mike Rapoport , Suren Baghdasaryan , cgroups@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, kernel-team@meta.com Subject: Re: [PATCH 0/6 v3] mm/memcontrol, page_counter: move stock from mem_cgroup to page_counter Date: Fri, 5 Jun 2026 10:07:42 -0700 Message-ID: <20260605170743.1292597-1-joshua.hahnjy@gmail.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260605153603.234296-1-joshua.hahnjy@gmail.com> References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit On Fri, 5 Jun 2026 08:35:56 -0700 Joshua Hahn wrote: > Memcg currently keeps a "stock" of 64 pages per-cpu to cache pre-charged > allocations, allowing small allocations to avoid walking the expensive > mem_cgroup hierarchy traversal and atomic operations on each charge. > This design introduces a fastpath, but there is room for improvement: > > 1. Currently, each CPU tracks up to 7 (NR_MEMCG_STOCK) mem_cgroups. When > more than 7 mem_cgroups are actively charging on a single CPU, a > random victim is evicted and its associated stock is drained. > > 2. Stock management is tightly coupled to struct mem_cgroup, which makes > it difficult to add a new page_counter to mem_cgroup and have > multiple sources of stock management, which is required when trying > to introduce fastpaths to multiple hard limit checks. > > This series moves the per-cpu stock down into the page_counter which > consolidates stock limit checking and page_counter limit checking into > page_counter_try_charge. This eliminates the 7-memcg-per-cpu slot limit, > the random evictions (drain & refill), and slot traversal. Hello reviewers, I was hoping to receive some input on a point that Sashiko raises. The draining work we do per-cpu uses work_on_cpu(), which does schedule_work_on() and flush_work() on the system_percpu_wq, which is not WQ_MEM_RECLAIM. And drain_all_stock() runs from try_charge_memcg() on the reclaim path, so it actually triggers the check_flush_dependency() since a wq_mem_reclaim is flushing a !wq_mem_reclaim. In my testing, I haven't seen this become an issue. The flushing work and draining only takes a local_lock() and does atomic operations, and it never allocates, so there is no question on whether we can make forward progress. But this does slip up the WARN_ON since this is not obvious to the system. I see three options here: 1. Trust that this is OK, and document that we can alwyas make forward progress. 2. Keep the draining work synchronous, but queue and flush on memcg_wq marked WQ_MEM_RECLAIM instead of just using work_on_cpu(). This would add 2 words per-cpu-memcg for the work struct backpointer. 3. Go back to asynchronous, which would get rid of all the synchronous concerns, but add an additional 2 words per-cpu-memcg for the work struct backpointer here as well. What do you think is the right decision here? I was thinking about this quite a bit recently but just decided to send it out, but I think I should have asked for upstream opinion sooner... I would prefer to keep the memory footprint of this series minimal, and opting to do things synchronously helped achieve this goal since we can get rid of the backpointers. But I think this is beginning to show up as a tradeoff, so I would really appreciate any input on what seems to be the best decision here. Thank you very much for your time! Joshua