From patchwork Wed Aug 22 09:32:26 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oscar Salvador X-Patchwork-Id: 10572781 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 BC45A139B for ; Wed, 22 Aug 2018 09:32:47 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AD60D298D3 for ; Wed, 22 Aug 2018 09:32:47 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A03852AAEC; Wed, 22 Aug 2018 09:32:47 +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=-2.9 required=2.0 tests=BAYES_00,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 1701C298D3 for ; Wed, 22 Aug 2018 09:32:47 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5DBE06B23B0; Wed, 22 Aug 2018 05:32:37 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 566C06B23B2; Wed, 22 Aug 2018 05:32:37 -0400 (EDT) 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 412166B23B3; Wed, 22 Aug 2018 05:32:37 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) by kanga.kvack.org (Postfix) with ESMTP id BB5D46B23B0 for ; Wed, 22 Aug 2018 05:32:36 -0400 (EDT) Received: by mail-wr1-f69.google.com with SMTP id v11-v6so733243wrn.19 for ; Wed, 22 Aug 2018 02:32:36 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:message-id:in-reply-to:references; bh=Pr2O40TB9sxq7YnJMaW3tfAKxlcOinscuFYdiw5J9bo=; b=lm3OM0f3yMYoHFghtc/6hTUnW7xy8fPxgBkXZIKn0alBPkRqogyGboKtslBJWR+k5p /rW7ZoXCdYtMOS314CouMGrMAUyyNsB/n3ZCZRAz2cqIA+30bqoQVDRTUqtrOzr6qzCR j6obAJHbIldS2aAL1qg4by/DNQoRyfWGPROLRssn23S3z3Uery7QE+5c/UlqQYm9TGPi Yr9wDLqu9eoBnj21N6I/1FQ2PGiYToSIZINLto/pIpWJh8ZKerZA085vXqkwHYshYA7k XfCC8NSHkr+odgRYoI0NuMm2ejFEGY934RnkU4a/0jXhjUftUjWbGkW7bnjoRwTSCCbB s8Fw== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of osalvador.vilardaga@gmail.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=osalvador.vilardaga@gmail.com X-Gm-Message-State: APzg51CcJ84O+xVsHCKcSAdu048BWkle1asFBVUC1n8OJlmErVavl7/U qEm/6IRXcOd0iV4oIwxMBrQf9mdzvRpKFEDKBITgv+B5lux1FEki3AAFGFDP/awzCd3h3SV/Q8h NfYEK+WCiE+W76tIgevSm5W9Wt9IpvAGCyshbDl4SNXwrpXSQzhQQDsw8/sSkFDOJk731FXR5TJ xmZV5kDHhAXeVXGjpj7JlM7dX+7wYcTq3XjK8PEzzQebWCq4GnLhFWDxrLvVFksgM1PkoILAtZJ Bsx/0xFyKJ0kHCyWkkTEFG9YFJxljDn0NMxAyyaaaLvrfL02BzAPYhAHer1pkETw9/wxxNMYs0l wVwXjwG32TPcuGTSlNzIKYlJk0pgfE91XyEL2irQYSBDegGunL3AJ/Dv/Q9fFcJUdJK8KNfMGw= = X-Received: by 2002:a1c:b143:: with SMTP id a64-v6mr1985701wmf.114.1534930356288; Wed, 22 Aug 2018 02:32:36 -0700 (PDT) X-Received: by 2002:a1c:b143:: with SMTP id a64-v6mr1985668wmf.114.1534930355404; Wed, 22 Aug 2018 02:32:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1534930355; cv=none; d=google.com; s=arc-20160816; b=ozI65h4EDRhbdeEsFUfx0MVIOP0d9NQ21OjD9WeYciIYHOgOURAP7xcoD/m5Da/1yN Cy1WYwQvQezyo1xtuJhY+/Yvo0Y89giBys0Y2/CsLGV3So4e0v9UY9UMjI8rDGCBMTcO Px5Yb9BruXm16xF9U7zd0zzRiRs6a8om9/y7v9QJybPi/6DEv0OVnYNeEpNrdYp7jxf7 mQC9ig3zFTX3dyQMtU/ItIWTW8R9CHSKEWCzk3aJDjhflATyv3JcOLK240q6xxxr8RxU zZbSqjeTbIz0tkCdHZjTh5NuXec3i5/D2PUDIHG75MILwu6pnr5bPdj+XGnkmFJjdN8b e2lA== 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 :arc-authentication-results; bh=Pr2O40TB9sxq7YnJMaW3tfAKxlcOinscuFYdiw5J9bo=; b=p5ER+SmjUrB9rAA2DVA5Vas5Y4KPkYHcI9LRe8V97JsG+WCJy7omqCZcNEXaf4KF5O XjX/seiHIkLNH6VX3W5iuxJ1iQztUnNXQmQaKjGUwPG9glpzFSLV/2XJUJlMRn6qCDyz Ks2MlRl9z5G83dNwc5hhPiU4HQV5XOH+THe7U8xUdaKtAldmwMDJz1cQO8wTESWny2Bj wW9DVEk1irw8OkJ4jC6eV1cqcfGJw1ZrmFRibw6a4VSXTRQ956cHtg7EIKAu8rBfu60h xz61cdoCeS4ZqgnySS/cHDQ0t6Qi3hCLM7qqi3/nBzlII/mjmd6nHy0XvSam9I+rSVfI FHJQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of osalvador.vilardaga@gmail.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=osalvador.vilardaga@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 b190-v6sor341566wma.69.2018.08.22.02.32.35 for (Google Transport Security); Wed, 22 Aug 2018 02:32:35 -0700 (PDT) Received-SPF: pass (google.com: domain of osalvador.vilardaga@gmail.com designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; spf=pass (google.com: domain of osalvador.vilardaga@gmail.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=osalvador.vilardaga@gmail.com X-Google-Smtp-Source: ANB0VdYEvE1cm5Z7++E5F9Lg9empOICLxh/N6KJ06RqF1VehZVmu68vt1tdFj0Io/1zvFd2xctnlmQ== X-Received: by 2002:a1c:3663:: with SMTP id d96-v6mr672209wma.92.1534930355096; Wed, 22 Aug 2018 02:32:35 -0700 (PDT) Received: from techadventures.net (techadventures.net. [62.201.165.239]) by smtp.gmail.com with ESMTPSA id q5-v6sm2363469wmd.29.2018.08.22.02.32.32 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 22 Aug 2018 02:32:34 -0700 (PDT) Received: from d104.suse.de (nat.nue.novell.com [195.135.221.2]) by techadventures.net (Postfix) with ESMTPA id D506A124A17; Wed, 22 Aug 2018 11:32:31 +0200 (CEST) From: Oscar Salvador To: akpm@linux-foundation.org Cc: mhocko@suse.com, dan.j.williams@intel.com, malat@debian.org, david@redhat.com, Pavel.Tatashin@microsoft.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Oscar Salvador Subject: [RFC PATCH 5/5] mm/memory_hotplug: Simplify node_states_check_changes_offline Date: Wed, 22 Aug 2018 11:32:26 +0200 Message-Id: <20180822093226.25987-6-osalvador@techadventures.net> X-Mailer: git-send-email 2.13.6 In-Reply-To: <20180822093226.25987-1-osalvador@techadventures.net> References: <20180822093226.25987-1-osalvador@techadventures.net> 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 From: Oscar Salvador This patch tries to simplify node_states_check_changes_offline and make the code more understandable by: - Removing the if (N_MEMORY == N_NORMAL_MEMORY) wrong statement - Removing the if (N_MEMORY == N_HIGH_MEMORY) wrong statement - Re-structure the code a bit - Removing confusing comments Signed-off-by: Oscar Salvador --- mm/memory_hotplug.c | 81 ++++++++++++++++++++++------------------------------- 1 file changed, 33 insertions(+), 48 deletions(-) diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c index 006a7b817724..b45bc681e6db 100644 --- a/mm/memory_hotplug.c +++ b/mm/memory_hotplug.c @@ -1487,51 +1487,40 @@ static void node_states_check_changes_offline(unsigned long nr_pages, enum zone_type zt, zone_last = ZONE_NORMAL; /* - * If we have HIGHMEM or movable node, node_states[N_NORMAL_MEMORY] - * contains nodes which have zones of 0...ZONE_NORMAL, - * set zone_last to ZONE_NORMAL. - * - * If we don't have HIGHMEM nor movable node, - * node_states[N_NORMAL_MEMORY] contains nodes which have zones of - * 0...ZONE_MOVABLE, set zone_last to ZONE_MOVABLE. + * If the current zone is whithin (0..ZONE_NORMAL], + * check if the amount of pages that are going to be + * offlined is above or equal to the sum of the present + * pages of these zones. + * If that happens, we need to take this node out of + * node_state[N_NORMAL_MEMORY] */ - if (N_MEMORY == N_NORMAL_MEMORY) - zone_last = ZONE_MOVABLE; + if (zone_idx(zone) <= zone_last) { + for (zt = 0; zt <= zone_last; zt++) + present_pages += pgdat->node_zones[zt].present_pages; - /* - * check whether node_states[N_NORMAL_MEMORY] will be changed. - * If the memory to be offline is in a zone of 0...zone_last, - * and it is the last present memory, 0...zone_last will - * become empty after offline , thus we can determind we will - * need to clear the node from node_states[N_NORMAL_MEMORY]. - */ - for (zt = 0; zt <= zone_last; zt++) - present_pages += pgdat->node_zones[zt].present_pages; - if (zone_idx(zone) <= zone_last && nr_pages >= present_pages) - arg->status_change_nid_normal = zone_to_nid(zone); - else - arg->status_change_nid_normal = -1; + if (nr_pages >= present_pages) + arg->status_change_nid_normal = zone_to_nid(zone); + else + arg->status_change_nid_normal = -1; + } #ifdef CONFIG_HIGHMEM /* - * If we have movable node, node_states[N_HIGH_MEMORY] - * contains nodes which have zones of 0...ZONE_HIGHMEM, - * set zone_last to ZONE_HIGHMEM. - * - * If we don't have movable node, node_states[N_NORMAL_MEMORY] - * contains nodes which have zones of 0...ZONE_MOVABLE, - * set zone_last to ZONE_MOVABLE. + * If the current zone is whithin (0..ZONE_HIGHMEM], check if + * the amount of pages that are going to be offlined is above + * or equal to the sum of the present pages of these zones. + * If that happens, we need to take this node out of + * node_state[N_HIGH_MEMORY] */ - zone_last = ZONE_HIGHMEM; - if (N_MEMORY == N_HIGH_MEMORY) - zone_last = ZONE_MOVABLE; - - for (; zt <= zone_last; zt++) + if (zone_idx(zone) <= ZONE_HIGHMEM) { + zt = ZONE_HIGHMEM; present_pages += pgdat->node_zones[zt].present_pages; - if (zone_idx(zone) <= zone_last && nr_pages >= present_pages) - arg->status_change_nid_high = zone_to_nid(zone); - else - arg->status_change_nid_high = -1; + + if (nr_pages >= present_pages) + arg->status_change_nid_high = zone_to_nid(zone); + else + arg->status_change_nid_high = -1; + } #else /* * When !CONFIG_HIGHMEM, N_HIGH_MEMORY equals N_NORMAL_MEMORY @@ -1541,18 +1530,14 @@ static void node_states_check_changes_offline(unsigned long nr_pages, #endif /* - * node_states[N_HIGH_MEMORY] contains nodes which have 0...ZONE_MOVABLE + * Count pages from ZONE_MOVABLE as well. + * If the amount of pages that are going to be offlined is above + * or equal the sum of the present pages of all zones, we need + * to remove this node from node_state[N_MEMORY] */ - zone_last = ZONE_MOVABLE; + zt = ZONE_MOVABLE; + present_pages += pgdat->node_zones[zt].present_pages; - /* - * check whether node_states[N_HIGH_MEMORY] will be changed - * If we try to offline the last present @nr_pages from the node, - * we can determind we will need to clear the node from - * node_states[N_HIGH_MEMORY]. - */ - for (; zt <= zone_last; zt++) - present_pages += pgdat->node_zones[zt].present_pages; if (nr_pages >= present_pages) arg->status_change_nid = zone_to_nid(zone); else