~ubuntu-branches/ubuntu/precise/linux-ti-omap4/precise

« back to all changes in this revision

Viewing changes to mm/memory-failure.c

  • Committer: Bazaar Package Importer
  • Author(s): Paolo Pisati
  • Date: 2011-06-29 15:23:51 UTC
  • mfrom: (26.1.1 natty-proposed)
  • Revision ID: james.westby@ubuntu.com-20110629152351-xs96tm303d95rpbk
Tags: 3.0.0-1200.2
* Rebased against 3.0.0-6.7
* BSP from TI based on 3.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
52
52
#include <linux/swapops.h>
53
53
#include <linux/hugetlb.h>
54
54
#include <linux/memory_hotplug.h>
 
55
#include <linux/mm_inline.h>
55
56
#include "internal.h"
56
57
 
57
58
int sysctl_memory_failure_early_kill __read_mostly = 0;
208
209
         * Don't use force here, it's convenient if the signal
209
210
         * can be temporarily blocked.
210
211
         * This could cause a loop when the user sets SIGBUS
211
 
         * to SIG_IGN, but hopefully noone will do that?
 
212
         * to SIG_IGN, but hopefully no one will do that?
212
213
         */
213
214
        ret = send_sig_info(SIGBUS, &si, t);  /* synchronous? */
214
215
        if (ret < 0)
239
240
        if (access) {
240
241
                int nr;
241
242
                do {
242
 
                        nr = shrink_slab(1000, GFP_KERNEL, 1000);
 
243
                        struct shrink_control shrink = {
 
244
                                .gfp_mask = GFP_KERNEL,
 
245
                        };
 
246
 
 
247
                        nr = shrink_slab(&shrink, 1000, 1000);
243
248
                        if (page_count(p) == 1)
244
249
                                break;
245
250
                } while (nr > 10);
386
391
        struct task_struct *tsk;
387
392
        struct anon_vma *av;
388
393
 
389
 
        read_lock(&tasklist_lock);
390
394
        av = page_lock_anon_vma(page);
391
395
        if (av == NULL) /* Not actually mapped anymore */
392
 
                goto out;
 
396
                return;
 
397
 
 
398
        read_lock(&tasklist_lock);
393
399
        for_each_process (tsk) {
394
400
                struct anon_vma_chain *vmac;
395
401
 
403
409
                                add_to_kill(tsk, page, vma, to_kill, tkc);
404
410
                }
405
411
        }
 
412
        read_unlock(&tasklist_lock);
406
413
        page_unlock_anon_vma(av);
407
 
out:
408
 
        read_unlock(&tasklist_lock);
409
414
}
410
415
 
411
416
/*
419
424
        struct prio_tree_iter iter;
420
425
        struct address_space *mapping = page->mapping;
421
426
 
422
 
        /*
423
 
         * A note on the locking order between the two locks.
424
 
         * We don't rely on this particular order.
425
 
         * If you have some other code that needs a different order
426
 
         * feel free to switch them around. Or add a reverse link
427
 
         * from mm_struct to task_struct, then this could be all
428
 
         * done without taking tasklist_lock and looping over all tasks.
429
 
         */
430
 
 
 
427
        mutex_lock(&mapping->i_mmap_mutex);
431
428
        read_lock(&tasklist_lock);
432
 
        spin_lock(&mapping->i_mmap_lock);
433
429
        for_each_process(tsk) {
434
430
                pgoff_t pgoff = page->index << (PAGE_CACHE_SHIFT - PAGE_SHIFT);
435
431
 
449
445
                                add_to_kill(tsk, page, vma, to_kill, tkc);
450
446
                }
451
447
        }
452
 
        spin_unlock(&mapping->i_mmap_lock);
453
448
        read_unlock(&tasklist_lock);
 
449
        mutex_unlock(&mapping->i_mmap_mutex);
454
450
}
455
451
 
456
452
/*
634
630
                 * when the page is reread or dropped.  If an
635
631
                 * application assumes it will always get error on
636
632
                 * fsync, but does other operations on the fd before
637
 
                 * and the page is dropped inbetween then the error
 
633
                 * and the page is dropped between then the error
638
634
                 * will not be properly reported.
639
635
                 *
640
636
                 * This can already happen even without hwpoisoned
728
724
 * The table matches them in order and calls the right handler.
729
725
 *
730
726
 * This is quite tricky because we can access page at any time
731
 
 * in its live cycle, so all accesses have to be extremly careful.
 
727
 * in its live cycle, so all accesses have to be extremely careful.
732
728
 *
733
729
 * This is not complete. More states could be added.
734
730
 * For any missing state don't attempt recovery.
945
941
                collect_procs(ppage, &tokill);
946
942
 
947
943
        if (hpage != ppage)
948
 
                lock_page_nosync(ppage);
 
944
                lock_page(ppage);
949
945
 
950
946
        ret = try_to_unmap(ppage, ttu);
951
947
        if (ret != SWAP_SUCCESS)
1038
1034
                         * Check "just unpoisoned", "filter hit", and
1039
1035
                         * "race with other subpage."
1040
1036
                         */
