From patchwork Thu Feb 8 06:26:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Byungchul Park X-Patchwork-Id: 13549360 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 01DECC48260 for ; Thu, 8 Feb 2024 06:26:40 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 359206B009F; Thu, 8 Feb 2024 01:26:31 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 2B5A26B00A4; Thu, 8 Feb 2024 01:26:31 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E04B36B00A1; Thu, 8 Feb 2024 01:26:30 -0500 (EST) 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 C90E86B00A2 for ; Thu, 8 Feb 2024 01:26:30 -0500 (EST) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 9B417A0915 for ; Thu, 8 Feb 2024 06:26:30 +0000 (UTC) X-FDA: 81767652540.04.E1CE898 Received: from invmail4.hynix.com (exvmail4.skhynix.com [166.125.252.92]) by imf08.hostedemail.com (Postfix) with ESMTP id A86A4160002 for ; Thu, 8 Feb 2024 06:26:28 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf08.hostedemail.com: domain of byungchul@sk.com designates 166.125.252.92 as permitted sender) smtp.mailfrom=byungchul@sk.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1707373589; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:content-type: content-transfer-encoding:in-reply-to:in-reply-to: references:references; bh=z8N3K7cEzP29wp8OmV1x4SKhsG69RUNKzzZ3XrSlbEU=; b=qaFKpYg3sbPEtqq/RjsPaCBxNOeDm7UAw5nyLYvpiTMCsPFPso61qMfIgn0lFNCrtavgGj n5Kz2hEdFxPQvTNUtSUPPNpMKV/Qbqfxxxx+SDVS6U6vF2KKtqt99yc9cKzXmVINTcejfw p+r5Se8ofDCw1iG7igKb9iuo9DBd8qc= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf08.hostedemail.com: domain of byungchul@sk.com designates 166.125.252.92 as permitted sender) smtp.mailfrom=byungchul@sk.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1707373589; a=rsa-sha256; cv=none; b=pSweWMMHGLc2+jPsGvkg/z6d3h+2tePlh2AZi+xeKocWblcNgXSpk/37cCEIUL/MJ/I4+v pfTreZAvqZjLd+Z2PNTRRYpY52XwNreiZ9+DWkaHIbcDRhcRUUPnSPQsqlQ2etxZ6dQsWr /QjmegmMhvYcCevrpciHZiZ4KESPbOg= 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: H4sI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X3WPBplKPzSu0PBbv ecnksWlVJ5vHpk+T2D3enTvH7nFixm8Wj3knAz3e77vK5rH4xQcmj62/7Dwap15j8/i8Sc7j 3fy3bAECUVw2Kak5mWWpRfp2CVwZXW3/2QqmqlT83mTVwLhftouRk0NCwETicu9WRhCbTUBd 4saNn8wgtoiAmcTB1j/sXYxcHMwCH5kkVn/vYAFJCAsESBxpbWYFsVkEVCVuN54Ba+YVMJWY eHomC8RQeYnVGw6ADeIEGrRz2ymweiGgmhezJ7NNYORawMiwilEkM68sNzEzx1SvODujMi+z Qi85P3cTIzC4l9X+mbiD8ctl90OMAhyMSjy8J8oPpwqxJpYVV+YeYpTgYFYS4TXbcSBViDcl sbIqtSg/vqg0J7X4EKM0B4uSOK9XeGqCkEB6YklqdmpqQWoRTJaJg1OqgbFAmtFb6Hr81b3/ kk53HOzf6fH6/K6CgIjdHJf5br+stGBccGvCGnHFB4HnT2p/3bvLg+ugQP7kCa+vnWA4szjB ZU5w6qyXe3dxHNpzd0/B780s1TKnV3Tymu15N/nYvfWzjFtrtz8r3PRXuPtTVVFn2aN7krL2 X1UY1Uumqu8vP6Uhcy15x7SPSizFGYmGWsxFxYkAeC9GyWoCAAA= X-CFilter-Loop: Reflected X-Rspamd-Queue-Id: A86A4160002 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: imc7f6iotcbk866d817pcppgc8f4f3p9 X-HE-Tag: 1707373588-568703 X-HE-Meta: U2FsdGVkX196lBj+sCwnTsOoeXJNuGjeRukrPEBvkJRhITLwUqk0QzvcC505bSF2kad7CCEN1rG8Nl/ow+a9JUyX7NA3ZMCMynoEaIi3fpxYIkEvl3i0sJ8TeDd8nOakQfOyj/CJVN9g5Eqc282RIHRJzSGPcFSL7jNj0bndLtH8NQo155GIZHdl++rZPrmQe7csLdBJofA4dbot9P5Q0fE2G5AXgvHdZWQD51dlX7QidaE6lLcmu9fhx9/HelNeYD9nEmYHzv34//XShF2fAD4+BXBf3bfs799TrLGIoZQsCN9YUrVc9LH5UAwExVHoLYigbRghncQXLcMfS6p7EknQuxEVjkK/cYcqdxtRCKQExKkJofhFIyB1gAQ4QqNuStItE69O+PxkSu3bm7bDCPKWlI/2t377o/9sEUHUzuskYTet4bcneHWDfXiGPGphWsN3A7r7vkT+TPHHBkBxz4cG26bY7mHKenDmf301lfs7gj+Cf4c1+vVOfeKPqyEyzLRwNh5ltwgiXm60HA/R0Nwk9885qmrlQWzLb4y/cF+xQomQrBlAyksUHdZFCe5FIUVJNjEJroYgC6NL1r8czzlUAqdClRbllgQDBHr0l09tjWXb/gyPXceF1NhEoJ5KNO696j6BIdNfxspS3J0IrS+rqmf2Tyf17nGX5U+0yFiL2abA/2NKR+cfw+d5KC4ktbn/Vmr9qfY6UI4w9871moXi0b5IurJa1sWDenYa4F9OlVuC1+MUokr3LBCzlnUQmuMxCF3y5bA0JjbBLxipMz51jm15yI2TEAKtroXE2cb+1FJpoHkfgFIS1sqNK6ZfcsOE1sUM3bVDOYAP6EM6F1gdB39f9p47Six78OIeYwaQ/cx2BG+WDYJOCZRgmBEdobBUCiANgGrguFnpjyNK/hycBEf2s7dkSqieTjpZvPLaj5uYT7MCt/+ZSQ6k3Brm+HDJTof0a6cd666Kdj+ OLg== 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: 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; }