달력

2

« 2025/2 »

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
2012. 1. 3. 19:58

bio OS이야기2012. 1. 3. 19:58

buffer_cache 안쓰는 이유?
buffer_cache의 메타데이터가 하나의 섹터를 관리하는데, 메타데이터의 크기가 너무 크다.
그래서, bio구조체를 이용해서 여러개의 섹터를 관리할 수 있는 자료구조를 만들어냈다.

struct bio {
  34        sector_t                bi_sector;      /* device address in 512 byte
  35                                                   sectors */
  36        struct bio              *bi_next;       /* request queue link */
  37        struct block_device     *bi_bdev;
  38        unsigned long           bi_flags;       /* status, command, etc */
  39        unsigned long           bi_rw;          /* bottom bits READ/WRITE,
  40                                                 * top bits priority
  41                                                 */
  42
  43        unsigned short          bi_vcnt;        /* how many bio_vec's */
  44        unsigned short          bi_idx;         /* current index into bvl_vec */
  45
  46        /* Number of segments in this BIO after
  47         * physical address coalescing is performed.
  48         */
  49        unsigned int            bi_phys_segments;
  50
  51        unsigned int            bi_size;        /* residual I/O count */
  52
  53        /*
  54         * To keep track of the max segment size, we account for the
  55         * sizes of the first and last mergeable segments in this bio.
  56         */
  57        unsigned int            bi_seg_front_size;
  58        unsigned int            bi_seg_back_size;
  59
  60        unsigned int            bi_max_vecs;    /* max bvl_vecs we can hold */
  61
  62        unsigned int            bi_comp_cpu;    /* completion CPU */
  63
  64        atomic_t                bi_cnt;         /* pin count */
  65
  66        struct bio_vec          *bi_io_vec;     /* the actual vec list */
  67
  68        bio_end_io_t            *bi_end_io;
  69
  70        void                    *bi_private;
  71#if defined(CONFIG_BLK_DEV_INTEGRITY)
  72        struct bio_integrity_payload *bi_integrity;  /* data integrity */
  73#endif
  74
  75        bio_destructor_t        *bi_destructor; /* destructor */
  76
  77        /*
  78         * We can inline a number of vecs at the end of the bio, to avoid
  79         * double allocations for a small number of bio_vecs. This member
  80         * MUST obviously be kept at the very end of the bio.
  81         */
  82        struct bio_vec          bi_inline_vecs[0]; 
83};

 
 
struct block_device {
 660        dev_t                   bd_dev;  /* not a kdev_t - it's a search key */
 661        int                     bd_openers;
 662        struct inode *          bd_inode;       /* will die */
 663        struct super_block *    bd_super;
 664        struct mutex            bd_mutex;       /* open/close mutex */
 665        struct list_head        bd_inodes;
 666        void *                  bd_claiming;
 667        void *                  bd_holder;
 668        int                     bd_holders;
 669        bool                    bd_write_holder;
 670#ifdef CONFIG_SYSFS
 671        struct list_head        bd_holder_disks;
 672#endif
 673        struct block_device *   bd_contains;
 674        unsigned                bd_block_size;
 675        struct hd_struct *      bd_part;
 676        /* number of times partitions within this device have been opened. */
 677        unsigned                bd_part_count;
 678        int                     bd_invalidated;
 679        struct gendisk *        bd_disk;
 680        struct list_head        bd_list;
 681        /*
 682         * Private data.  You must have bd_claim'ed the block_device
 683         * to use this.  NOTE:  bd_claim allows an owner to claim
 684         * the same device multiple times, the owner must take special
 685         * care to not mess up bd_private for that case.
 686         */
 687        unsigned long           bd_private;
 688
 689        /* The counter of freeze processes */
 690        int                     bd_fsfreeze_count;
 691        /* Mutex for freeze */
 692        struct mutex            bd_fsfreeze_mutex
693}; 

struct gendisk {
 156        /* major, first_minor and minors are input parameters only,
 157         * don't use directly.  Use disk_devt() and disk_max_parts().
 158         */
 159        int major;                      /* major number of driver */
 160        int first_minor;
 161        int minors;                     /* maximum number of minors, =1 for
 162                                         * disks that can't be partitioned. */
 163
 164        char disk_name[DISK_NAME_LEN];  /* name of major driver */
 165        char *(*devnode)(struct gendisk *gd, mode_t *mode);
 166
 167        unsigned int events;            /* supported events */
 168        unsigned int async_events;      /* async events, subset of all */
 169
 170        /* Array of pointers to partitions indexed by partno.
 171         * Protected with matching bdev lock but stat and other
 172         * non-critical accesses use RCU.  Always access through
 173         * helpers.
 174         */
 175        struct disk_part_tbl __rcu *part_tbl;
 176        struct hd_struct part0;
 177
 178        const struct block_device_operations *fops;
 179        struct request_queue *queue;
 180        void *private_data;
 181
 182        int flags;
 183        struct device *driverfs_dev;  // FIXME: remove
 184        struct kobject *slave_dir;
 185
 186        struct timer_rand_state *random;
 187        atomic_t sync_io;               /* RAID */
 188        struct disk_events *ev;
 189#ifdef  CONFIG_BLK_DEV_INTEGRITY
 190        struct blk_integrity *integrity;
 191#endif
 192        int node_id
193}; 

struct root_device_t *root_dev = (struct root_device_t *)bio->bi_bdev->bd_disk->private_data;

strucr root_device_t 는 블록 디바이스를 다루기위해 모듈내에 선언한 자료구조
 

'OS이야기' 카테고리의 다른 글

mm_struct, vm_area_struct  (0) 2012.01.03
kmap() 함수  (0) 2012.01.03
프로세스의 .text, .data, .lib 구하기  (0) 2012.01.02
proc  (0) 2011.12.31
문자 디바이스 호출과정  (0) 2011.12.31
:
Posted by НooпeУ


Code Start Code End