Skip to contentSkip to conversation

hugetlb: wrap release path with release_key()

PATCH New William Lee Irwin III 1 participant 1 message Nov 12, 2002

lore
Share & tools
lore
#0 lore raw

PATCH 3/11 hugetlb: wrap release path with release_key()

This wraps the release path in alloc_shared_hugetlb_pages() with a release_key() function that handles the release.

 hugetlbpage.c |   31 ++++++++++++++++++++-----------
 1 files changed, 20 insertions(+), 11 deletions(-)
arch/i386/mm/hugetlbpage.c +20 -11
diff -urpN htlb-2.5.47-2/arch/i386/mm/hugetlbpage.c htlb-2.5.47-3/arch/i386/mm/hugetlbpage.c
@@ -101,6 +101,23 @@ struct hugetlb_key *alloc_key(int key, u
 	return (struct hugetlb_key *)inode;
 }
 
+static void release_key(struct hugetlb_key *key)
+{
+	int i;
+	struct inode *inode = (struct inode *)key;;
+
+	spin_lock(&htlbpage_lock);
+	for(i = 0;i < MAX_ID; ++i)
+		if (htlbpagek[i].key != inode->i_ino)
+			continue;
+
+	BUG_ON(i >= MAX_ID);
+	htlbpagek[i].key = 0;
+	htlbpagek[i].in = NULL;
+	kfree(inode);
+	spin_unlock(&htlbpage_lock);
+}
+
 static struct page *alloc_hugetlb_page(void)
 {
 	int i;
@@ -339,7 +356,6 @@ static int alloc_shared_hugetlb_pages(in
 	struct vm_area_struct *vma;
 	struct inode *inode;
 	struct address_space *mapping;
-	int idx;
 	int retval = -ENOMEM;
 	int newalloc = 0;
 
@@ -390,16 +406,9 @@ out:
 	return retval;
 out_err: spin_unlock(&htlbpage_lock);
 freeinode:
-	 if (newalloc) {
-		 for(idx=0;idx<MAX_ID;idx++)
-			 if (htlbpagek[idx].key == inode->i_ino) {
-				 htlbpagek[idx].key = 0;
-				 htlbpagek[idx].in = NULL;
-				 break;
-			 }
-		 kfree(inode);
-	 }
-	 return retval;
+	if (newalloc)
+		release_key((struct hugetlb_key *)inode);
+	return retval;
 }
 
 int hugetlb_prefault(struct address_space *mapping, struct vm_area_struct *vma)