Skip to contentSkip to conversation

x86_64: pageattr cleanups

PATCH In review Nick Piggin 2 participants 5 messages Jan 18, 2006 – Jan 19, 2006

lore
Share & tools
lore
#0 lore raw

cover x86_64: pageattr cleanups

The following patches remove __put_page from x86-64 pageattr.c and tidies it up a bit. They've had some testing.

Nick

#1 lore raw

PATCH 1/2 x86_64: pageattr use single list

Use page->lru.next to implement the singly linked list of pages rather than the struct deferred_page which needs to be allocated and freed for each page.

arch/x86_64/mm/pageattr.c +12 -27
Index: linux-2.6/arch/x86_64/mm/pageattr.c
===================================================================
@@ -77,26 +77,12 @@ static inline void flush_map(unsigned lo
 	on_each_cpu(flush_kernel_map, (void *)address, 1, 1);
 }
 
-struct deferred_page { 
-	struct deferred_page *next; 
-	struct page *fpage;
-	unsigned long address;
-}; 
-static struct deferred_page *df_list; /* protected by init_mm.mmap_sem */
+static struct page *deferred_pages; /* protected by init_mm.mmap_sem */
 
-static inline void save_page(unsigned long address, struct page *fpage)
+static inline void save_page(struct page *fpage)
 {
-	struct deferred_page *df;
-	df = kmalloc(sizeof(struct deferred_page), GFP_KERNEL); 
-	if (!df) {
-		flush_map(address);
-		__free_page(fpage);
-	} else { 
-		df->next = df_list;
-		df->fpage = fpage;
-		df->address = address;
-		df_list = df;
-	} 			
+	fpage->lru.next = (struct list_head *)deferred_pages;
+	deferred_pages = fpage;
 }
 
 /* 
@@ -163,7 +149,7 @@ __change_page_attr(unsigned long address
 
 	switch (page_count(kpte_page)) {
  	case 1:
-		save_page(address, kpte_page); 		     
+		save_page(kpte_page);
 		revert_page(address, ref_prot);
 		break;
  	case 0:
@@ -220,17 +206,16 @@ int change_page_attr(struct page *page, 
 
 void global_flush_tlb(void)
 { 
-	struct deferred_page *df, *next_df;
+	struct page *dpage;
 
 	down_read(&init_mm.mmap_sem);
-	df = xchg(&df_list, NULL);
+	dpage = xchg(&deferred_pages, NULL);
 	up_read(&init_mm.mmap_sem);
-	flush_map((df && !df->next) ? df->address : 0);
-	for (; df; df = next_df) { 
-		next_df = df->next;
-		if (df->fpage) 
-			__free_page(df->fpage);
-		kfree(df);
+
+	flush_map((dpage && !dpage->lru.next) ? (unsigned long)page_address(dpage) : 0);
+	while (dpage) {
+		__free_page(dpage);
+		dpage = (struct page *)dpage->lru.next;
 	} 
 } 
 
#2 lore raw

Re: [patch 1/2] x86_64: pageattr use single list

Quoted 9 lines · Nick Piggin

Use page->lru.next to implement the singly linked list of pages rather than the struct deferred_page which needs to be allocated and freed for each page.

Index: linux-2.6/arch/x86_64/mm/pageattr.c
===================================================================

...

arch/x86_64/mm/pageattr.c int change_page_attr(struct page *page, · line 220

Quoted 8 lines
arch/x86_64/mm/pageattr.c +5 -0
+
+	flush_map((dpage && !dpage->lru.next) ? (unsigned long)page_address(dpage) : 0);
+	while (dpage) {
+		__free_page(dpage);
+		dpage = (struct page *)dpage->lru.next;
 	} 
 } 

do you want to be touching a struct page that was just freed?

-Jason

#3 lore raw

Re: [patch 1/2] x86_64: pageattr use single list

Quoted 15 lines · Jason Baron
Quoted 9 lines · Nick Piggin

Use page->lru.next to implement the singly linked list of pages rather than the struct deferred_page which needs to be allocated and freed for each page.

Index: linux-2.6/arch/x86_64/mm/pageattr.c
===================================================================

...

Quoted 11 lines

arch/x86_64/mm/pageattr.c int change_page_attr(struct page *page, · line 220

Quoted 8 lines
arch/x86_64/mm/pageattr.c +5 -0
+
+	flush_map((dpage && !dpage->lru.next) ? (unsigned long)page_address(dpage) : 0);
+	while (dpage) {
+		__free_page(dpage);
+		dpage = (struct page *)dpage->lru.next;
 	} 
 } 

do you want to be touching a struct page that was just freed?

No, thanks. Good catch.

Nick

#4 lore raw

PATCH 2/2 x86_64: pageattr remove __put_page

In reply to Nick Piggin

Remove page_count and __put_page from x86-64 pageattr

arch/x86_64/mm/pageattr.c +8 -7
Index: linux-2.6/arch/x86_64/mm/pageattr.c
===================================================================
@@ -45,6 +45,9 @@ static struct page *split_large_page(uns
 	pte_t *pbase;
 	if (!base) 
 		return NULL;
+	SetPagePrivate(base);
+	page_private(base) = 0;
+
 	address = __pa(address);
 	addr = address & LARGE_PAGE_MASK; 
 	pbase = (pte_t *)page_address(base);
@@ -137,23 +140,20 @@ __change_page_attr(unsigned long address
 			set_pte(kpte,mk_pte(split, ref_prot2));
 			kpte_page = split;
 		}	
-		get_page(kpte_page);
+		page_private(kpte_page)++;
 	} else if ((kpte_flags & _PAGE_PSE) == 0) { 
 		set_pte(kpte, pfn_pte(pfn, ref_prot));
-		__put_page(kpte_page);
+		BUG_ON(page_private(kpte_page) == 0);
+		page_private(kpte_page)--;
 	} else
 		BUG();
 
 	/* on x86-64 the direct mapping set at boot is not using 4k pages */
  	BUG_ON(PageReserved(kpte_page));
 
-	switch (page_count(kpte_page)) {
- 	case 1:
+	if (page_private(kpte_page) == 0) {
 		save_page(kpte_page);
 		revert_page(address, ref_prot);
-		break;
- 	case 0:
- 		BUG(); /* memleak and failed 2M page regeneration */
  	}
 	return 0;
 } 
@@ -214,6 +214,7 @@ void global_flush_tlb(void)
 
 	flush_map((dpage && !dpage->lru.next) ? (unsigned long)page_address(dpage) : 0);
 	while (dpage) {
+		ClearPagePrivate(dpage);
 		__free_page(dpage);
 		dpage = (struct page *)dpage->lru.next;
 	}