Skip to contentSkip to conversation

: affinity-on-next-touch

RFC PATCH In review Stefan Lankes 1 participant 1 message May 11, 2009

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/4 : affinity-on-next-touch

[Patch 1/4]: Extend the system call madvise with a new parameter MADV_ACCESS_LWP (the same as used in Solaris). The specified memory area then uses "affinity-on-next-touch". In this case, madvise_access_lwp protects the memory area from read and write access. To avoid unnecessary list operations, the patch changes the permissions only in the page table entries and does not update the list of VMAs. Beside this, the system call madvise set also the new "untouched bit" of the "page" record.

include/asm-generic/mman.h |    1 +
include/linux/page-flags.h |    7 +++
mm/madvise.c               |  126
++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 134 insertions(+), 0 deletions(-)
include/asm-generic/mman.h +0 -0
index 5e3dde2..62fdc8c 100644
@@ -29,6 +29,7 @@
 #define MADV_SEQUENTIAL        2               /* expect sequential page

references */

 #define MADV_WILLNEED  3               /* will need these pages */
 #define MADV_DONTNEED  4               /* don't need these pages */

+#define MADV_ACCESS_LWP 5 /* the next LWP will access
these pages at most */

/* common parameters: try to keep these consistent across architectures */
#define MADV_REMOVE 9 /* remove these pages & resources */

include/linux/page-flags.h +4 -0
index 62214c7..e701c5a 100644
@@ -104,6 +104,10 @@ enum pageflags {
 #ifdef CONFIG_IA64_UNCACHED_ALLOCATOR
        PG_uncached,            /* Page has been mapped as uncached */
 #endif
+#ifdef CONFIG_AFFINITY_ON_NEXT_TOUCH
+        PG_untouched,           /* migrate page on next touch */
+#endif
+
        __NR_PAGEFLAGS,
 
        /* Filesystems */
@@ -225,6 +229,9 @@ PAGEFLAG(OwnerPriv1, owner_priv_1)

TESTCLEARFLAG(OwnerPriv1, owner_priv_1)
*/
TESTPAGEFLAG(Writeback, writeback) TESTSCFLAG(Writeback, writeback) __PAGEFLAG(Buddy, buddy)
+#ifdef CONFIG_AFFINITY_ON_NEXT_TOUCH +PAGEFLAG(Untouched, untouched) TESTCLEARFLAG(Untouched, untouched) +#endif
PAGEFLAG(MappedToDisk, mappedtodisk)

/* PG_readahead is only used for file reads; PG_reclaim is only for writes
*/

mm/madvise.c +79 -0

94 lines not on this page · raw message

irrelevant.
+ * Therefore, on such architectures we doesn't change the access permissions.
+ */
+static long madvise_access_lwp(struct vm_area_struct *vma,
+ unsigned long start, unsigned long end)
+{

+       struct mm_struct * mm = vma->vm_mm;
+       pgd_t *pgd;
+       pgprot_t newprot;
+       unsigned long addr, next;

+
+ /* On UMA architectures is no page migration necessary. */
+ if (num_online_nodes() == 1)
+ return 0;
+
+ if (!vma_migratable(vma))
+ return -EINVAL;
+
+ newprot = protection_map[PROT_NONE &
+ (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)];
+

+       mmu_notifier_invalidate_range_start(mm, start, end);
+       addr = start;
+       pgd = pgd_offset(mm, start);
+       flush_cache_range(vma, start, end);
+       do {

+ next = pgd_addr_end(addr, end);
+ if (pgd_none_or_clear_bad(pgd))
+ continue;
+ change_pud_range(vma, mm, pgd, addr, next, newprot);

+       } while (pgd++, addr = next, addr != end);
+       flush_tlb_range(vma, start, end);
+       mmu_notifier_invalidate_range_end(mm, start, end);

+
+ lru_add_drain();
+
+ return 0;
+}
+#endif
+
static long
madvise_vma(struct vm_area_struct *vma, struct vm_area_struct **prev,
unsigned long start, unsigned long end, int behavior)
@@ -246,6 +364,12 @@ madvise_vma(struct vm_area_struct *vma, struct vm_area_struct **prev,

                error = madvise_dontneed(vma, prev, start, end);
                break;

+#ifdef CONFIG_AFFINITY_ON_NEXT_TOUCH
+ case MADV_ACCESS_LWP:
+ error = madvise_access_lwp(vma, start, end);
+ break;
+#endif
+

        default:
                error = -EINVAL;
                break;

@@ -277,6 +401,8 @@ madvise_vma(struct vm_area_struct *vma, struct vm_area_struct **prev,
* so the kernel can free resources associated with it.
* MADV_REMOVE - the application wants to free up the given range of
* pages and associated backing store.
+ * MADV_ACCESS_LWP - the next LWP, which touch the specified address
+ * range, will access it heavily
*
* return values:
* zero - success