mmu.c 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /* mmu.c: mmu memory info files
  2. *
  3. * Copyright (C) 2004 Red Hat, Inc. All Rights Reserved.
  4. * Written by David Howells (dhowells@redhat.com)
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License
  8. * as published by the Free Software Foundation; either version
  9. * 2 of the License, or (at your option) any later version.
  10. */
  11. #include <linux/spinlock.h>
  12. #include <linux/vmalloc.h>
  13. #include <linux/highmem.h>
  14. #include <asm/pgtable.h>
  15. #include "internal.h"
  16. void get_vmalloc_info(struct vmalloc_info *vmi)
  17. {
  18. struct vm_struct *vma;
  19. unsigned long free_area_size;
  20. unsigned long prev_end;
  21. vmi->used = 0;
  22. if (!vmlist) {
  23. vmi->largest_chunk = VMALLOC_TOTAL;
  24. }
  25. else {
  26. vmi->largest_chunk = 0;
  27. prev_end = VMALLOC_START;
  28. read_lock(&vmlist_lock);
  29. for (vma = vmlist; vma; vma = vma->next) {
  30. unsigned long addr = (unsigned long) vma->addr;
  31. /*
  32. * Some archs keep another range for modules in vmlist
  33. */
  34. if (addr < VMALLOC_START)
  35. continue;
  36. if (addr >= VMALLOC_END)
  37. break;
  38. vmi->used += vma->size;
  39. free_area_size = addr - prev_end;
  40. if (vmi->largest_chunk < free_area_size)
  41. vmi->largest_chunk = free_area_size;
  42. prev_end = vma->size + addr;
  43. }
  44. if (VMALLOC_END - prev_end > vmi->largest_chunk)
  45. vmi->largest_chunk = VMALLOC_END - prev_end;
  46. read_unlock(&vmlist_lock);
  47. }
  48. }