From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-qk1-f171.google.com (mail-qk1-f171.google.com [209.85.222.171]) (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 55CD915623A for ; Fri, 24 Jan 2025 15:54:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.171 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737734070; cv=none; b=ohGnlGbS9SPfyv/QPDCmftgf+DNuKeLToRLqOtIMJZyewZ7Pvwct7IKuylAlCgsh5mIEZdwxbm6PF3J+tjKJpBJeJSSxqQYKkZODpkyfBQxA7kFCPxAWOEmGUVT+Cw1hj7/GXl9RqBcpPDl4O+oxtJLXTfugPNkx42sQGA+Bflo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737734070; c=relaxed/simple; bh=qxridkHxaY97JQm3SeHc/9g4JU7IA7islWSnMI7J1+k=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=T5H8/1riFcoLTvx3nZjb5g1a40RdCwJl0LfCDhc//HUefDqQqMfwqB3nr0dMjlpJ7pFkuDsAKxjHdtn4UgXiOWEGCJFQwH6E2B34DV5xsipU1DzGvn9eJpewwz3DoDJRUrT46ltngJaWSnCTSf1U3wWXWmrjSLOZr2fnXj4UJi4= 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.20230601.gappssmtp.com header.i=@cmpxchg-org.20230601.gappssmtp.com header.b=Bz/pUqP7; arc=none smtp.client-ip=209.85.222.171 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.20230601.gappssmtp.com header.i=@cmpxchg-org.20230601.gappssmtp.com header.b="Bz/pUqP7" Received: by mail-qk1-f171.google.com with SMTP id af79cd13be357-7b7041273ddso205498885a.3 for ; Fri, 24 Jan 2025 07:54:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cmpxchg-org.20230601.gappssmtp.com; s=20230601; t=1737734066; x=1738338866; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=jaO5J1OLleA0s2cJXfqZOWGHbYpMpsF93JnDLodR8mk=; b=Bz/pUqP7PpkO+XA/K1NdBjAmG3zenV9T+5PIwRnF9+1UHTFGJbXxElHcNa5+d9sIr9 1c6Pl6aMiyE830EXCnBu8J9zhTyOYXhWhRMMXP0i+BFreT6Nq3VeV/AKP1uj0Nh8QAFf tuKBKvsImN0VNozoF8egGEJZM66825J6T5eUYwp9ro4PTtzF9afgJxF0QMV1iSz9TRB1 c19Qu57bRR/3tMDdqXvYqkq83QI5ICGauILXs1E0fnCPRi9b60MBpayyC1epNLypXYBB kjofTiyrg7cQ7mJGXeEJXQ+2PM1NBiGITY9X2f/kYYMrz0qX78FEhId7Tt6CzjHzQTpw B95w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737734066; x=1738338866; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=jaO5J1OLleA0s2cJXfqZOWGHbYpMpsF93JnDLodR8mk=; b=AA2T4HJg1/vvkW/4VeJZ/60y9lxF0iDrnSVGcPo7aQqSY8Uv/1FJzNmMM58DEv/B/G FqClpgIGa9i1KceFl5NdQDeer0tZHqem67lv3a03a/IYGxPwxVF6J3wzKCEh0yppFpAI LJ0bD6ehLSQP6HCVh7aU55K1wbdOpYkW5f4Hx4mUhZORObwcNnKNVa1D0yE1Q/EtGVvA L0/1NpLakf+DS0O4Wa+PH0zh5ngftKol/OCnjCdVPaXq95U60GtP7fkHum6WPB4iTczA eMpvC22vFVeN9krnDL1+o4voAFXYDthGh5SphRnJ3bTq65a3Su/VtTIrOQofe9eejz/7 NREA== X-Forwarded-Encrypted: i=1; AJvYcCUaAMZwBce0wB3Abg5AtFg3iLuWPReqv1JRLQnv4Zy9xeAKmGofGdFb5DHlBSKVqDXwYnLzm7xGIMWqIAM=@vger.kernel.org X-Gm-Message-State: AOJu0Yz99d1PslmBxb1a0sNBLkLlnb4OQStQJLtscx9j5abvkOhFNg1I F+4Z6HpYrkonLmrxItEWJT73z2BevwTiDVA9CPqq5mePhD1HR8K/Kb6eyT2ieMk= X-Gm-Gg: ASbGnctZmbq+t1y3CDAO923Wi3M9c/kTu4hzIVjHmv5sgoCIvsYyVOuolyzBEuGbVo7 S1EMGyvKNQ0Dd1BtV4/0yBBiR7wucGZA6GbjnYca6OfRHQ3bYoksCcWBm3u6Crz5ETHIKa5GYFi XZF+4V92Rfo4Y03VNaFhPptB2PM4b3LyKwll3Aan89mMdH0oXykEOnaLmmwLz3S3FnXWv0KgHSK uc6kVw6wkQ9/luccaVxs6Djj0kCc0pShUaLCxBHZmHnWOELJbok6JtZR1gXmfVptatd36bfRKr+ GrY= X-Google-Smtp-Source: AGHT+IF7MEA53OVqDa9yY3jpDkbRjQbEp6o5hVbXuPIzBO08qcAzX4X3mShK2xIPJXxXgBs5Mq02Uw== X-Received: by 2002:a05:620a:29c1:b0:7b6:e8c3:4b60 with SMTP id af79cd13be357-7be632385c7mr4427127285a.28.1737734066003; Fri, 24 Jan 2025 07:54:26 -0800 (PST) Received: from localhost ([2603:7000:c01:2716:cbb0:8ad0:a429:60f5]) by smtp.gmail.com with UTF8SMTPSA id af79cd13be357-7be9ae7ec0asm105917285a.12.2025.01.24.07.54.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Jan 2025 07:54:25 -0800 (PST) Date: Fri, 24 Jan 2025 10:54:20 -0500 From: Johannes Weiner To: Hugh Dickins Cc: Andrew Morton , Michal Hocko , Roman Gushchin , Shakeel Butt , Muchun Song , linux-mm@kvack.org, cgroups@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] mm: memcontrol: move memsw charge callbacks to v1 Message-ID: <20250124155420.GA1222@cmpxchg.org> References: <20250124054132.45643-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-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: On Thu, Jan 23, 2025 at 10:53:04PM -0800, Hugh Dickins wrote: > On Fri, 24 Jan 2025, Johannes Weiner wrote: > > > The interweaving of two entirely different swap accounting strategies > > has been one of the more confusing parts of the memcg code. Split out > > the v1 code to clarify the implementation and a handful of callsites, > > and to avoid building the v1 bits when !CONFIG_MEMCG_V1. > > > > text data bss dec hex filename > > 39253 6446 4160 49859 c2c3 mm/memcontrol.o.old > > 38877 6382 4160 49419 c10b mm/memcontrol.o > > > > Signed-off-by: Johannes Weiner > > I'm not really looking at this, but want to chime in that I found the > memcg1 swap stuff in mm/memcontrol.c, not in mm/memcontrol-v1.c, very > misleading when I was doing the folio_unqueue_deferred_split() business: > so, without looking into the details of it, strongly approve of the > direction you're taking here - thank you. Thanks, I'm glad to hear that! > But thought you could go even further, given that > static inline bool do_memsw_account(void) > { > return !cgroup_subsys_on_dfl(memory_cgrp_subsys); > } > > I thought that amounted to do_memsw_account iff memcg_v1; > but I never did grasp cgroup_subsys_on_dfl very well, > so ignore me if I'm making no sense to you. Yes, technically we should be able to move all the code guarded by this check to v1 proper in some form. [ It's a runtime check for whether the memory controller is attached to a cgroup1 or a cgroup2 mount. You can still mount the v1 controller when !CONFIG_MEMCG_V1, but in that case it won't have any memory control files, so whether we update the memsw counter or not, the results of it won't be visible. ] But memcg1_swapout()/swapin() are special in that they are completely separate, v1-specific memcg entry points. The same is not true for the other occurrences: - mem_cgroup_margin(): - mem_cgroup_get_max(): The v1 part is about half the function in both cases. We could split that out into a v1 subfunction, but IMO at a relatively high cost to the readability of the v1 control flow. - drain_stock: - try_charge_memcg: - uncharge_batch: - mem_cgroup_replace_folio: - __mem_cgroup_try_charge_swap: - __mem_cgroup_uncharge_swap: - mem_cgroup_get_nr_swap_pages: - mem_cgroup_swap_full: The majority of the code applies to v2 or both versions, and the v1 checks either cause an early return or guard the update to the memsw page_counter. So not much to farm out code-wise. And the test uses a static branch, so not much overhead to be cut either.