Skip to contentSkip to conversation

Huge TLB pages always physically continious?

PATCH Ingo Oeser 3 participants 4 messages Nov 1, 2002 – Nov 4, 2002

Subsystems (2)
lore
Share & tools
lore

Ingo Oeser

author
#0 lore raw

Hi there,

are huge TLB pages always physically continous in memory?

What does follow_hugetlb_page do exactly? I simply don't understand what the code does.

I would like to build up a simplified get_user_pages_sgl() to build a scatter gather list from user space adresses.

If I want to coalesce physically continous pages (if they are also virtually continious) anyway, can I write up a simplified follow_hugetlb_page_sgl() function which handles the huge page really as only one page?

Motivation:

Currently doing scatter gather DMA of user pages requires THREE runs over the pages and I would like to save at least the second one and possibly shorten the third one.

The three steps required:

1) get_user_pages() to obtain the pages and lock them in page_cache
2) translate the vector of pointers to struct page to a vector of struct scatterlist
3) pci_map_sg() a decent amount[1], DMA it, wait for completion or abortion, pci_unmap_sg() it and start again with the remainder

Step 2) could be eliminated completely and also the allocation of the temporary vector of struct page.

Step 3) could be shortend, if I coalesce physically continous ranges into a single scatterlist entry with just a ->length bigger than PAGE_SIZE. I know that this is only worth it on architectures, where physical address == bus address.

As each step is a for() loop and should be considered running on more than 1MB worth of memory, I see significant improvements.

Without supporting huge TLB pages, I only add 700 bytes to the kernel while simply copying get_user_pages() into a function, which takes an vector of struct scatterlist instead of struct page.

This sounds a promising tradeoff for a first time implementation.

Patch attached. No users yet, but they will follow. First candidate is the v4l DMA stuff.

Regards

Ingo Oeser

[1] How much can I safely map on the strange architectures, where this is a limited? AFAIK there is no value or function telling me how far I can go.

Signature · 1 line
Science is what we can tell a computer. Art is everything else. --- D.E.Knuth
kernel/ksyms.c +1 -0
diff -Naur linux-2.5.44/kernel/ksyms.c linux-2.5.44-ioe/kernel/ksyms.c
@@ -136,6 +136,7 @@
 EXPORT_SYMBOL(page_address);
 #endif
 EXPORT_SYMBOL(get_user_pages);
+EXPORT_SYMBOL(get_user_pages_sgl);
 
 /* filesystem internal functions */
 EXPORT_SYMBOL(def_blk_fops);
mm/memory.c +80 -0

92 lines not on this page · raw message

#1 lore raw
Quoted 4 lines · Ingo Oeser

Hi there,

are huge TLB pages always physically continous in memory?

Yes.

Quoted 2 lines

What does follow_hugetlb_page do exactly? I simply don't understand what the code does.

It allows get_user_pages() to work correctly across hugepage regions. It walks a chunk of memory which is covered by hugepages and installs (at *pages) the list of 4k-pages which are covered by the hugepage. So

 |--------------------------------------------------|  <- hugepage
 |--|--|--|--|--|--|--|--|--|--|--|--|--|--|--|--|--|  <- 4k pages

get_user_pages( ^here ^to here)

will install the spanned 4k pages into the caller's pages[] array.

Quoted 7 lines

I would like to build up a simplified get_user_pages_sgl() to build a scatter gather list from user space adresses.

If I want to coalesce physically continous pages (if they are also virtually continious) anyway, can I write up a simplified follow_hugetlb_page_sgl() function which handles the huge page really as only one page?

I suggest that you restructure get_user_pages thusly:

1: Write a simplified get_user_page(). Most callers of get_user_pages()
only want a single page anyway, and don't need to concoct all those arguments.

2: Split get_user_pages up into a pagetable walker and a callback function.
So it walks the pages, calling back to the caller's callback function for each page with

	(*callback)(struct page *page, <other stuff>, void *callerdata);

You'll need to extend follow_hugetlb_page() to take the callback info and to perform the callbacks for its pages as well.

3: Reimplement the current get_user_pages() using the core engine from 2
(ie: write the callback for it)

4: Implement your sg engine using the walker+callback arrangement. This
way, you can do your coalescing on-the-fly, and you only take one pass across the pages list and you do not need to know about hugepages
at all. Sure you'll do a *little* more work than you need to, but
not having that special case is nicer.

5: Fix up the ia64 follow_hugetlb_page too.

#2 lore raw

Now that hugetlbfs is merged, can we remove the hugetlb syscalls? Pretty please? ;-)

What I've heard in the background is that all the Big Users(tm) of hugetlbs greatly prefer the existing syscalls (a.k.a. hugetlbfs) to adding support to new ones in the various userland portability layers in use...

Jeff

author
#3 lore raw

get_user_pages rewrite (was: Huge TLB pages always physically continious?)

In reply to Andrew Morton

Hi Andrew,

Quoted 1 line · Andrew Morton

