Received: by 2002:a05:7412:3b8b:b0:fc:a2b0:25d7 with SMTP id nd11csp80671rdb; Wed, 7 Feb 2024 22:29:47 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVru7KaIgLMNpdYYFlnrrheg5gnbXxTivYQiA/4zemmBQwBS6BQmB55oVUgKj/G8+z2gB6C9RI6dzPaszInTVFU2rPQOv3HNsR/aKIGDg== X-Google-Smtp-Source: AGHT+IHagdeGGKA5o0UKl/vLHU76I5MpLT5RpOk6fpHDSAbwCtGKXNwXTwb4fMuAdpndGDmzzdEt X-Received: by 2002:a05:6a20:d39a:b0:19e:98a1:1160 with SMTP id iq26-20020a056a20d39a00b0019e98a11160mr8072922pzb.28.1707373787581; Wed, 07 Feb 2024 22:29:47 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707373787; cv=pass; d=google.com; s=arc-20160816; b=vXFXsv8lQwhesgU3FBfx+SbBkgX4X8v027ccx3596P+7B4o8rRwVSp2RKUrpzQ7DHD KTgnusrj/BwRamFnp6seWfaElvIpJ21u0b6MU3eXwxLYahvBJvxephMcQAVo2P/QvY24 5Gs1rLdJp6IeuYIGMx2/xxioti9R57k2IAVai+Yca6bkHQxF4b3oTlw3kakCvxAbJ7z0 pGS9xZS5aW1ev8vN1jsLOyuxU+vMpKlrkknzDn4eVv7fuhbpf7iyxpD/JTmBzu7QxaHF T91vsroC/Z6XL8Xych6fJbFwtwEqnmdfVyvKSPVwtY3f5DaQKZsLvXprXUWnXxBGqxuI 6Sqg== 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=GedeGRc9MrdLVcM239wMAWvZpplJfwp6efauaM7lOZg=; b=r+V53qMCPDJjMEXa8O+8g5/JyBF8pRo1hqFMVMvh8TwB/KyBaG19Ce+ktWY2fef0YG vu7jj/3NeBWfJZ3ESxnU9zhfqDxq5KAExWrNRu47zzQ58E4CYzZliKhdeBKh9yvhzNZj CReJSuDHmnL9hY4vSL2uM6HhAZlOyJKNXdm0eQkQpT0wBvRH7ZT084Ks4LviUXvuGx6L wKJl2dV+CY60r4eodxCTHaoY2hRUchsN1U0Ivh9jdpP7C+WdaEsgbcYWtNaG4J8msI9d DNgI1IGc80769SEeFxsjcFuc7JIuDQroeUdQay9k3Gnbft3y2180iTmjmyYtTGHXfgvO HNLA==; 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-57519-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-57519-linux.lists.archive=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=2; AJvYcCV1NqY5Pbpqbd63sQttXJuLu1XBS36dH18VZXz3Z6yjynYu6o7MLp3Q2DXTJ1nxUP85MZ+iaCsrUjH1Yr0LQA7AUbczXkn1QO/Me5Kz/Q== Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id y65-20020a638a44000000b005dbdc98c15csi3259385pgd.709.2024.02.07.22.29.47 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Feb 2024 22:29:47 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-57519-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=sk.com); spf=pass (google.com: domain of linux-kernel+bounces-57519-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-57519-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id E7501B2381D for ; Thu, 8 Feb 2024 06:28:02 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id DB14F67E61; Thu, 8 Feb 2024 06:26:32 +0000 (UTC) Received: from invmail4.hynix.com (exvmail4.skhynix.com [166.125.252.92]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D78256997B for ; Thu, 8 Feb 2024 06:26:29 +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=1707373592; cv=none; b=iRhzwrgEaGSms+hcuZ2/EMOLtYg1vNxmajVrMYZvPsY+VwwOUI9nB78z9G+rIlZ1xWbncDcLrka/AVaWTMfEze5Qvd7MP7orTsV0Be/srZJIar3S7ObjZL7yvviatPrTLIYYL6YpZ5tT69R6FBl8a9ce6VQl9ynZk4FBXKo4CbM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707373592; c=relaxed/simple; bh=+1VdXIPG+erpF/AVFX/h+PqqlvJOGm1O0Tz9NB8RbNk=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References; b=Fo0nQo/kNKH/8X7etmn0cCzPNzhTpRahqwZpngxCpatMqK5OaPF0zdO0NLhxrgCivYk6PtPSqCuaK4JdHhXFz9bttvcV7am9YkSApbRYdkk28Wpr3PsqxwjNHLZLT3iDJgOohxH74f4o+uPzxYDq3jJmZNyV6TTA3EddSsqPyK4= 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-d85ff70000001748-92-65c4740b9853 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: [RESEND PATCH v7 8/8] mm: Pause migrc mechanism at high memory pressure Date: Thu, 8 Feb 2024 15:26:08 +0900 Message-Id: <20240208062608.44351-9-byungchul@sk.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240208062608.44351-1-byungchul@sk.com> References: <20240208062608.44351-1-byungchul@sk.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrALMWRmVeSWpSXmKPExsXC9ZZnkS53yZFUg2OLFS3mrF/DZvF5wz82 ixcb2hktvq7/xWzx9FMfi8XlXXPYLO6t+c9qcX7XWlaLHUv3MVlcOrCAyeL6roeMFsd7DzBZ zL/3mc1i86apzBbHp0xltPj9A6jj5KzJLA6CHt9b+1g8ds66y+6xYFOpx+YVWh6L97xk8ti0 qpPNY9OnSewe786dY/c4MeM3i8e8k4Ee7/ddZfPY+svOo3HqNTaPz5vkPN7Nf8sWwB/FZZOS mpNZllqkb5fAldHV9p+tYKpKxe9NVg2M+2W7GDk5JARMJD72/2eFsS/3bmUEsdkE1CVu3PjJ DGKLCJhJHGz9w97FyMXBLPCRSWL19w4WkISwQIDEkdZmsGYWAVWJ241nwJp5BUwlJp6eyQIx VF5i9YYDYIM4gQbt3HYKrF4IqObF7MlsIEMlBJrZJd5f3s0M0SApcXDFDZYJjLwLGBlWMQpl 5pXlJmbmmOhlVOZlVugl5+duYgTGw7LaP9E7GD9dCD7EKMDBqMTDe6L8c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Ftrtz8r3PRXuPtTVVFn2aN7krL2 X1UY1Uumqu8vP6Uhcy15x7SPSizFGYmGWsxFxYkAeC9GyWoCAAA= X-CFilter-Loop: Reflected Precedence: bulk X-Mailing-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