《操作系统》的实验代码。
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

65 lines
2.4 KiB

12 years ago
  1. #ifndef __KERN_MM_SWAP_H__
  2. #define __KERN_MM_SWAP_H__
  3. #include <defs.h>
  4. #include <memlayout.h>
  5. #include <pmm.h>
  6. #include <vmm.h>
  7. /* *
  8. * swap_entry_t
  9. * --------------------------------------------
  10. * | offset | reserved | 0 |
  11. * --------------------------------------------
  12. * 24 bits 7 bits 1 bit
  13. * */
  14. #define MAX_SWAP_OFFSET_LIMIT (1 << 24)
  15. extern size_t max_swap_offset;
  16. /* *
  17. * swap_offset - takes a swap_entry (saved in pte), and returns
  18. * the corresponding offset in swap mem_map.
  19. * */
  20. #define swap_offset(entry) ({ \
  21. size_t __offset = (entry >> 8); \
  22. if (!(__offset > 0 && __offset < max_swap_offset)) { \
  23. panic("invalid swap_entry_t = %08x.\n", entry); \
  24. } \
  25. __offset; \
  26. })
  27. struct swap_manager
  28. {
  29. const char *name;
  30. /* Global initialization for the swap manager */
  31. int (*init) (void);
  32. /* Initialize the priv data inside mm_struct */
  33. int (*init_mm) (struct mm_struct *mm);
  34. /* Called when tick interrupt occured */
  35. int (*tick_event) (struct mm_struct *mm);
  36. /* Called when map a swappable page into the mm_struct */
  37. int (*map_swappable) (struct mm_struct *mm, uintptr_t addr, struct Page *page, int swap_in);
  38. /* When a page is marked as shared, this routine is called to
  39. * delete the addr entry from the swap manager */
  40. int (*set_unswappable) (struct mm_struct *mm, uintptr_t addr);
  41. /* Try to swap out a page, return then victim */
  42. int (*swap_out_victim) (struct mm_struct *mm, struct Page **ptr_page, int in_tick);
  43. /* check the page relpacement algorithm */
  44. int (*check_swap)(void);
  45. };
  46. extern volatile int swap_init_ok;
  47. int swap_init(void);
  48. int swap_init_mm(struct mm_struct *mm);
  49. int swap_tick_event(struct mm_struct *mm);
  50. int swap_map_swappable(struct mm_struct *mm, uintptr_t addr, struct Page *page, int swap_in);
  51. int swap_set_unswappable(struct mm_struct *mm, uintptr_t addr);
  52. int swap_out(struct mm_struct *mm, int n, int in_tick);
  53. int swap_in(struct mm_struct *mm, uintptr_t addr, struct Page **ptr_result);
  54. //#define MEMBER_OFFSET(m,t) ((int)(&((t *)0)->m))
  55. //#define FROM_MEMBER(m,t,a) ((t *)((char *)(a) - MEMBER_OFFSET(m,t)))
  56. #endif