1041
 
                        lock_page_nosync(hpage);
 
1037
                        lock_page(hpage);
1042
1038
                        if (!PageHWPoison(hpage)
1043
1039
                            || (hwpoison_filter(p) && TestClearPageHWPoison(p))
1044
1040
                            || (p != hpage && TestSetPageHWPoison(hpage))) {
1088
1084
         * It's very difficult to mess with pages currently under IO
1089
1085
         * and in many cases impossible, so we just avoid it here.
1090
1086
         */
1091
 
        lock_page_nosync(hpage);
 
1087
        lock_page(hpage);
1092
1088
 
1093
1089
        /*
1094
1090
         * unpoison always clear PG_hwpoison inside page lock
1130
1126
 
1131
1127
        /*
1132
1128
         * Now take care of user space mappings.
1133
 
         * Abort on fail: __remove_from_page_cache() assumes unmapped page.
 
1129
         * Abort on fail: __delete_from_page_cache() assumes unmapped page.
1134
1130
         */
1135
1131
        if (hwpoison_user_mappings(p, pfn, trapno) != SWAP_SUCCESS) {
1136
1132
                printk(KERN_ERR "MCE %#lx: cannot unmap page, give up\n", pfn);
1231
1227
                return 0;
1232
1228
        }
1233
1229
 
1234
 
        lock_page_nosync(page);
 
1230
        lock_page(page);
1235
1231
        /*
1236
1232
         * This test is racy because PG_hwpoison is set outside of page lock.
1237
1233
         * That's acceptable because that won't trigger kernel panic. Instead,
1440
1436
         */
1441
1437
        ret = invalidate_inode_page(page);
1442
1438
        unlock_page(page);
1443
 
 
1444
1439
        /*
1445
 
         * Drop count because page migration doesn't like raised
1446
 
         * counts. The page could get re-allocated, but if it becomes
1447
 
         * LRU the isolation will just fail.
1448
1440
         * RED-PEN would be better to keep it isolated here, but we
1449
1441
         * would need to fix isolation locking first.
1450
1442
         */
1451
 
        put_page(page);
1452
1443
        if (ret == 1) {
 
1444
                put_page(page);
1453
1445
                ret = 0;
1454
1446
                pr_info("soft_offline: %#lx: invalidated\n", pfn);
1455
1447
                goto done;
1461
1453
         * handles a large number of cases for us.
1462
1454
         */
1463
1455
        ret = isolate_lru_page(page);
 
1456
        /*
 
1457
         * Drop page reference which is came from get_any_page()
 
1458
         * successful isolate_lru_page() already took another one.
 
1459
         */
 
1460
        put_page(page);
1464
1461
        if (!ret) {
1465
1462
                LIST_HEAD(pagelist);
1466
 
 
 
1463
                inc_zone_page_state(page, NR_ISOLATED_ANON +
 
1464
                                            page_is_file_cache(page));
1467
1465
                list_add(&page->lru, &pagelist);
1468
1466
                ret = migrate_pages(&pagelist, new_page, MPOL_MF_MOVE_ALL,
1469
1467
                                                                0, true);
1487
1485
        /* keep elevated page count for bad page */
1488
1486
        return ret;
1489
1487
}
1490
 
 
1491
 
/*
1492
 
 * The caller must hold current->mm->mmap_sem in read mode.
1493
 
 */
1494
 
int is_hwpoison_address(unsigned long addr)
1495
 
{
1496
 
        pgd_t *pgdp;
1497
 
        pud_t pud, *pudp;
1498
 
        pmd_t pmd, *pmdp;
1499
 
        pte_t pte, *ptep;
1500
 
        swp_entry_t entry;
1501
 
 
1502
 
        pgdp = pgd_offset(current->mm, addr);
1503
 
        if (!pgd_present(*pgdp))
1504
 
                return 0;
1505
 
        pudp = pud_offset(pgdp, addr);
1506
 
        pud = *pudp;
1507
 
        if (!pud_present(pud) || pud_large(pud))
1508
 
                return 0;
1509
 
        pmdp = pmd_offset(pudp, addr);
1510
 
        pmd = *pmdp;
1511
 
        if (!pmd_present(pmd) || pmd_large(pmd))
1512
 
                return 0;
1513
 
        ptep = pte_offset_map(pmdp, addr);
1514
 
        pte = *ptep;
1515
 
        pte_unmap(ptep);
1516
 
        if (!is_swap_pte(pte))
1517
 
                return 0;
1518
 
        entry = pte_to_swp_entry(pte);
1519
 
        return is_hwpoison_entry(entry);
1520
 
}
1521
 
EXPORT_SYMBOL_GPL(is_hwpoison_address);