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 6040FD11185 for ; Mon, 4 Nov 2024 06:46:08 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D74C06B0083; Mon, 4 Nov 2024 01:46:07 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id D246F6B0085; Mon, 4 Nov 2024 01:46:07 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BC4E46B0088; Mon, 4 Nov 2024 01:46:07 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 998C46B0083 for ; Mon, 4 Nov 2024 01:46:07 -0500 (EST) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 0879F1A046F for ; Mon, 4 Nov 2024 06:46:07 +0000 (UTC) X-FDA: 82747477596.02.E796450 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.16]) by imf02.hostedemail.com (Postfix) with ESMTP id 9340E80009 for ; Mon, 4 Nov 2024 06:45:04 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=Lslcgs5s; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf02.hostedemail.com: domain of ying.huang@intel.com designates 192.198.163.16 as permitted sender) smtp.mailfrom=ying.huang@intel.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1730702599; 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=ijbmuJ8QhC+zqY/wceRzcoSKC7fcOVs9egD4grLDp3w=; b=Nqy/7V5k4onhRsxyfnMgNY3hadc0u36SJHw5udWcsBMmGbu8fWHqmvDLJtc5mnAz3VsJIX PrzB8rfs/dt6/IKfr0rzJdqGLVcWdy6+wuflGjWJTlTPbEpgvNTUPYpI2Hh2D5jMk0FZ8C aD4cc4h9hgR2UzRQ3PElKXCDeK9jmLA= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=Lslcgs5s; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf02.hostedemail.com: domain of ying.huang@intel.com designates 192.198.163.16 as permitted sender) smtp.mailfrom=ying.huang@intel.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1730702599; a=rsa-sha256; cv=none; b=0zc3uOixH6sh7FG3B9eJku1ALbCjOfzOaaTDsb2aW7xbmiYyyUNtV9kJkYW1RAdWxqdWyS QghhK19Q64L0t0HB0ldyRkmFH4YzI4rYXdggtiVGx2yZlvV2IM+KRfyKc6O16ZJ93kjLdl DN59YrQ1wLSatLwA1U3WDcbHrJDbYeE= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1730702764; x=1762238764; h=from:to:cc:subject:in-reply-to:references:date: message-id:mime-version:content-transfer-encoding; bh=9vGR0YQIvHMo6L5jVnyVbE9ShD0ZT3SSjFtwHagm3Fg=; b=Lslcgs5sQibxiI+1yVSKXektXT9SsuD0S3QNYQrchH/pQalUnr9M0akf hSSauqWRlqlwG9yItmcPXqg+8BXz/vDVHvqA2AgBVtZZg9M18rtB4EK/L 7kpao5eXer409RCC4md+TEcpPkgJ40iJbalyF8u8neYED3NdcGODqZfW+ oy1mPDrbg42CQOQCqEOLeyeb3MNtCJaS8fXR4cD5pvqShniycy2l8aOun hGYzqovmGsovOfCtbT9K5tUWqbEXYS4BPjzE+APO2XTfH3KGssmWbbmGh mcg+2BuKz6QW8zoPizueZCyyP3xFlwr9FAqw1wZxo5xj9WAFrxb/Wi75x A==; X-CSE-ConnectionGUID: KYAo5VgJQ6SNTD+e8MMuUQ== X-CSE-MsgGUID: sdEU3OhEQs+vdsJ9FVPckw== X-IronPort-AV: E=McAfee;i="6700,10204,11245"; a="18003266" X-IronPort-AV: E=Sophos;i="6.11,256,1725346800"; d="scan'208";a="18003266" Received: from orviesa009.jf.intel.com ([10.64.159.149]) by fmvoesa110.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Nov 2024 22:46:02 -0800 X-CSE-ConnectionGUID: 4VnCjYr1QGi6HIQAGYiobA== X-CSE-MsgGUID: dXoz8yVPQx2ps68GIKnJXg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,256,1725346800"; d="scan'208";a="83443891" Received: from yhuang6-desk2.sh.intel.com (HELO yhuang6-desk2.ccr.corp.intel.com) ([10.238.208.55]) by orviesa009-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Nov 2024 22:45:58 -0800 From: "Huang, Ying" To: Johannes Weiner , Barry Song <21cnbao@gmail.com> Cc: Yosry Ahmed , Usama Arif , akpm@linux-foundation.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Barry Song , Kanchana P Sridhar , David Hildenbrand , Baolin Wang , Chris Li , Kairui Song , Ryan Roberts , Michal Hocko , Roman Gushchin , Shakeel Butt , Muchun Song Subject: Re: [PATCH RFC] mm: mitigate large folios usage and swap thrashing for nearly full memcg In-Reply-To: <20241031153830.GA799903@cmpxchg.org> (Johannes Weiner's message of "Thu, 31 Oct 2024 11:38:30 -0400") References: <20241027001444.3233-1-21cnbao@gmail.com> <33c5d5ca-7bc4-49dc-b1c7-39f814962ae0@gmail.com> <852211c6-0b55-4bdd-8799-90e1f0c002c1@gmail.com> <20241031153830.GA799903@cmpxchg.org> Date: Mon, 04 Nov 2024 14:42:25 +0800 Message-ID: <87a5ef8ppq.fsf@yhuang6-desk2.ccr.corp.intel.com> User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 9340E80009 X-Stat-Signature: m7mnhj55u1knnnrkdgdwtdee5iiaeo4n X-Rspam-User: X-HE-Tag: 1730702704-674815 X-HE-Meta: U2FsdGVkX18GKB+jgCno86jZPv2Irg2SAcSd4xqDNCutdlWBYlMJubkEhHc/Xc4sPFWwOZBqRq2lmad7FY1c7ukk1/vfyvdpx+KFVfFcx/aH6aLEgTzdtkA+y6yfWyrs3yQoYMzlSsxsu/Y/HmLpG08bHOXA9Pw296OmlyNjJxSmb9tle+LJ//rtAWWTB20eb7WescRahoFojSJ4ecq4ez20mIW6L9qmJzc35UMLW08AptJ5USOS3sJHdh+53uNVKmuOe5U8+194v3yjyh6w11s/9YmfEWYTIYZPUIPXHsrVZHUrzQTxiz2mcODFHAX+u9swh8ByhqOlZpBroEqfCMCyFEEHH9/O7++th+C0GBuRM19flrwKK5nUq3sIdhOGIVtGLDsRfeJSzb6uq3CY27nWoqU7PVSHV0S+Ewtx33w5vco0KpFC1xorZpZDCIOb6JmOsRI47i5vCXEnaY594vYV7TKR+9+Z0TlvDoYipgus9KMj0mGfP7lRhYDnq5Ezbx0JtFTO9kn3n7h9a+iAIkIf8BFZxzH5w+ZB4UzFed/YSrt2CkGcbi7WY5vPwLKZjFatvVwGvdzqLTNDeWgYcbSbEtCIyZxPvnBHE21VYB+wzFmvwbToxJXcdz82TCk0MSvdKxQo9/fEo0TNSqneCAslzHsPM4+y24tkIfXZvpd+TpqzKwZxnSePBKN0UHBq3zrIfvJD8UtY1dHtJFu0IR7kGrHn3vr4T50Ad6y0ixDwVg78gUKZndBvQfuTTlEC80GQ3tGfLmrxkMwj6zwuuvIJjv/DHN7hlS/yB9srqEY1VoYyWwtqEixHaURtZG5F9mk/zKgorTAEoQkb+gw8CI2HI5DzcTZgG2K1pGFnx5suu4+jho9S8zgYcEwSt96GnGS6N8zeQUcY0h0j1NIUSnqSaFsSrd6DU4qhISOOyN2uOB07NJByYZZNMLywcqCKej4fw3Mvxu8Po9PTZ// Cd8P70hL R6Pv8gZFjhCXmHwvaj6xry2dJoFRwd5Wjc50jtAcctSAHg/XGhYRGaJiH7j7UOILKzJ5tdbfiz1vD5IYJ0bOn6EJuP6Br3cqfLaQZ8hH4u6Bv+svWFXJ01IImQhmJF24QxyqxPPMonV7OvqORjvGVbAC8eoxTfK7I1wLmVNsJhuS5K9s+dckg1MgMBAFrWpXbtB1dQc/afILqs2IVU0oQcr3JHlS8KGdJnyWnkCzIw5iduk5ZOLB/vRrCacmb4U6DkBvs 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: Johannes Weiner writes: > On Wed, Oct 30, 2024 at 02:18:09PM -0700, Yosry Ahmed wrote: >> On Wed, Oct 30, 2024 at 2:13=E2=80=AFPM Usama Arif wrote: >> > On 30/10/2024 21:01, Yosry Ahmed wrote: >> > > On Wed, Oct 30, 2024 at 1:25=E2=80=AFPM Usama Arif wrote: >> > >>>> I am not sure that the approach we are trying in this patch is th= e right way: >> > >>>> - This patch makes it a memcg issue, but you could have memcg dis= abled and >> > >>>> then the mitigation being tried here wont apply. >> > >>> >> > >>> Is the problem reproducible without memcg? I imagine only if the >> > >>> entire system is under memory pressure. I guess we would want the = same >> > >>> "mitigation" either way. >> > >>> >> > >> What would be a good open source benchmark/workload to test without= limiting memory >> > >> in memcg? >> > >> For the kernel build test, I can only get zswap activity to happen = if I build >> > >> in cgroup and limit memory.max. >> > > >> > > You mean a benchmark that puts the entire system under memory >> > > pressure? I am not sure, it ultimately depends on the size of memory >> > > you have, among other factors. >> > > >> > > What if you run the kernel build test in a VM? Then you can limit is >> > > size like a memcg, although you'd probably need to leave more room >> > > because the entire guest OS will also subject to the same limit. >> > > >> > >> > I had tried this, but the variance in time/zswap numbers was very high. >> > Much higher than the AMD numbers I posted in reply to Barry. So found >> > it very difficult to make comparison. >>=20 >> Hmm yeah maybe more factors come into play with global memory >> pressure. I am honestly not sure how to test this scenario, and I >> suspect variance will be high anyway. >>=20 >> We can just try to use whatever technique we use for the memcg limit >> though, if possible, right? > > You can boot a physical machine with mem=3D1G on the commandline, which > restricts the physical range of memory that will be initialized. > Double check /proc/meminfo after boot, because part of that physical > range might not be usable RAM. > > I do this quite often to test physical memory pressure with workloads > that don't scale up easily, like kernel builds. > >> > >>>> - Instead of this being a large folio swapin issue, is it more of= a readahead >> > >>>> issue? If we zswap (without the large folio swapin series) and ch= ange the window >> > >>>> to 1 in swap_vma_readahead, we might see an improvement in linux = kernel build time >> > >>>> when cgroup memory is limited as readahead would probably cause s= wap thrashing as >> > >>>> well. > > +1 > > I also think there is too much focus on cgroup alone. The bigger issue > seems to be how much optimistic volume we swap in when we're under > pressure already. This applies to large folios and readahead; global > memory availability and cgroup limits. The current swap readahead logic is something like, 1. try readahead some pages for sequential access pattern, mark them as readahead 2. if these readahead pages get accessed before swapped out again, increase 'hits' counter 3. for next swap in, try readahead 'hits' pages and clear 'hits'. So, if there's heavy memory pressure, the readaheaded pages will not be accessed before being swapped out again (in 2 above), the readahead pages will be minimal. IMHO, mTHP swap-in is kind of swap readahead in effect. That is, in addition to the pages accessed are swapped in, the adjacent pages are swapped in (swap readahead) too. If these readahead pages are not accessed before swapped out again, system runs into more severe thrashing. This is because we lack the swap readahead window scaling mechanism as above. And, this is why I suggested to combine the swap readahead mechanism and mTHP swap-in by default before. That is, when kernel swaps in a page, it checks current swap readahead window, and decides mTHP order according to window size. So, if there are heavy memory pressure, so that the nearby pages will not be accessed before being swapped out again, the mTHP swap-in order can be adjusted automatically. > It happens to manifest with THP in cgroups because that's what you > guys are testing. But IMO, any solution to this problem should > consider the wider scope. > >> > >>> I think large folio swapin would make the problem worse anyway. I = am >> > >>> also not sure if the readahead window adjusts on memory pressure or >> > >>> not. >> > >>> >> > >> readahead window doesnt look at memory pressure. So maybe the same = thing is being >> > >> seen here as there would be in swapin_readahead? >> > > >> > > Maybe readahead is not as aggressive in general as large folio >> > > swapins? Looking at swap_vma_ra_win(), it seems like the maximum ord= er >> > > of the window is the smaller of page_cluster (2 or 3) and >> > > SWAP_RA_ORDER_CEILING (5). >> > Yes, I was seeing 8 pages swapin (order 3) when testing. So might >> > be similar to enabling 32K mTHP? >>=20 >> Not quite. > > Actually, I would expect it to be... Me too. >> > > Also readahead will swapin 4k folios AFAICT, so we don't need a >> > > contiguous allocation like large folio swapin. So that could be >> > > another factor why readahead may not reproduce the problem. >>=20 >> Because of this ^. > > ...this matters for the physical allocation, which might require more > reclaim and compaction to produce the 32k. But an earlier version of > Barry's patch did the cgroup margin fallback after the THP was already > physically allocated, and it still helped. > > So the issue in this test scenario seems to be mostly about cgroup > volume. And then 8 4k charges should be equivalent to a singular 32k > charge when it comes to cgroup pressure. -- Best Regards, Huang, Ying