Skip to contentSkip to conversation

Remove initialization of page_table in one_page_table_init()

PATCH NAK Zhaolei 3 participants 5 messages Jul 14, 2009 – Jul 20, 2009

Subsystems (2)
lore
Share & tools
lore

Zhaolei

author
#0 lore raw

PATCH 1/1 Remove initialization of page_table in one_page_table_init()

Only judge if (!page_table) when CONFIG_DEBUG_PAGEALLOC or CONFIG_KMEMCHECK are defined, then we don't need to set init value for page_table.

---
arch/x86/mm/init_32.c | 4 ++--

1 files changed, 2 insertions(+), 2 deletions(-)
arch/x86/mm/init_32.c +0 -0
index 3cd7711..55da09b 100644
@@ -108,13 +108,13 @@ static pmd_t * __init one_md_table_init(pgd_t *pgd)

static pte_t * __init one_page_table_init(pmd_t *pmd)

{
    if (!(pmd_val(*pmd) & _PAGE_PRESENT)) {

- pte_t *page_table = NULL;
+ pte_t *page_table;

        if (after_bootmem) {
#if defined(CONFIG_DEBUG_PAGEALLOC) || defined(CONFIG_KMEMCHECK)
            page_table = (pte_t *) alloc_bootmem_pages(PAGE_SIZE);
-#endif
            if (!page_table)
+#endif
                page_table =
                (pte_t *)alloc_bootmem_low_pages(PAGE_SIZE);
        } else
Signature · 1 line
1.5.5.3
#1 lore raw
Quoted 10 lines · Zhaolei
arch/x86/mm/init_32.c +1 -1
index 3cd7711..55da09b 100644
@@ -108,13 +108,13 @@ static pmd_t * __init one_md_table_init(pgd_t *pgd)
 static pte_t * __init one_page_table_init(pmd_t *pmd)
 {
    if (!(pmd_val(*pmd) & _PAGE_PRESENT)) {
-        pte_t *page_table = NULL;
+        pte_t *page_table;

arch/x86/mm/init_32.c static pmd_t * __init one_md_table_init(pgd_t *pgd) · line 120

Quoted 10 lines
arch/x86/mm/init_32.c +1 -1
 
        if (after_bootmem) {
 #if defined(CONFIG_DEBUG_PAGEALLOC) || defined(CONFIG_KMEMCHECK)
            page_table = (pte_t *) alloc_bootmem_pages(PAGE_SIZE);
-#endif
            if (!page_table)
+#endif
                page_table =
                (pte_t *)alloc_bootmem_low_pages(PAGE_SIZE);
        } else

Nack, gcc will already optimize the branch out for configs without CONFIG_DEBUG_PAGEALLOC and CONFIG_KMEMCHECK. The only thing this change does is make the code less readable.

#2 lore raw
In reply to Zhaolei
Quoted 17 lines · Zhaolei

Only judge if (!page_table) when CONFIG_DEBUG_PAGEALLOC or CONFIG_KMEMCHECK are defined, then we don't need to set init value for page_table.

---
arch/x86/mm/init_32.c | 4 ++--

1 files changed, 2 insertions(+), 2 deletions(-)
arch/x86/mm/init_32.c +0 -1
index 3cd7711..55da09b 100644
@@ -108,13 +108,13 @@ static pmd_t * __init one_md_table_init(pgd_t *pgd)
 static pte_t * __init one_page_table_init(pmd_t *pmd)
 {
    if (!(pmd_val(*pmd) & _PAGE_PRESENT)) {
-        pte_t *page_table = NULL;

arch/x86/mm/init_32.c static pmd_t * __init one_md_table_init(pgd_t *pgd) · line 119

Quoted 10 lines
arch/x86/mm/init_32.c +2 -1
+        pte_t *page_table;
 
        if (after_bootmem) {
 #if defined(CONFIG_DEBUG_PAGEALLOC) || defined(CONFIG_KMEMCHECK)
            page_table = (pte_t *) alloc_bootmem_pages(PAGE_SIZE);
-#endif
            if (!page_table)
+#endif
                page_table =
                (pte_t *)alloc_bootmem_low_pages(PAGE_SIZE);

I think the original code was cleaner - putting an #ifdef straight into the middle of a control block is quite fragile.

Ingo

author
#3 lore raw
Quoted 33 lines · Ingo Molnar
Quoted 17 lines · Zhaolei

Only judge if (!page_table) when CONFIG_DEBUG_PAGEALLOC or CONFIG_KMEMCHECK are defined, then we don't need to set init value for page_table.

---
arch/x86/mm/init_32.c | 4 ++--

1 files changed, 2 insertions(+), 2 deletions(-)
arch/x86/mm/init_32.c +0 -1
index 3cd7711..55da09b 100644
@@ -108,13 +108,13 @@ static pmd_t * __init one_md_table_init(pgd_t *pgd)
 static pte_t * __init one_page_table_init(pmd_t *pmd)
 {
    if (!(pmd_val(*pmd) & _PAGE_PRESENT)) {
-        pte_t *page_table = NULL;

arch/x86/mm/init_32.c static pmd_t * __init one_md_table_init(pgd_t *pgd) · line 119

Quoted 10 lines
arch/x86/mm/init_32.c +2 -1
+        pte_t *page_table;
 
        if (after_bootmem) {
 #if defined(CONFIG_DEBUG_PAGEALLOC) || defined(CONFIG_KMEMCHECK)
            page_table = (pte_t *) alloc_bootmem_pages(PAGE_SIZE);
-#endif
            if (!page_table)
+#endif
                page_table =
                (pte_t *)alloc_bootmem_low_pages(PAGE_SIZE);

I think the original code was cleaner - putting an #ifdef straight into the middle of a control block is quite fragile.

Quoted 2 lines

Ingo

Hello, Ingo

David Rientjes said that:
Nack, gcc will already optimize the branch out for configs without CONFIG_DEBUG_PAGEALLOC and CONFIG_KMEMCHECK. The only thing this change does is make the code less readable.

I tested it with gcc -O2, and proved that David is correct.
Initialization of page_table and additional "if (!page_table)" was removed by optimization. Please ignore this patch.

Thanks
Zhaolei

#4 lore raw
Quoted 39 lines · Zhaolei
Quoted 33 lines · Ingo Molnar
Quoted 17 lines · Zhaolei

Only judge if (!page_table) when CONFIG_DEBUG_PAGEALLOC or CONFIG_KMEMCHECK are defined, then we don't need to set init value for page_table.

---
arch/x86/mm/init_32.c | 4 ++--

1 files changed, 2 insertions(+), 2 deletions(-)
arch/x86/mm/init_32.c +0 -1
index 3cd7711..55da09b 100644
@@ -108,13 +108,13 @@ static pmd_t * __init one_md_table_init(pgd_t *pgd)
 static pte_t * __init one_page_table_init(pmd_t *pmd)
 {
    if (!(pmd_val(*pmd) & _PAGE_PRESENT)) {
-        pte_t *page_table = NULL;

arch/x86/mm/init_32.c static pmd_t * __init one_md_table_init(pgd_t *pgd) · line 119

Quoted 10 lines
arch/x86/mm/init_32.c +2 -1
+        pte_t *page_table;
 
        if (after_bootmem) {
 #if defined(CONFIG_DEBUG_PAGEALLOC) || defined(CONFIG_KMEMCHECK)
            page_table = (pte_t *) alloc_bootmem_pages(PAGE_SIZE);
-#endif
            if (!page_table)
+#endif
                page_table =
                (pte_t *)alloc_bootmem_low_pages(PAGE_SIZE);

I think the original code was cleaner - putting an #ifdef straight into the middle of a control block is quite fragile.

Quoted 2 lines

Ingo

Hello, Ingo

Quoted 8 lines

David Rientjes said that:
Nack, gcc will already optimize the branch out for configs without CONFIG_DEBUG_PAGEALLOC and CONFIG_KMEMCHECK. The only thing this change does is make the code less readable.

I tested it with gcc -O2, and proved that David is correct. Initialization of page_table and additional "if (!page_table)" was removed by optimization. Please ignore this patch.

Yeah - and note that even if GCC _didnt_ optimize it out, the patch was not acceptable in this form.

Ingo