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 5C0C2C3DA61 for ; Wed, 24 Jul 2024 23:32:09 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D0DD26B008C; Wed, 24 Jul 2024 19:32:08 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id CBF316B0092; Wed, 24 Jul 2024 19:32:08 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B853E6B0093; Wed, 24 Jul 2024 19:32:08 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 9B5C46B008C for ; Wed, 24 Jul 2024 19:32:08 -0400 (EDT) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id F149A40B80 for ; Wed, 24 Jul 2024 23:32:07 +0000 (UTC) X-FDA: 82376246694.23.95B43AC Received: from out-179.mta1.migadu.com (out-179.mta1.migadu.com [95.215.58.179]) by imf05.hostedemail.com (Postfix) with ESMTP id DA09810000B for ; Wed, 24 Jul 2024 23:32:05 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=BoqNk3s8; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf05.hostedemail.com: domain of roman.gushchin@linux.dev designates 95.215.58.179 as permitted sender) smtp.mailfrom=roman.gushchin@linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1721863872; 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=pqINtMpqerirwytDRn2yUhT9tOOj5Ldg0qn/p88A8pU=; b=KcX7ypovSAKDFu4W+c/aiAfHt2TAXp1FOVkLL4kuq2bNTcHq7o08UXCIYjevzQypvDh2js 3Ps4UbfS/sDVqpE98DXCfWJ14sxrebBb8GEggjOq2Na+9bhnU11hUwt8H3CvFUehfddfVM d6EK+ZsdvU/kQzRgkBc8k3kDrq8NrcQ= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1721863872; a=rsa-sha256; cv=none; b=NA93x2x7dLvl3tfIPl0sm5WvWS1VX4+9NBhIe6ykcv63pjCnhh4AhGWE39KX8yVzyc6cO3 LijOUHgUwwWra/Sz/Jf6chrNuoejoXqssYjQ1zc6KkZ6rq97/fiSxOOwb0x23bsUz6YaW7 Jg1vWQlyts/Wqtj1HIMDS8ozBdVbFMQ= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=BoqNk3s8; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf05.hostedemail.com: domain of roman.gushchin@linux.dev designates 95.215.58.179 as permitted sender) smtp.mailfrom=roman.gushchin@linux.dev Date: Wed, 24 Jul 2024 23:31:58 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1721863923; h=from:from: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; bh=pqINtMpqerirwytDRn2yUhT9tOOj5Ldg0qn/p88A8pU=; b=BoqNk3s8xNDnNwtcI8X8LcVtoz6mTiPxTiIKroFIi+KNWFThNcrlxYhmxLs3cdp/EMiytO 1K1QoPWIKxDsGh0bcwLH3Vd0K32iyy7kmQ5NkgH8Xdl+KHv81w0mO3GaEAyLC7tzNmy9Hq lx7sujOZvALnyGWF/cAxS9WCmhpnMSM= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Roman Gushchin To: Yosry Ahmed Cc: Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Johannes Weiner , Michal Hocko , Shakeel Butt , Muchun Song Subject: Re: [PATCH v2 1/5] mm: memcg: don't call propagate_protected_usage() needlessly Message-ID: References: <20240724202103.1210065-1-roman.gushchin@linux.dev> <20240724202103.1210065-2-roman.gushchin@linux.dev> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Migadu-Flow: FLOW_OUT X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: DA09810000B X-Stat-Signature: fgwysakpspsymj375r6ofw4yczkfyi13 X-Rspam-User: X-HE-Tag: 1721863925-689132 X-HE-Meta: U2FsdGVkX196Z+Blpr2wcEA9vqWtq9PyV6OBEqJ1hhsgp7j/lobZusEzX1RZDo5FkFpnFM6iwvTvpEKDpAlfI10ShryhhYvZ+blmthgycK3OZIFEN+E100NHQ7M+4V9Vy9w4VPk79mtS2A6rUaamS2YvzxcF7KchXws+hqZ0wIXoyPt5olNzkvwtGC4nIPS9oeBfpKbwEWbX9DidY34qTPJdOKBVZA8A+nMkEN4xadzE7ZOMVzbAGrYN1jBUYU1UjXrbG9thIUg1d6AF56vWtJbfrIqvY2ujC8zx4Nx4LFFplc69QAH6azna2//hu5VT4vLxoK28fz+E5KCLH1hSmU3Ky7UXTGUXVenzO5fe53BOa+wES8wFIIuhQKWWFefYA7aDU4Jntex0CkpV1DMZ+6YeWY//vq0z5Z6ajtmpIlxtalA+zhbqscvG3nx4aPoZCnNVeoXGU+YdmZIlhLo6m5fIZIDaax/r3rPN2wjcRf9LbLVDuXYT2bmi0IgUdj9d7bOA7BimErmOW2JuNQGVEF101mzJcmL6MebEnPOh0HvKkTncml+TpVvsC25cULc41djrpwN1mNk2sIcfUPcVcNLQMo3ZVg/g/8lmwNniBOn/L6JeJmcZRFNDL4qUyfpA2L43bEi80csjaGE5hqNmndlyC3R1niaufsuzPOva6v/UzaWqRkxQxFLIkZc1hI0Kg7oombErmbq6eTotBRD9nYYbf7ddE13zlUP/qKleZIwjfUQ+A0ifFMqGC6K7TcwSren59GpldWb/BntK8yr2v+9l9vnZTe+ta6SCYkNjDcbpJqYoZcsruqUIALge4j8R1ZWMdhk3jKb06jmnshPN0HsFMlRED3J8WkPVlhL6obqTkE4pnrVGxg5Hd4hGBG9xzEl/lmy28jPx15TWH+dtjzJQsQMInAvUonNl3w+lbDEjDiuHiA9XbhsSDdsbKkTYJxPLxjSP7IjDbPc7yB7 XoTLFaJV NMIvVp0YttV6gHxYoLSULpzW+G83cOGpPfxlFvM2UDwC/fsiuQ75cqO5eYz3fcO0eXrx1pdPiO8N5fCV/LBPNfafdxJ2+auUBV5jyepmAwEjQ6cNMRyAWdGOBQo/5MTRjDKiRPYXQy0hbeF4UUmOdtSaNyT8yjUa0WWbDZvUDW7AaK4oRO7wGC0X2Gw== 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 04:13:17PM -0700, Yosry Ahmed wrote: > On Wed, Jul 24, 2024 at 1:21 PM 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_counter.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=true, 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 expect 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. Thanks!