[PATCH 2/2] hugetlb: synchronize alloc with page cache insert

From: Adam Litke
Date: Wed Jan 11 2006 - 17:23:01 EST


On Wed, 2006-01-11 at 16:02 -0600, Adam Litke wrote:
> here). The patch doesn't completely close the race (there is a much
> smaller window without the zeroing though). The next patch should close
> the race window completely.

My only concern is if I am using the correct lock for the job here.

hugetlb.c | 14 ++++++++++----
1 files changed, 10 insertions(+), 4 deletions(-)
diff -upN reference/mm/hugetlb.c current/mm/hugetlb.c
--- reference/mm/hugetlb.c
+++ current/mm/hugetlb.c
@@ -445,6 +445,7 @@ int hugetlb_no_page(struct mm_struct *mm
struct page *page;
struct address_space *mapping;
pte_t new_pte;
+ int shared = vma->vm_flags & VM_SHARED;

mapping = vma->vm_file->f_mapping;
idx = ((address - vma->vm_start) >> HPAGE_SHIFT)
@@ -454,26 +455,31 @@ int hugetlb_no_page(struct mm_struct *mm
* Use page lock to guard against racing truncation
* before we get page_table_lock.
*/
-retry:
page = find_lock_page(mapping, idx);
if (!page) {
if (hugetlb_get_quota(mapping))
goto out;
+
+ if (shared)
+ spin_lock(&mapping->host->i_lock);
+
page = alloc_unzeroed_huge_page(vma, address);
if (!page) {
hugetlb_put_quota(mapping);
+ if (shared)
+ spin_unlock(&mapping->host->i_lock);
goto out;
}

- if (vma->vm_flags & VM_SHARED) {
+ if (shared) {
int err;

err = add_to_page_cache(page, mapping, idx, GFP_KERNEL);
+ spin_unlock(&mapping->host->i_lock);
if (err) {
put_page(page);
hugetlb_put_quota(mapping);
- if (err == -EEXIST)
- goto retry;
+ BUG_ON(-EEXIST);
goto out;
}
} else


--
Adam Litke - (agl at us.ibm.com)
IBM Linux Technology Center

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/