Skip to contentSkip to conversation

Fragmentation Avoidance V16

PATCH In review Mel Gorman 4 participants 27 messages Oct 5, 2005 – Oct 6, 2005

Subsystems (11)
lore
Share & tools
lore

Mel Gorman

author
#0 lore raw

cover Fragmentation Avoidance V16

Changelog since V14 (V15 not released)
o Update against 2.6.14-rc3
o Resync with Joel's work. All suggestions made on fix-ups to his last set of patches should also be in here. e.g. __GFP_USER is still __GFP_USER but is better commented.
o Large amount of CodingStyle, readability cleanups and corrections pointed out by Dave Hansen.
o Fix CONFIG_NUMA error that corrupted per-cpu lists
o Patches broken out to have one-feature-per-patch rather than more-code-per-patch
o Fix fallback bug where pages for RCLM_NORCLM end up on random other free lists.

Changelog since V13
o Patches are now broken out
o Added per-cpu draining of userrclm pages
o Brought the patch more in line with memory hotplug work
o Fine-grained use of the __GFP_USER and __GFP_KERNRCLM flags
o Many coding-style corrections
o Many whitespace-damage corrections

Changelog since V12
o Minor whitespace damage fixed as pointed by Joel Schopp

Changelog since V11
o Mainly a redefiff against 2.6.12-rc5
o Use #defines for indexing into pcpu lists
o Fix rounding error in the size of usemap

Changelog since V10
o All allocation types now use per-cpu caches like the standard allocator
o Removed all the additional buddy allocator statistic code
o Elimated three zone fields that can be lived without
o Simplified some loops
o Removed many unnecessary calculations

Changelog since V9
o Tightened what pools are used for fallbacks, less likely to fragment
o Many micro-optimisations to have the same performance as the standard allocator. Modified allocator now faster than standard allocator using gcc 3.3.5
o Add counter for splits/coalescing

Changelog since V8
o rmqueue_bulk() allocates pages in large blocks and breaks it up into the requested size. Reduces the number of calls to __rmqueue()
o Beancounters are now a configurable option under "Kernel Hacking"
o Broke out some code into inline functions to be more Hotplug-friendly
o Increased the size of reserve for fallbacks from 10% to 12.5%.

Changelog since V7
o Updated to 2.6.11-rc4
o Lots of cleanups, mainly related to beancounters
o Fixed up a miscalculation in the bitmap size as pointed out by Mike Kravetz (thanks Mike)
o Introduced a 10% reserve for fallbacks. Drastically reduces the number of kernnorclm allocations that go to the wrong places
o Don't trigger OOM when large allocations are involved

Changelog since V6
o Updated to 2.6.11-rc2
o Minor change to allow prezeroing to be a cleaner looking patch

Changelog since V5
o Fixed up gcc-2.95 errors
o Fixed up whitespace damage

Changelog since V4
o No changes. Applies cleanly against 2.6.11-rc1 and 2.6.11-rc1-bk6. Applies with offsets to 2.6.11-rc1-mm1

Changelog since V3
o inlined get_pageblock_type() and set_pageblock_type()
o set_pageblock_type() now takes a zone parameter to avoid a call to page_zone()
o When taking from the global pool, do not scan all the low-order lists

Changelog since V2
o Do not to interfere with the "min" decay
o Update the __GFP_BITS_SHIFT properly. Old value broke fsync and probably anything to do with asynchronous IO

Changelog since V1
o Update patch to 2.6.11-rc1
o Cleaned up bug where memory was wasted on a large bitmap
o Remove code that needed the binary buddy bitmaps
o Update flags to avoid colliding with __GFP_ZERO changes
o Extended fallback_count bean counters to show the fallback count for each allocation type
o In-code documentation

Version 1
o Initial release against 2.6.9

This patch is designed to reduce fragmentation in the standard buddy allocator without impairing the performance of the allocator. High fragmentation in the standard binary buddy allocator means that high-order allocations can rarely be serviced. This patch works by dividing allocations into three different types of allocations;

UserReclaimable - These are userspace pages that are easily reclaimable. This
flag is set when it is known that the pages will be trivially reclaimed by writing the page out to swap or syncing with backing storage

KernelReclaimable - These are pages allocated by the kernel that are easily
reclaimed. This is stuff like inode caches, dcache, buffer_heads etc. These type of pages potentially could be reclaimed by dumping the caches and reaping the slabs

KernelNonReclaimable - These are pages that are allocated by the kernel that
are not trivially reclaimed. For example, the memory allocated for a loaded module would be in this category. By default, allocations are considered to be of this type

Instead of having one global MAX_ORDER-sized array of free lists, there are four, one for each type of allocation and another reserve for fallbacks.

Once a 2^MAX_ORDER block of pages it split for a type of allocation, it is added to the free-lists for that type, in effect reserving it. Hence, over time, pages of the different types can be clustered together. This means that if 2^MAX_ORDER number of pages were required, the system could linearly scan a block of pages allocated for UserReclaimable and page each of them out.

Fallback is used when there are no 2^MAX_ORDER pages available and there are no free pages of the desired type. The fallback lists were chosen in a way that keeps the most easily reclaimable pages together.

Three benchmark results are included all based on a 2.6.14-rc3 kernel compiled with gcc 3.4 (it is known that gcc 2.95 produces different results). The first is the output of portions of AIM9 for the vanilla allocator and the modified one;

(Tests run with bench-aim9.sh from VMRegress 0.14) 2.6.14-rc3
------------------------------------------------------------------------------------------------------------
Test Test Elapsed Iteration Iteration Operation
Number Name Time (sec) Count Rate (loops/sec) Rate (ops/sec)
------------------------------------------------------------------------------------------------------------

     1 creat-clo           60.04        963   16.03931        16039.31 File Creations and Closes/second
     2 page_test           60.01       4194   69.88835       118810.20 System Allocations & Pages/second
     3 brk_test            60.03       1573   26.20356       445460.60 System Memory Allocations/second
     4 jmp_test            60.01     251144 4185.03583      4185035.83 Non-local gotos/second
     5 signal_test         60.02       5118   85.27158        85271.58 Signal Traps/second
     6 exec_test           60.03        758   12.62702           63.14 Program Loads/second
     7 fork_test           60.03        820   13.65984         1365.98 Task Creations/second
     8 link_test           60.02       5326   88.73709         5590.44 Link/Unlink Pairs/second

2.6.14-rc3-mbuddy-v16
------------------------------------------------------------------------------------------------------------
Test Test Elapsed Iteration Iteration Operation
Number Name Time (sec) Count Rate (loops/sec) Rate (ops/sec)
------------------------------------------------------------------------------------------------------------

     1 creat-clo           60.06        959   15.96737        15967.37 File Creations and Closes/second
     2 page_test           60.02       4067   67.76075       115193.27 System Allocations & Pages/second
     3 brk_test            60.01       1578   26.29562       447025.50 System Memory Allocations/second
     4 jmp_test            60.01     251498 4190.93484      4190934.84 Non-local gotos/second
     5 signal_test         60.01       5127   85.43576        85435.76 Signal Traps/second
     6 exec_test           60.03        753   12.54373           62.72 Program Loads/second
     7 fork_test           60.02        802   13.36221         1336.22 Task Creations/second
     8 link_test           60.01       5307   88.43526         5571.42 Link/Unlink Pairs/second

