From patchwork Sat Nov 17 02:20:22 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Yang X-Patchwork-Id: 10687323 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1969D14BD for ; Sat, 17 Nov 2018 02:21:42 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 073DF2C831 for ; Sat, 17 Nov 2018 02:21:42 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id ED2522CD3E; Sat, 17 Nov 2018 02:21:41 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7A7C52C831 for ; Sat, 17 Nov 2018 02:21:41 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 47ACB6B0CAD; Fri, 16 Nov 2018 21:21:40 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 42A806B0CAE; Fri, 16 Nov 2018 21:21:40 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 341B06B0CAF; Fri, 16 Nov 2018 21:21:40 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pl1-f199.google.com (mail-pl1-f199.google.com [209.85.214.199]) by kanga.kvack.org (Postfix) with ESMTP id E779F6B0CAD for ; Fri, 16 Nov 2018 21:21:39 -0500 (EST) Received: by mail-pl1-f199.google.com with SMTP id a22-v6so11649710plm.23 for ; Fri, 16 Nov 2018 18:21:39 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:from:to:cc:subject:date :message-id; bh=+9Z44NmphK2W23yabjHUtVc0Xe27PKOh1QWCLgS1rjo=; b=i6Qjy95Tzjg3DHjhQp+x53C6tJl3o3mHpWQFdCFMa3OjXlMwl/s6ntZphopYLvE1IN VJo3ZTW53z8h6IfPNZ8Qrc45SQs7G5jsLILQFwv2dOhWR0XyRZZ/mXgxruSvdMjq5a94 N3dDvbL7o69XmBnB+bevFq6oRBCFKS2XqRi+J+FnF/q2GFnjgM0bPqeNIU9Z+41d4URs uVLYWu8ElcSm6hOHLLQKESpOYgEtrxptUGqyz+5jvsPxEvLv/oBoCnR3SSZlRNgl1JyF zro1bh5eQjtnni0thJRocAjhXrtY5lKNJjH36nuHTgviRiz9pQh8UQEGERCB7ugWtodM rbSA== X-Gm-Message-State: AGRZ1gKUmllB3XhbcQ03+BMzJp37z9kjsbZ1MiUJtxaSMM1AK3QnAuEO ShvtGw1DClUBNABnZs1iqhweqrLvQ1+rnoTtxo4SG7CRTx0+ujW+RCf8B3kqXLx/OKzx03LPQFe T+G3USFLHSzoBOIzd55p4vLrHf4Jm9llr/qbcMhspfD5uYiI5tXjdhyYElneRZruQ3h6srP3hys zw50Ld68dYtx+er9m6GAW+HIddjxQXpxQvAlZ3ZgYXPoRUnOIvhD3bbsgTq4zp7v7sjQYKG4RPh d3rVlltrVg1yAh2SfUuxCKnYYB6x6M8vY8yXzJz6XeG49H0cs72y2aNe3ewFwasJjMmd7Ky0n/m l3PSxdpWQC8YYTQie5KMa+5b0M5094nayVf39E0oJjg0b5W+6315DOC4mOSEAOh/tGI2ivuBXmC w X-Received: by 2002:a63:68c4:: with SMTP id d187mr12029251pgc.11.1542421299369; Fri, 16 Nov 2018 18:21:39 -0800 (PST) X-Received: by 2002:a63:68c4:: with SMTP id d187mr12029210pgc.11.1542421298554; Fri, 16 Nov 2018 18:21:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542421298; cv=none; d=google.com; s=arc-20160816; b=QatQPjB2a6OCVjS1TqinPxeRZ55lGGXyQ1XqPjPcrqOA1ujFUf6cMB+tzU1M7bMt9/ 91mWmBZTOvi14yfGwrKq5pzw0gmHPv91KgVLn/pkh3YPq59HJunIuQBQnlcdPSq3LNzs Hypq3NQaYfHnSY4iHEr6ZqaIKSf6/yUnRpIOFZYinIggeZDG4EbY1kZb0h8Eaa4MMUMy zk7UEs1CoeyLuzyskvbK88EYUSJCHKnbfV/x05lG39E9KrSmN9YXU2gD3pP1eds2J3xO 5TaZktdp0s3U6cNAgXLrun2Pv7Fk5iJ4XqSvzfNdRTtYjKx+bqtTxjosQIRO/Gvj84ix Irvw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=message-id:date:subject:cc:to:from:dkim-signature; bh=+9Z44NmphK2W23yabjHUtVc0Xe27PKOh1QWCLgS1rjo=; b=CC32I7A0eLQfXTgXvk4/jRi5OkVWmmG47SCa6fpgQrZN1WBPwa5MOQ53iP/CmqwCMj d7pdPpX/HBCWmozLcKMgO/3aG1m13fOHngrhpsrO1vJvonluGb/teizVoRs2/+7iqop6 T8sZPh9dRXN/Kgw+QUciOG/8QVBEYVodPDHRHP9M1IE9SRWrvOCEZOAyk/BhHJnDR2I2 vfga7igxImn0Re6zHfQowoENqPu60jxuSANqZLzfLx2bcBGgoQ+sIU7peb4aPefxg7zq kU3aMdFkwBtsN/19HITP/7znwmGr4vgGeOMzE5Rl+c+9LtClG1EV2c5o4+PHnmcmMMu5 CuWQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=sc6PcDNi; spf=pass (google.com: domain of richard.weiyang@gmail.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=richard.weiyang@gmail.com; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id 24sor4220851pgq.13.2018.11.16.18.21.38 for (Google Transport Security); Fri, 16 Nov 2018 18:21:38 -0800 (PST) Received-SPF: pass (google.com: domain of richard.weiyang@gmail.com designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=sc6PcDNi; spf=pass (google.com: domain of richard.weiyang@gmail.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=richard.weiyang@gmail.com; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=+9Z44NmphK2W23yabjHUtVc0Xe27PKOh1QWCLgS1rjo=; b=sc6PcDNiK29Ywx9OpNiq+2msbWLZhkkEN+meEiRekolxMizX1AFo6GvtHU2Ryw0cHO TStwzJBzA2DgyyhQg9PwcpNBmgKNrcnzrZ3+H6E7wmEe9h2cBSTLW7LRFA7ONQqgCnhX NG/SxzvNI3fylGj4ZPmtxn+UsEXGNrIFzgf870KE/s4VgSZxzFYWsSJyjILkDR/MQxMP Itt4kdG/F6/RimIHyZKe9TmVkEzfJkuj2drMvvr+lzQR2pOLSu5DYWUhUVmWLyWIJ2te dxsh8w1zeoWWIqkjNlyC2DLqm4lzbwXSCrdYN4TKLVN6ss73o9+qTR3a+0kCT8TDUSi1 DrNQ== X-Google-Smtp-Source: AJdET5d3lf23huv9SyF9V3rDYxodR+EgRdAlA31jDzL3Jlx1urm0RuXkyzGfbLG+VZoiSfqVWxK+Kw== X-Received: by 2002:a63:4b18:: with SMTP id y24-v6mr12451592pga.181.1542421297799; Fri, 16 Nov 2018 18:21:37 -0800 (PST) Received: from localhost ([185.92.221.13]) by smtp.gmail.com with ESMTPSA id q199sm16586140pfc.97.2018.11.16.18.21.36 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 16 Nov 2018 18:21:37 -0800 (PST) From: Wei Yang To: akpm@linux-foundation.org, mhocko@suse.com, dave.hansen@intel.com Cc: linux-mm@kvack.org, Wei Yang Subject: [PATCH] mm, page_alloc: fix calculation of pgdat->nr_zones Date: Sat, 17 Nov 2018 10:20:22 +0800 Message-Id: <20181117022022.9956-1-richard.weiyang@gmail.com> X-Mailer: git-send-email 2.15.1 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: X-Virus-Scanned: ClamAV using ClamSMTP Function init_currently_empty_zone() will adjust pgdat->nr_zones and set it to 'zone_idx(zone) + 1' unconditionally. This is correct in the normal case, while not exact in hot-plug situation. This function is used in two places: * free_area_init_core() * move_pfn_range_to_zone() In the first case, we are sure zone index increase monotonically. While in the second one, this is under users control. One way to reproduce this is: ---------------------------- 1. create a virtual machine with empty node1 -m 4G,slots=32,maxmem=32G \ -smp 4,maxcpus=8 \ -numa node,nodeid=0,mem=4G,cpus=0-3 \ -numa node,nodeid=1,mem=0G,cpus=4-7 2. hot-add cpu 3-7 cpu-add [3-7] 2. hot-add memory to nod1 object_add memory-backend-ram,id=ram0,size=1G device_add pc-dimm,id=dimm0,memdev=ram0,node=1 3. online memory with following order echo online_movable > memory47/state echo online > memory40/state After this, node1 will have its nr_zones equals to (ZONE_NORMAL + 1) instead of (ZONE_MOVABLE + 1). Signed-off-by: Wei Yang Acked-by: Michal Hocko Reviewed-by: Oscar Salvador --- mm/page_alloc.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 5b7cd20dbaef..2d3c54201255 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -5823,8 +5823,10 @@ void __meminit init_currently_empty_zone(struct zone *zone, unsigned long size) { struct pglist_data *pgdat = zone->zone_pgdat; + int zone_idx = zone_idx(zone) + 1; - pgdat->nr_zones = zone_idx(zone) + 1; + if (zone_idx > pgdat->nr_zones) + pgdat->nr_zones = zone_idx; zone->zone_start_pfn = zone_start_pfn;