I suggest that you restructure get_user_pages thusly:

Ok, first step follows.

Quoted 9 lines

1: Write a simplified get_user_page(). Most callers of get_user_pages()
only want a single page anyway, and don't need to concoct all those arguments.

2: Split get_user_pages up into a pagetable walker and a callback function.
So it walks the pages, calling back to the caller's callback function for each page with

Quoted 7 lines
	(*callback)(struct page *page, <other stuff>, void *callerdata);

You'll need to extend follow_hugetlb_page() to take the callback info and to perform the callbacks for its pages as well.

3: Reimplement the current get_user_pages() using the core engine from 2
(ie: write the callback for it)

CONFIG_HUGETLB_PAGES is currently broken by this patch, but will be fixed NOW.

Patch implementing 1-3 of your 5 points is attached.

This also enables get_user_pages() callers to do more cleanup, if things failed, which wasn't ensured before (namely pagecache references where not always released on errors).

The OBSOLETE_PAGE_WALKER define is there to catch callers, which use the vmas-pointer of get_user_pages.

There are 3 kinds of callers in the kernel:

a) Caller needs a VMA and only ONE page of it
-> will be converted to get_one_user_page() and must do
find_extend_vma() itself. Since it needs a vma anyway, it can also look for it, right? ;-)

b) Caller doesn't need VMA, but will take care of pages passed.
-> Will be converted to NEW variant get_user_pages(), which
will not support the "vmas" parameter anymore.

But since we pass the VMA anyway for unlocking the page_table_lock of the MM it belongs to, any user outside of the kernel can use it's own custom_page_walker_t and account them, too.

c) Caller does need neither VMA nor pages
-> is converted to use walk_user_pages()

This caller was mm/memory.c:make_pages_present and is covered by the patch attached already.

My problems are now with the handling of follow_hugetlb_pages().

1) follow_hugetlb_pages() don't need the page_table_lock, but the custom_page_walker_t expects it to be locked and will unlock it on error. But since everything inside follow_hugetlb_pages() is happening quite fast (it cannot sleep), there should be not much contention.

2) It looks benefical to implement follow_one_hugetlb_page(), which doesn't need the page_table_lock and will only look up one small page. But it has to be implemented for every hugetlb_page implemtation.

Is this acceptable, because it covers the common case?

Thanks for your input so far. It has been very helpful.

Patch compiles so far. Testing will be done, after I converted all users and the generic design is ACKed ;-)

Regards

Ingo Oeser

include/linux/mm.h +40 -2
diff -Naur --exclude=.err --exclude=.out --exclude=[.].* linux-2.5.44/include/linux/mm.h linux-2.5.44-ioe/include/linux/mm.h
@@ -370,9 +370,47 @@
 extern int make_pages_present(unsigned long addr, unsigned long end);
 extern int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write);
 
+/*** Page walking API ***/
+
+/* &custom_page_walker - A custom page walk handler for walk_user_pages().
+ * vma:         The vma we walk pages of.
+ * page:        The page we found or an %ERR_PTR() value
+ * virt_addr:   The virtual address we are at while walking.
+ * customdata:  Anything you would like to pass additionally.
+ *
+ * Returns:
+ *      Negative values -> ERRNO values.
+ *      0               -> continue page walking.
+ *      1               -> abort page walking.
+ *
+ * If this functions gets a page, for which %IS_ERR(@page) is true, than it
+ * should do it's cleanup of customdata and return -PTR_ERR(@page).
+ *
+ * This function is called with @vma->vm_mm->page_table_lock held,
+ * if IS_ERR(@vma) is not true.
+ *
+ * But if IS_ERR(@vma) is true, IS_ERR(@page) is also true, since if we have no
+ * vma, then we also have no user space page.
+ *
+ * If it returns a negative value, then the page_table_lock must be dropped
+ * by this function, if it is held.
+ */
+typedef int (*custom_page_walker_t)(struct vm_area_struct *vma, 
+		struct page *page, unsigned long virt_addr, void *customdata);
+
 extern struct page * follow_page(struct mm_struct *mm, unsigned long address, int write);
-int get_user_pages(struct task_struct *tsk, struct mm_struct *mm, unsigned long start,
-		int len, int write, int force, struct page **pages, struct vm_area_struct **vmas);
+
+struct page *get_one_user_page(struct task_struct *tsk, 
+		struct mm_struct *mm, struct vm_area_struct *vma,
+		unsigned long start, int write, int force);
+
+int walk_user_pages(struct task_struct *tsk, struct mm_struct *mm,
+		unsigned long start, int write, int force,
+		custom_page_walker_t walker, void *customdata);
+
+int get_user_pages(struct task_struct *tsk, struct mm_struct *mm, 
+		unsigned long start, int len, int write, int force, 
+		struct page **pages, struct vm_area_struct **vmas);
 
 int __set_page_dirty_buffers(struct page *page);
 int __set_page_dirty_nobuffers(struct page *page);
mm/memory.c +309 -59

420 lines not on this page · raw message