Difference in performance operations report generated by diff-aim9.sh

                   Clean   mbuddy-v16
                ---------- ----------
 1 creat-clo      16039.31   15967.37     -71.94 -0.45% File Creations and Closes/second
 2 page_test     118810.20  115193.27   -3616.93 -3.04% System Allocations & Pages/second
 3 brk_test      445460.60  447025.50    1564.90  0.35% System Memory Allocations/second
 4 jmp_test     4185035.83 4190934.84    5899.01  0.14% Non-local gotos/second
 5 signal_test    85271.58   85435.76     164.18  0.19% Signal Traps/second
 6 exec_test         63.14      62.72      -0.42 -0.67% Program Loads/second
 7 fork_test       1365.98    1336.22     -29.76 -2.18% Task Creations/second
 8 link_test       5590.44    5571.42     -19.02 -0.34% Link/Unlink Pairs/second

In this test, there were regressions in the page_test. However, it is known that different kernel configurations, compilers and even different runs show similar varianes of +/- 3% . I do not consider it significant.

The second benchmark tested the CPU cache usage to make sure it was not getting clobbered. The test was to repeatedly render a large postscript file 10 times and get the average. The result is;

2.6.13-clean: Average: 42.725 real, 42.626 user, 0.041 sys
2.6.13-mbuddy-v14: Average: 42.793 real, 42.695 user, 0.034 sys

So there are no adverse cache effects. The last test is to show that the allocator can satisfy more high-order allocations, especially under load, than the standard allocator. The test performs the following;

1. Start updatedb running in the background
2. Load kernel modules that tries to allocate high-order blocks on demand
3. Clean a kernel tree
4. Make 4 copies of the tree. As each copy finishes, a compile starts at -j4
5. Start compiling the primary tree
6. Sleep 3 minutes while the 5 trees are being compiled
7. Use the kernel module to attempt 160 times to allocate a 2^10 block of pages
- note, it only attempts 160 times, no matter how often it succeeds
- An allocation is attempted every 1/10th of a second
- Performance will get badly shot as it forces consider amounts of pageout

The result of the allocations under load (load averaging 18) were;

2.6.14-rc3 Clean

Order:                 10
Allocation type:       HighMem
Attempted allocations: 160
Success allocs:        46
Failed allocs:         114
DMA zone allocs:       1
Normal zone allocs:    32
HighMem zone allocs:   13

% Success: 28

2.6.14-rc3 MBuddy V14

Order:                 10
Allocation type:       HighMem
Attempted allocations: 160
Success allocs:        97
Failed allocs:         63
DMA zone allocs:       1
Normal zone allocs:    89
HighMem zone allocs:   7

% Success: 60

One thing that had to be changed in the 2.6.14-rc3-clean test was to disable the OOM killer. During one test, the OOM killer had better results but invoked the OOM killer 457 times to achieve it. The patch with the placement policy never invoked the OOM killer.

When the system is at rest after the test and the kernel trees deleted, the standard allocator was able to allocate 54 order-10 pages and the modified allocator allocated 159.

The results show that the modified allocator has comparable speed has no adverse cache effects but is far less fragmented and able to satisfy high-order allocations.

Signature · 9 lines
Mel Gorman
Part-time Phd Student                          Java Applications Developer
University of Limerick                         IBM Dublin Software Lab

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
author
#1 lore raw

PATCH 1/7 Fragmentation Avoidance V16: 001_antidefrag_flags

This patch adds two flags __GFP_USER and __GFP_KERNRCLM that are used to trap the type of allocation the caller is made. Allocations using the __GFP_USER flag are expected to be easily reclaimed by syncing with backing storage (be it a file or swap) or cleaning the buffers and discarding. Allocations using the __GFP_KERNRCLM flag belong to slab caches that can be shrunk by the kernel.

