__vmalloc allocates spurious page?

__vmalloc allocates spurious page?

Post by Marcus Alane » Wed, 16 Oct 2002 21:40:09



Hi,

I think __vmalloc allocates an unnecessary page. While the virtual
address space should have a one-page hole in it, that is taken care of
by get_vm_area. All other routines (particularly map_vm_area)
subtract PAGE_SIZE from area->size before usage, so the last page
table entry isn't even set up.

The unnecessary page is allocated only if size is initially a multiple
of PAGE_SIZE, which sounds like a common case.

Marcus

diff -Naurd --exclude-from=/home/maalanen/linux/base/diff_exclude linus-2.5.42/mm/vmalloc.c msa-2.5.42/mm/vmalloc.c
--- linus-2.5.42/mm/vmalloc.c   Sat Oct 12 16:42:57 2002

        if (!area)
                return NULL;

-       nr_pages = (size+PAGE_SIZE) >> PAGE_SHIFT;
+       nr_pages = (size+PAGE_SIZE-1) >> PAGE_SHIFT;
        array_size = (nr_pages * sizeof(struct page *));

        area->nr_pages = nr_pages;

--
Marcus Alanen                       * Software Construction Laboratory *

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in

More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

 
 
 

__vmalloc allocates spurious page?

Post by Marcus Alane » Thu, 17 Oct 2002 00:00:20


Quote:>The unnecessary page is allocated only if size is initially a multiple
>of PAGE_SIZE, which sounds like a common case.

Actually, size is already PAGE_ALIGNed, so we get the amount of pages
even easier.

Marcus

diff -Naurd --exclude-from=/home/maalanen/linux/base/diff_exclude linus-2.5.42/mm/vmalloc.c msa-2.5.42/mm/vmalloc.c
--- linus-2.5.42/mm/vmalloc.c   Sat Oct 12 16:42:57 2002

        if (!area)
                return NULL;

-       nr_pages = (size+PAGE_SIZE) >> PAGE_SHIFT;
+       nr_pages = size >> PAGE_SHIFT;
        array_size = (nr_pages * sizeof(struct page *));

        area->nr_pages = nr_pages;

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in

More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

 
 
 

__vmalloc allocates spurious page?

Post by Russell Kin » Thu, 17 Oct 2002 00:20:06



> >The unnecessary page is allocated only if size is initially a multiple
> >of PAGE_SIZE, which sounds like a common case.

> Actually, size is already PAGE_ALIGNed, so we get the amount of pages
> even easier.

IIRC, back in the dim and distant past, the extra page was originally to
catch things running off the end of their space (eg, modules).  The
idea was that modules (and other vmalloc'd areas) would be separated
by one unmapped page.

It looks like this got broken recently though.

--

             http://www.arm.linux.org.uk/personal/aboutme.html

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in

More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

 
 
 

__vmalloc allocates spurious page?

Post by William Lee Irwin II » Thu, 17 Oct 2002 00:20:11



>> Actually, size is already PAGE_ALIGNed, so we get the amount of pages
>> even easier.

> IIRC, back in the dim and distant past, the extra page was originally to
> catch things running off the end of their space (eg, modules).  The
> idea was that modules (and other vmalloc'd areas) would be separated
> by one unmapped page.
> It looks like this got broken recently though.

Hmm? I looked briefly to check the patch and the guard page was added
onto the thing elsewhere in vmalloc.c

Bill
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in

More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

 
 
 

__vmalloc allocates spurious page?

Post by Andrew Morto » Thu, 17 Oct 2002 00:40:08




> > >The unnecessary page is allocated only if size is initially a multiple
> > >of PAGE_SIZE, which sounds like a common case.

> > Actually, size is already PAGE_ALIGNed, so we get the amount of pages
> > even easier.

> IIRC, back in the dim and distant past, the extra page was originally to
> catch things running off the end of their space (eg, modules).  The
> idea was that modules (and other vmalloc'd areas) would be separated
> by one unmapped page.

> It looks like this got broken recently though.

Still there I think.

struct vm_struct *get_vm_area(unsigned long size, unsigned long flags)
{
        ...

        /*
         * We always allocate a guard page.
         */
        size += PAGE_SIZE;

Marcus's patch looks reasonable.
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in

More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

 
 
 

1. [2.4] update ref counts on all allocated pages

The following patch sets the ref count on all pages of an
allocation.  This allows an allocation with order>0 to be freed
via individual __free_page() calls within vfree().

This is important on non cache coherent processors which
have a pci_alloc_consistent/consistent_alloc() implementation
that involves creating a vmalloc area cache inhibited mapping
of allocated pages.

Because of this implementation, the implementation
of pci_free_consistent/consistent_free is done via
a vfree().  Without this patch only the first page
of the allocated memory is freed since successive pages
all have ref counts of zero.

-Matt

===== mm/page_alloc.c 1.56 vs edited =====
--- 1.56/mm/page_alloc.c        Tue Aug 20 04:39:48 2002

        struct list_head *head, *curr;
        unsigned long flags;
        struct page *page;
+       int i;

        spin_lock_irqsave(&zone->lock, flags);

                        page = expand(zone, page, index, order, curr_order, area);
                        spin_unlock_irqrestore(&zone->lock, flags);

-                       set_page_count(page, 1);
+                       /* Set ref count on all pages */
+                       for (i = 0; i < (1 << order); i++)
+                               set_page_count(page+i, 1);
+
                        if (BAD_RANGE(zone,page))
                                BUG();
                        if (PageLRU(page))

--
Matt Porter

This is Linux Country. On a quiet night, you can hear Windows reboot.
--
Matt Porter

This is Linux Country. On a quiet night, you can hear Windows reboot.
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in

More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

2. Help on partitioning disks

3. cannot allocate free page

4. building sendmail on Solaris 2.4

5. Arch option to touch newly allocated pages

6. US-IL-CHI Linux/Unix Systems Administrator/Programmer

7. avoid allocating pte_chains for unshared pages

8. Pls help: SCSI problem

9. Allocating memory for multiple pages

10. allocating 4MB page from kernel

11. howto allocate page aligned memory segments?

12. Aix 4.3 what is the proper paging space to allocate?

13. growreg - Insufficient memory to allocate 106274 pages