Skip to contentSkip to conversation

ramfs accounting in -ac broken

PATCH New Christoph Rohland 1 participant 1 message May 17, 2001

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ramfs accounting in -ac broken

Hi Alan,

The ramfs accounting is broken for shared mmaps. It simply does not recognize the pages allocated by writing into a shared mapping but takes them into account when freed.

The attached patch should fix that.

Greetings
Christoph

fs/ramfs/inode.c +7 -8
@@ -163,9 +163,6 @@
 	struct ramfs_sb_info *rsb = RAMFS_SB(inode->i_sb);
 	int ret = 1;
 
-	if (PageDirty(page)) /* It's already been allocated */
-		return 1;
-
 	lock_rsb(rsb);
 		
 	if ( (rsb->free_pages > 0) &&
@@ -185,8 +182,7 @@
 {
 	struct ramfs_sb_info *rsb = RAMFS_SB(inode->i_sb);
 
-	if (! PageDirty(page)) /* The page was never allocated 
-				  this can happen if it was only read */
+	if (! Page_Uptodate(page))
 		return;
 
 	lock_rsb(rsb);
@@ -241,6 +237,8 @@
 static int ramfs_readpage(struct file *file, struct page * page)
 {
 	if (!Page_Uptodate(page)) {
+		if (!ramfs_alloc_page(file->f_dentry->d_inode, page))
+			return -ENOSPC;
 		memset(kmap(page), 0, PAGE_CACHE_SIZE);
 		kunmap(page);
 		flush_dcache_page(page);
@@ -266,11 +264,12 @@
 	struct inode *inode = (struct inode *)page->mapping->host;
 	void *addr;
 	
-	if (! ramfs_alloc_page(inode, page))
-		return -ENOSPC;
-
 	addr = (void *) kmap(page);
 	if (!Page_Uptodate(page)) {
+		if (! ramfs_alloc_page(inode, page)) {
+			kunmap(page);
+			return -ENOSPC;
+		}
 		memset(addr, 0, PAGE_CACHE_SIZE);
 		flush_dcache_page(page);
 		SetPageUptodate(page);