fs/buffer.c +8 -2
diff -rup -X /usr/src/patchset-0.5/bin//dontdiff linux-2.6.14-rc3-clean/fs/buffer.c linux-2.6.14-rc3-001_antidefrag_flags/fs/buffer.c
@@ -1119,7 +1119,12 @@ grow_dev_page(struct block_device *bdev,
 	struct page *page;
 	struct buffer_head *bh;
 
-	page = find_or_create_page(inode->i_mapping, index, GFP_NOFS);
+	/*
+	 * Mark as __GFP_USER because from a fragmentation avoidance and
+	 * reclamation point of view this memory behaves like user memory.
+	 */
+	page = find_or_create_page(inode->i_mapping, index,
+				   GFP_NOFS | __GFP_USER);
 	if (!page)
 		return NULL;
 
@@ -3047,7 +3052,8 @@ static void recalc_bh_state(void)
 	
 struct buffer_head *alloc_buffer_head(unsigned int __nocast gfp_flags)
 {
-	struct buffer_head *ret = kmem_cache_alloc(bh_cachep, gfp_flags);
+	struct buffer_head *ret = kmem_cache_alloc(bh_cachep,
+						   gfp_flags|__GFP_KERNRCLM);
 	if (ret) {
 		get_cpu_var(bh_accounting).nr++;
 		recalc_bh_state();
fs/compat.c +1 -1
diff -rup -X /usr/src/patchset-0.5/bin//dontdiff linux-2.6.14-rc3-clean/fs/compat.c linux-2.6.14-rc3-001_antidefrag_flags/fs/compat.c
@@ -1352,7 +1352,7 @@ static int compat_copy_strings(int argc,
 			page = bprm->page[i];
 			new = 0;
 			if (!page) {
-				page = alloc_page(GFP_HIGHUSER);
+				page = alloc_page(GFP_HIGHUSER|__GFP_USER);
 				bprm->page[i] = page;
 				if (!page) {
 					ret = -ENOMEM;
fs/dcache.c +1 -1
diff -rup -X /usr/src/patchset-0.5/bin//dontdiff linux-2.6.14-rc3-clean/fs/dcache.c linux-2.6.14-rc3-001_antidefrag_flags/fs/dcache.c
@@ -714,7 +714,7 @@ struct dentry *d_alloc(struct dentry * p
 	struct dentry *dentry;
 	char *dname;
 
-	dentry = kmem_cache_alloc(dentry_cache, GFP_KERNEL); 
+	dentry = kmem_cache_alloc(dentry_cache, GFP_KERNEL|__GFP_KERNRCLM);
 	if (!dentry)
 		return NULL;
 
fs/exec.c +1 -1
diff -rup -X /usr/src/patchset-0.5/bin//dontdiff linux-2.6.14-rc3-clean/fs/exec.c linux-2.6.14-rc3-001_antidefrag_flags/fs/exec.c
@@ -237,7 +237,7 @@ static int copy_strings(int argc, char _
 			page = bprm->page[i];
 			new = 0;
 			if (!page) {
-				page = alloc_page(GFP_HIGHUSER);
+				page = alloc_page(GFP_HIGHUSER|__GFP_USER);
 				bprm->page[i] = page;
 				if (!page) {
 					ret = -ENOMEM;
fs/ext2/super.c +2 -1
diff -rup -X /usr/src/patchset-0.5/bin//dontdiff linux-2.6.14-rc3-clean/fs/ext2/super.c linux-2.6.14-rc3-001_antidefrag_flags/fs/ext2/super.c
@@ -141,7 +141,8 @@ static kmem_cache_t * ext2_inode_cachep;
 static struct inode *ext2_alloc_inode(struct super_block *sb)
 {
 	struct ext2_inode_info *ei;
-	ei = (struct ext2_inode_info *)kmem_cache_alloc(ext2_inode_cachep, SLAB_KERNEL);
+	ei = (struct ext2_inode_info *)kmem_cache_alloc(ext2_inode_cachep,
+						SLAB_KERNEL|__GFP_KERNRCLM);
 	if (!ei)
 		return NULL;
 #ifdef CONFIG_EXT2_FS_POSIX_ACL
fs/ext3/super.c +1 -1
diff -rup -X /usr/src/patchset-0.5/bin//dontdiff linux-2.6.14-rc3-clean/fs/ext3/super.c linux-2.6.14-rc3-001_antidefrag_flags/fs/ext3/super.c
@@ -441,7 +441,7 @@ static struct inode *ext3_alloc_inode(st
 {
 	struct ext3_inode_info *ei;
 
-	ei = kmem_cache_alloc(ext3_inode_cachep, SLAB_NOFS);
+	ei = kmem_cache_alloc(ext3_inode_cachep, SLAB_NOFS|__GFP_KERNRCLM);
 	if (!ei)
 		return NULL;
 #ifdef CONFIG_EXT3_FS_POSIX_ACL
fs/inode.c +1 -1
diff -rup -X /usr/src/patchset-0.5/bin//dontdiff linux-2.6.14-rc3-clean/fs/inode.c linux-2.6.14-rc3-001_antidefrag_flags/fs/inode.c
@@ -146,7 +146,7 @@ static struct inode *alloc_inode(struct 
 		mapping->a_ops = &empty_aops;
  		mapping->host = inode;
 		mapping->flags = 0;
-		mapping_set_gfp_mask(mapping, GFP_HIGHUSER);
+		mapping_set_gfp_mask(mapping, GFP_HIGHUSER|__GFP_USER);
 		mapping->assoc_mapping = NULL;
 		mapping->backing_dev_info = &default_backing_dev_info;
 
fs/ntfs/inode.c +2 -2
diff -rup -X /usr/src/patchset-0.5/bin//dontdiff linux-2.6.14-rc3-clean/fs/ntfs/inode.c linux-2.6.14-rc3-001_antidefrag_flags/fs/ntfs/inode.c
@@ -317,7 +317,7 @@ struct inode *ntfs_alloc_big_inode(struc
 	ntfs_inode *ni;
 
 	ntfs_debug("Entering.");
-	ni = kmem_cache_alloc(ntfs_big_inode_cache, SLAB_NOFS);
+	ni = kmem_cache_alloc(ntfs_big_inode_cache, SLAB_NOFS|__GFP_KERNRCLM);
 	if (likely(ni != NULL)) {
 		ni->state = 0;
 		return VFS_I(ni);
@@ -342,7 +342,7 @@ static inline ntfs_inode *ntfs_alloc_ext
 	ntfs_inode *ni;
 
 	ntfs_debug("Entering.");
-	ni = kmem_cache_alloc(ntfs_inode_cache, SLAB_NOFS);
+	ni = kmem_cache_alloc(ntfs_inode_cache, SLAB_NOFS|__GFP_KERNRCLM);
 	if (likely(ni != NULL)) {
 		ni->state = 0;
 		return ni;
include/asm-i386/page.h +1 -1
diff -rup -X /usr/src/patchset-0.5/bin//dontdiff linux-2.6.14-rc3-clean/include/asm-i386/page.h linux-2.6.14-rc3-001_antidefrag_flags/include/asm-i386/page.h
@@ -36,7 +36,7 @@
 #define clear_user_page(page, vaddr, pg)	clear_page(page)
 #define copy_user_page(to, from, vaddr, pg)	copy_page(to, from)
 
-#define alloc_zeroed_user_highpage(vma, vaddr) alloc_page_vma(GFP_HIGHUSER | __GFP_ZERO, vma, vaddr)
+#define alloc_zeroed_user_highpage(vma, vaddr) alloc_page_vma(GFP_HIGHUSER | __GFP_ZERO | __GFP_USER, vma, vaddr)
 #define __HAVE_ARCH_ALLOC_ZEROED_USER_HIGHPAGE
 
 /*
include/linux/gfp.h +8 -2
diff -rup -X /usr/src/patchset-0.5/bin//dontdiff linux-2.6.14-rc3-clean/include/linux/gfp.h linux-2.6.14-rc3-001_antidefrag_flags/include/linux/gfp.h
@@ -42,14 +42,20 @@ struct vm_area_struct;
 #define __GFP_NORECLAIM  0x20000u /* No realy zone reclaim during allocation */
 #define __GFP_HARDWALL   0x40000u /* Enforce hardwall cpuset memory allocs */
 
-#define __GFP_BITS_SHIFT 20	/* Room for 20 __GFP_FOO bits */
+/* Allocation type modifiers, group together if possible */
+#define __GFP_USER       0x80000u  /* User and other easily reclaimed pages */
+#define __GFP_KERNRCLM   0x100000u /* Kernel page that is reclaimable */
+#define __GFP_RCLM_BITS  (__GFP_USER|__GFP_KERNRCLM)
+
+#define __GFP_BITS_SHIFT 21	/* Room for 21 __GFP_FOO bits */
 #define __GFP_BITS_MASK ((1 << __GFP_BITS_SHIFT) - 1)
 
 /* if you forget to add the bitmask here kernel will crash, period */
 #define GFP_LEVEL_MASK (__GFP_WAIT|__GFP_HIGH|__GFP_IO|__GFP_FS| \
 			__GFP_COLD|__GFP_NOWARN|__GFP_REPEAT| \
 			__GFP_NOFAIL|__GFP_NORETRY|__GFP_NO_GROW|__GFP_COMP| \
-			__GFP_NOMEMALLOC|__GFP_NORECLAIM|__GFP_HARDWALL)
+			__GFP_NOMEMALLOC|__GFP_NORECLAIM|__GFP_HARDWALL | \
+			__GFP_USER | __GFP_KERNRCLM)
 
 #define GFP_ATOMIC	(__GFP_HIGH)
 #define GFP_NOIO	(__GFP_WAIT)
include/linux/highmem.h +1 -1
diff -rup -X /usr/src/patchset-0.5/bin//dontdiff linux-2.6.14-rc3-clean/include/linux/highmem.h linux-2.6.14-rc3-001_antidefrag_flags/include/linux/highmem.h
@@ -47,7 +47,7 @@ static inline void clear_user_highpage(s
 static inline struct page *
 alloc_zeroed_user_highpage(struct vm_area_struct *vma, unsigned long vaddr)
 {
-	struct page *page = alloc_page_vma(GFP_HIGHUSER, vma, vaddr);
+	struct page *page = alloc_page_vma(GFP_HIGHUSER|__GFP_USER, vma, vaddr);
 
 	if (page)
 		clear_user_highpage(page, vaddr);
mm/memory.c +3 -2
diff -rup -X /usr/src/patchset-0.5/bin//dontdiff linux-2.6.14-rc3-clean/mm/memory.c linux-2.6.14-rc3-001_antidefrag_flags/mm/memory.c
@@ -1296,7 +1296,8 @@ static int do_wp_page(struct mm_struct *
 		if (!new_page)
 			goto no_new_page;
 	} else {
-		new_page = alloc_page_vma(GFP_HIGHUSER, vma, address);
+		new_page = alloc_page_vma(GFP_HIGHUSER|__GFP_USER,
+							vma, address);
 		if (!new_page)
 			goto no_new_page;
 		copy_user_highpage(new_page, old_page, address);
@@ -1871,7 +1872,7 @@ retry:
 
 		if (unlikely(anon_vma_prepare(vma)))
 			goto oom;
-		page = alloc_page_vma(GFP_HIGHUSER, vma, address);
+		page = alloc_page_vma(GFP_HIGHUSER | __GFP_USER, vma, address);
 		if (!page)
 			goto oom;
 		copy_user_highpage(page, new_page, address);
mm/shmem.c +2 -2
diff -rup -X /usr/src/patchset-0.5/bin//dontdiff linux-2.6.14-rc3-clean/mm/shmem.c linux-2.6.14-rc3-001_antidefrag_flags/mm/shmem.c
@@ -908,7 +908,7 @@ shmem_alloc_page(unsigned long gfp, stru
 	pvma.vm_policy = mpol_shared_policy_lookup(&info->policy, idx);
 	pvma.vm_pgoff = idx;
 	pvma.vm_end = PAGE_SIZE;
-	page = alloc_page_vma(gfp | __GFP_ZERO, &pvma, 0);
+	page = alloc_page_vma(gfp | __GFP_ZERO | __GFP_USER, &pvma, 0);
 	mpol_free(pvma.vm_policy);
 	return page;
 }
@@ -924,7 +924,7 @@ static inline struct page *
 shmem_alloc_page(unsigned int __nocast gfp,struct shmem_inode_info *info,
 				 unsigned long idx)
 {
-	return alloc_page(gfp | __GFP_ZERO);
+	return alloc_page(gfp | __GFP_ZERO | __GFP_USER);
 }
 #endif
 
mm/swap_state.c +2 -1
diff -rup -X /usr/src/patchset-0.5/bin//dontdiff linux-2.6.14-rc3-clean/mm/swap_state.c linux-2.6.14-rc3-001_antidefrag_flags/mm/swap_state.c
@@ -335,7 +335,8 @@ struct page *read_swap_cache_async(swp_e
 		 * Get a new page to read into from swap.
 		 */
 		if (!new_page) {
-			new_page = alloc_page_vma(GFP_HIGHUSER, vma, addr);
+			new_page = alloc_page_vma(GFP_HIGHUSER | __GFP_USER,
+							vma, addr);
 			if (!new_page)
 				break;		/* Out of memory */
 		}

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

author
#4 lore raw

PATCH 2/7 Fragmentation Avoidance V16: 002_usemap

In reply to Mel Gorman

This patch adds a "usemap" to the allocator. When a PAGE_PER_MAXORDER block of pages (i.e. 2^(MAX_ORDER-1)) is split, the usemap is updated with the type of allocation when splitting. This information is used in an anti-fragmentation patch to group related allocation types together.

The __GFP_USER and __GFP_KERNRCLM bits are used to enumerate three allocation types;

RCLM_NORLM: These are kernel allocations that cannot be reclaimed
on demand.
RCLM_USER: These are pages allocated with __GFP_USER flag set. They are
considered to be user and other easily reclaimed pages such as buffers
RCLM_KERN: Allocated for the kernel but for caches that can be reclaimed
on demand.

gfpflags_to_rclmtype() converts gfp_flags to their corresponding RCLM_TYPE by masking out irrelevant bits and shifting the result right by RCLM_SHIFT. Compile-time checks are made on RCLM_SHIFT to ensure gfpflags_to_rclmtype() keeps working. ffz() could be used to avoid static checks, but it would be runtime overhead for a compile-time constant.

include/linux/mm.h +7 -0
diff -rup -X /usr/src/patchset-0.5/bin//dontdiff linux-2.6.14-rc3-001_antidefrag_flags/include/linux/mm.h linux-2.6.14-rc3-002_usemap/include/linux/mm.h
@@ -522,6 +522,13 @@ static inline void set_page_links(struct
 extern struct page *mem_map;
 #endif
 
+/*
+ * Return what type of page is being allocated from this 2^MAX_ORDER-1 block
+ * of pages.
+ */
+extern unsigned int get_pageblock_type(struct zone *zone,
+						struct page *page);
+
 static inline void *lowmem_page_address(struct page *page)
 {
 	return __va(page_to_pfn(page) << PAGE_SHIFT);
include/linux/mmzone.h +49 -0

85 lines not on this page · raw message

mm/page_alloc.c +133 -6

199 lines not on this page · raw message

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

author
#7 lore raw

PATCH 3/7 Fragmentation Avoidance V16: 003_fragcore

In reply to Mel Gorman

This patch adds the core of the anti-fragmentation strategy. It works by grouping related allocation types together. The idea is that large groups of pages that may be reclaimed are placed near each other. The zone->free_area list is broken into three free lists for each RCLM_TYPE.

include/linux/mmzone.h +2 -1
diff -rup -X /usr/src/patchset-0.5/bin//dontdiff linux-2.6.14-rc3-002_usemap/include/linux/mmzone.h linux-2.6.14-rc3-003_fragcore/include/linux/mmzone.h
@@ -148,7 +148,6 @@ struct zone {
 	 * free areas of different sizes
 	 */
 	spinlock_t		lock;
-	struct free_area	free_area[MAX_ORDER];
 
 #ifndef CONFIG_SPARSEMEM
 	/*
@@ -158,6 +157,8 @@ struct zone {
 	unsigned long		*free_area_usemap;
 #endif
 
+	struct free_area	free_area_lists[RCLM_TYPES][MAX_ORDER];
+
 	ZONE_PADDING(_pad1_)
 
 	/* Fields commonly accessed by the page reclaim scanner */
mm/page_alloc.c +111 -37

273 lines not on this page · raw message

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

author
#14 lore raw

PATCH 4/7 Fragmentation Avoidance V16: 004_largealloc_tryharder

In reply to Mel Gorman

Fragmentation avoidance patches increase our chances of satisfying high order allocations. So this patch takes more than one iteration at trying to fulfill those allocations because, unlike before, the extra iterations are often useful.

mm/page_alloc.c +13 -1
diff -rup -X /usr/src/patchset-0.5/bin//dontdiff linux-2.6.14-rc3-003_fragcore/mm/page_alloc.c linux-2.6.14-rc3-004_largealloc_tryharder/mm/page_alloc.c
@@ -939,6 +939,7 @@ __alloc_pages(unsigned int __nocast gfp_
 	int do_retry;
 	int can_try_harder;
 	int did_some_progress;
+	int highorder_retry = 3;
 
 	might_sleep_if(wait);
 
@@ -1087,7 +1088,16 @@ rebalance:
 				goto got_pg;
 		}
 
-		out_of_memory(gfp_mask, order);
+		if (order < MAX_ORDER/2)
+			out_of_memory(gfp_mask, order);
+
+		/*
+		 * Due to low fragmentation efforts, we should try a little
+		 * harder to satisfy high order allocations
+		 */
+		if (order >= MAX_ORDER/2 && --highorder_retry > 0)
+			goto rebalance;
+
 		goto restart;
 	}
 
@@ -1104,6 +1114,8 @@ rebalance:
 			do_retry = 1;
 		if (gfp_mask & __GFP_NOFAIL)
 			do_retry = 1;
+		if (order >= MAX_ORDER/2 && --highorder_retry > 0)
+			do_retry = 1;
 	}
 	if (do_retry) {
 		blk_congestion_wait(WRITE, HZ/50);

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

author
#15 lore raw

PATCH 5/7 Fragmentation Avoidance V16: 005_fallback

In reply to Mel Gorman

This patch implements fallback logic. In the event there is no 2^(MAX_ORDER-1) blocks of pages left, this will help the system decide what list to use. The highlights of the patch are;

o Define a RCLM_FALLBACK type for fallbacks
o Use a percentage of each zone for fallbacks. When a reserved pool of pages is depleted, it will try and use RCLM_FALLBACK before using anything else. This greatly reduces the amount of fallbacks causing fragmentation without needing complex balancing algorithms
o Add a fallback_reserve and fallback_balance so that the system knows how may 2^(MAX_ORDER-1) blocks are being used for fallbacks and if more need to be reserved.
o Adds a fallback_allocs[] array that determines the order of freelists are used for each allocation type

include/linux/mmzone.h +27 -1
diff -rup -X /usr/src/patchset-0.5/bin//dontdiff linux-2.6.14-rc3-004_largealloc_tryharder/include/linux/mmzone.h linux-2.6.14-rc3-005_fallback/include/linux/mmzone.h
@@ -29,7 +29,8 @@
 #define RCLM_NORCLM   0
 #define RCLM_USER     1
 #define RCLM_KERN     2
-#define RCLM_TYPES    3
+#define RCLM_FALLBACK 3
+#define RCLM_TYPES    4
 #define BITS_PER_RCLM_TYPE 2
 
 struct free_area {
@@ -159,6 +160,13 @@ struct zone {
 
 	struct free_area	free_area_lists[RCLM_TYPES][MAX_ORDER];
 
+	/*
+	 * Track what percentage of the zone should be used for fallbacks and
+	 * how much is being currently used
+	 */
+	unsigned long		fallback_reserve;
+	long			fallback_balance;
+
 	ZONE_PADDING(_pad1_)
 
 	/* Fields commonly accessed by the page reclaim scanner */
@@ -271,6 +279,24 @@ struct zonelist {
 	struct zone *zones[MAX_NUMNODES * MAX_NR_ZONES + 1]; // NULL delimited
 };
 
+static inline void inc_reserve_count(struct zone* zone, int type)
+{
+	if (type == RCLM_FALLBACK)
+		zone->fallback_reserve++;
+#ifdef CONFIG_ALLOCSTATS
+	zone->reserve_count[type]++;
+#endif
+}
+
+static inline void dec_reserve_count(struct zone* zone, int type)
+{
+	if (type == RCLM_FALLBACK && zone->fallback_reserve)
+		zone->fallback_reserve--;
+#ifdef CONFIG_ALLOCSTATS
+	if (zone->reserve_count[type] > 0)
+		zone->reserve_count[type]--;
+#endif
+}
 
 /*
  * The pg_data_t structure is used in machines with CONFIG_DISCONTIGMEM
mm/page_alloc.c +121 -1

165 lines not on this page · raw message

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

author
#25 lore raw

PATCH 6/7 Fragmentation Avoidance V16: 006_percpu

In reply to Mel Gorman

The freelists for each allocation type can slowly become corrupted due to the per-cpu list. Consider what happens when the following happens

1. A 2^(MAX_ORDER-1) list is reserved for __GFP_USER pages
2. An order-0 page is allocated from the newly reserved block
3. The page is freed and placed on the per-cpu list
4. alloc_page() is called with GFP_KERNEL as the gfp_mask
5. The per-cpu list is used to satisfy the allocation

Now, a kernel page is in the middle of a __GFP_USER page. This means that over long periods of the time, the anti-fragmentation scheme slowly degrades to the standard allocator.

This patch divides the per-cpu lists into Kernel and User lists. RCLM_NORCLM and RCLM_KERN use the Kernel list and RCLM_USER uses the user list. Strictly speaking, there should be three lists but as little effort is made to reclaim RCLM_KERN pages, it is not worth the overhead *yet*.

include/linux/mmzone.h +11 -2
diff -rup -X /usr/src/patchset-0.5/bin//dontdiff linux-2.6.14-rc3-005_fallback/include/linux/mmzone.h linux-2.6.14-rc3-006_percpu/include/linux/mmzone.h
@@ -55,12 +55,17 @@ struct zone_padding {
 #define ZONE_PADDING(name)
 #endif
 
+/* Indices into pcpu_list */
+#define PCPU_KERNEL 0
+#define PCPU_USER   1
+#define PCPU_TYPES  2
+
 struct per_cpu_pages {
-	int count;		/* number of pages in the list */
+	int count[PCPU_TYPES];  /* Number of pages on each list */
 	int low;		/* low watermark, refill needed */
 	int high;		/* high watermark, emptying needed */
 	int batch;		/* chunk size for buddy add/remove */
-	struct list_head list;	/* the list of pages */
+	struct list_head list[PCPU_TYPES]; /* the lists of pages */
 };
 
 struct per_cpu_pageset {
@@ -75,6 +80,10 @@ struct per_cpu_pageset {
 #endif
 } ____cacheline_aligned_in_smp;
 
+/* Helpers for per_cpu_pages */
+#define pset_count(pset) (pset.count[PCPU_KERNEL] + pset.count[PCPU_USER])
+#define for_each_pcputype(pindex) \
+	for (pindex=0; pindex < RCLM_TYPES; pindex++)
 #ifdef CONFIG_NUMA
 #define zone_pcp(__z, __cpu) ((__z)->pageset[(__cpu)])
 #else
mm/page_alloc.c +65 -28

170 lines not on this page · raw message

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

author
#26 lore raw

PATCH 7/7 Fragmentation Avoidance V16: 007_stats

In reply to Mel Gorman

It is not necessary to apply this patch to get all the anti-fragmentation code. This patch adds a new config option called CONFIG_ALLOCSTATS. If set, a number of new bean counters are added that are related to the anti-fragmentation code. The information is exported via /proc/buddyinfo. This is very useful when debugging why high-order pages are not available for allocation.

include/linux/mmzone.h +24 -0
diff -rup -X /usr/src/patchset-0.5/bin//dontdiff linux-2.6.14-rc3-006_percpu/include/linux/mmzone.h linux-2.6.14-rc3-007_stats/include/linux/mmzone.h
@@ -176,6 +176,19 @@ struct zone {
 	unsigned long		fallback_reserve;
 	long			fallback_balance;
 
+#ifdef CONFIG_ALLOCSTATS
+	/*
+	 * These are beancounters that track how the placement policy
+	 * of the buddy allocator is performing
+	 */
+	unsigned long fallback_count[RCLM_TYPES];
+	unsigned long alloc_count[RCLM_TYPES];
+	unsigned long reserve_count[RCLM_TYPES];
+	unsigned long kernnorclm_full_steal;
+	unsigned long kernnorclm_partial_steal;
+#endif
+
+
 	ZONE_PADDING(_pad1_)
 
 	/* Fields commonly accessed by the page reclaim scanner */
@@ -265,6 +278,17 @@ struct zone {
 	char			*name;
 } ____cacheline_maxaligned_in_smp;
 
+#ifdef CONFIG_ALLOCSTATS
+#define inc_fallback_count(zone, type) zone->fallback_count[type]++
+#define inc_alloc_count(zone, type) zone->alloc_count[type]++
+#define inc_kernnorclm_partial_steal(zone) zone->kernnorclm_partial_steal++
+#define inc_kernnorclm_full_steal(zone) zone->kernnorclm_full_steal++
+#else
+#define inc_fallback_count(zone, type) do {} while (0)
+#define inc_alloc_count(zone, type) do {} while (0)
+#define inc_kernnorclm_partial_steal(zone) do {} while (0)
+#define inc_kernnorclm_full_steal(zone) do {} while (0)
+#endif
 
 /*
  * The "priority" of VM scanning is how much of the queues we will scan in one
lib/Kconfig.debug +11 -0
diff -rup -X /usr/src/patchset-0.5/bin//dontdiff linux-2.6.14-rc3-006_percpu/lib/Kconfig.debug linux-2.6.14-rc3-007_stats/lib/Kconfig.debug
@@ -77,6 +77,17 @@ config SCHEDSTATS
 	  application, you can say N to avoid the very slight overhead
 	  this adds.
 
+config ALLOCSTATS
+	bool "Collection buddy allocator statistics"
+	depends on DEBUG_KERNEL && PROC_FS
+	help
+	  If you say Y here, additional code will be inserted into the
+	  page allocator routines to collect statistics on the allocator
+	  behavior and provide them in /proc/buddyinfo. These stats are
+	  useful for measuring fragmentation in the buddy allocator. If
+	  you are not debugging or measuring the allocator, you can say N
+	  to avoid the slight overhead this adds.
+
 config DEBUG_SLAB
 	bool "Debug memory allocations"
 	depends on DEBUG_KERNEL
mm/page_alloc.c +118 -0

160 lines not on this page · raw message

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#8 lore raw

Re: [PATCH 3/7] Fragmentation Avoidance V16: 003_fragcore

In reply to Mel Gorman

mm/page_alloc.c void show_free_areas(void) · line 1546

Quoted 11 lines · Mel Gorman
mm/page_alloc.c +4 -2
@@ -1483,8 +1540,10 @@ void show_free_areas(void)
 
                spin_lock_irqsave(&zone->lock, flags);
                for (order = 0; order < MAX_ORDER; order++) {
-                       nr = zone->free_area[order].nr_free;
-                       total += nr << order;
+                       for (type=0; type < RCLM_TYPES; type++) {
+                               nr = zone->free_area_lists[type][order].nr_free;
+                               total += nr << order;
+                       }

Can that use the new for_each_ macro?

-- Dave

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#16 lore raw

Re: [PATCH 5/7] Fragmentation Avoidance V16: 005_fallback

In reply to Mel Gorman

include/linux/mmzone.h struct zonelist { · line 288

Quoted 4 lines · Mel Gorman
include/linux/mmzone.h +3 -0
+#ifdef CONFIG_ALLOCSTATS
+       zone->reserve_count[type]++;
+#endif

Did this sneak up from another patch?

-- Dave

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#18 lore raw

Re: [PATCH 5/7] Fragmentation Avoidance V16: 005_fallback

In reply to Mel Gorman
Quoted 5 lines · Mel Gorman

+ */

mm/page_alloc.c +3 -0
+static inline struct free_area *
+fallback_buddy_reserve(int start_alloctype, struct zone *zone,
+                       unsigned int current_order, struct page *page,

mm/page_alloc.c remove_page(struct zone *zone, struct pa · line 666

Quoted 10 lines
mm/page_alloc.c +10 -0
+                       struct free_area *area)
+{
+       if (start_alloctype != RCLM_NORCLM)
+               return area;
+
+       area = &(zone->free_area_lists[RCLM_NORCLM][current_order]);
+
+       /* Reserve the whole block if this is a large split */
+       if (current_order >= MAX_ORDER / 2) {
+               int reserve_type=RCLM_NORCLM;

-EBADCODINGSTYLE.

-- Dave

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#22 lore raw

Re: [PATCH 5/7] Fragmentation Avoidance V16: 005_fallback

In reply to Mel Gorman
Quoted 3 lines · Mel Gorman
(quoted diff) +2 -0
+static struct page *
+fallback_alloc(int alloctype, struct zone *zone, unsigned int order)

{

...

mm/page_alloc.c remove_page(struct zone *zone, struct pa · line 699

Quoted 6 lines
mm/page_alloc.c +6 -0
+       /*
+        * Here, the alloc type lists has been depleted as well as the global
+        * pool, so fallback. When falling back, the largest possible block
+        * will be taken to keep the fallbacks clustered if possible
+        */
+       while ((alloctype = *(++fallback_list)) != -1) {

That's a bit obtuse. Is there no way to simplify it? Just keeping an index instead of a fallback_list pointer should make it quite a bit easier to grok.

-- Dave

author
#9 lore raw

Re: [PATCH 3/7] Fragmentation Avoidance V16: 003_fragcore

In reply to Dave Hansen
Quoted 4 lines · Dave Hansen
Quoted 3 lines · Mel Gorman
(quoted diff) +0 -0
@@ -1483,8 +1540,10 @@ void show_free_areas(void)
 
Quoted 11 lines

mm/page_alloc.c void show_free_areas(void) · line 1546

Quoted 8 lines
mm/page_alloc.c +4 -2
                spin_lock_irqsave(&zone->lock, flags);
                for (order = 0; order < MAX_ORDER; order++) {
-                       nr = zone->free_area[order].nr_free;
-                       total += nr << order;
+                       for (type=0; type < RCLM_TYPES; type++) {
+                               nr = zone->free_area_lists[type][order].nr_free;
+                               total += nr << order;
+                       }

Can that use the new for_each_ macro?

Yes, yes it can. Not sure why I dismissed it the first time around.

Signature · 9 lines
Mel Gorman
Part-time Phd Student                          Java Applications Developer
University of Limerick                         IBM Dublin Software Lab

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
author
#17 lore raw

Re: [PATCH 5/7] Fragmentation Avoidance V16: 005_fallback

In reply to Dave Hansen
Quoted 8 lines · Dave Hansen

include/linux/mmzone.h struct zonelist { · line 288

Quoted 4 lines · Mel Gorman
include/linux/mmzone.h +3 -0
+#ifdef CONFIG_ALLOCSTATS
+       zone->reserve_count[type]++;
+#endif

Did this sneak up from another patch?

Worse, it is not active until a later patch - 007_stats. Both patches fixed now.

Signature · 9 lines
Mel Gorman
Part-time Phd Student                          Java Applications Developer
University of Limerick                         IBM Dublin Software Lab

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
author
#10 lore raw

Re: [PATCH 3/7] Fragmentation Avoidance V16: 003_fragcore

In reply to Dave Hansen
Quoted 4 lines · Dave Hansen
Quoted 3 lines · Mel Gorman
(quoted diff) +0 -0
@@ -1483,8 +1540,10 @@ void show_free_areas(void)
 
Quoted 11 lines

mm/page_alloc.c void show_free_areas(void) · line 1546

Quoted 8 lines
mm/page_alloc.c +4 -2
                spin_lock_irqsave(&zone->lock, flags);
                for (order = 0; order < MAX_ORDER; order++) {
-                       nr = zone->free_area[order].nr_free;
-                       total += nr << order;
+                       for (type=0; type < RCLM_TYPES; type++) {
+                               nr = zone->free_area_lists[type][order].nr_free;
+                               total += nr << order;
+                       }

Can that use the new for_each_ macro?

Now I remember why, it's because of the printf below "for (type=0" . The printf has to happen once for each order. With the for_each_macro, it would happen for each type *and* order.

Signature · 9 lines
Mel Gorman
Part-time Phd Student                          Java Applications Developer
University of Limerick                         IBM Dublin Software Lab

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
author
#19 lore raw

Re: [PATCH 5/7] Fragmentation Avoidance V16: 005_fallback

In reply to Dave Hansen
Quoted 19 lines · Dave Hansen
Quoted 5 lines · Mel Gorman

+ */

mm/page_alloc.c +3 -0
+static inline struct free_area *
+fallback_buddy_reserve(int start_alloctype, struct zone *zone,
+                       unsigned int current_order, struct page *page,

mm/page_alloc.c remove_page(struct zone *zone, struct pa · line 666

Quoted 10 lines
mm/page_alloc.c +10 -0
+                       struct free_area *area)
+{
+       if (start_alloctype != RCLM_NORCLM)
+               return area;
+
+       area = &(zone->free_area_lists[RCLM_NORCLM][current_order]);
+
+       /* Reserve the whole block if this is a large split */
+       if (current_order >= MAX_ORDER / 2) {
+               int reserve_type=RCLM_NORCLM;

-EBADCODINGSTYLE.

Changed to;

+static inline struct free_area * +fallback_buddy_reserve(int start_alloctype, struct zone *zone,
+ unsigned int current_order, struct page *page,
+ struct free_area *area)
+{
+ int reserve_type;
+ if (start_alloctype != RCLM_NORCLM)
+ return area;
+
+ area = &(zone->free_area_lists[RCLM_NORCLM][current_order]);
+
+ /* Reserve the whole block if this is a large split */
+ if (current_order >= MAX_ORDER / 2) {
+ reserve_type=RCLM_NORCLM;

(Ignore the whitespace damage, cutting and pasting just so you can see it)

Signature · 9 lines
Mel Gorman
Part-time Phd Student                          Java Applications Developer
University of Limerick                         IBM Dublin Software Lab

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
author
#23 lore raw

Re: [PATCH 5/7] Fragmentation Avoidance V16: 005_fallback

In reply to Dave Hansen
Quoted 12 lines · Dave Hansen
Quoted 3 lines · Mel Gorman
(quoted diff) +2 -0
+static struct page *
+fallback_alloc(int alloctype, struct zone *zone, unsigned int order)

{

...

mm/page_alloc.c remove_page(struct zone *zone, struct pa · line 699

Quoted 6 lines
mm/page_alloc.c +6 -0
+       /*
+        * Here, the alloc type lists has been depleted as well as the global
+        * pool, so fallback. When falling back, the largest possible block
+        * will be taken to keep the fallbacks clustered if possible
+        */
+       while ((alloctype = *(++fallback_list)) != -1) {
Quoted 4 lines

That's a bit obtuse. Is there no way to simplify it? Just keeping an index instead of a fallback_list pointer should make it quite a bit easier to grok.

Changed to

for (i = 0; (alloctype = fallback_list[i]) != -1; i++) {

where i is declared a the start of the function. It's essentially the same as how we move through the zones fallback list so should seem familiar. Is that better?

Signature · 9 lines
Mel Gorman
Part-time Phd Student                          Java Applications Developer
University of Limerick                         IBM Dublin Software Lab

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#20 lore raw

Re: [PATCH 5/7] Fragmentation Avoidance V16: 005_fallback

In reply to Mel Gorman
Quoted 5 lines · Mel Gorman

+ reserve_type=RCLM_NORCLM;

(Ignore the whitespace damage, cutting and pasting just so you can see it)

Sorry, should have been more specific. You need spaces around the '='.

-- Dave

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#11 lore raw

Re: [PATCH 3/7] Fragmentation Avoidance V16: 003_fragcore

In reply to Mel Gorman
Quoted 16 lines · Mel Gorman
Quoted 4 lines · Dave Hansen
Quoted 3 lines · Mel Gorman
(quoted diff) +0 -0
@@ -1483,8 +1540,10 @@ void show_free_areas(void)
 
Quoted 10 lines

mm/page_alloc.c void show_free_areas(void) · line 1546

Quoted 8 lines
mm/page_alloc.c +4 -2
                spin_lock_irqsave(&zone->lock, flags);
                for (order = 0; order < MAX_ORDER; order++) {
-                       nr = zone->free_area[order].nr_free;
-                       total += nr << order;
+                       for (type=0; type < RCLM_TYPES; type++) {
+                               nr = zone->free_area_lists[type][order].nr_free;
+                               total += nr << order;
+                       }

Can that use the new for_each_ macro?

Quoted 3 lines

Now I remember why, it's because of the printf below "for (type=0" . The printf has to happen once for each order. With the for_each_macro, it would happen for each type *and* order.

Actually, that's for debugging, so we might want to do that anyway. Can you put it in a separate patch and explain?

-- Dave

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#24 lore raw

Re: [PATCH 5/7] Fragmentation Avoidance V16: 005_fallback

In reply to Mel Gorman
Quoted 7 lines · Mel Gorman

Changed to

for (i = 0; (alloctype = fallback_list[i]) != -1; i++) {

where i is declared a the start of the function. It's essentially the same as how we move through the zones fallback list so should seem familiar. Is that better?

Yep, at least I understand what it's doing :)

One thing you might consider is not doing the assignment in the for() body:

	for (i = 0; fallback_list[i] != -1; i++) {
		alloctype = fallback_list[i];
		...

-- Dave

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

author
#21 lore raw

Re: [PATCH 5/7] Fragmentation Avoidance V16: 005_fallback

In reply to Dave Hansen
Quoted 9 lines · Dave Hansen
Quoted 5 lines · Mel Gorman

+ reserve_type=RCLM_NORCLM;

(Ignore the whitespace damage, cutting and pasting just so you can see it)

Sorry, should have been more specific. You need spaces around the '='.

Ah. It's now added to my growing list of "Highlight bad style in red" list of vim macros. Sholdn't happen again.

Signature · 9 lines
Mel Gorman
Part-time Phd Student                          Java Applications Developer
University of Limerick                         IBM Dublin Software Lab

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
author
#12 lore raw

Re: [PATCH 3/7] Fragmentation Avoidance V16: 003_fragcore

In reply to Dave Hansen
Quoted 17 lines · Dave Hansen
Quoted 16 lines · Mel Gorman
Quoted 14 lines · Dave Hansen

mm/page_alloc.c void show_free_areas(void) · line 1546

Quoted 11 lines · Mel Gorman
mm/page_alloc.c +4 -2
@@ -1483,8 +1540,10 @@ void show_free_areas(void)
 
                spin_lock_irqsave(&zone->lock, flags);
                for (order = 0; order < MAX_ORDER; order++) {
-                       nr = zone->free_area[order].nr_free;
-                       total += nr << order;
+                       for (type=0; type < RCLM_TYPES; type++) {
+                               nr = zone->free_area_lists[type][order].nr_free;
+                               total += nr << order;
+                       }

Can that use the new for_each_ macro?

Quoted 7 lines
Quoted 3 lines

Now I remember why, it's because of the printf below "for (type=0" . The printf has to happen once for each order. With the for_each_macro, it would happen for each type *and* order.

Actually, that's for debugging, so we might want to do that anyway. Can you put it in a separate patch and explain?

To print out for each type and order, I'll need the type_names[] array from 007_stats but I don't see it as a problem.

The problem is that by putting all the changes to this function in another patch, the kernel will not build after applying 003_fragcore. I am assuming that is bad. I think it makes sense to leave this patch as it is, but have a 004_showfree patch that adds the type_names[] array and a more detailed printout in show_free_areas. The remaining patches get bumped up a number.

Would you be happy with that?

Signature · 9 lines
Mel Gorman
Part-time Phd Student                          Java Applications Developer
University of Limerick                         IBM Dublin Software Lab

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#13 lore raw

Re: [PATCH 3/7] Fragmentation Avoidance V16: 003_fragcore

Quoted 8 lines · Mel Gorman

The problem is that by putting all the changes to this function in another patch, the kernel will not build after applying 003_fragcore. I am assuming that is bad. I think it makes sense to leave this patch as it is, but have a 004_showfree patch that adds the type_names[] array and a more detailed printout in show_free_areas. The remaining patches get bumped up a number.

Would you be happy with that?

Seems reasonable to me.

-- Dave

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#5 lore raw

Re: [PATCH 2/7] Fragmentation Avoidance V16: 002_usemap

In reply to Mel Gorman
Quoted 1 line
mm/page_alloc.c +1 -0
+	unsigned int type = 0;

...

mm/page_alloc.c EXPORT_SYMBOL(totalram_pages); · line 127

Quoted 3 lines
mm/page_alloc.c +3 -0
+	bitidx = pfn_to_bitidx(zone, pfn);
+	usemap = pfn_to_usemap(zone, pfn);
+

There seems no strong reason not to use "unsigned long" for "type" and besides that will provide the required alignment for the bitops interfaces. "unsigned int" is not sufficient.

Then we also don't need to thing about "does this work on big-endian 64-bit" and things of that nature.

Please audit your other bitops uses for this issue.

Thanks.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#2 lore raw

Re: [PATCH 1/7] Fragmentation Avoidance V16: 001_antidefrag_flags

In reply to Mel Gorman
Quoted 1 line · Mel

+/* Allocation type modifiers, group together if possible */

Isn't that "if possible" bogus. I thought these two bits _had_ to be grouped together, at least with the current code.

What happened to the comment that Joel added to gpl.h:

+/* Allocation type modifiers, these are required to be adjacent
+ * __GPF_USER: Allocation for user page or a buffer page
+ * __GFP_KERNRCLM: Short-lived or reclaimable kernel allocation
+ * Both bits off: Kernel non-reclaimable or very hard to reclaim
+ * RCLM_SHIFT (defined elsewhere) depends on the location of these bits

Signature · 9 lines
                  I won't rest till it's the best ...
                  Programmer, Linux Scalability
                  Paul Jackson <[email protected]> 1.925.600.0401

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
author
#6 lore raw

Re: [PATCH 2/7] Fragmentation Avoidance V16: 002_usemap

In reply to David S. Miller
Quoted 5 lines · David S. Miller

From: Mel Gorman <[email protected]>
Date: Wed, 5 Oct 2005 15:45:57 +0100 (IST)

Quoted 1 line
mm/page_alloc.c +1 -0
+	unsigned int type = 0;

...

Quoted 8 lines

mm/page_alloc.c EXPORT_SYMBOL(totalram_pages); · line 127

Quoted 3 lines
mm/page_alloc.c +3 -0
+	bitidx = pfn_to_bitidx(zone, pfn);
+	usemap = pfn_to_usemap(zone, pfn);
+

There seems no strong reason not to use "unsigned long" for "type" and besides that will provide the required alignment for the bitops interfaces. "unsigned int" is not sufficient.

There is no strong reason. I'll convert them to unsigned longs and check for implicit type conversions.

Quoted 3 lines

Then we also don't need to thing about "does this work on big-endian 64-bit" and things of that nature.

Always a plus.

Quoted 2 lines

Please audit your other bitops uses for this issue.

I will. Thanks

Signature · 9 lines
Mel Gorman
Part-time Phd Student                          Java Applications Developer
University of Limerick                         IBM Dublin Software Lab

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
author
#3 lore raw

Re: [PATCH 1/7] Fragmentation Avoidance V16: 001_antidefrag_flags

In reply to Paul Jackson
Quoted 8 lines · Paul Jackson
Quoted 1 line · Mel

+/* Allocation type modifiers, group together if possible */

Isn't that "if possible" bogus. I thought these two bits _had_ to be grouped together, at least with the current code.

What happened to the comment that Joel added to gpl.h:

My bad. I missed it while resyncing with Joel. I have it in now.

Signature · 9 lines
Mel Gorman
Part-time Phd Student                          Java Applications Developer
University of Limerick                         IBM Dublin Software Lab

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>