Skip to contentSkip to conversation

LBS: fix unexported swapper_space

PATCH In review Hugh Dickins 2 participants 9 messages Sep 21, 2007 – Sep 26, 2007

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

PATCH 1/6 LBS: fix unexported swapper_space

If any loadable module uses the page_mapping() inline, we would need to export swapper_space (again: it was exported once, but janitorially unexported); but a filesystem sees only its own pages, so reiserfs can use page->mapping directly without needing the page_mapping() inline.

fs/reiserfs/stree.c +2 -2
@@ -1440,7 +1440,7 @@ static void unmap_buffers(struct page *p
 
 	if (page) {
 		if (page_has_buffers(page)) {
-			tail_index = page_cache_offset(page_mapping(page), pos);
+			tail_index = page_cache_offset(page->mapping, pos);
 			cur_index = 0;
 			head = page_buffers(page);
 			bh = head;
@@ -1461,7 +1461,7 @@ static void unmap_buffers(struct page *p
 			} while (bh != head);
 			if (PAGE_SIZE == bh->b_size) {
 				cancel_dirty_page(page,
-					page_cache_size(page_mapping(page)));
+					page_cache_size(page->mapping));
 			}
 		}
 	}
#1 lore raw

PATCH 2/6 LBS: fix uninitialized swapper_space

Swapping crashed immediately: must initialize new fields of swapper_space.

mm/swap_state.c +4 -0
@@ -42,6 +42,10 @@ struct address_space swapper_space = {
 	.a_ops		= &swap_aops,
 	.i_mmap_nonlinear = LIST_HEAD_INIT(swapper_space.i_mmap_nonlinear),
 	.backing_dev_info = &swap_backing_dev_info,
+#ifdef CONFIG_LARGE_BLOCKSIZE
+	.shift		= PAGE_SHIFT,
+	.offset_mask	= PAGE_SIZE - 1,
+#endif
 };
 
 #define INC_CACHE_INFO(x)	do { swap_cache_info.x++; } while (0)
#2 lore raw

Re: [PATCH 2/6] LBS: fix uninitialized swapper_space

Quoted 1 line · Hugh Dickins

Swapping crashed immediately: must initialize new fields of swapper_space.

Thanks for finding that. It may be better though to use the new mapping_setup() function instead? That way there is no #ifdef.

#3 lore raw

Re: [PATCH 2/6] LBS: fix uninitialized swapper_space

Quoted 6 lines · Christoph Lameter
Quoted 1 line · Hugh Dickins

Swapping crashed immediately: must initialize new fields of swapper_space.

Thanks for finding that. It may be better though to use the new mapping_setup() function instead? That way there is no #ifdef.

Probably better, yes. In -mm Peter is doing an #ifdef CONFIG_SWAP bdi_init() on swapper_space. Would make sense to do both together, perhaps move them to a swapper_space_init() in swap_state.c, saving his #ifdef too. I suggest leave such cleanups until one or the other is mainlined.

Hugh

#4 lore raw

Re: [PATCH 2/6] LBS: fix uninitialized swapper_space

Quoted 5 lines · Hugh Dickins

Probably better, yes. In -mm Peter is doing an #ifdef CONFIG_SWAP bdi_init() on swapper_space. Would make sense to do both together, perhaps move them to a swapper_space_init() in swap_state.c, saving his #ifdef too. I suggest leave such cleanups until one or the other is mainlined.

Ok. I have updated the largeblock git tree with your patches and a new revision of the mmap patches. Still working on it. Fallback in the block layer is not yet working. I probably need to look at Nick's patches a bit.

#5 lore raw

PATCH 3/6 LBS: fix hang in isolate_lru_pages

In reply to Hugh Dickins

Hang in isolate_lru_pages: remember to increment scan in all cases.

mm/vmscan.c +2 -1
@@ -704,12 +704,14 @@ static unsigned long isolate_lru_pages(u
 		case -EBUSY:
 			/* else it is being freed elsewhere */
 			list_move(&page->lru, src);
+			scan++;
 			continue;
 
 		default:
 			BUG();
 		}
 
+		scan += pages;
 		if (!order)
 			continue;
 
@@ -755,7 +757,6 @@ static unsigned long isolate_lru_pages(u
 				break;
 			}
 		}
-		scan += pages;
 	}
 
 	*scanned = scan;
#6 lore raw

PATCH 4/6 LBS: fix oops in try_to_release_page

In reply to Hugh Dickins

It's uncommon, but try_to_release_page is sometimes called when page->mapping is NULL (see the check for mapping further down):
so its VM_BUG_ON(mapping_order(mapping)...) just causes an oops. There seem to be enough of those checks already, and no special reason to have one right here: just delete it.

