All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] Fix explanation of lower bits in the SPARSEMEM mem_map pointer
@ 2018-01-19  7:09 ` Petr Tesarik
  0 siblings, 0 replies; 14+ messages in thread
From: Petr Tesarik @ 2018-01-19  7:09 UTC (permalink / raw)
  To: linux-mm, Andrew Morton, Michal Hocko, Vlastimil Babka
  Cc: linux-kernel, Mel Gorman, Johannes Weiner, Kemi Wang,
	YASUAKI ISHIMATSU, Andrey Ryabinin, Nikolay Borisov

The comment is confusing. On the one hand, it refers to 32-bit
alignment (struct page alignment on 32-bit platforms), but this
would only guarantee that the 2 lowest bits must be zero. On the
other hand, it claims that at least 3 bits are available, and 3 bits
are actually used.

This is not broken, because there is a stronger alignment guarantee,
just less obvious. Let's fix the comment to make it clear how many
bits are available and why.

Signed-off-by: Petr Tesarik <ptesarik@suse.com>
---
 include/linux/mmzone.h | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
index 67f2e3c38939..7522a6987595 100644
--- a/include/linux/mmzone.h
+++ b/include/linux/mmzone.h
@@ -1166,8 +1166,16 @@ extern unsigned long usemap_size(void);
 
 /*
  * We use the lower bits of the mem_map pointer to store
- * a little bit of information.  There should be at least
- * 3 bits here due to 32-bit alignment.
+ * a little bit of information.  The pointer is calculated
+ * as mem_map - section_nr_to_pfn(pnum).  The result is
+ * aligned to the minimum alignment of the two values:
+ *   1. All mem_map arrays are page-aligned.
+ *   2. section_nr_to_pfn() always clears PFN_SECTION_SHIFT
+ *      lowest bits.  PFN_SECTION_SHIFT is arch-specific
+ *      (equal SECTION_SIZE_BITS - PAGE_SHIFT), and the
+ *      worst combination is powerpc with 256k pages,
+ *      which results in PFN_SECTION_SHIFT equal 6.
+ * To sum it up, at least 6 bits are available.
  */
 #define	SECTION_MARKED_PRESENT	(1UL<<0)
 #define SECTION_HAS_MEM_MAP	(1UL<<1)
-- 
2.13.6

^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2018-01-25 11:46 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-01-19  7:09 [PATCH] Fix explanation of lower bits in the SPARSEMEM mem_map pointer Petr Tesarik
2018-01-19  7:09 ` Petr Tesarik
2018-01-19 12:39 ` Michal Hocko
2018-01-19 12:39   ` Michal Hocko
2018-01-19 13:21   ` Petr Tesarik
2018-01-19 13:21     ` Petr Tesarik
2018-01-24 12:43     ` Michal Hocko
2018-01-24 12:43       ` Michal Hocko
2018-01-24 13:57       ` Petr Tesarik
2018-01-24 13:57         ` Petr Tesarik
2018-01-25  9:05         ` [PATCH v2] " Petr Tesarik
2018-01-25  9:05           ` Petr Tesarik
2018-01-25 11:46           ` Michal Hocko
2018-01-25 11:46             ` Michal Hocko

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.