aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--mm/page_alloc.c58
1 files changed, 30 insertions, 28 deletions
diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index 6b92a945ae6..ad3d0202cde 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -308,7 +308,7 @@ static inline int page_is_buddy(struct page *page, int order)
308 * -- wli 308 * -- wli
309 */ 309 */
310 310
311static inline void __free_pages_bulk (struct page *page, 311static inline void __free_one_page(struct page *page,
312 struct zone *zone, unsigned int order) 312 struct zone *zone, unsigned int order)
313{ 313{
314 unsigned long page_idx; 314 unsigned long page_idx;
@@ -383,40 +383,42 @@ static inline int free_pages_check(struct page *page)
383 * And clear the zone's pages_scanned counter, to hold off the "all pages are 383 * And clear the zone's pages_scanned counter, to hold off the "all pages are
384 * pinned" detection logic. 384 * pinned" detection logic.
385 */ 385 */
386static int 386static void free_pages_bulk(struct zone *zone, int count,
387free_pages_bulk(struct zone *zone, int count, 387 struct list_head *list, int order)
388 struct list_head *list, unsigned int order)
389{ 388{
390 struct page *page = NULL;
391 int ret = 0;
392
393 spin_lock(&zone->lock); 389 spin_lock(&zone->lock);
394 zone->all_unreclaimable = 0; 390 zone->all_unreclaimable = 0;
395 zone->pages_scanned = 0; 391 zone->pages_scanned = 0;
396 while (!list_empty(list) && count--) { 392 while (count--) {
393 struct page *page;
394
395 BUG_ON(list_empty(list));
397 page = list_entry(list->prev, struct page, lru); 396 page = list_entry(list->prev, struct page, lru);
398 /* have to delete it as __free_pages_bulk list manipulates */ 397 /* have to delete it as __free_one_page list manipulates */
399 list_del(&page->lru); 398 list_del(&page->lru);
400 __free_pages_bulk(page, zone, order); 399 __free_one_page(page, zone, order);
401 ret++;
402 } 400 }
403 spin_unlock(&zone->lock); 401 spin_unlock(&zone->lock);
404 return ret;
405} 402}
406 403
407void __free_pages_ok(struct page *page, unsigned int order) 404static void free_one_page(struct zone *zone, struct page *page, int order)
408{ 405{
409 unsigned long flags;
410 LIST_HEAD(list); 406 LIST_HEAD(list);
407 list_add(&page->lru, &list);
408 free_pages_bulk(zone, 1, &list, order);
409}
410
411static void __free_pages_ok(struct page *page, unsigned int order)
412{
413 unsigned long flags;
411 int i; 414 int i;
412 int reserved = 0; 415 int reserved = 0;
413 416
414 arch_free_page(page, order); 417 arch_free_page(page, order);
415 418
416#ifndef CONFIG_MMU 419#ifndef CONFIG_MMU
417 if (order > 0) 420 for (i = 1 ; i < (1 << order) ; ++i)
418 for (i = 1 ; i < (1 << order) ; ++i) 421 __put_page(page + i);
419 __put_page(page + i);
420#endif 422#endif
421 423
422 for (i = 0 ; i < (1 << order) ; ++i) 424 for (i = 0 ; i < (1 << order) ; ++i)
@@ -424,11 +426,10 @@ void __free_pages_ok(struct page *page, unsigned int order)
424 if (reserved) 426 if (reserved)
425 return; 427 return;
426 428
427 list_add(&page->lru, &list); 429 kernel_map_pages(page, 1 << order, 0);
428 kernel_map_pages(page, 1<<order, 0);
429 local_irq_save(flags); 430 local_irq_save(flags);
430 __mod_page_state(pgfree, 1 << order); 431 __mod_page_state(pgfree, 1 << order);
431 free_pages_bulk(page_zone(page), 1, &list, order); 432 free_one_page(page_zone(page), page, order);
432 local_irq_restore(flags); 433 local_irq_restore(flags);
433} 434}
434 435
@@ -602,9 +603,8 @@ void drain_remote_pages(void)
602 struct per_cpu_pages *pcp; 603 struct per_cpu_pages *pcp;
603 604
604 pcp = &pset->pcp[i]; 605 pcp = &pset->pcp[i];
605 if (pcp->count) 606 free_pages_bulk(zone, pcp->count, &pcp->list, 0);
606 pcp->count -= free_pages_bulk(zone, pcp->count, 607 pcp->count = 0;
607 &pcp->list, 0);
608 } 608 }
609 } 609 }
610 local_irq_restore(flags); 610 local_irq_restore(flags);
@@ -627,8 +627,8 @@ static void __drain_pages(unsigned int cpu)
627 627
628 pcp = &pset->pcp[i]; 628 pcp = &pset->pcp[i];
629 local_irq_save(flags); 629 local_irq_save(flags);
630 pcp->count -= free_pages_bulk(zone, pcp->count, 630 free_pages_bulk(zone, pcp->count, &pcp->list, 0);
631 &pcp->list, 0); 631 pcp->count = 0;
632 local_irq_restore(flags); 632 local_irq_restore(flags);
633 } 633 }
634 } 634 }
@@ -719,8 +719,10 @@ static void fastcall free_hot_cold_page(struct page *page, int cold)
719 __inc_page_state(pgfree); 719 __inc_page_state(pgfree);
720 list_add(&page->lru, &pcp->list); 720 list_add(&page->lru, &pcp->list);
721 pcp->count++; 721 pcp->count++;
722 if (pcp->count >= pcp->high) 722 if (pcp->count >= pcp->high) {
723 pcp->count -= free_pages_bulk(zone, pcp->batch, &pcp->list, 0); 723 free_pages_bulk(zone, pcp->batch, &pcp->list, 0);
724 pcp->count -= pcp->batch;
725 }
724 local_irq_restore(flags); 726 local_irq_restore(flags);
725 put_cpu(); 727 put_cpu();
726} 728}
@@ -759,7 +761,7 @@ static struct page *buffered_rmqueue(struct zonelist *zonelist,
759 761
760again: 762again:
761 cpu = get_cpu(); 763 cpu = get_cpu();
762 if (order == 0) { 764 if (likely(order == 0)) {
763 struct per_cpu_pages *pcp; 765 struct per_cpu_pages *pcp;
764 766
765 pcp = &zone_pcp(zone, cpu)->pcp[cold]; 767 pcp = &zone_pcp(zone, cpu)->pcp[cold];
acct() is the only system call needed to implement process * accounting. It takes the name of the file where accounting records * should be written. If the filename is NULL, accounting will be * shutdown. */ asmlinkage long sys_acct(const char __user *name) { int error; if (!capable(CAP_SYS_PACCT)) return -EPERM; if (name) { char *tmp = getname(name); if (IS_ERR(tmp)) return (PTR_ERR(tmp)); error = acct_on(tmp); putname(tmp); } else { error = security_acct(NULL); if (!error) { spin_lock(&acct_globals.lock); acct_file_reopen(NULL); spin_unlock(&acct_globals.lock); } } return error; } /** * acct_auto_close - turn off a filesystem's accounting if it is on * @m: vfsmount being shut down * * If the accounting is turned on for a file in the subtree pointed to * to by m, turn accounting off. Done when m is about to die. */ void acct_auto_close_mnt(struct vfsmount *m) { spin_lock(&acct_globals.lock); if (acct_globals.file && acct_globals.file->f_path.mnt == m) acct_file_reopen(NULL); spin_unlock(&acct_globals.lock); } /** * acct_auto_close - turn off a filesystem's accounting if it is on * @sb: super block for the filesystem * * If the accounting is turned on for a file in the filesystem pointed * to by sb, turn accounting off. */ void acct_auto_close(struct super_block *sb) { spin_lock(&acct_globals.lock); if (acct_globals.file && acct_globals.file->f_path.mnt->mnt_sb == sb) { acct_file_reopen(NULL); } spin_unlock(&acct_globals.lock); } /* * encode an unsigned long into a comp_t * * This routine has been adopted from the encode_comp_t() function in * the kern_acct.c file of the FreeBSD operating system. The encoding * is a 13-bit fraction with a 3-bit (base 8) exponent. */ #define MANTSIZE 13 /* 13 bit mantissa. */ #define EXPSIZE 3 /* Base 8 (3 bit) exponent. */ #define MAXFRACT ((1 << MANTSIZE) - 1) /* Maximum fractional value. */ static comp_t encode_comp_t(unsigned long value) { int exp, rnd; exp = rnd = 0; while (value > MAXFRACT) { rnd = value & (1 << (EXPSIZE - 1)); /* Round up? */ value >>= EXPSIZE; /* Base 8 exponent == 3 bit shift. */ exp++; } /* * If we need to round up, do it (and handle overflow correctly). */ if (rnd && (++value > MAXFRACT)) { value >>= EXPSIZE; exp++; } /* * Clean it up and polish it off. */ exp <<= MANTSIZE; /* Shift the exponent into place */ exp += value; /* and add on the mantissa. */ return exp; } #if ACCT_VERSION==1 || ACCT_VERSION==2 /* * encode an u64 into a comp2_t (24 bits) * * Format: 5 bit base 2 exponent, 20 bits mantissa. * The leading bit of the mantissa is not stored, but implied for * non-zero exponents. * Largest encodable value is 50 bits. */ #define MANTSIZE2 20 /* 20 bit mantissa. */ #define EXPSIZE2 5 /* 5 bit base 2 exponent. */ #define MAXFRACT2 ((1ul << MANTSIZE2) - 1) /* Maximum fractional value. */ #define MAXEXP2 ((1 <<EXPSIZE2) - 1) /* Maximum exponent. */ static comp2_t encode_comp2_t(u64 value) { int exp, rnd; exp = (value > (MAXFRACT2>>1)); rnd = 0; while (value > MAXFRACT2) { rnd = value & 1; value >>= 1; exp++; } /* * If we need to round up, do it (and handle overflow correctly). */ if (rnd && (++value > MAXFRACT2)) { value >>= 1; exp++; } if (exp > MAXEXP2) { /* Overflow. Return largest representable number instead. */ return (1ul << (MANTSIZE2+EXPSIZE2-1)) - 1; } else { return (value & (MAXFRACT2>>1)) | (exp << (MANTSIZE2-1)); } } #endif #if ACCT_VERSION==3 /* * encode an u64 into a 32 bit IEEE float */ static u32 encode_float(u64 value) { unsigned exp = 190; unsigned u; if (value==0) return 0; while ((s64)value > 0){ value <<= 1; exp--; } u = (u32)(value >> 40) & 0x7fffffu; return u | (exp << 23); } #endif /* * Write an accounting entry for an exiting process * * The acct_process() call is the workhorse of the process * accounting system. The struct acct is built here and then written * into the accounting file. This function should only be called from * do_exit() or when switching to a different output file. */ /* * do_acct_process does all actual work. Caller holds the reference to file. */ static void do_acct_process(struct pid_namespace *ns, struct file *file) { struct pacct_struct *pacct = &current->signal->pacct; acct_t ac; mm_segment_t fs; unsigned long flim; u64 elapsed; u64 run_time; struct timespec uptime; struct tty_struct *tty; /* * First check to see if there is enough free_space to continue * the process accounting system. */ if (!check_free_space(file)) return; /* * Fill the accounting struct with the needed info as recorded * by the different kernel functions. */ memset((caddr_t)&ac, 0, sizeof(acct_t)); ac.ac_version = ACCT_VERSION | ACCT_BYTEORDER; strlcpy(ac.ac_comm, current->comm, sizeof(ac.ac_comm)); /* calculate run_time in nsec*/ do_posix_clock_monotonic_gettime(&uptime); run_time = (u64)uptime.tv_sec*NSEC_PER_SEC + uptime.tv_nsec; run_time -= (u64)current->group_leader->start_time.tv_sec * NSEC_PER_SEC + current->group_leader->start_time.tv_nsec; /* convert nsec -> AHZ */ elapsed = nsec_to_AHZ(run_time); #if ACCT_VERSION==3 ac.ac_etime = encode_float(elapsed); #else ac.ac_etime = encode_comp_t(elapsed < (unsigned long) -1l ? (unsigned long) elapsed : (unsigned long) -1l); #endif #if ACCT_VERSION==1 || ACCT_VERSION==2 { /* new enlarged etime field */ comp2_t etime = encode_comp2_t(elapsed); ac.ac_etime_hi = etime >> 16; ac.ac_etime_lo = (u16) etime; } #endif do_div(elapsed, AHZ); ac.ac_btime = get_seconds() - elapsed; /* we really need to bite the bullet and change layout */ ac.ac_uid = current->uid; ac.ac_gid = current->gid; #if ACCT_VERSION==2 ac.ac_ahz = AHZ; #endif #if ACCT_VERSION==1 || ACCT_VERSION==2 /* backward-compatible 16 bit fields */ ac.ac_uid16 = current->uid; ac.ac_gid16 = current->gid; #endif #if ACCT_VERSION==3 ac.ac_pid = task_tgid_nr_ns(current, ns); rcu_read_lock(); ac.ac_ppid = task_tgid_nr_ns(rcu_dereference(current->real_parent), ns); rcu_read_unlock(); #endif spin_lock_irq(&current->sighand->siglock); tty = current->signal->tty; ac.ac_tty = tty ? old_encode_dev(tty_devnum(tty)) : 0; ac.ac_utime = encode_comp_t(jiffies_to_AHZ(cputime_to_jiffies(pacct->ac_utime))); ac.ac_stime = encode_comp_t(jiffies_to_AHZ(cputime_to_jiffies(pacct->ac_stime))); ac.ac_flag = pacct->ac_flag; ac.ac_mem = encode_comp_t(pacct->ac_mem); ac.ac_minflt = encode_comp_t(pacct->ac_minflt); ac.ac_majflt = encode_comp_t(pacct->ac_majflt); ac.ac_exitcode = pacct->ac_exitcode; spin_unlock_irq(&current->sighand->siglock); ac.ac_io = encode_comp_t(0 /* current->io_usage */); /* %% */ ac.ac_rw = encode_comp_t(ac.ac_io / 1024); ac.ac_swaps = encode_comp_t(0); /* * Kernel segment override to datasegment and write it * to the accounting file. */ fs = get_fs(); set_fs(KERNEL_DS); /* * Accounting records are not subject to resource limits. */ flim = current->signal->rlim[RLIMIT_FSIZE].rlim_cur; current->signal->rlim[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY; file->f_op->write(file, (char *)&ac, sizeof(acct_t), &file->f_pos); current->signal->rlim[RLIMIT_FSIZE].rlim_cur = flim; set_fs(fs); } /** * acct_init_pacct - initialize a new pacct_struct * @pacct: per-process accounting info struct to initialize */ void acct_init_pacct(struct pacct_struct *pacct) { memset(pacct, 0, sizeof(struct pacct_struct)); pacct->ac_utime = pacct->ac_stime = cputime_zero; } /** * acct_collect - collect accounting information into pacct_struct * @exitcode: task exit code * @group_dead: not 0, if this thread is the last one in the process. */ void acct_collect(long exitcode, int group_dead) { struct pacct_struct *pacct = &current->signal->pacct; unsigned long vsize = 0; if (group_dead && current->mm) { struct vm_area_struct *vma; down_read(&current->mm->mmap_sem); vma = current->mm->mmap; while (vma) { vsize += vma->vm_end - vma->vm_start; vma = vma->vm_next; } up_read(&current->mm->mmap_sem); } spin_lock_irq(&current->sighand->siglock); if (group_dead) pacct->ac_mem = vsize / 1024; if (thread_group_leader(current)) { pacct->ac_exitcode = exitcode; if (current->flags & PF_FORKNOEXEC) pacct->ac_flag |= AFORK; } if (current->flags & PF_SUPERPRIV) pacct->ac_flag |= ASU; if (current->flags & PF_DUMPCORE) pacct->ac_flag |= ACORE; if (current->flags & PF_SIGNALED) pacct->ac_flag |= AXSIG; pacct->ac_utime = cputime_add(pacct->ac_utime, current->utime); pacct->ac_stime = cputime_add(pacct->ac_stime, current->stime); pacct->ac_minflt += current->min_flt; pacct->ac_majflt += current->maj_flt; spin_unlock_irq(&current->sighand->siglock); } /** * acct_process - now just a wrapper around do_acct_process * @exitcode: task exit code * * handles process accounting for an exiting task */ void acct_process(void) { struct file *file = NULL; struct pid_namespace *ns; /* * accelerate the common fastpath: */ if (!acct_globals.file) return; spin_lock(&acct_globals.lock); file = acct_globals.file; if (unlikely(!file)) { spin_unlock(&acct_globals.lock); return; } get_file(file); ns = get_pid_ns(acct_globals.ns); spin_unlock(&acct_globals.lock); do_acct_process(ns, file); fput(file); put_pid_ns(ns); }