Subversion Repositories HelenOS-historic

Rev

Rev 479 | Rev 489 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 479 Rev 480
Line 1... Line 1...
1
/*
1
/*
2
 * Copyright (C) 2005 Jakub Jermar
2
 * Copyright (C) 2005 Jakub Jermar
-
 
3
 * Copyright (C) 2005 Sergey Bondari
3
 * All rights reserved.
4
 * All rights reserved.
4
 *
5
 *
5
 * Redistribution and use in source and binary forms, with or without
6
 * Redistribution and use in source and binary forms, with or without
6
 * modification, are permitted provided that the following conditions
7
 * modification, are permitted provided that the following conditions
7
 * are met:
8
 * are met:
Line 36... Line 37...
36
#include <mm/buddy.h>
37
#include <mm/buddy.h>
37
 
38
 
38
#define FRAME_KA    1   /* skip frames conflicting with user address space */
39
#define FRAME_KA    1   /* skip frames conflicting with user address space */
39
#define FRAME_PANIC 2   /* panic on failure */
40
#define FRAME_PANIC 2   /* panic on failure */
40
 
41
 
41
#define FRAME2ADDR(zone, frame)     ((zone)->base + ((frame) - (zone)->frames) * FRAME_SIZE)
42
#define FRAME2ADDR(zone, frame)         ((zone)->base + ((frame) - (zone)->frames) * FRAME_SIZE)
42
#define ADDR2FRAME(zone, addr)      (&((zone)->frames[((addr) - (zone)->base) / FRAME_SIZE]))
43
#define ADDR2FRAME(zone, addr)          (&((zone)->frames[((addr) - (zone)->base) / FRAME_SIZE]))
-
 
44
#define FRAME_INDEX(zone, frame)        ((count_t)((frame) - (zone)->frames))
-
 
45
#define IS_BUDDY_LEFT_BLOCK(zone, frame)    ((FRAME_INDEX((zone), (frame)) % (1 >> ((frame)->buddy_order + 1))) == 0)
-
 
46
#define IS_BUDDY_RIGHT_BLOCK(zone, frame)   ((FRAME_INDEX((zone), (frame)) % (1 >> ((frame)->buddy_order + 1))) == (1 >> (frame)->buddy_order))
-
 
47
 
-
 
48
 
43
 
49
 
44
struct zone {
50
struct zone {
45
    link_t link;        /**< link to previous and next zone */
51
    link_t link;        /**< link to previous and next zone */
46
 
52
 
47
    spinlock_t lock;    /**< this lock protects everything below */
53
    spinlock_t lock;    /**< this lock protects everything below */
Line 49... Line 55...
49
    frame_t *frames;    /**< array of frame_t structures in this zone */
55
    frame_t *frames;    /**< array of frame_t structures in this zone */
50
    link_t free_head;   /**< list of free frame_t structures */
56
    link_t free_head;   /**< list of free frame_t structures */
51
    count_t free_count; /**< number of frame_t structures in free list */
57
    count_t free_count; /**< number of frame_t structures in free list */
52
    count_t busy_count; /**< number of frame_t structures not in free list */
58
    count_t busy_count; /**< number of frame_t structures not in free list */
53
   
59
   
54
    buddy_system_t * buddy_system; /**< buddy system allocator for the zone */
60
    buddy_system_t * buddy_system; /**< buddy system for the zone */
55
    int flags;
61
    int flags;
56
};
62
};
57
 
63
 
58
struct frame {
64
struct frame {
59
    count_t refcount;   /**< when == 0, the frame is in free list */
65
    count_t refcount;   /**< when == 0, the frame is in free list */
60
    link_t link;        /**< link to zone free list when refcount == 0 */
66
    link_t link;        /**< link to zone free list when refcount == 0 */
61
    __u8 order;     /**< buddy system  block order */
67
    __u8 buddy_order;   /**< buddy system block order */
62
    link_t buddy_link;  /**< link to the next free block inside one order*/
68
    link_t buddy_link;  /**< link to the next free block inside one order*/
63
};
69
};
64
 
70
 
65
extern spinlock_t zone_head_lock;   /**< this lock protects zone_head list */
71
extern spinlock_t zone_head_lock;   /**< this lock protects zone_head list */
66
extern link_t zone_head;        /**< list of all zones in the system */
72
extern link_t zone_head;        /**< list of all zones in the system */
Line 73... Line 79...
73
extern void frame_initialize(frame_t *frame, zone_t *zone);
79
extern void frame_initialize(frame_t *frame, zone_t *zone);
74
__address frame_alloc(int flags);
80
__address frame_alloc(int flags);
75
extern void frame_free(__address addr);
81
extern void frame_free(__address addr);
76
extern void frame_not_free(__address addr);
82
extern void frame_not_free(__address addr);
77
extern void frame_region_not_free(__address start, __address stop);
83
extern void frame_region_not_free(__address start, __address stop);
-
 
84
zone_t * get_zone_by_frame(frame_t * frame);
78
 
85
 
79
/*
86
/*
80
 * Buddy system operations
87
 * Buddy system operations
81
 */
88
 */
82
link_t * zone_buddy_find_buddy(link_t * buddy);
89
link_t * zone_buddy_find_buddy(link_t * buddy);