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 B1AD0C3DA4A for ; Thu, 22 Aug 2024 09:01:04 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3EA9E6B00BD; Thu, 22 Aug 2024 05:01:04 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 371B06B0134; Thu, 22 Aug 2024 05:01:04 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1C6108001F; Thu, 22 Aug 2024 05:01:04 -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 EE05D8001E for ; Thu, 22 Aug 2024 05:01:03 -0400 (EDT) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 6051FC13BD for ; Thu, 22 Aug 2024 09:01:03 +0000 (UTC) X-FDA: 82479286806.18.D29B172 Received: from mail-ed1-f44.google.com (mail-ed1-f44.google.com [209.85.208.44]) by imf18.hostedemail.com (Postfix) with ESMTP id 558281C002C for ; Thu, 22 Aug 2024 09:01:01 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=suse.com header.s=google header.b=OSAHzAP9; spf=pass (imf18.hostedemail.com: domain of mhocko@suse.com designates 209.85.208.44 as permitted sender) smtp.mailfrom=mhocko@suse.com; dmarc=pass (policy=quarantine) header.from=suse.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1724317220; a=rsa-sha256; cv=none; b=I43chKtf/ZVE279kPF/f7gamQ8LFMjwKC4Uk3nkNA6O/DdpTW9ctty38SEqDXeSbsPNMDM vFbnuXTiBnBO6uBChQpXaPeNSVz6cpaCbYtUrPtxYpoNXW9vvoS28ml7LUVlCMXrYCDD5t m3dF6eGJu025GneavvemWWAb3JRSbgc= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=suse.com header.s=google header.b=OSAHzAP9; spf=pass (imf18.hostedemail.com: domain of mhocko@suse.com designates 209.85.208.44 as permitted sender) smtp.mailfrom=mhocko@suse.com; dmarc=pass (policy=quarantine) header.from=suse.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1724317220; 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=uE7q2R79ra943CHmNIYAz4Se/oF9orTNMf7om9x/0w8=; b=dNIgYLhsd+xyaYau1839jsjHIDzUfOP2z207GXNG2o60Al6g1vetG4/VKj3W2vc//Kqgti qzE0Q82FDNZ50Vl0uJ7+oA3gylfyy/sT2irahpwf7XoNwggMVcT5fIaTv3qsYjXqa4kVEN kpeJk1rVXJyvIwr4Nqk2jdb9E3FL9nI= Received: by mail-ed1-f44.google.com with SMTP id 4fb4d7f45d1cf-5bec78c3f85so753822a12.1 for ; Thu, 22 Aug 2024 02:01:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1724317260; x=1724922060; 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=uE7q2R79ra943CHmNIYAz4Se/oF9orTNMf7om9x/0w8=; b=OSAHzAP9tVfhk75avPLwej12RUjr2rbyWbG2vObWZ+2RxKffUijt/AuhWzf+YfDSgH RaHpnScDGQm2m5GhKN4U6MRMcgfEGb1Ihab47NQh50EGYi00fVhIZ+ZrH2uJxloP1xb0 CjYsZrIMD0bSysZrU4J8xlSbcWEKQ9umU8hHYJCisHwlm1RWH2/8U2bnjloc1t/vQMMU tXtvfnavDUsGsMepYvyPEi/JIOd5ySFN3GQL8ttdj/38zy7pFqQP6kfpK+SJGkpphGW0 /WzKLl2iZFCQDTDLZo78GvG1DwuUbPypS0TNlubM8pYKfWppYWonKV9x5HizctpNFirL odEw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724317260; x=1724922060; 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=uE7q2R79ra943CHmNIYAz4Se/oF9orTNMf7om9x/0w8=; b=BM5grTM0kMzGewf5hO9ZRqllIFQQJlLlylgtf9EU/7aHAYtAnk5k76wxe0gjL5AFnn 0FFNdp9hSJ/2R/9NfBbcfGgHlDeB+HWQ03jAUg/uNGSpUMt1Ud5h01PFOn3016W6U8vc DUlsi4BRKajv/VXSK7nEXfRWw4Gc+6kB+BImBHBDrdQuGgGeXIikdy9KtByxBO7Oljdc arIf3W4IC0lqPn+zIVKfVm0+QFYrhSLuEVkkbt2aukBtYyA0fhRRYM3IVjXRaxNkNyca JeTc+WesJI3PALgmkju4ctRzbK7syoLJZQ9rsyXADPnq5sELCdn+5aragObdVY0KJEsC 0lYg== X-Forwarded-Encrypted: i=1; AJvYcCVmeMwOIEOvrJ2Lnekc/e9SoX0Lu1+B2p9fvV2OIw9w1v4RWBHWbAlyKyYCo7QOLAvnXOxx8Y0OSw==@kvack.org X-Gm-Message-State: AOJu0Yw+C8Ku2mA6MU9meSBRBqBwIiuhg3WLej4+wxhMoGqi2XN9upay Egrno6xWdEqtTsFPvw0BUV1pKg27QYkHjU6ylMy1PSMxLDb0x22LP88mTg9eg78= X-Google-Smtp-Source: AGHT+IFRHcWUO3cIfl5f6DBKBpDvlWiZOWF7yzXIw1+52agalZunwjd6e1IbdV4DxmmtLRMKBbuxQA== X-Received: by 2002:a05:6402:5251:b0:5be:fd3a:558 with SMTP id 4fb4d7f45d1cf-5bf1f0d7cd9mr3866329a12.9.1724317259593; Thu, 22 Aug 2024 02:00:59 -0700 (PDT) Received: from localhost (109-81-92-13.rct.o2.cz. [109.81.92.13]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5c044ddc0fcsm647618a12.5.2024.08.22.02.00.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Aug 2024 02:00:59 -0700 (PDT) Date: Thu, 22 Aug 2024 11:00:58 +0200 From: Michal Hocko To: Zhongkun He Cc: akpm@linux-foundation.org, mgorman@techsingularity.net, hannes@cmpxchg.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, lizefan.x@bytedance.com Subject: Re: [PATCH V1] mm:page_alloc: fix the NULL ac->nodemask in __alloc_pages_slowpath() Message-ID: References: <20240822083842.3167137-1-hezhongkun.hzk@bytedance.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240822083842.3167137-1-hezhongkun.hzk@bytedance.com> X-Stat-Signature: kkszrzqegwi9z5qu33hu86czraffa61w X-Rspamd-Queue-Id: 558281C002C X-Rspam-User: X-Rspamd-Server: rspam10 X-HE-Tag: 1724317261-850184 X-HE-Meta: U2FsdGVkX1/XqWqUAAnTWeIKM+GDh5mjssZDAus2HVlgjHRo0T8EBkmaXhIEmKYWsn3PQ+pdiDQGvSRa608GrZ9khTTsTkYmdfOrv5r6mqRiLSxZnqphUHab1mC8hun2q/W687AfeNUBxeoLwNUfgZVHr+lL7iYPDaFZXLEfAthKhLVi3SfL96jvuPkFx/jdl8nytgJJ5ZwskLHyeJ5PsUDs6mvK4/Vw47LXXj7xVtLRHStjRfykkfaF8MDfKLZd9aZhu6IuioI72fL75Jlj6JjRzQwqxP6mwEUX7cEXG20yyA/rcOioYG+HSP+EF/qvnakPPF9/O10GeXkuXLTiAr47wM5BdbiAEZpxCbcLzaY/LtrJJ9HTPUIvl8vFklT6SsCKUW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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 22-08-24 16:38:42, Zhongkun He wrote: > 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. I would update the problem description because from the above it is not really clear what the actual problem is. should_reclaim_retry is not ALLOC_CPUSET aware and that means that it considers reclaimability of NUMA nodes which are outside of the cpuset. If other nodes have a lot of reclaimable memory then should_reclaim_retry would instruct page allocator to retry even though there is no memory reclaimable on the cpuset nodemask. This is not really a huge problem because the number of retries without any reclaim progress is bound but it could be certainly improved. This is a cold path so this shouldn't really have a measurable impact on performance on most workloads. > > 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 > You can drop the following > 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 > And only keep this > 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 With those changes you can add Acked-by: Michal Hocko Thanks! > --- > 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); > > -- > 2.20.1 -- Michal Hocko SUSE Labs