Received: by 2002:a05:7412:cfc7:b0:fc:a2b0:25d7 with SMTP id by7csp957949rdb; Sun, 18 Feb 2024 22:05:56 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXE7pTHUFgkJDkdkw6GEXq0plY6DRs0KOkGwfJGytTIYQF2RmewXiROanhupkKStW9gZ7IME+h1Nvs//hXMc1iUuEbhW4nWVZx8V2hgVw== X-Google-Smtp-Source: AGHT+IHw0/EABqZJ3XBRURu9X+oKGuHzJ0fvbwzYoKHr6c/2kL6dyP8nXLKSKS33I0XZk30mMUPE X-Received: by 2002:a05:6402:784:b0:564:7962:4553 with SMTP id d4-20020a056402078400b0056479624553mr822140edy.16.1708322756213; Sun, 18 Feb 2024 22:05:56 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708322756; cv=pass; d=google.com; s=arc-20160816; b=ljkMKOsOrd3u+MY4/S6/A2YgdeYZ9wBNXtJ+HPbRNS76RnOFrujpNBgMWtCFcO8Qwa eKa11qkj72n4bNuT7yqjYMQux6vI+S/enPK4sRrErlpvN/b3P09Ecg5XD9Lha/BPwNNc UjmG6QxtFjBtYpzQ/wegmckS3znIPsdu8qP0Q6y1HCg9iF5CWrdnjh3aj4/4887GcJ8D LfXwaKCC3j7Fm5ADSd9HWnyGiZJPArmM2hX8vCMy+Q0dV9X37omo9TuxJRXsy8+vq3rW oA/jA31MzgzQC+26m3iZaZjdh58ZDYskNPfu9BdX1F9KD7YSevhIjmWY6pZarIBJ479e nX3w== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-unsubscribe:list-subscribe:list-id:precedence:references :in-reply-to:message-id:date:subject:cc:to:from; bh=z8N3K7cEzP29wp8OmV1x4SKhsG69RUNKzzZ3XrSlbEU=; fh=I/fJb8ryqmmGEnsMy9AhDuMN2ego/v5YAM2Gbv30rAg=; b=vWnKZOs1tfiFR5m+xGc+dnFFPO8zRQaTpWpJ7QVQU5RSEzoxXGEQbbI8rvZE3ZVrB3 dU9x0BpcDYnM5sY/Jpkqz161AMof9WlpR9jECNf1zSlJ5ja2GfOtZwu1EFWHVeO2AKbD LO2YuZcaGffC13FM9OzQ/m+tJ70g3dmFAlqxA+ugAZ9gpANQ1ORqakJukEtoSjugIe0d +vKx0ceuRFsw8/JMyF2EHEswCxImlf5uBcvCIQP03OUDgarEx28YMtwrSJ0Q7Rt1D4dF 0LG3OG2lY48fsgwjI75HWDSmqIv3DuUO09YWBj7gXmkfxK5UnwiKc+wzkVsA5KFgpI1L t65A==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=sk.com); spf=pass (google.com: domain of linux-kernel+bounces-70755-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-70755-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id z12-20020aa7cf8c000000b00560d778193asi2221098edx.431.2024.02.18.22.05.56 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 18 Feb 2024 22:05:56 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-70755-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=sk.com); spf=pass (google.com: domain of linux-kernel+bounces-70755-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-70755-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id BC03A1F2273B for ; Mon, 19 Feb 2024 06:05:55 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 551AE21A02; Mon, 19 Feb 2024 06:04:39 +0000 (UTC) Received: from invmail4.hynix.com (exvmail4.hynix.com [166.125.252.92]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A0D30210F2 for ; Mon, 19 Feb 2024 06:04:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=166.125.252.92 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708322678; cv=none; b=Jb8G15nPydZbpH8J63CfQiuH1c5+7J3TwWj5LT4KoWd+Uyg549/QeTCoSnHVUf+Wxtnj0uRUE8o+LkHz4fk4IN8mwdFADbXAhzUFh+z23xb4LEkcXZ6+oHipTjc3sIBEOlPo7JMd7iAcxRIdid7R7508ObFIQvjxDqI2fyilW9U= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708322678; c=relaxed/simple; bh=+1VdXIPG+erpF/AVFX/h+PqqlvJOGm1O0Tz9NB8RbNk=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References; b=M3sA4fEySQeeifuRdjwL+VzFgtY3GEjHXhf6tpNFbTPObYZwrq9Lo5xJYUqJUq4j2YC0Fx+9xvKFDtHu7UGiOb+b9/FHyeTN2xXaoNO4zgEJ1vZrfCs/dWS2KczzqYN57OrEcwLAH41pdAh7sxzNn1bw65YAQl0hs/se7m+KZY4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=sk.com; spf=pass smtp.mailfrom=sk.com; arc=none smtp.client-ip=166.125.252.92 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=sk.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=sk.com X-AuditID: a67dfc5b-d6dff70000001748-e1-65d2ef629e08 From: Byungchul Park To: linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: kernel_team@skhynix.com, akpm@linux-foundation.org, ying.huang@intel.com, namit@vmware.com, vernhao@tencent.com, mgorman@techsingularity.net, hughd@google.com, willy@infradead.org, david@redhat.com, peterz@infradead.org, luto@kernel.org, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, rjgolo@gmail.com Subject: [PATCH v8 8/8] mm: Pause migrc mechanism at high memory pressure Date: Mon, 19 Feb 2024 15:04:07 +0900 Message-Id: <20240219060407.25254-9-byungchul@sk.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240219060407.25254-1-byungchul@sk.com> References: <20240219060407.25254-1-byungchul@sk.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrHLMWRmVeSWpSXmKPExsXC9ZZnkW7S+0upBlOOc1rMWb+GzeLzhn9s Fi82tDNafF3/i9ni6ac+FovLu+awWdxb85/V4vyutawWO5buY7K4dGABk8X1XQ8ZLY73HmCy mH/vM5vF5k1TmS2OT5nKaPH7B1DHyVmTWRwEPb639rF47Jx1l91jwaZSj80rtDwW73nJ5LFp VSebx6ZPk9g93p07x+5xYsZvFo95JwM93u+7yuax9ZedR+PUa2wenzfJebyb/5YtgD+KyyYl NSezLLVI3y6BK6Or7T9bwVSVit+brBoY98t2MXJySAiYSLx6e5Adxn45exeYzSagLnHjxk9m EFtEwEziYOsfoDgXB7PARyaJ1d87WEASwgKeEnNn3wBKcHCwCKhKtPRbgIR5BUwlOjZfZ4KY KS+xesMBZpASTqA5uw8KgYSFgEpOXJ3MBDJSQuA/m8ShN7uYIeolJQ6uuMEygZF3ASPDKkah zLyy3MTMHBO9jMq8zAq95PzcTYzAWFhW+yd6B+OnC8GHGAU4GJV4eDNELqUKsSaWFVfmHmKU 4GBWEuF1b7qQKsSbklhZlVqUH19UmpNafIhRmoNFSZzX6Ft5ipBAemJJanZqakFqEUyWiYNT qoFx4R97/cSKU/zXXhgsmuN7Xom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ing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Regression was observed when the system is in high memory pressure with swap on, where migrc might keep a number of folios in its pending queue, which possibly makes it worse. So temporarily prevented migrc from working on that condition. Signed-off-by: Byungchul Park --- mm/internal.h | 20 ++++++++++++++++++++ mm/migrate.c | 18 +++++++++++++++++- mm/page_alloc.c | 13 +++++++++++++ 3 files changed, 50 insertions(+), 1 deletion(-) diff --git a/mm/internal.h b/mm/internal.h index ab02cb8306e2..55781f879fb2 100644 --- a/mm/internal.h +++ b/mm/internal.h @@ -1285,6 +1285,8 @@ static inline void shrinker_debugfs_remove(struct dentry *debugfs_entry, #endif /* CONFIG_SHRINKER_DEBUG */ #if defined(CONFIG_MIGRATION) && defined(CONFIG_ARCH_WANT_BATCHED_UNMAP_TLB_FLUSH) +extern atomic_t migrc_pause_cnt; + /* * Reset the indicator indicating there are no writable mappings at the * beginning of every rmap traverse for unmap. Migrc can work only when @@ -1313,6 +1315,21 @@ static inline bool can_migrc_test(void) return current->can_migrc && current->tlb_ubc_ro.flush_required; } +static inline void migrc_pause(void) +{ + atomic_inc(&migrc_pause_cnt); +} + +static inline void migrc_resume(void) +{ + atomic_dec(&migrc_pause_cnt); +} + +static inline bool migrc_paused(void) +{ + return !!atomic_read(&migrc_pause_cnt); +} + /* * Return the number of folios pending TLB flush that have yet to get * freed in the zone. @@ -1332,6 +1349,9 @@ void migrc_flush_end(struct tlbflush_unmap_batch *batch); static inline void can_migrc_init(void) {} static inline void can_migrc_fail(void) {} static inline bool can_migrc_test(void) { return false; } +static inline void migrc_pause(void) {} +static inline void migrc_resume(void) {} +static inline bool migrc_paused(void) { return false; } static inline int migrc_pending_nr_in_zone(struct zone *z) { return 0; } static inline bool migrc_flush_free_folios(void) { return false; } static inline void migrc_flush_start(void) {} diff --git a/mm/migrate.c b/mm/migrate.c index cbe5372f159e..fbc8586ed735 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -62,6 +62,12 @@ static struct tlbflush_unmap_batch migrc_ubc; static LIST_HEAD(migrc_folios); static DEFINE_SPINLOCK(migrc_lock); +/* + * Increase on entry of handling high memory pressure e.g. direct + * reclaim, decrease on the exit. See __alloc_pages_slowpath(). + */ +atomic_t migrc_pause_cnt = ATOMIC_INIT(0); + static void init_tlb_ubc(struct tlbflush_unmap_batch *ubc) { arch_tlbbatch_clear(&ubc->arch); @@ -1922,7 +1928,8 @@ static int migrate_pages_batch(struct list_head *from, */ init_tlb_ubc(&pending_ubc); do_migrc = IS_ENABLED(CONFIG_ARCH_WANT_BATCHED_UNMAP_TLB_FLUSH) && - (reason == MR_DEMOTION || reason == MR_NUMA_MISPLACED); + (reason == MR_DEMOTION || reason == MR_NUMA_MISPLACED) && + !migrc_paused(); for (pass = 0; pass < nr_pass && retry; pass++) { retry = 0; @@ -1961,6 +1968,15 @@ static int migrate_pages_batch(struct list_head *from, continue; } + /* + * In case that the system is in high memory + * pressure, give up migrc mechanism this turn. + */ + if (unlikely(do_migrc && migrc_paused())) { + fold_ubc(tlb_ubc, &pending_ubc); + do_migrc = false; + } + can_migrc_init(); rc = migrate_folio_unmap(get_new_folio, put_new_folio, private, folio, &dst, mode, reason, diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 6ef0c22b1109..366777afce7f 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -4072,6 +4072,7 @@ __alloc_pages_slowpath(gfp_t gfp_mask, unsigned int order, unsigned int cpuset_mems_cookie; unsigned int zonelist_iter_cookie; int reserve_flags; + bool migrc_paused = false; restart: compaction_retries = 0; @@ -4203,6 +4204,16 @@ __alloc_pages_slowpath(gfp_t gfp_mask, unsigned int order, if (page) goto got_pg; + /* + * The system is in very high memory pressure. Pause migrc from + * expanding its pending queue temporarily. + */ + if (!migrc_paused) { + migrc_pause(); + migrc_paused = true; + migrc_flush_free_folios(); + } + /* Caller is not willing to reclaim, we can't balance anything */ if (!can_direct_reclaim) goto nopage; @@ -4330,6 +4341,8 @@ __alloc_pages_slowpath(gfp_t gfp_mask, unsigned int order, warn_alloc(gfp_mask, ac->nodemask, "page allocation failure: order:%u", order); got_pg: + if (migrc_paused) + migrc_resume(); return page; } -- 2.17.1