mm/filemap.c +0 -1
@@ -2247,7 +2247,6 @@ int try_to_release_page(struct page *pag
 	struct address_space * const mapping = page->mapping;
 
 	BUG_ON(!PageLocked(page));
-	VM_BUG_ON(mapping_order(mapping) != page_cache_page_order(page));
 	if (PageWriteback(page))
 		return 0;
 
#7 lore raw

PATCH 5/6 LBS: fix crashes in vma_address

In reply to Hugh Dickins

vma_address oopsed on mapping_order(page->mapping): because page may now be a tail page in which page->mapping is NULL. There's (too!) many ways to do this, I went for page_cache_page_order(page_cache_head(page)) so
we can also avoid the PageAnon test. Indeed, use page_cache_page_order
throughout, to simplify those "page_cache_shift(mapping) - PAGE_SHIFT"s.

vma_address bugged on !PageAnon because loops over page_cache_base_pages may try a component file page outside the range of the vma: just delete that BUG_ON now it no longer applies.

mm/rmap.c +5 -12
@@ -191,17 +191,10 @@ vma_address(struct page *page, struct vm
 	pgoff_t pgoff;
 	unsigned long address;
 
-	if (PageAnon(page))
-		pgoff = page->index;
-	else
-		pgoff = page->index << mapping_order(page->mapping);
-
+	pgoff = page->index << page_cache_page_order(page_cache_head(page));
 	address = vma->vm_start + ((pgoff - vma->vm_pgoff) << PAGE_SHIFT);
-	if (unlikely(address < vma->vm_start || address >= vma->vm_end)) {
-		/* page should be within any vma from prio_tree_next */
-		BUG_ON(!PageAnon(page));
+	if (unlikely(address < vma->vm_start || address >= vma->vm_end))
 		return -EFAULT;
-	}
 	return address;
 }
 
@@ -352,7 +345,7 @@ static int page_referenced_file(struct p
 {
 	unsigned int mapcount;
 	struct address_space *mapping = page->mapping;
-	pgoff_t pgoff = page->index << (page_cache_shift(mapping) - PAGE_SHIFT);
+	pgoff_t pgoff = page->index << page_cache_page_order(page);
 	struct vm_area_struct *vma;
 	struct prio_tree_iter iter;
 	int referenced = 0;
@@ -475,7 +468,7 @@ static int page_mkclean_one(struct page 
 
 static int page_mkclean_file(struct address_space *mapping, struct page *page)
 {
-	pgoff_t pgoff = page->index << (page_cache_shift(mapping) - PAGE_SHIFT);
+	pgoff_t pgoff = page->index << page_cache_page_order(page);
 	struct vm_area_struct *vma;
 	struct prio_tree_iter iter;
 	int ret = 0;
@@ -907,7 +900,7 @@ static int try_to_unmap_anon(struct page
 static int try_to_unmap_file(struct page *page, int migration)
 {
 	struct address_space *mapping = page->mapping;
-	pgoff_t pgoff = page->index << (page_cache_shift(mapping) - PAGE_SHIFT);
+	pgoff_t pgoff = page->index << page_cache_page_order(page);
 	struct vm_area_struct *vma;
 	struct prio_tree_iter iter;
 	int ret = SWAP_AGAIN;
#8 lore raw

PATCH 6/6 LBS: support largeblocked swapfile

In reply to Hugh Dickins

Adjust setup_swap_extents so as not to assume that PAGE_SIZE is a multiple of its swapfile blocksize: blocksize might now be a multiple of PAGE_SIZE. Not vital to support this, but LTP in ext2 -b 32768 /tmp was failing before.

mm/swapfile.c +20 -7
@@ -1057,6 +1057,7 @@ static int setup_swap_extents(struct swa
 {
 	struct inode *inode;
 	unsigned blocks_per_page;
+	unsigned pages_per_block;
 	unsigned long page_no;
 	unsigned blkbits;
 	sector_t probe_block;
@@ -1074,7 +1075,13 @@ static int setup_swap_extents(struct swa
 	}
 
 	blkbits = inode->i_blkbits;
-	blocks_per_page = PAGE_SIZE >> blkbits;
+	if (blkbits <= PAGE_SHIFT) {
+		blocks_per_page = 1 << (PAGE_SHIFT - blkbits);
+		pages_per_block = 1;
+	} else {
+		blocks_per_page = 1;
+		pages_per_block = 1 << (blkbits - PAGE_SHIFT);
+	}
 
 	/*
 	 * Map all the blocks into the extent list.  This code doesn't try
@@ -1114,28 +1121,34 @@ static int setup_swap_extents(struct swa
 			}
 		}
 
-		first_block >>= (PAGE_SHIFT - blkbits);
+		if (blkbits <= PAGE_SHIFT)
+			first_block >>= (PAGE_SHIFT - blkbits);
+		else {
+			first_block <<= (blkbits - PAGE_SHIFT);
+			if (page_no + pages_per_block > sis->max)
+				pages_per_block = sis->max - page_no;
+		}
 		if (page_no) {	/* exclude the header page */
 			if (first_block < lowest_block)
 				lowest_block = first_block;
-			if (first_block > highest_block)
-				highest_block = first_block;
+			if (first_block >= highest_block)
+				highest_block = first_block + pages_per_block;
 		}
 
 		/*
 		 * We found a PAGE_SIZE-length, PAGE_SIZE-aligned run of blocks
 		 */
-		ret = add_swap_extent(sis, page_no, 1, first_block);
+		ret = add_swap_extent(sis,page_no,pages_per_block,first_block);
 		if (ret < 0)
 			goto out;
 		nr_extents += ret;
-		page_no++;
+		page_no += pages_per_block;
 		probe_block += blocks_per_page;
 reprobe:
 		continue;
 	}
 	ret = nr_extents;
-	*span = 1 + highest_block - lowest_block;
+	*span = highest_block - lowest_block;
 	if (page_no == 0)
 		page_no = 1;	/* force Empty message */
 	sis->max = page_no;