Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp125206ybz; Thu, 16 Apr 2020 21:01:58 -0700 (PDT) X-Google-Smtp-Source: APiQypLNJTTuwXf8oc/2B4bMtywipQD9sfax+Ubt/bAMJ1/DHAIIHUj7pOm2AF81VXc6/LaSDRXP X-Received: by 2002:aa7:d518:: with SMTP id y24mr1178197edq.222.1587096117912; Thu, 16 Apr 2020 21:01:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587096117; cv=none; d=google.com; s=arc-20160816; b=MRaP1PgijS2yXl7zeGOH2ZR5/1xdozERvKn3zcJyWB4OubCN8wwLVCq2cHWd5XTwk7 KdeZ7CKWlKGRTFCdAqHi3BBlpzdOSKyuECsPoNRVdQA+ITe6FeMxokiKRoI7im0Cvotm 0EjhRwMR85DawiwkCflMLgyZGLGxgAwr78ropnP6HUZJVTBzJuhN2Nk+w5I0Y/4UT3Dh AH7EyUGO4d0gS4i/JWTPJ08qFZIsY/GBacttDY2riAwzZRJ3rtMKSfl6LLWeL+tEhX/r NDbw3jM8eHi9upNZ+aDZ6Gy6s8ZEIXqNFATuMHSRZ3zPdkJGsXz4W2HMZJKy3HF8iOli clgA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=i/x9+PN0Y2dQcilV25O8EbsPUWIw66JdCN7ycSFqHlU=; b=gTYsBd8joOMOsX/snEGW03xRQWsvpP7kkNjzJYyuP4vLGmcTTcLE5lrEHquPRgjuWQ hyyAGAFEDtEGdmQgxFWCwo/7P4r54NtTFsmr4XF04deM9F+T6cAZMIpJGUEjodxisy8w zS85E/HmESRewv6dW/KswUD9pU9C7DX7GGXLzg/cW8H+6cp2PeepDmRQuhFHVSU0TzDo Vdq+QULXqG0xv0bBxEg8IJWwOFcGmal3FD4d4/+fWWY5qZ/6JSjoHS9jhXehGjqgkyr7 yEUqOlnwC1FosxOSygdzUUZ6YdQweZrnKgTmxUNntqxftYsjyKxdHnDclBXjt0ApD0lg +FDw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=BKVa2tW7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h21si13845261ejt.479.2020.04.16.21.01.11; Thu, 16 Apr 2020 21:01:57 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=BKVa2tW7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727825AbgDQD7P (ORCPT + 99 others); Thu, 16 Apr 2020 23:59:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50330 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1725294AbgDQD7O (ORCPT ); Thu, 16 Apr 2020 23:59:14 -0400 Received: from mail-pl1-x642.google.com (mail-pl1-x642.google.com [IPv6:2607:f8b0:4864:20::642]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D0D5EC061A0C for ; Thu, 16 Apr 2020 20:59:14 -0700 (PDT) Received: by mail-pl1-x642.google.com with SMTP id z6so474922plk.10 for ; Thu, 16 Apr 2020 20:59:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=i/x9+PN0Y2dQcilV25O8EbsPUWIw66JdCN7ycSFqHlU=; b=BKVa2tW7nOR8Z5UQPPcyVVjsOgQeVYgtqQ9ORfq1ZyVXhiHwzvKv0d3wLBzGxlaYoB +MqK5rYQE/oHB4dl7dooB6IctPGwXK0K9so101FtFEbFI0cm6m/J8q42pzXmwOey5M2Z ZQ9wgiDQkOPkaP5XC8tg+eL+S7hAg9ajARBmzFESRyir2FYuuQnXN8WDzTIjef16nhqG +pztz1bAoeEA4xV9MniHMwl3DiG3vVxj/xxaFY92ahaDgJLvf8hFBJVXqGiUkA3yQC1v 8zmBTvuL7qF63hprfLVkzOnDYHr3NhfMqnyFTRzWEYnnbQB0W8pDkaPk9gnxue4V4dF3 512w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=i/x9+PN0Y2dQcilV25O8EbsPUWIw66JdCN7ycSFqHlU=; b=hH4LXxX8dYrJ3ILG3638tVYhPn/bAOUoemjbmV2V1/i49QGHMUjyJP7AB0skhx8D12 /LcD9BVTQSAy6qP3l4gvHf47QVixufm9Lxox6bB/HGiBCjLdYxUIZjY6NHr5AcCZL7SV zKLMK7JaAL2MT1aZ1k0zWmL0A5PP5eZ+t/ZjRnEWRDqBQdTj+/64jUjw0Qdpsvg5Ar4H jw5JcmJsGfzW4ikwseiNECgN6JEFZZGFHA5CD+tfl6H/n1L6VfJ8II2Xm9w06rvnlM/q q7dMCD5Pbh61IJmf0eYGEN7fSiqm7vyYmFmlX8bK7K0uyhFFkEkflMpJkkcRFN9IvVcO f/tQ== X-Gm-Message-State: AGi0Pua2R0oDJHUc0VrNr68yyNT02r3ZNqE4OX3xCCZf/dnGEk+Xge/e 4+EaY2z9458wLzzTL6iJB8yYqZZyGlU= X-Received: by 2002:a17:90b:3014:: with SMTP id hg20mr2004522pjb.56.1587095954277; Thu, 16 Apr 2020 20:59:14 -0700 (PDT) Received: from localhost.localdomain ([114.206.198.176]) by smtp.gmail.com with ESMTPSA id g12sm3525454pfm.129.2020.04.16.20.59.10 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 16 Apr 2020 20:59:13 -0700 (PDT) From: js1304@gmail.com X-Google-Original-From: iamjoonsoo.kim@lge.com To: Andrew Morton Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Johannes Weiner , Michal Hocko , Minchan Kim , Vlastimil Babka , Mel Gorman , kernel-team@lge.com, Ye Xiaolong , David Rientjes , Baoquan He , Joonsoo Kim Subject: [PATCH v5 1/2] mm/page_alloc: use ac->high_zoneidx for classzone_idx Date: Fri, 17 Apr 2020 12:58:42 +0900 Message-Id: <1587095923-7515-2-git-send-email-iamjoonsoo.kim@lge.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1587095923-7515-1-git-send-email-iamjoonsoo.kim@lge.com> References: <1587095923-7515-1-git-send-email-iamjoonsoo.kim@lge.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Joonsoo Kim Currently, we use classzone_idx to calculate lowmem reserve proetection for an allocation request. This classzone_idx causes a problem on NUMA systems when the lowmem reserve protection exists for some zones on a node that do not exist on other nodes. Before further explanation, I should first clarify how to compute the classzone_idx and the high_zoneidx. - ac->high_zoneidx is computed via the arcane gfp_zone(gfp_mask) and represents the index of the highest zone the allocation can use - classzone_idx was supposed to be the index of the highest zone on the local node that the allocation can use, that is actually available in the system Think about following example. Node 0 has 4 populated zone, DMA/DMA32/NORMAL/MOVABLE. Node 1 has 1 populated zone, NORMAL. Some zones, such as MOVABLE, doesn't exist on node 1 and this makes following difference. Assume that there is an allocation request whose gfp_zone(gfp_mask) is the zone, MOVABLE. Then, it's high_zoneidx is 3. If this allocation is initiated on node 0, it's classzone_idx is 3 since actually available/usable zone on local (node 0) is MOVABLE. If this allocation is initiated on node 1, it's classzone_idx is 2 since actually available/usable zone on local (node 1) is NORMAL. You can see that classzone_idx of the allocation request are different according to their starting node, even if their high_zoneidx is the same. Think more about these two allocation requests. If they are processed on local, there is no problem. However, if allocation is initiated on node 1 are processed on remote, in this example, at the NORMAL zone on node 0, due to memory shortage, problem occurs. Their different classzone_idx leads to different lowmem reserve and then different min watermark. See the following example. root@ubuntu:/sys/devices/system/memory# cat /proc/zoneinfo Node 0, zone DMA per-node stats ... pages free 3965 min 5 low 8 high 11 spanned 4095 present 3998 managed 3977 protection: (0, 2961, 4928, 5440) ... Node 0, zone DMA32 pages free 757955 min 1129 low 1887 high 2645 spanned 1044480 present 782303 managed 758116 protection: (0, 0, 1967, 2479) ... Node 0, zone Normal pages free 459806 min 750 low 1253 high 1756 spanned 524288 present 524288 managed 503620 protection: (0, 0, 0, 4096) ... Node 0, zone Movable pages free 130759 min 195 low 326 high 457 spanned 1966079 present 131072 managed 131072 protection: (0, 0, 0, 0) ... Node 1, zone DMA pages free 0 min 0 low 0 high 0 spanned 0 present 0 managed 0 protection: (0, 0, 1006, 1006) Node 1, zone DMA32 pages free 0 min 0 low 0 high 0 spanned 0 present 0 managed 0 protection: (0, 0, 1006, 1006) Node 1, zone Normal per-node stats ... pages free 233277 min 383 low 640 high 897 spanned 262144 present 262144 managed 257744 protection: (0, 0, 0, 0) ... Node 1, zone Movable pages free 0 min 0 low 0 high 0 spanned 262144 present 0 managed 0 protection: (0, 0, 0, 0) - static min watermark for the NORMAL zone on node 0 is 750. - lowmem reserve for the request with classzone idx 3 at the NORMAL on node 0 is 4096. - lowmem reserve for the request with classzone idx 2 at the NORMAL on node 0 is 0. So, overall min watermark is: allocation initiated on node 0 (classzone_idx 3): 750 + 4096 = 4846 allocation initiated on node 1 (classzone_idx 2): 750 + 0 = 750 allocation initiated on node 1 will have some precedence than allocation initiated on node 0 because min watermark of the former allocation is lower than the other. So, allocation initiated on node 1 could succeed on node 0 when allocation initiated on node 0 could not, and, this could cause too many numa_miss allocation. Then, performance could be downgraded. Recently, there was a regression report about this problem on CMA patches since CMA memory are placed in ZONE_MOVABLE by those patches. I checked that problem is disappeared with this fix that uses high_zoneidx for classzone_idx. http://lkml.kernel.org/r/20180102063528.GG30397@yexl-desktop Using high_zoneidx for classzone_idx is more consistent way than previous approach because system's memory layout doesn't affect anything to it. With this patch, both classzone_idx on above example will be 3 so will have the same min watermark. allocation initiated on node 0: 750 + 4096 = 4846 allocation initiated on node 1: 750 + 4096 = 4846 One could wonder if there is a side effect that allocation initiated on node 1 will use higher bar when allocation is handled on local since classzone_idx could be higher than before. It will not happen because the zone without managed page doesn't contributes lowmem_reserve at all. Reported-by: Ye Xiaolong Tested-by: Ye Xiaolong Reviewed-by: Baoquan He Acked-by: Vlastimil Babka Signed-off-by: Joonsoo Kim --- mm/internal.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm/internal.h b/mm/internal.h index b5634e7..0ab58df 100644 --- a/mm/internal.h +++ b/mm/internal.h @@ -142,7 +142,7 @@ struct alloc_context { bool spread_dirty_pages; }; -#define ac_classzone_idx(ac) zonelist_zone_idx(ac->preferred_zoneref) +#define ac_classzone_idx(ac) (ac->high_zoneidx) /* * Locate the struct page for both the matching buddy in our -- 2.7.4