From patchwork Tue Aug 28 21:01:58 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oscar Salvador X-Patchwork-Id: 10579155 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 E96011822 for ; Tue, 28 Aug 2018 21:02:12 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DD1472ACE0 for ; Tue, 28 Aug 2018 21:02:12 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D02B92ACEE; Tue, 28 Aug 2018 21:02:12 +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 550C12ACE0 for ; Tue, 28 Aug 2018 21:02:12 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 44EC16B480F; Tue, 28 Aug 2018 17:02:11 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 424A16B4810; Tue, 28 Aug 2018 17:02:11 -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 3160A6B4811; Tue, 28 Aug 2018 17:02:11 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-wm0-f72.google.com (mail-wm0-f72.google.com [74.125.82.72]) by kanga.kvack.org (Postfix) with ESMTP id C7F4D6B480F for ; Tue, 28 Aug 2018 17:02:10 -0400 (EDT) Received: by mail-wm0-f72.google.com with SMTP id m129-v6so1794259wma.8 for ; Tue, 28 Aug 2018 14:02:10 -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; bh=SeY6d0/ITeqoecKbPWVqyAHHkb7nxCmq1kmKXUf6pfc=; b=uN88ZSSCqn5F2pkwezEhjjmK2lDc3urrqx5LACsC8CxEfxtanrqtb9okw1eA3Od7u4 khLyGDvWRU7E7YdKOFLY59PDESBdw1TgcYofJyliKV7dmA6NKBt0mbvMT9j9XCXtJ7Ed v7fb+tlq4vLAAjRCTAM1qI/Df2pdOOsx2f+VHXtLZkWkySM2PiHiCWJvZ/lHqVEqi+ju d15zQ2uDpWDM389dvGjePuU+OnoKxImW5hj9CYk0H0wOBF36vAX8pGQtONDd3jneP2R/ iN96ePLbtkExiRC2cl9TS5so0bfxYEM5AS4xeW33N4z300h6qOiBan2VZ5a0rmirBuBl 1tig== 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: APzg51AoyaopYUZnTvf+Cfc1NGkMf25NHQQCw8DBNqEKYqfvdUfO2A2R 3kEdbhq0wo/4GuNl3LwqkSHcqC6ZsHucIkO8U11cHL9NqHFWqTm+46ynSRLxo8wsb+zo6pwStnv NvBQSge9Vubi+0nASq9jakmuF57tUorw5o3/qOEpXz8wat9suxLQOzIXmh3Yc3eKpjRPHfqjOAk DyqzW7Nxitt8EX82VwRZ3fbMJgB1qQRoB91p0ex/GHmEDbXVKZCnEG0s4INV+/mBWIfClWgGAK1 4pSqzzY+z7YH37MadY+tvRm3oIkgG0lp1eqXIMscb9pjvEX6pRL0+aI9InLZQcIEoeMHsHwpzOb 8VhF6qXk3/Ya2lolS4c2HWRFn1ZVwDbdE8wywSXU1C3+VhwOB2A/2iE3ou/6taGlglVmHxdASQ= = X-Received: by 2002:adf:9e06:: with SMTP id u6-v6mr2262071wre.51.1535490130316; Tue, 28 Aug 2018 14:02:10 -0700 (PDT) X-Received: by 2002:adf:9e06:: with SMTP id u6-v6mr2262034wre.51.1535490129546; Tue, 28 Aug 2018 14:02:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535490129; cv=none; d=google.com; s=arc-20160816; b=EYHA5ZDX7yF6PIOcxSM5RJ6Yf27ursuaR9q2xpsiPXRmhhuU95uCiualawWJkj7boN PfkDydsOgQPl7t2YUqnMA2UtIrrxPzSGRULCl6wr+ih+mI6TSCHBEWLjHq80BIrtcmf5 cveIg2JUZ4FSY/wqJ2lUzeBZ6cE6u5FoSMDFgoqZI1uH9Z91xGKyCRH1aGj6vVsm7F8h KuP5/dwMoyF8snfT7LdKOpVnUySy12JZQVVB1Fq8u/O2GRwkirD0mnHeF4By7XrOlxlf tXfOVvoRiq6RrIlhg8GKbETQz7G59oL+nw0TYcOcnpKtNM5sHlf3KntEiCatEttApvJI Ui0g== 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:arc-authentication-results; bh=SeY6d0/ITeqoecKbPWVqyAHHkb7nxCmq1kmKXUf6pfc=; b=JBfpWbnKMAlEZkxGweSNK9LUHgC5avmFaM0sXteIyIxG5Xu7puenJxs8zxNf8JHjos zY1B0wqtSb7VgSsfaO5dOMzqqMNv8ajJfucaQsTjX/jRftvtErtu7El1eCMmlwJUtVYM +fEq0DZLWnJvBvsmCFLBQ5qliLuZ5q/QEzjCngsMJDSVOLuiXMroKgU5cPOzmbsJWa5b t4NsCuyaruvtnb84gMUnZvEZ6uWywKCpRExPiKBDmYQjM+Qq1sxDe7wy5cDCjhhNXHQ+ sFBRngF6XemQURjBMPcL95G4C2uczip8Dd3QvLkXnmQv99EwdAud/BngqANbXmMUSGuz YmUQ== 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 t82-v6sor675389wmg.76.2018.08.28.14.02.09 for (Google Transport Security); Tue, 28 Aug 2018 14:02:09 -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: ANB0VdaRSACAJUpy11fVV90YRu9xjoE8gaNbdvJ4n0Zm+XH6Abl+083EHXn14mHkiuCv2TQm8hTtvw== X-Received: by 2002:a1c:a8d0:: with SMTP id r199-v6mr2261406wme.97.1535490129272; Tue, 28 Aug 2018 14:02:09 -0700 (PDT) Received: from techadventures.net (techadventures.net. [62.201.165.239]) by smtp.gmail.com with ESMTPSA id f13-v6sm2148183wrt.9.2018.08.28.14.02.08 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 28 Aug 2018 14:02:08 -0700 (PDT) Received: from d104.suse.de (charybdis-ext.suse.de [195.135.221.2]) by techadventures.net (Postfix) with ESMTPA id A6C33124BC2; Tue, 28 Aug 2018 23:02:07 +0200 (CEST) From: Oscar Salvador To: akpm@linux-foundation.org Cc: mhocko@suse.com, vbabka@suse.cz, Pavel.Tatashin@microsoft.com, sfr@canb.auug.org.au, iamjoonsoo.kim@lge.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Oscar Salvador Subject: [PATCH] mm/page_alloc: Clean up check_for_memory Date: Tue, 28 Aug 2018 23:01:58 +0200 Message-Id: <20180828210158.4617-1-osalvador@techadventures.net> X-Mailer: git-send-email 2.13.6 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 check_for_memory looks a bit confusing. First of all, we have this: if (N_MEMORY == N_NORMAL_MEMORY) return; Checking the ENUM declaration, looks like N_MEMORY canot be equal to N_NORMAL_MEMORY. I could not find where N_MEMORY is set to N_NORMAL_MEMORY, or the other way around either, so unless I am missing something, this condition will never evaluate to true. It makes sense to get rid of it. Moving forward, the operations whithin the loop look a bit confusing as well. We set N_HIGH_MEMORY unconditionally, and then we set N_NORMAL_MEMORY in case we have CONFIG_HIGHMEM (N_NORMAL_MEMORY != N_HIGH_MEMORY) and zone <= ZONE_NORMAL. (N_HIGH_MEMORY falls back to N_NORMAL_MEMORY on !CONFIG_HIGHMEM systems, and that is why we can just go ahead and set N_HIGH_MEMORY unconditionally) Although this works, it is a bit subtle. I think that this could be easier to follow: First, we should only set N_HIGH_MEMORY in case we have CONFIG_HIGHMEM. And then we should set N_NORMAL_MEMORY in case zone <= ZONE_NORMAL, without further checking whether we have CONFIG_HIGHMEM or not. Signed-off-by: Oscar Salvador --- mm/page_alloc.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 839e0cc17f2c..6aa947f9e614 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -6819,15 +6819,12 @@ static void check_for_memory(pg_data_t *pgdat, int nid) { enum zone_type zone_type; - if (N_MEMORY == N_NORMAL_MEMORY) - return; - for (zone_type = 0; zone_type <= ZONE_MOVABLE - 1; zone_type++) { struct zone *zone = &pgdat->node_zones[zone_type]; if (populated_zone(zone)) { - node_set_state(nid, N_HIGH_MEMORY); - if (N_NORMAL_MEMORY != N_HIGH_MEMORY && - zone_type <= ZONE_NORMAL) + if (IS_ENABLED(CONFIG_HIGHMEM)) + node_set_state(nid, N_HIGH_MEMORY); + if (zone_type <= ZONE_NORMAL) node_set_state(nid, N_NORMAL_MEMORY); break; }