From patchwork Thu Aug 22 08:38:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhongkun He X-Patchwork-Id: 13772995 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 3E9C0C3DA4A for ; Thu, 22 Aug 2024 08:38:58 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C11D98001D; Thu, 22 Aug 2024 04:38:57 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id BC12780017; Thu, 22 Aug 2024 04:38:57 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A38DE8001D; Thu, 22 Aug 2024 04:38:57 -0400 (EDT) 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 7CF0580017 for ; Thu, 22 Aug 2024 04:38:57 -0400 (EDT) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 1B89BA884A for ; Thu, 22 Aug 2024 08:38:57 +0000 (UTC) X-FDA: 82479231114.26.2AFF511 Received: from mail-pl1-f179.google.com (mail-pl1-f179.google.com [209.85.214.179]) by imf18.hostedemail.com (Postfix) with ESMTP id F202A1C0016 for ; Thu, 22 Aug 2024 08:38:53 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=JUWcTXDQ; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf18.hostedemail.com: domain of hezhongkun.hzk@bytedance.com designates 209.85.214.179 as permitted sender) smtp.mailfrom=hezhongkun.hzk@bytedance.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1724315875; a=rsa-sha256; cv=none; b=0RcpCwm7JSWPu6dz1wwctxzuLp6ZLW2sDkErF9eXVfyEHt9AvzcnmRawGpxD1dfUVOdMl6 hifk8Hqbit9fGyNSVhqvsZ8Y6SUeeuNwtuC2uGvFMSl4702XB7X/4wMFPqrBaI/0+Y3Vw5 9bs1UuQzYvU0Gz4PZyOPb7mrWgJUdxY= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=JUWcTXDQ; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf18.hostedemail.com: domain of hezhongkun.hzk@bytedance.com designates 209.85.214.179 as permitted sender) smtp.mailfrom=hezhongkun.hzk@bytedance.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1724315875; 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-transfer-encoding:content-transfer-encoding: in-reply-to:references:dkim-signature; bh=b2u1WsAxt5JgAdG/+BbrIkNxjYeux2TdSi6nksps3OA=; b=dE1M1C0N/K8/abC0AX+d6JqIFynquSj5GbGY5uQU4Wic1RuA8Ehab7YDKPoVwJkqQfcQ0P N/t+ieuPJZji/2qfDaldhcf8K1nGHazA77eHxeAGy6628shXX1FAL4A9kXzaJq8OxAFqwk apU0DFQQSCXwy5PI9Tk+2HaRTf6UI1o= Received: by mail-pl1-f179.google.com with SMTP id d9443c01a7336-201fba05363so3794265ad.3 for ; Thu, 22 Aug 2024 01:38:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1724315932; x=1724920732; darn=kvack.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=b2u1WsAxt5JgAdG/+BbrIkNxjYeux2TdSi6nksps3OA=; b=JUWcTXDQgR8sRSByuLZi7CgJkvXmuPR2tvLcm6aO05AqLGdvoPCC4UrrJ+JBphq8aN CTtFb8BRmZlSpFT9b33YCIjMu71y9kMHeCbfg0LhM1qmzSwfS/2vj6fsS01Qi6gvDsIR OM/dz0++ftthI0R8vcoJjPKJ7cp77LZbz+CHUBwXh/alUK8cPUcW9cdIRgHwM+KPnF0i fXr524ID/4xHBW8Xhpp/97DyXqINaRme85fz88GW/o0wIOaIAJCqmO5yz1d4BU89sle/ nZQJUSJcUsImYkqd2G5xyEEVefKnBvDwArHcIQhB5ZgOAltz66W+z+NyK9KcDvijdBnI LEXA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724315932; x=1724920732; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=b2u1WsAxt5JgAdG/+BbrIkNxjYeux2TdSi6nksps3OA=; b=JCRIh31yEjdUazXwWPM3McNB+KRh1irgKzhyL/PQ5nghUjiHKKy4QiMFE1to8Ax6ek AdTQeT/Oe8ereT+tBhT5psq4ZBiz1yCIy9kXt6JWJlxuEsoQhGHzsEMppO3I3h9jVpOo 3RSg26b0WOylrOE5R0tQuxObYefaVsihaXLOSHfeXEG21GsGRy9TE5NN7Lcy1aQNHZ12 AULbgZLBo4gF+Cq8Awey39odu3j33Ljkj0x9UWUznpiottd2koEB4zTp1zAqPkUWYd9z 6TaOQJ3xc2W3fHqvddNocS8u2DPl8OOSBmijW9DvSvt6ehysmCglyt3ZM3vOYLUR2vPm oQiA== X-Gm-Message-State: AOJu0YyNcDDmRh/wHpq9KoNX3DYA/Tqfj0eSU4aN7v4TVvfOLUar2RI3 +Cg4Vxsi+bEDrzelJTjBDlpC90yKdkKmknL01lZlcRByNBRysyo7tlFb/DwwWC8= X-Google-Smtp-Source: AGHT+IE6zPuDFiYPZ9j6ugZo61SY5bpPFGgMRvk+dLzDnZlHpisUHQTef0KsNQ2Vz/xKZ70B17VEWA== X-Received: by 2002:a17:902:da8f:b0:1fd:8c25:415d with SMTP id d9443c01a7336-20367f6ad3bmr63104275ad.36.1724315932202; Thu, 22 Aug 2024 01:38:52 -0700 (PDT) Received: from n37-034-248.byted.org ([180.184.51.142]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-203855816dcsm7870835ad.112.2024.08.22.01.38.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Aug 2024 01:38:51 -0700 (PDT) From: Zhongkun He To: mhocko@suse.com, akpm@linux-foundation.org, mgorman@techsingularity.net, hannes@cmpxchg.org Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, lizefan.x@bytedance.com, Zhongkun He Subject: [PATCH V1] mm:page_alloc: fix the NULL ac->nodemask in __alloc_pages_slowpath() Date: Thu, 22 Aug 2024 16:38:42 +0800 Message-Id: <20240822083842.3167137-1-hezhongkun.hzk@bytedance.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 X-Rspamd-Queue-Id: F202A1C0016 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: rsfz3t7euakd7r3ricf1xqp6huuj8fpp X-HE-Tag: 1724315933-5915 X-HE-Meta: U2FsdGVkX18d7f5gFC+EypXLeARmWk4lOp2KHFhb3Oe4UiViQhR8E9GZUUBaj4QV2J4intOfe0VLD0J4Ho9wKvxOfa41OHYlg3GsYwwvSJVXmuH3vZOYgLodosgOoug84/dbDE05AoJNpHD0/7Q9ORxkqGc/L2gcfMaDO/PQYQ6RAvQHL9Pvk9wfXMg+WI0BEsIENZNbjqchivz9PdnQZwly8RysYEiXwNLseiNkelZvA5cnzuP3nKVkRCZjFQvVD8xHFcrFjUURcW5NMuxRRWARZ9ifUdRallxE5BSShq+A+ddPUDq3zOEo8wzJVu8egw872AnFQBmx4t9DiS4LmekT315KmxHn8s/aCVW2Y7LdRsuG3mqOMQ8/ODc9oTGkF3/qg1jbTETFPhFJEcH0YisXLjxmtuGYvOqoWh29sag6ZGEcWDsdgRTbvAWvw2OSidN8eMh5kuv7UN3KxMhr/4IgUgJCbGRL5dHqsTlQnati+lfVVuVlpy018+teOPlltRQKzXG+7eSPG7DB4adF/JZqrVZn82FM6g1lBnJ3tQUKD3VAcY9nw3IbwtKCAPmprJmQ+BjVVzF9+ZW8reS0O4Q4CvrYWZRicEokz1sa48g/L/2wH2A5jR2EG4amivh4Cdgh2vdGk1pER3CWgAzvYDlQu7AWU209zHHt+di1gbe5nD2WIOjnunKrZIxmSh2///W4BgvOKiC2suntLvI/l3vbc4zKeKtpcXtkNeNOL1daLRjScf3zPNrbZrd/Z6YM7oacU/2WOiwGXuv5KxRx4AvdzT5XaMHgc/mmlGg1S1EQ/M3hbPG42MF2gBKamwUOD8f5M+ZQ+YqJJ5vMV7c4bggFriFK9PdK2IWIq6i9wDIzNvplsVTX5AwF3IhFY5PjhPF9JiPDzbYncfeNRA8lfpclyMYcztsMXOEMyL+V8KsM+6QOFTtSqj8xoTrQZ9Pp4iXamVbtZtaPSvHGPeP C4MIdzQm tUHldk4D8w9YLwqu6w8YPwYFQ/6BJWVi6UOK8iF9hg75Mt/L25s3vsA5P99Wd7kZ4gU9kPaGbmL5bPyhvZ9Gjlsuq37aF2ZP8+ubz6PbN06IKMT2dNH2ZW0bI5Ul4JLRZcGeMywgVSB41fjZ5Yn7aZrhWDPx4SeZCz+1VOazTAZHw7zvvRO24UymupgcEEtiDzuOy8idNb+KZKDgF+y0rdj6GC2YOcybLWWhe4P03enjo0S90kUJ+0O+LRn6AS7qMXNwHO6r+cgxercSmaxAxpprns23tbK6muMAmz1SqrjYoaWQX6EELB0AXjNodxaKSrOx/jto1UYNCEppUbfOMuA+6c7EizjrR9gYTdqy+yLi+Ta/XbX2xiksAOS/YnW6x538gsZD4aoreH5XN2JtD1o2lPKPi5Jfs5BA+HmdFxmaaah8= 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: I found a problem in my test machine that should_reclaim_retry() do not get the right node if i set the cpuset.mems. The should_reclaim_retry() and try_to_compact_pages() are iterating nodes which are not allowed by cpusets and that makes the retry loop happening more than unnecessary. 1.Test step and the machines. ------------ root@vm:/sys/fs/cgroup/test# numactl -H | grep size node 0 size: 9477 MB node 1 size: 10079 MB node 2 size: 10079 MB node 3 size: 10078 MB root@vm:/sys/fs/cgroup/test# cat cpuset.mems 2 root@vm:/sys/fs/cgroup/test# stress --vm 1 --vm-bytes 12g --vm-keep stress: info: [33430] dispatching hogs: 0 cpu, 0 io, 1 vm, 0 hdd stress: FAIL: [33430] (425) <-- worker 33431 got signal 9 stress: WARN: [33430] (427) now reaping child worker processes stress: FAIL: [33430] (461) failed run completed in 2s 2. reclaim_retry_zone info: We can only alloc pages from node=2, but the reclaim_retry_zone is node=0 and return true. root@vm:/sys/kernel/debug/tracing# cat trace stress-33431 [001] ..... 13223.617311: reclaim_retry_zone: node=0 zone=Normal order=0 reclaimable=4260 available=1772019 min_wmark=5962 no_progress_loops=1 wmark_check=1 stress-33431 [001] ..... 13223.617682: reclaim_retry_zone: node=0 zone=Normal order=0 reclaimable=4260 available=1772019 min_wmark=5962 no_progress_loops=2 wmark_check=1 stress-33431 [001] ..... 13223.618103: reclaim_retry_zone: node=0 zone=Normal order=0 reclaimable=4260 available=1772019 min_wmark=5962 no_progress_loops=3 wmark_check=1 stress-33431 [001] ..... 13223.618454: reclaim_retry_zone: node=0 zone=Normal order=0 reclaimable=4260 available=1772019 min_wmark=5962 no_progress_loops=4 wmark_check=1 stress-33431 [001] ..... 13223.618770: reclaim_retry_zone: node=0 zone=Normal order=0 reclaimable=4260 available=1772019 min_wmark=5962 no_progress_loops=5 wmark_check=1 stress-33431 [001] ..... 13223.619150: reclaim_retry_zone: node=0 zone=Normal order=0 reclaimable=4260 available=1772019 min_wmark=5962 no_progress_loops=6 wmark_check=1 stress-33431 [001] ..... 13223.619510: reclaim_retry_zone: node=0 zone=Normal order=0 reclaimable=4260 available=1772019 min_wmark=5962 no_progress_loops=7 wmark_check=1 stress-33431 [001] ..... 13223.619850: reclaim_retry_zone: node=0 zone=Normal order=0 reclaimable=4260 available=1772019 min_wmark=5962 no_progress_loops=8 wmark_check=1 stress-33431 [001] ..... 13223.620171: reclaim_retry_zone: node=0 zone=Normal order=0 reclaimable=4260 available=1772019 min_wmark=5962 no_progress_loops=9 wmark_check=1 stress-33431 [001] ..... 13223.620533: reclaim_retry_zone: node=0 zone=Normal order=0 reclaimable=4260 available=1772019 min_wmark=5962 no_progress_loops=10 wmark_check=1 stress-33431 [001] ..... 13223.620894: reclaim_retry_zone: node=0 zone=Normal order=0 reclaimable=4260 available=1772019 min_wmark=5962 no_progress_loops=11 wmark_check=1 stress-33431 [001] ..... 13223.621224: reclaim_retry_zone: node=0 zone=Normal order=0 reclaimable=4260 available=1772019 min_wmark=5962 no_progress_loops=12 wmark_check=1 stress-33431 [001] ..... 13223.621551: reclaim_retry_zone: node=0 zone=Normal order=0 reclaimable=4260 available=1772019 min_wmark=5962 no_progress_loops=13 wmark_check=1 stress-33431 [001] ..... 13223.621847: reclaim_retry_zone: node=0 zone=Normal order=0 reclaimable=4260 available=1772019 min_wmark=5962 no_progress_loops=14 wmark_check=1 stress-33431 [001] ..... 13223.622200: reclaim_retry_zone: node=0 zone=Normal order=0 reclaimable=4260 available=1772019 min_wmark=5962 no_progress_loops=15 wmark_check=1 stress-33431 [001] ..... 13223.622580: reclaim_retry_zone: node=0 zone=Normal order=0 reclaimable=4260 available=1772019 min_wmark=5962 no_progress_loops=16 wmark_check=1 3. Root cause: Nodemask usually comes from mempolicy in policy_nodemask(), which is always NULL unless the memory policy is bind or prefer_many. nodemask = NULL __alloc_pages_noprof() prepare_alloc_pages ac->nodemask = &cpuset_current_mems_allowed; get_page_from_freelist() ac.nodemask = nodemask; /*set NULL*/ __alloc_pages_slowpath() { f (!(alloc_flags & ALLOC_CPUSET) || reserve_flags) { ac->nodemask = NULL; ac->preferred_zoneref = first_zones_zonelist(ac->zonelist, ac->highest_zoneidx, ac->nodemask); /* so ac.nodemask = NULL */ } According to the function flow above, we do not have the memory limit to follow cpuset.mems, so we need to add it. Test result: Try 3 times with different cpuset.mems and alloc large memorys than that numa size. echo 1 > cpuset.mems stress --vm 1 --vm-bytes 12g --vm-hang 0 --------------- echo 2 > cpuset.mems stress --vm 1 --vm-bytes 12g --vm-hang 0 --------------- echo 3 > cpuset.mems stress --vm 1 --vm-bytes 12g --vm-hang 0 The retry trace look like: stress-2139 [003] ..... 666.934104: reclaim_retry_zone: node=1 zone=Normal order=0 reclaimable=7 available=7355 min_wmark=8598 no_progress_loops=1 wmark_check=0 stress-2204 [010] ..... 695.447393: reclaim_retry_zone: node=2 zone=Normal order=0 reclaimable=2 available=6916 min_wmark=8598 no_progress_loops=1 wmark_check=0 stress-2271 [008] ..... 725.683058: reclaim_retry_zone: node=3 zone=Normal order=0 reclaimable=17 available=8079 min_wmark=8597 no_progress_loops=1 wmark_check=0 With this patch, we can check the right node and get less retry in __alloc_pages_slowpath() because there is nothing to do. V1: Do the same with the page allocator using __cpuset_zone_allowed(). Suggested-by: Michal Hocko Signed-off-by: Zhongkun He Acked-by: Michal Hocko --- mm/compaction.c | 6 ++++++ mm/page_alloc.c | 5 +++++ 2 files changed, 11 insertions(+) diff --git a/mm/compaction.c b/mm/compaction.c index d1041fbce679..a2b16b08cbbf 100644 --- a/mm/compaction.c +++ b/mm/compaction.c @@ -23,6 +23,7 @@ #include #include #include +#include #include "internal.h" #ifdef CONFIG_COMPACTION @@ -2822,6 +2823,11 @@ enum compact_result try_to_compact_pages(gfp_t gfp_mask, unsigned int order, ac->highest_zoneidx, ac->nodemask) { enum compact_result status; + if (cpusets_enabled() && + (alloc_flags & ALLOC_CPUSET) && + !__cpuset_zone_allowed(zone, gfp_mask)) + continue; + if (prio > MIN_COMPACT_PRIORITY && compaction_deferred(zone, order)) { rc = max_t(enum compact_result, COMPACT_DEFERRED, rc); diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 29608ca294cf..8a67d760b71a 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -4128,6 +4128,11 @@ should_reclaim_retry(gfp_t gfp_mask, unsigned order, unsigned long min_wmark = min_wmark_pages(zone); bool wmark; + if (cpusets_enabled() && + (alloc_flags & ALLOC_CPUSET) && + !__cpuset_zone_allowed(zone, gfp_mask)) + continue; + available = reclaimable = zone_reclaimable_pages(zone); available += zone_page_state_snapshot(zone, NR_FREE_PAGES);