Received: by 2002:a05:6a10:17d3:0:0:0:0 with SMTP id hz19csp240470pxb; Fri, 16 Apr 2021 04:37:50 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyEajszROBh9a+bxY3bP0awJkr7BKSiT+pWlsnC22o/rYxPsefCiQxquKuciL/Y0vBMjj/+ X-Received: by 2002:a17:907:2151:: with SMTP id rk17mr7885646ejb.203.1618573070523; Fri, 16 Apr 2021 04:37:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618573070; cv=none; d=google.com; s=arc-20160816; b=lgRmK6qQ2lv+PSqBNd6BYsvRWsT5fKPC384eJ8QQE6qxAMxf2JNzE6KeIYPG2vU+px UKpNvYF+L49yzJECjgcFTFWs97Yo/YK+aQ7g054X5T/YjFVj2QGfnSs/5N7vHxUeCqH/ 0ZXPVF4BUX5vCGv3u5QmN59BHKU49Y61bk5m/uANUnYEr3mjUElIRJnmbT7eGUyH+FcJ eY+VqaW+AvdnJ4iR/cyvLF0p/wP/ZMB7drMkOXU2BjOmTC2/oEqyts+eFVxrNIhmBC7e UGZM8+Y8ldv/cbWe8h/+pYaQUKAn7MMD6qABo0LuKRTgroYHqRtqKY3XEW54FpdBHmW/ J9GQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=1U6zJRWvCMDhLtdbW/h1j1FIYDs88YYETx1ImQAJPRE=; b=ZJxXaRRCU3M732prXemiv054wNQ5EIDkxGr5+xLhakmgNBfx4DezLmxk6R1LAphAWm Yk3gZBXcpuqfiz/8JHNfkr6DWQzQRVflM4dekQbAl1V38vZd83vQDjwfbxYh5PcIfPsB Ak9n+BF+eKDwekdOzkl4r+kAt/WGO2Y99w/CLH6CqmrLNeeHjBJwxxfHNKDIwhnj+JoG NhkEVw+yxOLZi+yiqL0WIjf1i+RmZs7111QuvVdSHyb5K3c2WuTOXVMIP+DgWdejVN6U fOoSvWY4FUgKx6Jg0+nRGArf71cDPOBlbHLcshPG3m4vmOW+kPRKB2NqHdD5DpRaJ4K3 0sug== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id e9si4749245ejq.308.2021.04.16.04.37.27; Fri, 16 Apr 2021 04:37:50 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242565AbhDPLY5 (ORCPT + 99 others); Fri, 16 Apr 2021 07:24:57 -0400 Received: from mx2.suse.de ([195.135.220.15]:48622 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241793AbhDPLYs (ORCPT ); Fri, 16 Apr 2021 07:24:48 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id A4053B02A; Fri, 16 Apr 2021 11:24:23 +0000 (UTC) From: Oscar Salvador To: Andrew Morton Cc: David Hildenbrand , Michal Hocko , Anshuman Khandual , Pavel Tatashin , Vlastimil Babka , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Oscar Salvador Subject: [PATCH v9 3/8] mm,memory_hotplug: Factor out adjusting present pages into adjust_present_page_count() Date: Fri, 16 Apr 2021 13:24:06 +0200 Message-Id: <20210416112411.9826-4-osalvador@suse.de> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20210416112411.9826-1-osalvador@suse.de> References: <20210416112411.9826-1-osalvador@suse.de> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: David Hildenbrand Let's have a single place (inspired by adjust_managed_page_count()) where we adjust present pages. In contrast to adjust_managed_page_count(), only memory onlining/offlining is allowed to modify the number of present pages. Signed-off-by: David Hildenbrand Signed-off-by: Oscar Salvador Reviewed-by: Oscar Salvador --- mm/memory_hotplug.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c index 25e59d5dc13c..d05056b3c173 100644 --- a/mm/memory_hotplug.c +++ b/mm/memory_hotplug.c @@ -829,6 +829,16 @@ struct zone * zone_for_pfn_range(int online_type, int nid, unsigned start_pfn, return default_zone_for_pfn(nid, start_pfn, nr_pages); } +static void adjust_present_page_count(struct zone *zone, long nr_pages) +{ + unsigned long flags; + + zone->present_pages += nr_pages; + pgdat_resize_lock(zone->zone_pgdat, &flags); + zone->zone_pgdat->node_present_pages += nr_pages; + pgdat_resize_unlock(zone->zone_pgdat, &flags); +} + int __ref online_pages(unsigned long pfn, unsigned long nr_pages, int online_type, int nid) { @@ -882,11 +892,7 @@ int __ref online_pages(unsigned long pfn, unsigned long nr_pages, } online_pages_range(pfn, nr_pages); - zone->present_pages += nr_pages; - - pgdat_resize_lock(zone->zone_pgdat, &flags); - zone->zone_pgdat->node_present_pages += nr_pages; - pgdat_resize_unlock(zone->zone_pgdat, &flags); + adjust_present_page_count(zone, nr_pages); node_states_set_node(nid, &arg); if (need_zonelists_rebuild) @@ -1701,11 +1707,7 @@ int __ref offline_pages(unsigned long start_pfn, unsigned long nr_pages) /* removal success */ adjust_managed_page_count(pfn_to_page(start_pfn), -nr_pages); - zone->present_pages -= nr_pages; - - pgdat_resize_lock(zone->zone_pgdat, &flags); - zone->zone_pgdat->node_present_pages -= nr_pages; - pgdat_resize_unlock(zone->zone_pgdat, &flags); + adjust_present_page_count(zone, -nr_pages); init_per_zone_wmark_min(); -- 2.16.3