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 2024BC3DA63 for ; Wed, 24 Jul 2024 23:36:17 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AA20B6B008C; Wed, 24 Jul 2024 19:36:16 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A51226B0093; Wed, 24 Jul 2024 19:36:16 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8F0D06B0092; Wed, 24 Jul 2024 19:36:16 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 71F376B0088 for ; Wed, 24 Jul 2024 19:36:16 -0400 (EDT) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 1B34A80CA3 for ; Wed, 24 Jul 2024 23:36:16 +0000 (UTC) X-FDA: 82376257152.06.6C74B39 Received: from mail-lf1-f51.google.com (mail-lf1-f51.google.com [209.85.167.51]) by imf08.hostedemail.com (Postfix) with ESMTP id 3EDC316000A for ; Wed, 24 Jul 2024 23:36:14 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=1LB2Fd2Y; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf08.hostedemail.com: domain of yosryahmed@google.com designates 209.85.167.51 as permitted sender) smtp.mailfrom=yosryahmed@google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1721864135; a=rsa-sha256; cv=none; b=zJVDTb6+DzoQlffE0NVaMBZEWtx3WY40tIqmQH8pJeWTkIoNfFxexkyzYRSO7I4jXxVQMc u1Wy4MY0flie1nU/FWNF/Pf5zozyFr5MIBjtX8SnGztZvLjDImdT5Vn6uoULkHdBcjKxZ5 E0XRkPRtZYJ5TaVk/v/GFqVcPo3ocKw= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=1LB2Fd2Y; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf08.hostedemail.com: domain of yosryahmed@google.com designates 209.85.167.51 as permitted sender) smtp.mailfrom=yosryahmed@google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1721864135; 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:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=9Z14TG9ioLTTUthPr+yZnTAKsDPH8dPhxP34WA6DWGI=; b=w+5n8xrsxzxhsoBuZ5tPHMoyv8MEZit4JZTlva7wuvytAdRRGajJDo9GCoOi8223tDBByA QzOVuMxXs4c/TxZD+29dZZHlRJf7bsz754ffPXHWnwCTtSDAOSmQu+9onDxjR0Ov3DlTdV oGfux/7fjJ2HoeP/9YEY2fNPiyPWRCA= Received: by mail-lf1-f51.google.com with SMTP id 2adb3069b0e04-52ed741fe46so269013e87.0 for ; Wed, 24 Jul 2024 16:36:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1721864172; x=1722468972; darn=kvack.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=9Z14TG9ioLTTUthPr+yZnTAKsDPH8dPhxP34WA6DWGI=; b=1LB2Fd2YOQvZJ8Nbl124lpVUlc9hqVrQ9W1JQea4ZJddDPUuF0fslUPcFe1oDxIZ5l cW9b0uSo9ckkgVENEec72IHhUY0SM5ecO33j0R+3J3n/PxSFB5fDmapbd7o1D9Pe1jxa R0H8TglZLXGkbzJzP6NTfSVLtVMaDBKHR8cf52ObY3fpY6QchmnlLP8Ow7nwogiBaw+/ GeGqak7rHkNUkdKdng2flxgk7Furyy8IhBH9KuGoRF1c8xrfM3sR5ygFSulR+OjupFu2 RNDj4lwcRFZCpx3MD73z1oKTaCxSFwXqL/JuVek7yh0W0yFe89NOMmhYWQ48Zn7aVX1z G2Iw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721864172; x=1722468972; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=9Z14TG9ioLTTUthPr+yZnTAKsDPH8dPhxP34WA6DWGI=; b=Ud/VLUAVua/5Pj28gJOC99zCFpdcAxzUdGpGggwCcNFabVwi4RvXw6Gb6qSNYm93Tp okYwec/oUV8stNdZxLX3DWEOjGDfC9IAJAG+W1jmXccw6KOc/zYTt30AAX19e/VErlwC v0cn/CFDP7IfuSlj0dOpEspHFulpyNlUvDAHuEWXXT1WdLPpSqnRf5kGNXATEUwB/Q5D H3Hg3TwIM0IY1R4XuaQAoDaTXQMn0+NDWNS0I7owmjf/HwjdFzCJhIf4SHoU86e+dXBW 9ynUlfKRUFlhdF8xHKEKPTglHf1Fq4K7CUdbP1PROKOiVGSRFgPU209djT3wIyYIQNGG yfOQ== X-Forwarded-Encrypted: i=1; AJvYcCVWsu60HUos49eJQqMqzwKlZTSdJD3jaaYY8H6uFbUXkOtoMUzTfWa2JS1SPpIEaK5vsCwJKY7KPc2x+EkNSruVMpI= X-Gm-Message-State: AOJu0YzG/BYFw4uoojFBQPdky0D6xelZkF4CCnvHK050FFOlgAYtbx1k lavLowxCk7VFRDxniIzhm/aDJxMrd73XUvb8qy2chkB1ThqIf3CfPcWvvI7unzbwZB0yFvXP491 yqbT/InrIe3hPIkB9AO7G60f4UvCAN/1i26eF X-Google-Smtp-Source: AGHT+IGCWS0jFUejC8Nzs7Lc+2SXRvrtXA7Nz3f6ntT2JmGEMIeIIzGjTLtivQUEp0ahRgP4rBevjanPg2hd9f1ozAk= X-Received: by 2002:a05:6512:32c9:b0:52d:582e:4117 with SMTP id 2adb3069b0e04-52fd608f044mr91074e87.54.1721864171356; Wed, 24 Jul 2024 16:36:11 -0700 (PDT) MIME-Version: 1.0 References: <20240724202103.1210065-1-roman.gushchin@linux.dev> <20240724202103.1210065-2-roman.gushchin@linux.dev> In-Reply-To: From: Yosry Ahmed Date: Wed, 24 Jul 2024 16:35:35 -0700 Message-ID: Subject: Re: [PATCH v2 1/5] mm: memcg: don't call propagate_protected_usage() needlessly To: Roman Gushchin Cc: Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Johannes Weiner , Michal Hocko , Shakeel Butt , Muchun Song Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 3EDC316000A X-Stat-Signature: 9bbrceucpfngx7kqu355k4j87rfy9xbz X-Rspam-User: X-HE-Tag: 1721864173-301393 X-HE-Meta: U2FsdGVkX18QxWS5DcChEZ15QikfqdQNDCqdkPep/gFX9VfkJI13gL00T3g43l7fqWbUZS5QEwEbY+vDzMT/YfnSRUkOsC/TXfa7GuS+wcCow+0G4gSfqZ6d/aNy3dgAyaTeHKbdkslPYq2ju5i/FxVg5KynRiCs558nnTl1Rs8p5eCpoDs+pH/tDohuirAbcVEwIXlIkn5FbSsuJjn4WuTLvMmn3HPKq9O/TO9EcEF/yqi0WWoiZ/Hy9A+FR0yapcj/LCV8mFg7i7hgAgk1W4/6qIehdG3Fsve4TuULDpTI+3azUA1sstYo3bPXIRHo2hYRnKQh89C9hKOJbqk0DZ8Ml8RwTkE+f8AIfvJyULp3cPRbiVp7e3QrTju/Ozs41tzeKtMj31RbPobog6/EETNqhdER31PD0GHVg0HuILX/5OyJApaHg+CfmRE5cXjmCs563MWXhFdYiJMVuOr286O7eL+rIuNOhPDI/qbxGaiR3tg5BCLtA6gwizOBKQcOgENLhiPhmE0+72pvMABfu85LpOZp+lGKMOcS+5Dqj+wikJ+S9MXlIqMhsEyF3ya4oD+u2FaKhlVWlYJM4WEvzuw7bH4Nd4tNtpLTDjXnXXmNYtMD8RYcJdUxfkNry043G6Obh5v/7KLLxl3oYxc6lJR4NHqYD5Gv/rO+ZEgQjvmZVK4TT8IkGMf3G46w/1/cNUQuoKvKyDDyyb6pE1xPmlyypuc3x6/qhA47gDuIcUmOADNLbwwB1DVqTagsrKmXobXU6+q3yEepNSdBsojUl8KBtbJ1+AsXGtmZJp4IhEUIpzcTXhLFvpi6meqKgJg6aGGirdNzs9AmTdUPnRiuqubQW7SOVP51aXYzCGoctjjRqgksZy3APLVOFlnkFlJgmJwMtm56ZmD3RJmck5jtCHXoaoJ2ybtsH76eUkOH5IlXZX6drfoWQN9D9r/w75QEN9/h6jFgQxJQs5ZOcAq 2rR/H04e /XPtKvbZSu/Yj5yxKSwwBor1I8M4EJcrWeNZVTEMhaIU0t4oIC8Tx/mK0M0RFUG+41HR8U/tchpYqYW8vZ2iS25+B54zqmHAZusPLdDXP6n1108wot9MxLcvnNfhp5gpPxFbqCq2mrYi8nmJoZkVn9VQkhrgbC1l/aEUsw+MFQ+gzNo31hfDdU12xvn+jVT5j1QrmXGZY14KS4oSDSF+nYoR5Ug== 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 Wed, Jul 24, 2024 at 4:32=E2=80=AFPM Roman Gushchin wrote: > > On Wed, Jul 24, 2024 at 04:13:17PM -0700, Yosry Ahmed wrote: > > On Wed, Jul 24, 2024 at 1:21=E2=80=AFPM Roman Gushchin wrote: > > > > > > Memory protection (min/low) requires a constant tracking of > > > protected memory usage. propagate_protected_usage() is called > > > on each page counters update and does a number of operations > > > even in cases when the actual memory protection functionality > > > is not supported (e.g. hugetlb cgroups or memcg swap counters). > > > > > > It's obviously inefficient and leads to a waste of CPU cycles. > > > It can be addressed by calling propagate_protected_usage() only > > > for the counters which do support memory guarantees. As of now > > > it's only memcg->memory - the unified memory memcg counter. > > > > > > Signed-off-by: Roman Gushchin > > > --- > > > include/linux/page_counter.h | 8 +++++++- > > > mm/hugetlb_cgroup.c | 4 ++-- > > > mm/memcontrol.c | 16 ++++++++-------- > > > mm/page_counter.c | 16 +++++++++++++--- > > > 4 files changed, 30 insertions(+), 14 deletions(-) > > > > > > diff --git a/include/linux/page_counter.h b/include/linux/page_counte= r.h > > > index 860f313182e7..b31fd5b208aa 100644 > > > --- a/include/linux/page_counter.h > > > +++ b/include/linux/page_counter.h > > > @@ -32,6 +32,7 @@ struct page_counter { > > > /* Keep all the read most fields in a separete cacheline. */ > > > CACHELINE_PADDING(_pad2_); > > > > > > + bool protection_support; > > > unsigned long min; > > > unsigned long low; > > > unsigned long high; > > > @@ -45,12 +46,17 @@ struct page_counter { > > > #define PAGE_COUNTER_MAX (LONG_MAX / PAGE_SIZE) > > > #endif > > > > > > +/* > > > + * Protection is supported only for the first counter (with id 0). > > > + */ > > > static inline void page_counter_init(struct page_counter *counter, > > > - struct page_counter *parent) > > > + struct page_counter *parent, > > > + bool protection_support) > > > > Would it be better to make this an internal helper (e.g. > > __page_counter_init()), and add another API function that passes in > > protection_support=3Dtrue, for example: > > > > static inline void page_counter_init_protected(..) > > { > > __page_counter_init(.., true); > > } > > > > This will get rid of the naked booleans at the callsites of > > page_counter_init(), which are more difficult to interpret. It will > > also reduce the diff as we only need to change the page_counter_init() > > calls of memcg->memory. > > > > WDYT? > > No strong opinion here. There are basically 2 call sites and I don't expe= ct > this number to grow, so not sure if it makes sense to add 2 new helpers. > > Another option I thought about is to leave page_counter_init() as it is > and add a separate function to enable the protection tracking. Yeah this should work too, in fact it should give us a chance to choose a more descriptive name that page_counter_init_protected() (e.g. page_counter_enable_protection()). My main concern is the naked booleans, and secondarily the unnecessary diff to other init sites. I also don't feel strongly about it though. > > Thanks!