Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp3331517ybb; Sun, 22 Mar 2020 21:51:29 -0700 (PDT) X-Google-Smtp-Source: ADFU+vsISCJTK29aunq48lAp3CzCqKJKCA/0ttNUXou9EmqRTk+HsgDJD/2Up0MIK6RgQg0Dub5y X-Received: by 2002:aca:171a:: with SMTP id j26mr14159276oii.111.1584939089162; Sun, 22 Mar 2020 21:51:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1584939089; cv=none; d=google.com; s=arc-20160816; b=nV5UWg3JKoYBWnG+v032yy7SgGncquFL6UC1eFBy/upe+Rxpd/Vb9aZBJfnQ8ibczU oj0+GYid6IebGC48gbzoEbMDUTMQX46dZU+cmi8wfnigqBehRAmNRCp0BGygQ1g02WIH dHtCblnlDLplblf0XIfIMJU0ZXkxTnXQYNnb/CZGdHB3p1aVwniQRcUqXUbzwzF1Tc3Y SY3wBpQly+X9GX9v6UDLRZlliqlc9SzFQFqotr2IJ2z0KvO6WrVt6IH7VL0EzIfvFm6+ ygipPFfYUmX5SKejICnxLW+E1llUQQrwZAfGDvE2EKsFJWWaw3vA8L3xcOkTZXgXr2sl Si4w== 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=RyA/WFJ7OIIKWj1oEQMHX6SzWBI3+p9s2ndbG4zvYc0=; b=Vod197ZbPpFKlRukEJod+9gnRoTlIsa42RbFaM6holCAnffm95Z/gsOys4EHhUA4Ye w74s2JJse1Z1U7oDy7GHD9BnvMHcVVaMnk4fDsyYU5B0suwN+Yz0vmIYmscvvK7FZFmb jnHpfue+Zzjs+T9F39Aq/HlLllhdBSgTEFJ4zeqF97bNNs8T0O7iRPY5AdihewdTqOCZ 3igAmA1vQry3a/KldxOtosdJpq4/Aulu5nUzEUKX3FJ1rdBr10+3nvPRfXFq+AGrS5Zf JevHTk5/PjeqUkhlldU9WfqGXBn4y/Ea5QSxCMixIpDLn/7bm7zNo4Pj30ZOYZTvsbyc q9AA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b="MDd1f+L/"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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. [209.132.180.67]) by mx.google.com with ESMTP id l11si6678854oib.32.2020.03.22.21.50.46; Sun, 22 Mar 2020 21:51:29 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b="MDd1f+L/"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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 S1725975AbgCWEtz (ORCPT + 99 others); Mon, 23 Mar 2020 00:49:55 -0400 Received: from mail-pl1-f193.google.com ([209.85.214.193]:40192 "EHLO mail-pl1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725838AbgCWEty (ORCPT ); Mon, 23 Mar 2020 00:49:54 -0400 Received: by mail-pl1-f193.google.com with SMTP id h11so5403448plk.7 for ; Sun, 22 Mar 2020 21:49:53 -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=RyA/WFJ7OIIKWj1oEQMHX6SzWBI3+p9s2ndbG4zvYc0=; b=MDd1f+L/uULab5heF0EGov2GBDJoXND5VXz5Rfu2Ed3bQLGIEfmmCfrdlS1DntThgw qPIXJtVOPfZqC4LoR02tkN8R9U2E2vhzjDuJAuBcd84tcCdYC/lxN5EOP1qQoV8/HR2D u3nabHbiKRR435g2abZOzoCZapr4pl3GUj8vK6h79xj+gO72YNfts2Wv+sFhaYIZvPKg KXuewWxDWpfx4XoJtIV7jdVswQ/oFc1zXETpXPREimNohCuXzamSyJqp/KGaWWHG8zvl xEvP95Rb73uv/EOhcie9oBjfFxc5WBlq2HCx6qVdeSrMf2qKvFrcEVLgLWXAoyjlV6+0 v3Zg== 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=RyA/WFJ7OIIKWj1oEQMHX6SzWBI3+p9s2ndbG4zvYc0=; b=gRk87F3GXT5I8OD4xyVMBefSmOG9mT7L2tBEGy0w62eZqLvMchuwY99zhgkQTC4N2q xYBDHG9gxPnAnNeKZBNHWTCPCDZrn6JvE3rr3jDdZkfIDEZZ5gRE7acdyix7P43cBQj1 Z/o1WXvpqZpmZFc/V2fzW8d56SYrRzdGFWFhGF3MqNfqXYWa3WLhxZP9TRyPO1rRdKNd RiM+85tT4ypSmunzqISyZC2GyUw1+0sl5dMUv8mmW7SXY2j281PG3pbn8qfNtY/iUNM1 OaRXKK0Vg1DfZWdDQGE6/U9lJyQcUBE27dj+w/QsaM5B7dh+RkrI+/8VFmAN+IeBRJN4 E1wA== X-Gm-Message-State: ANhLgQ3ho7jAkPbpOux5bgi2xgxRkQCcmflp5AUSxQfNcXAa2Y8ynia0 5QsIlOuUaUO19pD4bDezKxM= X-Received: by 2002:a17:90a:c392:: with SMTP id h18mr11377828pjt.89.1584938993097; Sun, 22 Mar 2020 21:49:53 -0700 (PDT) Received: from localhost.localdomain ([114.206.198.176]) by smtp.gmail.com with ESMTPSA id c207sm11903982pfb.47.2020.03.22.21.49.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 22 Mar 2020 21:49:52 -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 v4 1/2] mm/page_alloc: use ac->high_zoneidx for classzone_idx Date: Mon, 23 Mar 2020 13:49:31 +0900 Message-Id: <1584938972-7430-2-git-send-email-iamjoonsoo.kim@lge.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1584938972-7430-1-git-send-email-iamjoonsoo.kim@lge.com> References: <1584938972-7430-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 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 c39c895..aebaa33 100644 --- a/mm/internal.h +++ b/mm/internal.h @@ -119,7 +119,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