Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp3045148ybi; Mon, 17 Jun 2019 15:23:15 -0700 (PDT) X-Google-Smtp-Source: APXvYqwzvxSK0L5AqnlglBL2ADf87ZIVBsbr3dONdyYc7TIM8aPAW/eMItJDmP9fTA7YjquN3XxI X-Received: by 2002:a17:902:5c5:: with SMTP id f63mr110071577plf.176.1560810195187; Mon, 17 Jun 2019 15:23:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560810195; cv=none; d=google.com; s=arc-20160816; b=nG36PvY7bIZmIfAQ9M/+pXvC/h0YIH0/eHefGIvGVLM3GddB3yEmR3Vm9n3ynghcdt xcJp0dxsnqo0jPj+iRnSNABDY1zglWJqRztWYJLVXWftfIP1Xl/+jzTYBg/U+6sE9f5s ++UvzE4AFXKv8xt3+DQwnGSFq4FxwD6yasl3KMNEhZrSasYIOFiFBJ8MhaB9UYR8wNoc xZwbYTwn+NuybpwSxww9P78Z8yFLCBtOs5BSdw49LuDEHIiDByNoQmzVEP330Fyf1JLn V+X0/Mfa4eUinBWvDQjqT3+bdzbGgtWLqP9yAI1pMK7EiK+6wbnagtT+2tgF5kT3xec4 xSmw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:reply-to:message-id :subject:cc:to:from:date:dkim-signature; bh=mqatRPhG4/yrICubl/YtsP1o46r2J2qqnG2uC01iPb4=; b=hnmEvoC7rTvaz4zaKSLdVtFJF9UIUrxtcCcJQvEUrlOte5es7N6jyO3mCY3WVuekMT NAizsaU8FNQdi5KJf7SpYMlbnEWSzvXK4gaXMmfT+5fo4/4eWid0TAjT+kCkqqV5zDZr opeIaJkkCcu6CEB6kTH4D9MmXqIqdyXRycN7JFm/qwkZrSfY6tEI2A/CyE0O/LshmmOb TYNC0xV8pDdLrQGGvXpX/fIluRIXRvORUoOqze4DJiG0Bmv/v/BRPgZ7GeLVcp64Vkcq RsZV5aD5gd0bt+ivOcOtJZLI+2kbXD2IWETYLmjEnj+LWjIs2lqRhbp1S3ojWHg11lmu Z0jw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=Sn59+fku; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i2si11417794pgs.265.2019.06.17.15.22.59; Mon, 17 Jun 2019 15:23:15 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=Sn59+fku; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729083AbfFQWWB (ORCPT + 99 others); Mon, 17 Jun 2019 18:22:01 -0400 Received: from mail-ed1-f65.google.com ([209.85.208.65]:34333 "EHLO mail-ed1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728571AbfFQWWA (ORCPT ); Mon, 17 Jun 2019 18:22:00 -0400 Received: by mail-ed1-f65.google.com with SMTP id s49so18487281edb.1 for ; Mon, 17 Jun 2019 15:21:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:reply-to:references:mime-version :content-disposition:in-reply-to:user-agent; bh=mqatRPhG4/yrICubl/YtsP1o46r2J2qqnG2uC01iPb4=; b=Sn59+fkuicsgo3YsVoW2qnw1bCXHgBCm2Otdf4Wce7TS4+FrikSNaMBZfYQNyrU729 UIMmhjtdabVHowgnlZZW6wyZPaZpNTOvJnjFkMwPMWs0WpyGklGYHwe5Lv4F4lKwkO10 HdjfYqURaByB1W1qfIy9U2J/5HoBKrePLbtsrhVFDxJ8cb46cSkWFEjDnOG+3w2md9TZ TNk8ByFIGCx6a3vMl+dRsBN08rY66zqmgyVrAT/iCyo3F0RD9seGbB8vhYUjKc9UbhPw XoRl22CkI3tf4rRvfDhmm80D5wjUGcKLq56Bo/oH1BZHmSrUFsqxgBWviu5hFG2iU1LT lEgg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:reply-to :references:mime-version:content-disposition:in-reply-to:user-agent; bh=mqatRPhG4/yrICubl/YtsP1o46r2J2qqnG2uC01iPb4=; b=hFyYxJxdVvs0UaWBl7P2v3fhWjnZ9uAjCLcMYim8Ao3s9fXlZF8lnZUz/sHicVrO16 HZltvjVi9zZjD5Yw60P81OnemIt3OqQOtLcVhrC7hu2KVM10+/5GYzG3wcz5wkM65HfW X7soO6aN8j4Wsx5fp6LlkBYruh/ChwQrmsPzeubNJIJxOHi0mIjxOBt8rK6A6QSJ6EkL RQ6M0g2qbX+6jMpT0Yz1/UztnZg9jn6A9Cu2jLqgvhb/0ohwVDgIFUr4Bg22OIst2QTT 6aQo70YsoIHDIVpaz3WgOisj0jajXMddhAIzaA91LznaX7OjxVLOzXJKUG3SZa5DPcZ1 AXUA== X-Gm-Message-State: APjAAAW84CD0cd58vA83ff2XxPDqITxPp4+Q281J9GuqDZjaYNIX1JB0 kyYiH0JT+FgVkrScVOaaIZw= X-Received: by 2002:a50:8bfd:: with SMTP id n58mr87510972edn.272.1560810118130; Mon, 17 Jun 2019 15:21:58 -0700 (PDT) Received: from localhost ([185.92.221.13]) by smtp.gmail.com with ESMTPSA id f3sm2407908ejo.90.2019.06.17.15.21.57 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 17 Jun 2019 15:21:57 -0700 (PDT) Date: Mon, 17 Jun 2019 22:21:56 +0000 From: Wei Yang To: Dan Williams Cc: akpm@linux-foundation.org, Michal Hocko , Vlastimil Babka , Logan Gunthorpe , Oscar Salvador , Pavel Tatashin , Jane Chu , linux-mm@kvack.org, linux-nvdimm@lists.01.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v9 02/12] mm/sparsemem: Add helpers track active portions of a section at boot Message-ID: <20190617222156.v6eaujbdrmkz35wr@master> Reply-To: Wei Yang References: <155977186863.2443951.9036044808311959913.stgit@dwillia2-desk3.amr.corp.intel.com> <155977187919.2443951.8925592545929008845.stgit@dwillia2-desk3.amr.corp.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <155977187919.2443951.8925592545929008845.stgit@dwillia2-desk3.amr.corp.intel.com> User-Agent: NeoMutt/20170113 (1.7.2) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Jun 05, 2019 at 02:57:59PM -0700, Dan Williams wrote: >Prepare for hot{plug,remove} of sub-ranges of a section by tracking a >sub-section active bitmask, each bit representing a PMD_SIZE span of the >architecture's memory hotplug section size. > >The implications of a partially populated section is that pfn_valid() >needs to go beyond a valid_section() check and read the sub-section >active ranges from the bitmask. The expectation is that the bitmask >(subsection_map) fits in the same cacheline as the valid_section() data, >so the incremental performance overhead to pfn_valid() should be >negligible. > >Cc: Michal Hocko >Cc: Vlastimil Babka >Cc: Logan Gunthorpe >Cc: Oscar Salvador >Cc: Pavel Tatashin >Tested-by: Jane Chu >Signed-off-by: Dan Williams >--- > include/linux/mmzone.h | 29 ++++++++++++++++++++++++++++- > mm/page_alloc.c | 4 +++- > mm/sparse.c | 35 +++++++++++++++++++++++++++++++++++ > 3 files changed, 66 insertions(+), 2 deletions(-) > >diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h >index ac163f2f274f..6dd52d544857 100644 >--- a/include/linux/mmzone.h >+++ b/include/linux/mmzone.h >@@ -1199,6 +1199,8 @@ struct mem_section_usage { > unsigned long pageblock_flags[0]; > }; > >+void subsection_map_init(unsigned long pfn, unsigned long nr_pages); >+ > struct page; > struct page_ext; > struct mem_section { >@@ -1336,12 +1338,36 @@ static inline struct mem_section *__pfn_to_section(unsigned long pfn) > > extern int __highest_present_section_nr; > >+static inline int subsection_map_index(unsigned long pfn) >+{ >+ return (pfn & ~(PAGE_SECTION_MASK)) / PAGES_PER_SUBSECTION; >+} >+ >+#ifdef CONFIG_SPARSEMEM_VMEMMAP >+static inline int pfn_section_valid(struct mem_section *ms, unsigned long pfn) >+{ >+ int idx = subsection_map_index(pfn); >+ >+ return test_bit(idx, ms->usage->subsection_map); >+} >+#else >+static inline int pfn_section_valid(struct mem_section *ms, unsigned long pfn) >+{ >+ return 1; >+} >+#endif >+ > #ifndef CONFIG_HAVE_ARCH_PFN_VALID > static inline int pfn_valid(unsigned long pfn) > { >+ struct mem_section *ms; >+ > if (pfn_to_section_nr(pfn) >= NR_MEM_SECTIONS) > return 0; >- return valid_section(__nr_to_section(pfn_to_section_nr(pfn))); >+ ms = __nr_to_section(pfn_to_section_nr(pfn)); >+ if (!valid_section(ms)) >+ return 0; >+ return pfn_section_valid(ms, pfn); > } > #endif > >@@ -1373,6 +1399,7 @@ void sparse_init(void); > #define sparse_init() do {} while (0) > #define sparse_index_init(_sec, _nid) do {} while (0) > #define pfn_present pfn_valid >+#define subsection_map_init(_pfn, _nr_pages) do {} while (0) > #endif /* CONFIG_SPARSEMEM */ > > /* >diff --git a/mm/page_alloc.c b/mm/page_alloc.c >index c6d8224d792e..bd773efe5b82 100644 >--- a/mm/page_alloc.c >+++ b/mm/page_alloc.c >@@ -7292,10 +7292,12 @@ void __init free_area_init_nodes(unsigned long *max_zone_pfn) > > /* Print out the early node map */ > pr_info("Early memory node ranges\n"); >- for_each_mem_pfn_range(i, MAX_NUMNODES, &start_pfn, &end_pfn, &nid) >+ for_each_mem_pfn_range(i, MAX_NUMNODES, &start_pfn, &end_pfn, &nid) { > pr_info(" node %3d: [mem %#018Lx-%#018Lx]\n", nid, > (u64)start_pfn << PAGE_SHIFT, > ((u64)end_pfn << PAGE_SHIFT) - 1); >+ subsection_map_init(start_pfn, end_pfn - start_pfn); >+ } Just curious about why we set subsection here? Function free_area_init_nodes() mostly handles pgdat, if I am correct. Setup subsection here looks like touching some lower level system data structure. > > /* Initialise every node */ > mminit_verify_pageflags_layout(); >diff --git a/mm/sparse.c b/mm/sparse.c >index 71da15cc7432..0baa2e55cfdd 100644 >--- a/mm/sparse.c >+++ b/mm/sparse.c >@@ -210,6 +210,41 @@ static inline unsigned long first_present_section_nr(void) > return next_present_section_nr(-1); > } > >+void subsection_mask_set(unsigned long *map, unsigned long pfn, >+ unsigned long nr_pages) >+{ >+ int idx = subsection_map_index(pfn); >+ int end = subsection_map_index(pfn + nr_pages - 1); >+ >+ bitmap_set(map, idx, end - idx + 1); >+} >+ >+void subsection_map_init(unsigned long pfn, unsigned long nr_pages) >+{ >+ int end_sec = pfn_to_section_nr(pfn + nr_pages - 1); >+ int i, start_sec = pfn_to_section_nr(pfn); >+ >+ if (!nr_pages) >+ return; >+ >+ for (i = start_sec; i <= end_sec; i++) { >+ struct mem_section *ms; >+ unsigned long pfns; >+ >+ pfns = min(nr_pages, PAGES_PER_SECTION >+ - (pfn & ~PAGE_SECTION_MASK)); >+ ms = __nr_to_section(i); >+ subsection_mask_set(ms->usage->subsection_map, pfn, pfns); >+ >+ pr_debug("%s: sec: %d pfns: %ld set(%d, %d)\n", __func__, i, >+ pfns, subsection_map_index(pfn), >+ subsection_map_index(pfn + pfns - 1)); >+ >+ pfn += pfns; >+ nr_pages -= pfns; >+ } >+} >+ > /* Record a memory area against a node. */ > void __init memory_present(int nid, unsigned long start, unsigned long end) > { -- Wei Yang Help you, Help me