From patchwork Mon Dec 3 20:50:16 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Yang X-Patchwork-Id: 10710581 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 B907914BD for ; Mon, 3 Dec 2018 20:50:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A993E2B227 for ; Mon, 3 Dec 2018 20:50:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9A7AD2B254; Mon, 3 Dec 2018 20:50:51 +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 0C3AA2B227 for ; Mon, 3 Dec 2018 20:50:50 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EE77A6B6B04; Mon, 3 Dec 2018 15:50:49 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id E70D16B6B05; Mon, 3 Dec 2018 15:50:49 -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 D39F96B6B06; Mon, 3 Dec 2018 15:50:49 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pg1-f198.google.com (mail-pg1-f198.google.com [209.85.215.198]) by kanga.kvack.org (Postfix) with ESMTP id 8D54D6B6B04 for ; Mon, 3 Dec 2018 15:50:49 -0500 (EST) Received: by mail-pg1-f198.google.com with SMTP id h9so7584515pgm.1 for ; Mon, 03 Dec 2018 12:50:49 -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:in-reply-to:references; bh=YY2MEt670EmjHA8qER6pbyY4uIhp3DWo0GTplQ3Y9Zw=; b=k52Xj/J6mHMlm/fm8rybBJJB7tc3/xOfN5s4h9fcQ7Z2KcM5QlWdh81U34EGHCUgAB +fFloZTfdnzv9Dh49ob5gR70UzTehHHtqsddyC9BOFjaQmdOSXvTUpGrohQqfHOY5DK0 faVV0RYgqkbJ982olU+qxVh3EMMQA2dsKDbVCT2w8IN4GDUyW2uHzH6jtZsLuqfPFAwz rhzzZdtc5RJY5gNd6JoqQafjG3ZVxFHybRITjcnFcEQe+AO5/mMGklYeF3Ljx37ur3Uf GnkwjJuX7KGjkD4MvFNNEH7qigahQz9WBgIoOf4z74BtrJcF/bUrM2FTOT7266UMh/nf siQA== X-Gm-Message-State: AA+aEWYXGv2t4/elL0Yd2bFzn65wXdG7Sl+CTFUQ+K2+okUaQvw/W1pH dkGjlt5ozPgbxegOWmUfaCQohw7cgpkj8F3Abj6or/y3yo7PT6WeK6T6JbE0v0dRoDC4swlzNGb GYaU5jXNR07ysJm2LJnzSZD8G1rqwq4QFdgapUSxVVgckg7tFPIW0/tDXXvDtI4OE6Y+FdIC6RW ps8ohAGUkwLiXSEBxAG/UH/T48NDHOlp6TBNEWjY/SlRB7KFF9JWCWmDSvEARTGBgtU+02XzkIx eg88g25p5M6PmtNnAVrrgHhZ7LBQNqW6s+Vr5mxbmGxcYZbiWw/Y4PKElxKN6kvrBcBOBWvLAAK ZGD+qI48SrKeUA54bY2EcZAIgcd/3UQA0ZX5Oeo/EMQu8U3ktCn3enZkc+OoMsE0fqnS3TIfjAc y X-Received: by 2002:a17:902:b48b:: with SMTP id y11mr16788967plr.200.1543870249155; Mon, 03 Dec 2018 12:50:49 -0800 (PST) X-Received: by 2002:a17:902:b48b:: with SMTP id y11mr16788924plr.200.1543870247820; Mon, 03 Dec 2018 12:50:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543870247; cv=none; d=google.com; s=arc-20160816; b=rYq8jOsxZh5tKHBS7GR8AVxbIatHQsIUWN7OCSqXZ9HPyfNh4aEPuMt+1YR+OJXA/m P18p2fyCBc5TjlWJgbr10PevxT82/QSTofcHhFnbLvvHUzbPMz+++uj4oJj57L+Z7VCx Hzuw4HQ12QkR3sCa+kieu0gjXJo3iGlX+XZff9iVE9EBsFO8XilRzLDQBoeMNuKockni kau1PsP2zKiURI/D1O4Ia8cGma/leyvDnuzn7Y1rH3w4dLTrPOe2vCCCIRk/7CXswu6o D1Ca1lpAW6HUsc19XNgX9svibpdfZqYFZrImOZAapzkPrE2drvEIubjIaFqubrsiMwqh 0Yyg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=YY2MEt670EmjHA8qER6pbyY4uIhp3DWo0GTplQ3Y9Zw=; b=TGheE0NxfsMOsgc2+OBYbWYshugaGyCYc6klzNTWukue9yom3/QaYcGcAu1BHhZsM+ VWfMiiPUPL5xIT+lZHWj/I3yqDLSAOXnkTaJ4LQKiRt3OLNk6e+tdpj4caYZ1hKa013h XrqEJbHIoQPY6UA7eKjRlgnSXkpK1+aWUfcmQxi4eEE1aoz72s7gSV+SCZGKm+9K+4nW 1h12cd7i3pGq2KHiZr5zKAp5Mvn6pF31vwzpx/2vNBLbC8SclGd/EfT1xClUAg9IvEvF 7HDJWnxoDiyjin+Pw8F13hssfp/5ECbvpJEjJ84zhPJvP9tA3DI2ag41zh+VxfrvkLe3 JZmQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=IlQ7HfXp; 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 o19sor19517506pll.44.2018.12.03.12.50.47 for (Google Transport Security); Mon, 03 Dec 2018 12:50:47 -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=IlQ7HfXp; 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:in-reply-to:references; bh=YY2MEt670EmjHA8qER6pbyY4uIhp3DWo0GTplQ3Y9Zw=; b=IlQ7HfXp47fw6knzAvgDjHWkEGGcsEwojnsg6RmxbxRzWsFIrChhJ2W88P6kAbbYQ3 TUogN3oF/GKi5qUSxN1Khq21c/T11WFMBQu9QhnTJj5frM0UHrSiLszaGuSPvS/MBrT1 dYBNpAUEstRX9PxQ/WvtVCAoaOWn6UIQbfFcNyL29W9PC2YzE2XVXGGymixFXU6M2s6I WX/6tWn8Rk599lGVkChHyjs0T9wR4lEog29CNC58DMeGNt9lx+JrIdKsMtEsa38Tq7vI YUWbtWAV+Omx5wBUFpYgoDcsDgi5hpXx5mO0npm9pm6hE0YNSxGj9CLwo3L5N+64tGjU HSLQ== X-Google-Smtp-Source: AFSGD/W0UhuI2Zbp7Lxw9/vejnF4XKxAChNlHXhJ2+JLoQRhajY5Se42gASESxtuwcpVrNo4R1vPJw== X-Received: by 2002:a17:902:7c0a:: with SMTP id x10mr17679149pll.65.1543870247199; Mon, 03 Dec 2018 12:50:47 -0800 (PST) Received: from localhost ([185.92.221.13]) by smtp.gmail.com with ESMTPSA id v62sm28130944pfd.163.2018.12.03.12.50.45 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 03 Dec 2018 12:50:46 -0800 (PST) From: Wei Yang To: mhocko@suse.com, osalvador@suse.de, david@redhat.com Cc: akpm@linux-foundation.org, linux-mm@kvack.org, Wei Yang Subject: [PATCH v4] mm, hotplug: move init_currently_empty_zone() under zone_span_lock protection Date: Tue, 4 Dec 2018 04:50:16 +0800 Message-Id: <20181203205016.14123-1-richard.weiyang@gmail.com> X-Mailer: git-send-email 2.15.1 In-Reply-To: <20181130065847.13714-1-richard.weiyang@gmail.com> References: <20181130065847.13714-1-richard.weiyang@gmail.com> 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 During online_pages phase, pgdat->nr_zones will be updated in case this zone is empty. Currently the online_pages phase is protected by the global locks (device_device_hotplug_lock and mem_hotplug_lock), which ensures there is no contention during the update of nr_zones. These global locks introduces scalability issues (especially the second one), which slow down code relying on get_online_mems(). This is also a preparation for not having to rely on get_online_mems() but instead some more fine grained locks. The patch moves init_currently_empty_zone under both zone_span_writelock and pgdat_resize_lock because both the pgdat state is changed (nr_zones) and the zone's start_pfn. Also this patch changes the documentation of node_size_lock to include the protection of nr_zones. Signed-off-by: Wei Yang Acked-by: Michal Hocko Reviewed-by: Oscar Salvador CC: David Hildenbrand --- v4: * mention the preparation for improving scalability by David's comment v3: * slightly modify the last paragraph of changelog based on Michal's comment v2: * commit log changes * modify the code in move_pfn_range_to_zone() instead of in init_currently_empty_zone() * pgdat_resize_lock documentation change --- include/linux/mmzone.h | 7 ++++--- mm/memory_hotplug.c | 5 ++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h index 3d0c472438d2..37d9c5c3faa6 100644 --- a/include/linux/mmzone.h +++ b/include/linux/mmzone.h @@ -635,9 +635,10 @@ typedef struct pglist_data { #endif #if defined(CONFIG_MEMORY_HOTPLUG) || defined(CONFIG_DEFERRED_STRUCT_PAGE_INIT) /* - * Must be held any time you expect node_start_pfn, node_present_pages - * or node_spanned_pages stay constant. Holding this will also - * guarantee that any pfn_valid() stays that way. + * Must be held any time you expect node_start_pfn, + * node_present_pages, node_spanned_pages or nr_zones stay constant. + * Holding this will also guarantee that any pfn_valid() stays that + * way. * * pgdat_resize_lock() and pgdat_resize_unlock() are provided to * manipulate node_size_lock without checking for CONFIG_MEMORY_HOTPLUG diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c index 61972da38d93..f626e7e5f57b 100644 --- a/mm/memory_hotplug.c +++ b/mm/memory_hotplug.c @@ -742,14 +742,13 @@ void __ref move_pfn_range_to_zone(struct zone *zone, unsigned long start_pfn, int nid = pgdat->node_id; unsigned long flags; - if (zone_is_empty(zone)) - init_currently_empty_zone(zone, start_pfn, nr_pages); - clear_zone_contiguous(zone); /* TODO Huh pgdat is irqsave while zone is not. It used to be like that before */ pgdat_resize_lock(pgdat, &flags); zone_span_writelock(zone); + if (zone_is_empty(zone)) + init_currently_empty_zone(zone, start_pfn, nr_pages); resize_zone_range(zone, start_pfn, nr_pages); zone_span_writeunlock(zone); resize_pgdat_range(pgdat, start_pfn, nr_pages);