linux-bk/mm/swapfile.c
<<
>>
Prefs
   1/*
   2 *  linux/mm/swapfile.c
   3 *
   4 *  Copyright (C) 1991, 1992, 1993, 1994  Linus Torvalds
   5 *  Swap reorganised 29.12.95, Stephen Tweedie
   6 */
   7
   8#include <linux/mm.h>
   9#include <linux/slab.h>
  10#include <linux/kernel_stat.h>
  11#include <linux/swap.h>
  12#include <linux/vmalloc.h>
  13#include <linux/pagemap.h>
  14#include <linux/namei.h>
  15#include <linux/shm.h>
  16#include <linux/blkdev.h>
  17#include <linux/buffer_head.h>
  18
  19#include <asm/pgtable.h>
  20#include <linux/swapops.h>
  21
  22spinlock_t swaplock = SPIN_LOCK_UNLOCKED;
  23unsigned int nr_swapfiles;
  24int total_swap_pages;
  25static int swap_overflow;
  26
  27static const char Bad_file[] = "Bad swap file entry ";
  28static const char Unused_file[] = "Unused swap file entry ";
  29static const char Bad_offset[] = "Bad swap offset entry ";
  30static const char Unused_offset[] = "Unused swap offset entry ";
  31
  32struct swap_list_t swap_list = {-1, -1};
  33
  34struct swap_info_struct swap_info[MAX_SWAPFILES];
  35
  36#define SWAPFILE_CLUSTER 256
  37
  38static inline int scan_swap_map(struct swap_info_struct *si)
  39{
  40        unsigned long offset;
  41        /* 
  42         * We try to cluster swap pages by allocating them
  43         * sequentially in swap.  Once we've allocated
  44         * SWAPFILE_CLUSTER pages this way, however, we resort to
  45         * first-free allocation, starting a new cluster.  This
  46         * prevents us from scattering swap pages all over the entire
  47         * swap partition, so that we reduce overall disk seek times
  48         * between swap pages.  -- sct */
  49        if (si->cluster_nr) {
  50                while (si->cluster_next <= si->highest_bit) {
  51                        offset = si->cluster_next++;
  52                        if (si->swap_map[offset])
  53                                continue;
  54                        si->cluster_nr--;
  55                        goto got_page;
  56                }
  57        }
  58        si->cluster_nr = SWAPFILE_CLUSTER;
  59
  60        /* try to find an empty (even not aligned) cluster. */
  61        offset = si->lowest_bit;
  62 check_next_cluster:
  63        if (offset+SWAPFILE_CLUSTER-1 <= si->highest_bit)
  64        {
  65                int nr;
  66                for (nr = offset; nr < offset+SWAPFILE_CLUSTER; nr++)
  67                        if (si->swap_map[nr])
  68                        {
  69                                offset = nr+1;
  70                                goto check_next_cluster;
  71                        }
  72                /* We found a completly empty cluster, so start
  73                 * using it.
  74                 */
  75                goto got_page;
  76        }
  77        /* No luck, so now go finegrined as usual. -Andrea */
  78        for (offset = si->lowest_bit; offset <= si->highest_bit ; offset++) {
  79                if (si->swap_map[offset])
  80                        continue;
  81                si->lowest_bit = offset+1;
  82        got_page:
  83                if (offset == si->lowest_bit)
  84                        si->lowest_bit++;
  85                if (offset == si->highest_bit)
  86                        si->highest_bit--;
  87                if (si->lowest_bit > si->highest_bit) {
  88                        si->lowest_bit = si->max;
  89                        si->highest_bit = 0;
  90                }
  91                si->swap_map[offset] = 1;
  92                nr_swap_pages--;
  93                si->cluster_next = offset+1;
  94                return offset;
  95        }
  96        si->lowest_bit = si->max;
  97        si->highest_bit = 0;
  98        return 0;
  99}
 100
 101swp_entry_t get_swap_page(void)
 102{
 103        struct swap_info_struct * p;
 104        unsigned long offset;
 105        swp_entry_t entry;
 106        int type, wrapped = 0;
 107
 108        entry.val = 0;  /* Out of memory */
 109        swap_list_lock();
 110        type = swap_list.next;
 111        if (type < 0)
 112                goto out;
 113        if (nr_swap_pages <= 0)
 114                goto out;
 115
 116        while (1) {
 117                p = &swap_info[type];
 118                if ((p->flags & SWP_ACTIVE) == SWP_ACTIVE) {
 119                        swap_device_lock(p);
 120                        offset = scan_swap_map(p);
 121                        swap_device_unlock(p);
 122                        if (offset) {
 123                                entry = swp_entry(type,offset);
 124                                type = swap_info[type].next;
 125                                if (type < 0 ||
 126                                        p->prio != swap_info[type].prio) {
 127                                                swap_list.next = swap_list.head;
 128                                } else {
 129                                        swap_list.next = type;
 130                                }
 131                                goto out;
 132                        }
 133                }
 134                type = p->next;
 135                if (!wrapped) {
 136                        if (type < 0 || p->prio != swap_info[type].prio) {
 137                                type = swap_list.head;
 138                                wrapped = 1;
 139                        }
 140                } else
 141                        if (type < 0)
 142                                goto out;       /* out of swap space */
 143        }
 144out:
 145        swap_list_unlock();
 146        return entry;
 147}
 148
 149static struct swap_info_struct * swap_info_get(swp_entry_t entry)
 150{
 151        struct swap_info_struct * p;
 152        unsigned long offset, type;
 153
 154        if (!entry.val)
 155                goto out;
 156        type = swp_type(entry);
 157        if (type >= nr_swapfiles)
 158                goto bad_nofile;
 159        p = & swap_info[type];
 160        if (!(p->flags & SWP_USED))
 161                goto bad_device;
 162        offset = swp_offset(entry);
 163        if (offset >= p->max)
 164                goto bad_offset;
 165        if (!p->swap_map[offset])
 166                goto bad_free;
 167        swap_list_lock();
 168        if (p->prio > swap_info[swap_list.next].prio)
 169                swap_list.next = type;
 170        swap_device_lock(p);
 171        return p;
 172
 173bad_free:
 174        printk(KERN_ERR "swap_free: %s%08lx\n", Unused_offset, entry.val);
 175        goto out;
 176bad_offset:
 177        printk(KERN_ERR "swap_free: %s%08lx\n", Bad_offset, entry.val);
 178        goto out;
 179bad_device:
 180        printk(KERN_ERR "swap_free: %s%08lx\n", Unused_file, entry.val);
 181        goto out;
 182bad_nofile:
 183        printk(KERN_ERR "swap_free: %s%08lx\n", Bad_file, entry.val);
 184out:
 185        return NULL;
 186}       
 187
 188static void swap_info_put(struct swap_info_struct * p)
 189{
 190        swap_device_unlock(p);
 191        swap_list_unlock();
 192}
 193
 194static int swap_entry_free(struct swap_info_struct *p, unsigned long offset)
 195{
 196        int count = p->swap_map[offset];
 197
 198        if (count < SWAP_MAP_MAX) {
 199                count--;
 200                p->swap_map[offset] = count;
 201                if (!count) {
 202                        if (offset < p->lowest_bit)
 203                                p->lowest_bit = offset;
 204                        if (offset > p->highest_bit)
 205                                p->highest_bit = offset;
 206                        nr_swap_pages++;
 207                }
 208        }
 209        return count;
 210}
 211
 212/*
 213 * Caller has made sure that the swapdevice corresponding to entry
 214 * is still around or has not been recycled.
 215 */
 216void swap_free(swp_entry_t entry)
 217{
 218        struct swap_info_struct * p;
 219
 220        p = swap_info_get(entry);
 221        if (p) {
 222                swap_entry_free(p, swp_offset(entry));
 223                swap_info_put(p);
 224        }
 225}
 226
 227/*
 228 * Check if we're the only user of a swap page,
 229 * when the page is locked.
 230 */
 231static int exclusive_swap_page(struct page *page)
 232{
 233        int retval = 0;
 234        struct swap_info_struct * p;
 235        swp_entry_t entry;
 236
 237        entry.val = page->index;
 238        p = swap_info_get(entry);
 239        if (p) {
 240                /* Is the only swap cache user the cache itself? */
 241                if (p->swap_map[swp_offset(entry)] == 1) {
 242                        /* Recheck the page count with the pagecache lock held.. */
 243                        read_lock(&swapper_space.page_lock);
 244                        if (page_count(page) - !!PagePrivate(page) == 2)
 245                                retval = 1;
 246                        read_unlock(&swapper_space.page_lock);
 247                }
 248                swap_info_put(p);
 249        }
 250        return retval;
 251}
 252
 253/*
 254 * We can use this swap cache entry directly
 255 * if there are no other references to it.
 256 *
 257 * Here "exclusive_swap_page()" does the real
 258 * work, but we opportunistically check whether
 259 * we need to get all the locks first..
 260 */
 261int can_share_swap_page(struct page *page)
 262{
 263        int retval = 0;
 264
 265        if (!PageLocked(page))
 266                BUG();
 267        switch (page_count(page)) {
 268        case 3:
 269                if (!PagePrivate(page))
 270                        break;
 271                /* Fallthrough */
 272        case 2:
 273                if (!PageSwapCache(page))
 274                        break;
 275                retval = exclusive_swap_page(page);
 276                break;
 277        case 1:
 278                if (PageReserved(page))
 279                        break;
 280                retval = 1;
 281        }
 282        return retval;
 283}
 284
 285/*
 286 * Work out if there are any other processes sharing this
 287 * swap cache page. Free it if you can. Return success.
 288 */
 289int remove_exclusive_swap_page(struct page *page)
 290{
 291        int retval;
 292        struct swap_info_struct * p;
 293        swp_entry_t entry;
 294
 295        BUG_ON(page_has_buffers(page));
 296        BUG_ON(!PageLocked(page));
 297
 298        if (!PageSwapCache(page))
 299                return 0;
 300        if (PageWriteback(page))
 301                return 0;
 302        if (page_count(page) != 2) /* 2: us + cache */
 303                return 0;
 304
 305        entry.val = page->index;
 306        p = swap_info_get(entry);
 307        if (!p)
 308                return 0;
 309
 310        /* Is the only swap cache user the cache itself? */
 311        retval = 0;
 312        if (p->swap_map[swp_offset(entry)] == 1) {
 313                /* Recheck the page count with the pagecache lock held.. */
 314                write_lock(&swapper_space.page_lock);
 315                if ((page_count(page) == 2) && !PageWriteback(page)) {
 316                        __delete_from_swap_cache(page);
 317                        SetPageDirty(page);
 318                        retval = 1;
 319                }
 320                write_unlock(&swapper_space.page_lock);
 321        }
 322        swap_info_put(p);
 323
 324        if (retval) {
 325                swap_free(entry);
 326                page_cache_release(page);
 327        }
 328
 329        return retval;
 330}
 331
 332/*
 333 * Free the swap entry like above, but also try to
 334 * free the page cache entry if it is the last user.
 335 */
 336void free_swap_and_cache(swp_entry_t entry)
 337{
 338        struct swap_info_struct * p;
 339        struct page *page = NULL;
 340
 341        p = swap_info_get(entry);
 342        if (p) {
 343                if (swap_entry_free(p, swp_offset(entry)) == 1)
 344                        page = find_trylock_page(&swapper_space, entry.val);
 345                swap_info_put(p);
 346        }
 347        if (page) {
 348                int one_user;
 349
 350                BUG_ON(page_has_buffers(page));
 351                page_cache_get(page);
 352                one_user = (page_count(page) == 2);
 353                /* Only cache user (+us), or swap space full? Free it! */
 354                if (!PageWriteback(page) && (one_user || vm_swap_full())) {
 355                        delete_from_swap_cache(page);
 356                        SetPageDirty(page);
 357                }
 358                unlock_page(page);
 359                page_cache_release(page);
 360        }
 361}
 362
 363/*
 364 * The swap entry has been read in advance, and we return 1 to indicate
 365 * that the page has been used or is no longer needed.
 366 *
 367 * Always set the resulting pte to be nowrite (the same as COW pages
 368 * after one process has exited).  We don't know just how many PTEs will
 369 * share this swap entry, so be cautious and let do_wp_page work out
 370 * what to do if a write is requested later.
 371 */
 372/* mmlist_lock and vma->vm_mm->page_table_lock are held */
 373static inline void unuse_pte(struct vm_area_struct * vma, unsigned long address,
 374        pte_t *dir, swp_entry_t entry, struct page* page)
 375{
 376        pte_t pte = *dir;
 377
 378        if (likely(pte_to_swp_entry(pte).val != entry.val))
 379                return;
 380        if (unlikely(pte_none(pte) || pte_present(pte)))
 381                return;
 382        get_page(page);
 383        set_pte(dir, pte_mkold(mk_pte(page, vma->vm_page_prot)));
 384        page_add_rmap(page, dir);
 385        swap_free(entry);
 386        ++vma->vm_mm->rss;
 387}
 388
 389/* mmlist_lock and vma->vm_mm->page_table_lock are held */
 390static inline void unuse_pmd(struct vm_area_struct * vma, pmd_t *dir,
 391        unsigned long address, unsigned long size, unsigned long offset,
 392        swp_entry_t entry, struct page* page)
 393{
 394        pte_t * pte;
 395        unsigned long end;
 396
 397        if (pmd_none(*dir))
 398                return;
 399        if (pmd_bad(*dir)) {
 400                pmd_ERROR(*dir);
 401                pmd_clear(dir);
 402                return;
 403        }
 404        pte = pte_offset_map(dir, address);
 405        offset += address & PMD_MASK;
 406        address &= ~PMD_MASK;
 407        end = address + size;
 408        if (end > PMD_SIZE)
 409                end = PMD_SIZE;
 410        do {
 411                unuse_pte(vma, offset+address-vma->vm_start, pte, entry, page);
 412                address += PAGE_SIZE;
 413                pte++;
 414        } while (address && (address < end));
 415        pte_unmap(pte - 1);
 416}
 417
 418/* mmlist_lock and vma->vm_mm->page_table_lock are held */
 419static inline void unuse_pgd(struct vm_area_struct * vma, pgd_t *dir,
 420        unsigned long address, unsigned long size,
 421        swp_entry_t entry, struct page* page)
 422{
 423        pmd_t * pmd;
 424        unsigned long offset, end;
 425
 426        if (pgd_none(*dir))
 427                return;
 428        if (pgd_bad(*dir)) {
 429                pgd_ERROR(*dir);
 430                pgd_clear(dir);
 431                return;
 432        }
 433        pmd = pmd_offset(dir, address);
 434        offset = address & PGDIR_MASK;
 435        address &= ~PGDIR_MASK;
 436        end = address + size;
 437        if (end > PGDIR_SIZE)
 438                end = PGDIR_SIZE;
 439        if (address >= end)
 440                BUG();
 441        do {
 442                unuse_pmd(vma, pmd, address, end - address, offset, entry,
 443                          page);
 444                address = (address + PMD_SIZE) & PMD_MASK;
 445                pmd++;
 446        } while (address && (address < end));
 447}
 448
 449/* mmlist_lock and vma->vm_mm->page_table_lock are held */
 450static void unuse_vma(struct vm_area_struct * vma, pgd_t *pgdir,
 451                        swp_entry_t entry, struct page* page)
 452{
 453        unsigned long start = vma->vm_start, end = vma->vm_end;
 454
 455        if (start >= end)
 456                BUG();
 457        do {
 458                unuse_pgd(vma, pgdir, start, end - start, entry, page);
 459                start = (start + PGDIR_SIZE) & PGDIR_MASK;
 460                pgdir++;
 461        } while (start && (start < end));
 462}
 463
 464static void unuse_process(struct mm_struct * mm,
 465                        swp_entry_t entry, struct page* page)
 466{
 467        struct vm_area_struct* vma;
 468
 469        /*
 470         * Go through process' page directory.
 471         */
 472        spin_lock(&mm->page_table_lock);
 473        for (vma = mm->mmap; vma; vma = vma->vm_next) {
 474                pgd_t * pgd = pgd_offset(mm, vma->vm_start);
 475                unuse_vma(vma, pgd, entry, page);
 476        }
 477        spin_unlock(&mm->page_table_lock);
 478        return;
 479}
 480
 481/*
 482 * Scan swap_map from current position to next entry still in use.
 483 * Recycle to start on reaching the end, returning 0 when empty.
 484 */
 485static int find_next_to_unuse(struct swap_info_struct *si, int prev)
 486{
 487        int max = si->max;
 488        int i = prev;
 489        int count;
 490
 491        /*
 492         * No need for swap_device_lock(si) here: we're just looking
 493         * for whether an entry is in use, not modifying it; false
 494         * hits are okay, and sys_swapoff() has already prevented new
 495         * allocations from this area (while holding swap_list_lock()).
 496         */
 497        for (;;) {
 498                if (++i >= max) {
 499                        if (!prev) {
 500                                i = 0;
 501                                break;
 502                        }
 503                        /*
 504                         * No entries in use at top of swap_map,
 505                         * loop back to start and recheck there.
 506                         */
 507                        max = prev + 1;
 508                        prev = 0;
 509                        i = 1;
 510                }
 511                count = si->swap_map[i];
 512                if (count && count != SWAP_MAP_BAD)
 513                        break;
 514        }
 515        return i;
 516}
 517
 518/*
 519 * We completely avoid races by reading each swap page in advance,
 520 * and then search for the process using it.  All the necessary
 521 * page table adjustments can then be made atomically.
 522 */
 523static int try_to_unuse(unsigned int type)
 524{
 525        struct swap_info_struct * si = &swap_info[type];
 526        struct mm_struct *start_mm;
 527        unsigned short *swap_map;
 528        unsigned short swcount;
 529        struct page *page;
 530        swp_entry_t entry;
 531        int i = 0;
 532        int retval = 0;
 533        int reset_overflow = 0;
 534
 535        /*
 536         * When searching mms for an entry, a good strategy is to
 537         * start at the first mm we freed the previous entry from
 538         * (though actually we don't notice whether we or coincidence
 539         * freed the entry).  Initialize this start_mm with a hold.
 540         *
 541         * A simpler strategy would be to start at the last mm we
 542         * freed the previous entry from; but that would take less
 543         * advantage of mmlist ordering (now preserved by swap_out()),
 544         * which clusters forked address spaces together, most recent
 545         * child immediately after parent.  If we race with dup_mmap(),
 546         * we very much want to resolve parent before child, otherwise
 547         * we may miss some entries: using last mm would invert that.
 548         */
 549        start_mm = &init_mm;
 550        atomic_inc(&init_mm.mm_users);
 551
 552        /*
 553         * Keep on scanning until all entries have gone.  Usually,
 554         * one pass through swap_map is enough, but not necessarily:
 555         * mmput() removes mm from mmlist before exit_mmap() and its
 556         * zap_page_range().  That's not too bad, those entries are
 557         * on their way out, and handled faster there than here.
 558         * do_munmap() behaves similarly, taking the range out of mm's
 559         * vma list before zap_page_range().  But unfortunately, when
 560         * unmapping a part of a vma, it takes the whole out first,
 561         * then reinserts what's left after (might even reschedule if
 562         * open() method called) - so swap entries may be invisible
 563         * to swapoff for a while, then reappear - but that is rare.
 564         */
 565        while ((i = find_next_to_unuse(si, i))) {
 566                /* 
 567                 * Get a page for the entry, using the existing swap
 568                 * cache page if there is one.  Otherwise, get a clean
 569                 * page and read the swap into it. 
 570                 */
 571                swap_map = &si->swap_map[i];
 572                entry = swp_entry(type, i);
 573                page = read_swap_cache_async(entry);
 574                if (!page) {
 575                        /*
 576                         * Either swap_duplicate() failed because entry
 577                         * has been freed independently, and will not be
 578                         * reused since sys_swapoff() already disabled
 579                         * allocation from here, or alloc_page() failed.
 580                         */
 581                        if (!*swap_map)
 582                                continue;
 583                        retval = -ENOMEM;
 584                        break;
 585                }
 586
 587                /*
 588                 * Don't hold on to start_mm if it looks like exiting.
 589                 */
 590                if (atomic_read(&start_mm->mm_users) == 1) {
 591                        mmput(start_mm);
 592                        start_mm = &init_mm;
 593                        atomic_inc(&init_mm.mm_users);
 594                }
 595
 596                /*
 597                 * Wait for and lock page.  When do_swap_page races with
 598                 * try_to_unuse, do_swap_page can handle the fault much
 599                 * faster than try_to_unuse can locate the entry.  This
 600                 * apparently redundant "wait_on_page_locked" lets try_to_unuse
 601                 * defer to do_swap_page in such a case - in some tests,
 602                 * do_swap_page and try_to_unuse repeatedly compete.
 603                 */
 604                wait_on_page_locked(page);
 605                wait_on_page_writeback(page);
 606                lock_page(page);
 607                wait_on_page_writeback(page);
 608
 609                /*
 610                 * Remove all references to entry, without blocking.
 611                 * Whenever we reach init_mm, there's no address space
 612                 * to search, but use it as a reminder to search shmem.
 613                 */
 614                swcount = *swap_map;
 615                if (swcount > 1) {
 616                        flush_page_to_ram(page);
 617                        if (start_mm == &init_mm)
 618                                shmem_unuse(entry, page);
 619                        else
 620                                unuse_process(start_mm, entry, page);
 621                }
 622                if (*swap_map > 1) {
 623                        int set_start_mm = (*swap_map >= swcount);
 624                        struct list_head *p = &start_mm->mmlist;
 625                        struct mm_struct *new_start_mm = start_mm;
 626                        struct mm_struct *mm;
 627
 628                        spin_lock(&mmlist_lock);
 629                        while (*swap_map > 1 &&
 630                                        (p = p->next) != &start_mm->mmlist) {
 631                                mm = list_entry(p, struct mm_struct, mmlist);
 632                                swcount = *swap_map;
 633                                if (mm == &init_mm) {
 634                                        set_start_mm = 1;
 635                                        shmem_unuse(entry, page);
 636                                } else
 637                                        unuse_process(mm, entry, page);
 638                                if (set_start_mm && *swap_map < swcount) {
 639                                        new_start_mm = mm;
 640                                        set_start_mm = 0;
 641                                }
 642                        }
 643                        atomic_inc(&new_start_mm->mm_users);
 644                        spin_unlock(&mmlist_lock);
 645                        mmput(start_mm);
 646                        start_mm = new_start_mm;
 647                }
 648
 649                /*
 650                 * How could swap count reach 0x7fff when the maximum
 651                 * pid is 0x7fff, and there's no way to repeat a swap
 652                 * page within an mm (except in shmem, where it's the
 653                 * shared object which takes the reference count)?
 654                 * We believe SWAP_MAP_MAX cannot occur in Linux 2.4.
 655                 *
 656                 * If that's wrong, then we should worry more about
 657                 * exit_mmap() and do_munmap() cases described above:
 658                 * we might be resetting SWAP_MAP_MAX too early here.
 659                 * We know "Undead"s can happen, they're okay, so don't
 660                 * report them; but do report if we reset SWAP_MAP_MAX.
 661                 */
 662                if (*swap_map == SWAP_MAP_MAX) {
 663                        swap_list_lock();
 664                        swap_device_lock(si);
 665                        nr_swap_pages++;
 666                        *swap_map = 1;
 667                        swap_device_unlock(si);
 668                        swap_list_unlock();
 669                        reset_overflow = 1;
 670                }
 671
 672                /*
 673                 * If a reference remains (rare), we would like to leave
 674                 * the page in the swap cache; but try_to_swap_out could
 675                 * then re-duplicate the entry once we drop page lock,
 676                 * so we might loop indefinitely; also, that page could
 677                 * not be swapped out to other storage meanwhile.  So:
 678                 * delete from cache even if there's another reference,
 679                 * after ensuring that the data has been saved to disk -
 680                 * since if the reference remains (rarer), it will be
 681                 * read from disk into another page.  Splitting into two
 682                 * pages would be incorrect if swap supported "shared
 683                 * private" pages, but they are handled by tmpfs files.
 684                 * Note shmem_unuse already deleted its from swap cache.
 685                 */
 686                if ((*swap_map > 1) && PageDirty(page) && PageSwapCache(page)) {
 687                        swap_writepage(page);
 688                        lock_page(page);
 689                        wait_on_page_writeback(page);
 690                }
 691                if (PageSwapCache(page))
 692                        delete_from_swap_cache(page);
 693
 694                /*
 695                 * So we could skip searching mms once swap count went
 696                 * to 1, we did not mark any present ptes as dirty: must
 697                 * mark page dirty so try_to_swap_out will preserve it.
 698                 */
 699                SetPageDirty(page);
 700                unlock_page(page);
 701                page_cache_release(page);
 702
 703                /*
 704                 * Make sure that we aren't completely killing
 705                 * interactive performance.  Interruptible check on
 706                 * signal_pending() would be nice, but changes the spec?
 707                 */
 708                if (need_resched())
 709                        schedule();
 710        }
 711
 712        mmput(start_mm);
 713        if (reset_overflow) {
 714                printk(KERN_WARNING "swapoff: cleared swap entry overflow\n");
 715                swap_overflow = 0;
 716        }
 717        return retval;
 718}
 719
 720/*
 721 * Use this swapdev's extent info to locate the (PAGE_SIZE) block which
 722 * corresponds to page offset `offset'.
 723 */
 724sector_t map_swap_page(struct swap_info_struct *sis, pgoff_t offset)
 725{
 726        struct swap_extent *se = sis->curr_swap_extent;
 727        struct swap_extent *start_se = se;
 728
 729        for ( ; ; ) {
 730                struct list_head *lh;
 731
 732                if (se->start_page <= offset &&
 733                                offset < (se->start_page + se->nr_pages)) {
 734                        return se->start_block + (offset - se->start_page);
 735                }
 736                lh = se->list.prev;
 737                if (lh == &sis->extent_list)
 738                        lh = lh->prev;
 739                se = list_entry(lh, struct swap_extent, list);
 740                sis->curr_swap_extent = se;
 741                BUG_ON(se == start_se);         /* It *must* be present */
 742        }
 743}
 744
 745/*
 746 * Free all of a swapdev's extent information
 747 */
 748static void destroy_swap_extents(struct swap_info_struct *sis)
 749{
 750        while (!list_empty(&sis->extent_list)) {
 751                struct swap_extent *se;
 752
 753                se = list_entry(sis->extent_list.next,
 754                                struct swap_extent, list);
 755                list_del(&se->list);
 756                kfree(se);
 757        }
 758        sis->nr_extents = 0;
 759}
 760
 761/*
 762 * Add a block range (and the corresponding page range) into this swapdev's
 763 * extent list.  The extent list is kept sorted in block order.
 764 *
 765 * This function rather assumes that it is called in ascending sector_t order.
 766 * It doesn't look for extent coalescing opportunities.
 767 */
 768static int
 769add_swap_extent(struct swap_info_struct *sis, unsigned long start_page,
 770                unsigned long nr_pages, sector_t start_block)
 771{
 772        struct swap_extent *se;
 773        struct swap_extent *new_se;
 774        struct list_head *lh;
 775
 776        lh = sis->extent_list.next;     /* The highest-addressed block */
 777        while (lh != &sis->extent_list) {
 778                se = list_entry(lh, struct swap_extent, list);
 779                if (se->start_block + se->nr_pages == start_block) {
 780                        /* Merge it */
 781                        se->nr_pages += nr_pages;
 782                        return 0;
 783                }
 784                lh = lh->next;
 785        }
 786
 787        /*
 788         * No merge.  Insert a new extent, preserving ordering.
 789         */
 790        new_se = kmalloc(sizeof(*se), GFP_KERNEL);
 791        if (new_se == NULL)
 792                return -ENOMEM;
 793        new_se->start_page = start_page;
 794        new_se->nr_pages = nr_pages;
 795        new_se->start_block = start_block;
 796
 797        lh = sis->extent_list.prev;     /* The lowest block */
 798        while (lh != &sis->extent_list) {
 799                se = list_entry(lh, struct swap_extent, list);
 800                if (se->start_block > start_block)
 801                        break;
 802                lh = lh->prev;
 803        }
 804        list_add_tail(&new_se->list, lh);
 805        sis->nr_extents++;
 806        return 0;
 807}
 808
 809/*
 810 * A `swap extent' is a simple thing which maps a contiguous range of pages
 811 * onto a contiguous range of disk blocks.  An ordered list of swap extents
 812 * is built at swapon time and is then used at swap_writepage/swap_readpage
 813 * time for locating where on disk a page belongs.
 814 *
 815 * If the swapfile is an S_ISBLK block device, a single extent is installed.
 816 * This is done so that the main operating code can treat S_ISBLK and S_ISREG
 817 * swap files identically.
 818 *
 819 * Whether the swapdev is an S_ISREG file or an S_ISBLK blockdev, the swap
 820 * extent list operates in PAGE_SIZE disk blocks.  Both S_ISREG and S_ISBLK
 821 * swapfiles are handled *identically* after swapon time.
 822 *
 823 * For S_ISREG swapfiles, setup_swap_extents() will walk all the file's blocks
 824 * and will parse them into an ordered extent list, in PAGE_SIZE chunks.  If
 825 * some stray blocks are found which do not fall within the PAGE_SIZE alignment
 826 * requirements, they are simply tossed out - we will never use those blocks
 827 * for swapping.
 828 *
 829 * The amount of disk space which a single swap extent represents varies.
 830 * Typically it is in the 1-4 megabyte range.  So we can have hundreds of
 831 * extents in the list.  To avoid much list walking, we cache the previous
 832 * search location in `curr_swap_extent', and start new searches from there.
 833 * This is extremely effective.  The average number of iterations in
 834 * map_swap_page() has been measured at about 0.3 per page.  - akpm.
 835 */
 836static int setup_swap_extents(struct swap_info_struct *sis)
 837{
 838        struct inode *inode;
 839        unsigned blocks_per_page;
 840        unsigned long page_no;
 841        unsigned blkbits;
 842        sector_t probe_block;
 843        sector_t last_block;
 844        int ret;
 845
 846        inode = sis->swap_file->f_dentry->d_inode;
 847        if (S_ISBLK(inode->i_mode)) {
 848                ret = add_swap_extent(sis, 0, sis->max, 0);
 849                goto done;
 850        }
 851
 852        blkbits = inode->i_blkbits;
 853        blocks_per_page = PAGE_SIZE >> blkbits;
 854
 855        /*
 856         * Map all the blocks into the extent list.  This code doesn't try
 857         * to be very smart.
 858         */
 859        probe_block = 0;
 860        page_no = 0;
 861        last_block = inode->i_size >> blkbits;
 862        while ((probe_block + blocks_per_page) <= last_block &&
 863                        page_no < sis->max) {
 864                unsigned block_in_page;
 865                sector_t first_block;
 866
 867                first_block = bmap(inode, probe_block);
 868                if (first_block == 0)
 869                        goto bad_bmap;
 870
 871                /*
 872                 * It must be PAGE_SIZE aligned on-disk
 873                 */
 874                if (first_block & (blocks_per_page - 1)) {
 875                        probe_block++;
 876                        goto reprobe;
 877                }
 878
 879                for (block_in_page = 1; block_in_page < blocks_per_page;
 880                                        block_in_page++) {
 881                        sector_t block;
 882
 883                        block = bmap(inode, probe_block + block_in_page);
 884                        if (block == 0)
 885                                goto bad_bmap;
 886                        if (block != first_block + block_in_page) {
 887                                /* Discontiguity */
 888                                probe_block++;
 889                                goto reprobe;
 890                        }
 891                }
 892
 893                /*
 894                 * We found a PAGE_SIZE-length, PAGE_SIZE-aligned run of blocks
 895                 */
 896                ret = add_swap_extent(sis, page_no, 1,
 897                                first_block >> (PAGE_SHIFT - blkbits));
 898                if (ret)
 899                        goto out;
 900                page_no++;
 901                probe_block += blocks_per_page;
 902reprobe:
 903                continue;
 904        }
 905        ret = 0;
 906        if (page_no == 0)
 907                ret = -EINVAL;
 908        sis->max = page_no;
 909        sis->highest_bit = page_no - 1;
 910done:
 911        sis->curr_swap_extent = list_entry(sis->extent_list.prev,
 912                                        struct swap_extent, list);
 913        goto out;
 914bad_bmap:
 915        printk(KERN_ERR "swapon: swapfile has holes\n");
 916        ret = -EINVAL;
 917out:
 918        return ret;
 919}
 920
 921asmlinkage long sys_swapoff(const char * specialfile)
 922{
 923        struct swap_info_struct * p = NULL;
 924        unsigned short *swap_map;
 925        struct file *swap_file;
 926        struct nameidata nd;
 927        int i, type, prev;
 928        int err;
 929        
 930        if (!capable(CAP_SYS_ADMIN))
 931                return -EPERM;
 932
 933        err = user_path_walk(specialfile, &nd);
 934        if (err)
 935                goto out;
 936
 937        prev = -1;
 938        swap_list_lock();
 939        for (type = swap_list.head; type >= 0; type = swap_info[type].next) {
 940                p = swap_info + type;
 941                if ((p->flags & SWP_ACTIVE) == SWP_ACTIVE) {
 942                        if (p->swap_file->f_dentry == nd.dentry)
 943                                break;
 944                }
 945                prev = type;
 946        }
 947        err = -EINVAL;
 948        if (type < 0) {
 949                swap_list_unlock();
 950                goto out_dput;
 951        }
 952
 953        if (prev < 0) {
 954                swap_list.head = p->next;
 955        } else {
 956                swap_info[prev].next = p->next;
 957        }
 958        if (type == swap_list.next) {
 959                /* just pick something that's safe... */
 960                swap_list.next = swap_list.head;
 961        }
 962        nr_swap_pages -= p->pages;
 963        total_swap_pages -= p->pages;
 964        p->flags &= ~SWP_WRITEOK;
 965        swap_list_unlock();
 966        err = try_to_unuse(type);
 967        if (err) {
 968                /* re-insert swap space back into swap_list */
 969                swap_list_lock();
 970                for (prev = -1, i = swap_list.head; i >= 0; prev = i, i = swap_info[i].next)
 971                        if (p->prio >= swap_info[i].prio)
 972                                break;
 973                p->next = i;
 974                if (prev < 0)
 975                        swap_list.head = swap_list.next = p - swap_info;
 976                else
 977                        swap_info[prev].next = p - swap_info;
 978                nr_swap_pages += p->pages;
 979                total_swap_pages += p->pages;
 980                p->flags |= SWP_WRITEOK;
 981                swap_list_unlock();
 982                goto out_dput;
 983        }
 984        swap_list_lock();
 985        swap_device_lock(p);
 986        swap_file = p->swap_file;
 987        p->swap_file = NULL;
 988        p->max = 0;
 989        swap_map = p->swap_map;
 990        p->swap_map = NULL;
 991        p->flags = 0;
 992        destroy_swap_extents(p);
 993        swap_device_unlock(p);
 994        swap_list_unlock();
 995        vfree(swap_map);
 996        if (S_ISBLK(swap_file->f_dentry->d_inode->i_mode)) {
 997                struct block_device *bdev;
 998                bdev = swap_file->f_dentry->d_inode->i_bdev;
 999                set_blocksize(bdev, p->old_block_size);
1000                bd_release(bdev);
1001        }
1002        filp_close(swap_file, NULL);
1003        err = 0;
1004
1005out_dput:
1006        path_release(&nd);
1007out:
1008        return err;
1009}
1010
1011int get_swaparea_info(char *buf)
1012{
1013        char * page = (char *) __get_free_page(GFP_KERNEL);
1014        struct swap_info_struct *ptr = swap_info;
1015        int i, len;
1016
1017        if (!page)
1018                return -ENOMEM;
1019
1020        len = sprintf(buf, "Filename\t\t\t\tType\t\tSize\tUsed\tPriority\n");
1021        for (i = 0 ; i < nr_swapfiles ; i++, ptr++) {
1022                int j, usedswap;
1023                struct file *file;
1024                char *path;
1025
1026                if (!(ptr->flags & SWP_USED) || !ptr->swap_map)
1027                        continue;
1028
1029                file = ptr->swap_file;
1030                path = d_path(file->f_dentry, file->f_vfsmnt, page, PAGE_SIZE);
1031                for (j = 0,usedswap = 0; j < ptr->max; ++j)
1032                        switch (ptr->swap_map[j]) {
1033                                case SWAP_MAP_BAD:
1034                                case 0:
1035                                        continue;
1036                                default:
1037                                        usedswap++;
1038                        }
1039                len += sprintf(buf + len, "%-39s %s\t%d\t%d\t%d\n",
1040                               path,
1041                               S_ISBLK(file->f_dentry->d_inode->i_mode) ?
1042                                        "partition" : "file\t",
1043                               ptr->pages << (PAGE_SHIFT - 10),
1044                               usedswap << (PAGE_SHIFT - 10),
1045                               ptr->prio);
1046        }
1047        free_page((unsigned long) page);
1048        return len;
1049}
1050
1051/*
1052 * Written 01/25/92 by Simmule Turner, heavily changed by Linus.
1053 *
1054 * The swapon system call
1055 */
1056asmlinkage long sys_swapon(const char * specialfile, int swap_flags)
1057{
1058        struct swap_info_struct * p;
1059        char *name = NULL;
1060        struct block_device *bdev = NULL;
1061        struct file *swap_file = NULL;
1062        struct address_space *mapping;
1063        unsigned int type;
1064        int i, prev;
1065        int error;
1066        static int least_priority = 0;
1067        union swap_header *swap_header = 0;
1068        int swap_header_version;
1069        int nr_good_pages = 0;
1070        unsigned long maxpages = 1;
1071        int swapfilesize;
1072        unsigned short *swap_map;
1073        struct page *page = NULL;
1074
1075        if (!capable(CAP_SYS_ADMIN))
1076                return -EPERM;
1077        swap_list_lock();
1078        p = swap_info;
1079        for (type = 0 ; type < nr_swapfiles ; type++,p++)
1080                if (!(p->flags & SWP_USED))
1081                        break;
1082        error = -EPERM;
1083        if (type >= MAX_SWAPFILES) {
1084                swap_list_unlock();
1085                goto out;
1086        }
1087        if (type >= nr_swapfiles)
1088                nr_swapfiles = type+1;
1089        INIT_LIST_HEAD(&p->extent_list);
1090        p->flags = SWP_USED;
1091        p->nr_extents = 0;
1092        p->swap_file = NULL;
1093        p->old_block_size = 0;
1094        p->swap_map = NULL;
1095        p->lowest_bit = 0;
1096        p->highest_bit = 0;
1097        p->cluster_nr = 0;
1098        p->sdev_lock = SPIN_LOCK_UNLOCKED;
1099        p->next = -1;
1100        if (swap_flags & SWAP_FLAG_PREFER) {
1101                p->prio =
1102                  (swap_flags & SWAP_FLAG_PRIO_MASK)>>SWAP_FLAG_PRIO_SHIFT;
1103        } else {
1104                p->prio = --least_priority;
1105        }
1106        swap_list_unlock();
1107        name = getname(specialfile);
1108        error = PTR_ERR(name);
1109        if (IS_ERR(name))
1110                goto bad_swap_2;
1111        swap_file = filp_open(name, O_RDWR, 0);
1112        error = PTR_ERR(swap_file);
1113        if (IS_ERR(swap_file)) {
1114                swap_file = NULL;
1115                goto bad_swap_2;
1116        }
1117
1118        p->swap_file = swap_file;
1119
1120        error = -EINVAL;
1121        if (S_ISBLK(swap_file->f_dentry->d_inode->i_mode)) {
1122                bdev = swap_file->f_dentry->d_inode->i_bdev;
1123                error = bd_claim(bdev, sys_swapon);
1124                if (error < 0) {
1125                        bdev = NULL;
1126                        goto bad_swap;
1127                }
1128                p->old_block_size = block_size(bdev);
1129                error = set_blocksize(swap_file->f_dentry->d_inode->i_bdev,
1130                                      PAGE_SIZE);
1131                if (error < 0)
1132                        goto bad_swap;
1133                p->bdev = bdev;
1134        } else if (S_ISREG(swap_file->f_dentry->d_inode->i_mode)) {
1135                p->bdev = swap_file->f_dentry->d_inode->i_sb->s_bdev;
1136        } else {
1137                goto bad_swap;
1138        }
1139
1140        mapping = swap_file->f_dentry->d_inode->i_mapping;
1141        swapfilesize = mapping->host->i_size >> PAGE_SHIFT;
1142
1143        error = -EBUSY;
1144        for (i = 0 ; i < nr_swapfiles ; i++) {
1145                struct swap_info_struct *q = &swap_info[i];
1146                if (i == type || !q->swap_file)
1147                        continue;
1148                if (mapping == q->swap_file->f_dentry->d_inode->i_mapping)
1149                        goto bad_swap;
1150        }
1151
1152        /*
1153         * Read the swap header.
1154         */
1155        page = read_cache_page(mapping, 0,
1156                        (filler_t *)mapping->a_ops->readpage, swap_file);
1157        if (IS_ERR(page)) {
1158                error = PTR_ERR(page);
1159                goto bad_swap;
1160        }
1161        wait_on_page_locked(page);
1162        if (!PageUptodate(page))
1163                goto bad_swap;
1164        kmap(page);
1165        swap_header = page_address(page);
1166
1167        if (!memcmp("SWAP-SPACE",swap_header->magic.magic,10))
1168                swap_header_version = 1;
1169        else if (!memcmp("SWAPSPACE2",swap_header->magic.magic,10))
1170                swap_header_version = 2;
1171        else {
1172                printk("Unable to find swap-space signature\n");
1173                error = -EINVAL;
1174                goto bad_swap;
1175        }
1176        
1177        switch (swap_header_version) {
1178        case 1:
1179                printk(KERN_ERR "version 0 swap is no longer supported. "
1180                        "Use mkswap -v1 %s\n", name);
1181                error = -EINVAL;
1182                goto bad_swap;
1183        case 2:
1184                /* Check the swap header's sub-version and the size of
1185                   the swap file and bad block lists */
1186                if (swap_header->info.version != 1) {
1187                        printk(KERN_WARNING
1188                               "Unable to handle swap header version %d\n",
1189                               swap_header->info.version);
1190                        error = -EINVAL;
1191                        goto bad_swap;
1192                }
1193
1194                p->lowest_bit  = 1;
1195                maxpages = swp_offset(swp_entry(0,~0UL)) - 1;
1196                if (maxpages > swap_header->info.last_page)
1197                        maxpages = swap_header->info.last_page;
1198                p->highest_bit = maxpages - 1;
1199
1200                error = -EINVAL;
1201                if (swap_header->info.nr_badpages > MAX_SWAP_BADPAGES)
1202                        goto bad_swap;
1203                
1204                /* OK, set up the swap map and apply the bad block list */
1205                if (!(p->swap_map = vmalloc(maxpages * sizeof(short)))) {
1206                        error = -ENOMEM;
1207                        goto bad_swap;
1208                }
1209
1210                error = 0;
1211                memset(p->swap_map, 0, maxpages * sizeof(short));
1212                for (i=0; i<swap_header->info.nr_badpages; i++) {
1213                        int page = swap_header->info.badpages[i];
1214                        if (page <= 0 || page >= swap_header->info.last_page)
1215                                error = -EINVAL;
1216                        else
1217                                p->swap_map[page] = SWAP_MAP_BAD;
1218                }
1219                nr_good_pages = swap_header->info.last_page -
1220                                swap_header->info.nr_badpages -
1221                                1 /* header page */;
1222                if (error) 
1223                        goto bad_swap;
1224        }
1225        
1226        if (swapfilesize && maxpages > swapfilesize) {
1227                printk(KERN_WARNING
1228                       "Swap area shorter than signature indicates\n");
1229                error = -EINVAL;
1230                goto bad_swap;
1231        }
1232        if (!nr_good_pages) {
1233                printk(KERN_WARNING "Empty swap-file\n");
1234                error = -EINVAL;
1235                goto bad_swap;
1236        }
1237        p->swap_map[0] = SWAP_MAP_BAD;
1238        p->max = maxpages;
1239        p->pages = nr_good_pages;
1240
1241        if (setup_swap_extents(p))
1242                goto bad_swap;
1243
1244        swap_list_lock();
1245        swap_device_lock(p);
1246        p->flags = SWP_ACTIVE;
1247        nr_swap_pages += nr_good_pages;
1248        total_swap_pages += nr_good_pages;
1249        printk(KERN_INFO "Adding %dk swap on %s.  Priority:%d extents:%d\n",
1250                nr_good_pages<<(PAGE_SHIFT-10), name,
1251                p->prio, p->nr_extents);
1252
1253        /* insert swap space into swap_list: */
1254        prev = -1;
1255        for (i = swap_list.head; i >= 0; i = swap_info[i].next) {
1256                if (p->prio >= swap_info[i].prio) {
1257                        break;
1258                }
1259                prev = i;
1260        }
1261        p->next = i;
1262        if (prev < 0) {
1263                swap_list.head = swap_list.next = p - swap_info;
1264        } else {
1265                swap_info[prev].next = p - swap_info;
1266        }
1267        swap_device_unlock(p);
1268        swap_list_unlock();
1269        error = 0;
1270        goto out;
1271bad_swap:
1272        if (bdev) {
1273                set_blocksize(bdev, p->old_block_size);
1274                bd_release(bdev);
1275        }
1276bad_swap_2:
1277        swap_list_lock();
1278        swap_map = p->swap_map;
1279        p->swap_file = NULL;
1280        p->swap_map = NULL;
1281        p->flags = 0;
1282        if (!(swap_flags & SWAP_FLAG_PREFER))
1283                ++least_priority;
1284        swap_list_unlock();
1285        destroy_swap_extents(p);
1286        if (swap_map)
1287                vfree(swap_map);
1288        if (swap_file && !IS_ERR(swap_file))
1289                filp_close(swap_file, NULL);
1290out:
1291        if (page && !IS_ERR(page)) {
1292                kunmap(page);
1293                page_cache_release(page);
1294        }
1295        if (name)
1296                putname(name);
1297        return error;
1298}
1299
1300void si_swapinfo(struct sysinfo *val)
1301{
1302        unsigned int i;
1303        unsigned long nr_to_be_unused = 0;
1304
1305        swap_list_lock();
1306        for (i = 0; i < nr_swapfiles; i++) {
1307                unsigned int j;
1308                if (!(swap_info[i].flags & SWP_USED) ||
1309                     (swap_info[i].flags & SWP_WRITEOK))
1310                        continue;
1311                for (j = 0; j < swap_info[i].max; ++j) {
1312                        switch (swap_info[i].swap_map[j]) {
1313                                case 0:
1314                                case SWAP_MAP_BAD:
1315                                        continue;
1316                                default:
1317                                        nr_to_be_unused++;
1318                        }
1319                }
1320        }
1321        val->freeswap = nr_swap_pages + nr_to_be_unused;
1322        val->totalswap = total_swap_pages + nr_to_be_unused;
1323        swap_list_unlock();
1324}
1325
1326/*
1327 * Verify that a swap entry is valid and increment its swap map count.
1328 *
1329 * Note: if swap_map[] reaches SWAP_MAP_MAX the entries are treated as
1330 * "permanent", but will be reclaimed by the next swapoff.
1331 */
1332int swap_duplicate(swp_entry_t entry)
1333{
1334        struct swap_info_struct * p;
1335        unsigned long offset, type;
1336        int result = 0;
1337
1338        type = swp_type(entry);
1339        if (type >= nr_swapfiles)
1340                goto bad_file;
1341        p = type + swap_info;
1342        offset = swp_offset(entry);
1343
1344        swap_device_lock(p);
1345        if (offset < p->max && p->swap_map[offset]) {
1346                if (p->swap_map[offset] < SWAP_MAP_MAX - 1) {
1347                        p->swap_map[offset]++;
1348                        result = 1;
1349                } else if (p->swap_map[offset] <= SWAP_MAP_MAX) {
1350                        if (swap_overflow++ < 5)
1351                                printk(KERN_WARNING "swap_dup: swap entry overflow\n");
1352                        p->swap_map[offset] = SWAP_MAP_MAX;
1353                        result = 1;
1354                }
1355        }
1356        swap_device_unlock(p);
1357out:
1358        return result;
1359
1360bad_file:
1361        printk(KERN_ERR "swap_dup: %s%08lx\n", Bad_file, entry.val);
1362        goto out;
1363}
1364
1365struct swap_info_struct *
1366get_swap_info_struct(unsigned type)
1367{
1368        return &swap_info[type];
1369}
1370
1371/*
1372 * swap_device_lock prevents swap_map being freed. Don't grab an extra
1373 * reference on the swaphandle, it doesn't matter if it becomes unused.
1374 */
1375int valid_swaphandles(swp_entry_t entry, unsigned long *offset)
1376{
1377        int ret = 0, i = 1 << page_cluster;
1378        unsigned long toff;
1379        struct swap_info_struct *swapdev = swp_type(entry) + swap_info;
1380
1381        if (!page_cluster)      /* no readahead */
1382                return 0;
1383        toff = (swp_offset(entry) >> page_cluster) << page_cluster;
1384        if (!toff)              /* first page is swap header */
1385                toff++, i--;
1386        *offset = toff;
1387
1388        swap_device_lock(swapdev);
1389        do {
1390                /* Don't read-ahead past the end of the swap area */
1391                if (toff >= swapdev->max)
1392                        break;
1393                /* Don't read in free or bad pages */
1394                if (!swapdev->swap_map[toff])
1395                        break;
1396                if (swapdev->swap_map[toff] == SWAP_MAP_BAD)
1397                        break;
1398                toff++;
1399                ret++;
1400        } while (--i);
1401        swap_device_unlock(swapdev);
1402        return ret;
1403}
1404
lxr.linux.no kindly hosted by Redpill Linpro AS, provider of Linux consulting and operations services since 1995.