From patchwork Mon Jul 22 12:33:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhongkun He X-Patchwork-Id: 13738812 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 42663C3DA5D for ; Mon, 22 Jul 2024 12:33:42 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B5FCE6B0082; Mon, 22 Jul 2024 08:33:41 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B103B6B0083; Mon, 22 Jul 2024 08:33:41 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9D8136B0085; Mon, 22 Jul 2024 08:33:41 -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 7998F6B0082 for ; Mon, 22 Jul 2024 08:33:41 -0400 (EDT) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 314951217B0 for ; Mon, 22 Jul 2024 12:33:41 +0000 (UTC) X-FDA: 82367329842.13.C65A67F Received: from mail-oa1-f46.google.com (mail-oa1-f46.google.com [209.85.160.46]) by imf29.hostedemail.com (Postfix) with ESMTP id C0E1012001B for ; Mon, 22 Jul 2024 12:33:38 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=Z5VHy5EO; spf=pass (imf29.hostedemail.com: domain of hezhongkun.hzk@bytedance.com designates 209.85.160.46 as permitted sender) smtp.mailfrom=hezhongkun.hzk@bytedance.com; dmarc=pass (policy=quarantine) header.from=bytedance.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1721651597; 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=FVWwL5VO4q04b45BWmiVgKpzDu/7jE1+3wyYKYbandI=; b=7dKfSWRu97YEPRBSxrPknj0cRkDoMxWayisSR3cjV2ToesrbEACj2MDdYYzPUkCSx5GKdM yuu3wPu6dmTjqKfFfTqUSQT3Pg2fcuxH/n8QFrBwekGKQz66sc3Izy3rDAAsX8yvHNn5/X I7Hg7CAf/7vj2KhbHPCwenaAXDaVjS8= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=Z5VHy5EO; spf=pass (imf29.hostedemail.com: domain of hezhongkun.hzk@bytedance.com designates 209.85.160.46 as permitted sender) smtp.mailfrom=hezhongkun.hzk@bytedance.com; dmarc=pass (policy=quarantine) header.from=bytedance.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1721651597; a=rsa-sha256; cv=none; b=gItVnQSCwBEgaMlvLHc00s9OeVb4r4Q/i8cQ5N/BgELmussZ+S2JjGKkPTF1lt4KaKW00N YXejg16BZCIB+44R0jooVYBIOVWbqtwBAKtatk4iE9SCsjLCAJoUFxiAba34rvAu1KBHac dfcwJ453bP8aGU040wBipxKYN7qYD2U= Received: by mail-oa1-f46.google.com with SMTP id 586e51a60fabf-25e3d8d9f70so2146342fac.2 for ; Mon, 22 Jul 2024 05:33:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1721651617; x=1722256417; 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=FVWwL5VO4q04b45BWmiVgKpzDu/7jE1+3wyYKYbandI=; b=Z5VHy5EOVqxazXtdWV9mb5pLeB2/lDcf1OPkbxERXQOvxVcaLUrxwxQpyS5hrhmVb/ EJ+9AOqVeCOc+zv1G5/vDgW3fbBF1KwzgpTfKI0sPIZ9pnrYPGLVW8j3DIxDOYgifhfH pZJ/9YuobTwSBl/SM89H8y1L9di9HnNbiqjA5RWDvKBtxmC/WmnLVLXojLeJOKVYwOqf WXMs/ucMDrd24nBJaATImz+v/d9qmMU5pr7ZX1iHmrISIndMrDXaJiEHcgfprHivgWsu uJ9pBCIDN2HDA/XgkO7W4v7FEdYVaGpFv9biWrdRVgtNfuV5dNJsyV9KDsE1wvLd+V7v ZejQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721651617; x=1722256417; 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=FVWwL5VO4q04b45BWmiVgKpzDu/7jE1+3wyYKYbandI=; b=fiZBME+Yt+1t30QIvUaldRYv+hv8odnm3oyVm04goWHgXigXh92m/lUy1rhaL82SrN 3ZEUEctRHTxPD4V5MBkfcBAaSHEBGjN9Ny1FJJBi3IYOCKVScr8+d3BDF+/y9r47nB7r X2vqg8BKDqIUNMRcRMtTnQMFXJIv5e3FsHszLRIIwHPqiVTLN/ANN3yKWNb+IN53YDnB pMkJgnf30F9nZ44PkdIGhlc9yMhp66lOQ7/BEgBMqLzdMZWlhL5t/6HI08hUGXdYh8hz rwSm3j6Mu7Og5MaoO+9dkTgsH53aMN1ZP0BdlSilrIxk5mWNT1Vq21Lo1SgbSWk+lFK7 O6Nw== X-Gm-Message-State: AOJu0Yzv1qAmC2l+pgDXKyvwIhLxHPl9CpOrg/juC1GT1N2VgszNram4 ILSmod3Me4jbrJPmUomBP9eKA3uoBgwH+dhIaXdctlPx5B1s1qjuvtY5v4PSAiI= X-Google-Smtp-Source: AGHT+IEdgVG9XJ+pUl9SRJ1Ab1oscuqPq6XDBYqsC81riN+r66R19akgikYx2rlNAaK0kbgS9WOekw== X-Received: by 2002:a05:6871:551:b0:254:c617:a9a0 with SMTP id 586e51a60fabf-26121652e01mr7197994fac.50.1721651617511; Mon, 22 Jul 2024 05:33:37 -0700 (PDT) Received: from n37-034-248.byted.org ([180.184.51.134]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-7a0eeec2bf0sm3191229a12.10.2024.07.22.05.33.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Jul 2024 05:33:36 -0700 (PDT) From: Zhongkun He To: peterz@infradead.org, mgorman@suse.de, ying.huang@intel.com Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Zhongkun He Subject: [PATCH] mm/numa_balancing: Fix the memory thrashing problem in the single-threaded process Date: Mon, 22 Jul 2024 20:33:20 +0800 Message-Id: <20240722123320.2382992-1-hezhongkun.hzk@bytedance.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 X-Rspamd-Server: rspam03 X-Rspam-User: X-Rspamd-Queue-Id: C0E1012001B X-Stat-Signature: rtruc3t88sjpjsmqgfjfytc1846jb4u1 X-HE-Tag: 1721651618-189150 X-HE-Meta: U2FsdGVkX1+oiyqRn52cw7mEcQqGVW35QjRCMEelY3H9fOj9FkwEHaPJkE7JrfaCujJ/NiZ1ALs/mKvsCCDYXMfUDfKWRnd5pXvnFQhoJbm0veOZflSQQ1WIOB/S+oQfHzLhEVsPAbtWCtZlgNvcsvVCW4AZoibq9Cjs8Uzzur+hhXugXlc9Wn9OY7xjhzEs/UwRSynYjwExWwJ0fOKRUHf6yPuf3Of1nb9iOsH1xkuZCDyvQlrkRlqLRVBTPrCcvMmllea3VJLe0wphTXwmP91J3Gf+r4/VJD2X6LxEJ+Gb5R/hHkkaP9UcYzaM152LYIDNWgYT/sm0Eoxzag1D56iPr7HLDXDdhol+i/Fzu66/bb2SXLU1BoO7nn+zd0TSiqPfUj0XLJtjDhd7EsCxvhXbbPFk6XGdcYa8n8F5I12cEq3RHCgb9tefUE9T4SVbdK5uOHidrXBgpsr5SkwbPq6ypEpFsjbcJebrMLgFIcQZMDtCE3qKY7Q5TJ6iUbWI5iI1bsqSD+UZdCaoI7bIdefqZwilZ5jBYcpw7Ad9GwzJfn2eYKwrbMqde0KTkmP4Wn+BmUZ4M8imTeoOyJ3WGYmq7JPiBW9vuJAFR+ZbsBLFAuCbery8boaNGrLglvJs1Jtw5xIVS/EHJdCcBjeUUB/QVwIlgOSG00qjDlPSbC+CRWFNVBWGHq/kBkaDCFsMrVxnlRX7pA6/O44FqBKxUFbaN/TGcQv+3l2b5Sx+114ggzB/aHZl+FdtDtTdogqRcCBHHEqEb8PeGK9f/XZ4/cDoGhBEi7wCT5YmSlmtvtC7kTb/F/NmCxYxZScWQGPvOyjp1Qzzt6QeMvam0rAa4neFJLNsxi2qzClj23F9nHviAZaHG7ClL+xOQAJZtjLlqBOJjZHa3s9fgeQ0msFZW9x+wjSGd3DubL9u8v5WFGH9e7ahJXPdxb80YqlO69WBy9uVOAeTujCyWAc9EeQ JQAQNQ6a JgbQJg9ZFkulcdXBcrUd6WNhkEx9hnn1qXrktvjKC8eFPF5NKYf7wN/QlwLE3SYL2NtnlkFm7/6lxsSYvUaqgiOjmOcm4pZGax4ViasYrWWku1NC+q/hr6MTTzz4JtXPFK7EW2w6qa5rSdi+0fk7Ct51FHytLooccVH9OvvD4lNR+8BHGQd1orllx3LPuXIfXb9UYJowinJulW79G01yYOGbqyKzQar7LnkTF3XT3j+AcGJLYrza5We+ieaQYsHVy4Y8K1ddVK8zbr5hxnXb4/YuqzQ7LUDAamBQhofqj8nMdzokHN7sR+uo0KldQai50S2RdNwkTCequWPhlwQCBBkI0xiHxmMiQoR2fiUbHkhneT34= 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 the memory of a process is repeatedly migrated between two nodes and does not stop. 1.Test step and the machines. ------------ VM machine: 4 numa nodes and 10GB per node. stress --vm 1 --vm-bytes 12g --vm-keep The info of numa stat: while :;do cat memory.numa_stat | grep -w anon;sleep 5;done anon N0=98304 N1=0 N2=10250747904 N3=2634334208 anon N0=98304 N1=0 N2=10250747904 N3=2634334208 anon N0=98304 N1=0 N2=9937256448 N3=2947825664 anon N0=98304 N1=0 N2=8863514624 N3=4021567488 anon N0=98304 N1=0 N2=7789772800 N3=5095309312 anon N0=98304 N1=0 N2=6716030976 N3=6169051136 anon N0=98304 N1=0 N2=5642289152 N3=7242792960 anon N0=98304 N1=0 N2=5105442816 N3=7779639296 anon N0=98304 N1=0 N2=5105442816 N3=7779639296 anon N0=98304 N1=0 N2=4837007360 N3=8048074752 anon N0=98304 N1=0 N2=3763265536 N3=9121816576 anon N0=98304 N1=0 N2=2689523712 N3=10195558400 anon N0=98304 N1=0 N2=2515148800 N3=10369933312 anon N0=98304 N1=0 N2=2515148800 N3=10369933312 anon N0=98304 N1=0 N2=2515148800 N3=10369933312 anon N0=98304 N1=0 N2=3320455168 N3=9564626944 anon N0=98304 N1=0 N2=4394196992 N3=8490885120 anon N0=98304 N1=0 N2=5105442816 N3=7779639296 anon N0=98304 N1=0 N2=6174195712 N3=6710886400 anon N0=98304 N1=0 N2=7247937536 N3=5637144576 anon N0=98304 N1=0 N2=8321679360 N3=4563402752 anon N0=98304 N1=0 N2=9395421184 N3=3489660928 anon N0=98304 N1=0 N2=10247872512 N3=2637209600 anon N0=98304 N1=0 N2=10247872512 N3=2637209600 2. Root cause: Since commit 3e32158767b0 ("mm/mprotect.c: don't touch single threaded PTEs which are on the right node")the PTE of local pages will not be changed in change_pte_range() for single-threaded process, so no page_faults information will be generated in do_numa_page(). If a single-threaded process has memory on another node, it will unconditionally migrate all of it's local memory to that node, even if the remote node has only one page. So, let's fix it. The memory of single-threaded process should follow the cpu, not the numa faults info in order to avoid memory thrashing. Signed-off-by: Zhongkun He Acked-by: "Huang, Ying" --- kernel/sched/fair.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index 24dda708b699..d7cbbda568fb 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -2898,6 +2898,12 @@ static void task_numa_placement(struct task_struct *p) numa_group_count_active_nodes(ng); spin_unlock_irq(group_lock); max_nid = preferred_group_nid(p, max_nid); + } else if (atomic_read(&p->mm->mm_users) == 1) { + /* + * The memory of a single-threaded process should + * follow the CPU in order to avoid memory thrashing. + */ + max_nid = numa_node_id(); } if (max_faults) {