From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1C548C02181 for ; Fri, 24 Jan 2025 15:54:30 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A72666B0140; Fri, 24 Jan 2025 10:54:29 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id A227D280065; Fri, 24 Jan 2025 10:54:29 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8C39A280064; Fri, 24 Jan 2025 10:54:29 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 6967A6B0140 for ; Fri, 24 Jan 2025 10:54:29 -0500 (EST) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 0B74E4A213 for ; Fri, 24 Jan 2025 15:54:29 +0000 (UTC) X-FDA: 83042792658.24.58EF406 Received: from mail-qk1-f174.google.com (mail-qk1-f174.google.com [209.85.222.174]) by imf29.hostedemail.com (Postfix) with ESMTP id F373F120011 for ; Fri, 24 Jan 2025 15:54:26 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=cmpxchg-org.20230601.gappssmtp.com header.s=20230601 header.b=Iv7ZSfV1; spf=pass (imf29.hostedemail.com: domain of hannes@cmpxchg.org designates 209.85.222.174 as permitted sender) smtp.mailfrom=hannes@cmpxchg.org; dmarc=pass (policy=none) header.from=cmpxchg.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1737734067; h=from:from:sender: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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=jaO5J1OLleA0s2cJXfqZOWGHbYpMpsF93JnDLodR8mk=; b=HDNEJFT6haUL8lV/WwWLtBpvHa4AFa8RbtPhFAtUhb3qJ/tGbgii0Vs6YNVg+4+QD97W2Z Kuc35C1W66naNpbHPMoPa85ApiB1ZOGBj+h9Gge5wWw90rI0ISLWtuGMh4EmzWYGfg3Omk dt5b/7X3Xoyyo0WRqfTHjAXuoTq3QWc= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=cmpxchg-org.20230601.gappssmtp.com header.s=20230601 header.b=Iv7ZSfV1; spf=pass (imf29.hostedemail.com: domain of hannes@cmpxchg.org designates 209.85.222.174 as permitted sender) smtp.mailfrom=hannes@cmpxchg.org; dmarc=pass (policy=none) header.from=cmpxchg.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1737734067; a=rsa-sha256; cv=none; b=2cNAxFl5vMyMMPM1NITGFuAY9GgjySH9AihZyg18bsLoNv/zTkt0AOjN/py/sG1Ehw1mHx f2oCduqmpMtDVP35TLO1vPtb8XcZHVY5c3vOFCNjsucctSSo+Hgwk3ufm/idieSR/6DAkf 989//KfhDTTPNwV1zQrqCsmlcNZyNQs= Received: by mail-qk1-f174.google.com with SMTP id af79cd13be357-7b6eeff1fdfso197799985a.2 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=kvack.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=Iv7ZSfV1x6+VDKAsVDmV6A6vDRvtN59NM8srtpGBSE2qr+UgKa3U8CGOtZhV7aY6wG 4/mH6QvpCpYW8C2RBDo3uqNTjP42gyQ20K5+kNk7dupcZpwslIt6VZbkoaf4+F6jcBMc bmL3jWacJdB7GHofHtFhoIATnRxaU7urME80+rmQ/w+z7AMYXsdHqVqaeoIUjYvg9dL8 IwHJLXvzMZ+9pyVcdGeYrZbD8PEiv75BKgxXl/Tgzz3QD8/PlZZ4B3SKsul23YXSi0Tx 9VLEOhqXqvqOCyCBLmqpiOTNOhNdpQsaxHwj2FQJl7cWh4+vOa2h9ztflCVK1sx1xnAY w2Yw== 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=iMclww49GNw0mmNmfKhtQJtTt/eyyDaL8LKbwU4XYnqLxqNM8QSQOMC02WwmrjcczZ SLnVYlSmQ4IEaiGm/meW8ULqHHrhw97YgFxnpkf0VPOapsm6kiuAIFZemm9h9k9Y+yYz 0j9wvBioItjlwrSyJ2G6lCCoYlSJTbqcQksh3frCf1+mvBkRipA4qIHD72+of5cO5P+g s9mZdpZ+7YLMK9MlmmfIwpi30cXlIvFqw/LPszubpzKewS3TtHm9TX9dSUfwpTuk1Smu HZnlyqPPNOGge84hqhRh5YpBz6xAangGMiTgB+KcmeL6un0xZhEPsrMXYxptQDRpJ9WZ mVng== X-Forwarded-Encrypted: i=1; AJvYcCVm6MqyIfUxonzk4pSn+4Noq4pzOrPp8A6ukFmlXkUIKlSsuA7bAyU9bP+GBLf/f8NULZ5KaO7b/g==@kvack.org X-Gm-Message-State: AOJu0YzawurGisI7zgEA4XCl+zmzSkTw/kmfWhFk5HyULlfmP+9S08Sm keoQbLpRZgtEEqJ8PeMYmUv1TZ2KxDcKm1kG7eaYiEH0VmRI7ZVe8WXe1JxYfPw= X-Gm-Gg: ASbGncu36L/GmAgeUUUjeg/8MVnvb+shX0COSfEY9XYcjYh5ojKoquvHGhxzhAilVLG vg1TNx6H7Y5qDmsMQoP93hzSRXVvYF1IU8wz0ArT8NiqOGH8X5KguCH5FnxoSueYSweuBC0QL4O rOCBS1AYyc702wmp0piAZJdl/Ul4o63VOcamLZ3gUgDO2IiNQ9il/A4WJf75LjOVALUmehNtgUA v6/+i0LvSUeZx/+holnxggcv5VDa3KYiLH9kuOXEiQYunz9Uq7vCquzi+oxCe3IofmLwjfb//b4 6Mc= 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> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: F373F120011 X-Stat-Signature: or7gewsjgyzhfbkdzybc3644mym9drqd X-Rspam-User: X-HE-Tag: 1737734066-81111 X-HE-Meta: U2FsdGVkX19iC+HaPXyOZUybm5b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+tSyhdumUnoHIq0KnVXYpMpabB51gTFbxUtbKOlltJwrgW5SwUKSjExSQ2L8n9Dh+eUGd13BGcmYT1n4Z8Xz1X6Qr7+0UbuLnkvrZy3DLWI7HrEPyP1SxvsWY3k8UiuIMIcOYWMo3aEuPL6Ptgyoy2Pv5tggpkYjdB69/cE2czffVD8lt0YkJmje/f5xGTonPnp9o3Cf0I1KGDIWpTpJXgEWU/VeRC529US0rfSBvIZFkVZEIwaO7thArmGuvZy6Ip/1wz2oZFr5h7MLck/N+2rqBae5jPYhblOM3FHEKIRLwgtIy63EWY4plmaBZVQcEXZG+6R+KpiMP4o4Iy0UXm9O27X4L3C9N9Xo8r4T8vNpwRxdQ2yeR8Nwl8dF0eQ= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: 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.