Data Structures in Memory

To dispense with the need to constantly read administration structures from slow hard disks, Linux saves the most important information that these structures contain in special data structures that reside permanently in RAM. Access is considerably faster, and less interaction with the hard disk is required. Then why aren't all filesystem management data held in RAM (with writeback of changes to disk at regular intervals)? Although theoretically this would be possible, it does not work in practice because so much memory would be required to hold all block and inode bitmaps of a large hard disk with several gigabytes — as found on many computers today.

The virtual filesystem provides an element named u in the struct super_block and struct inode structures. This element is used by the various filesystem implementations to store information not already included in the filesystem-independent contents of the structure. The Second Extended Filesystem uses the ext2_sb_info and ext2_inode_info structures for the same purpose. The latter is of no particular interest as compared to its counterpart on the hard disk.

ext2_sb_info is defined as follows:

struct ext2_sb_info {

unsigned long s_frag_size; /* Size of a fragment in bytes */

unsigned long s_frags_per_block;/* Number of fragments per block */ unsigned long s_inodes_per_block;/* Number of inodes per block */ unsigned long s_frags_per_group;/* Number of fragments in a group */ unsigned long s_blocks_per_group;/* Number of blocks in a group */ unsigned long s_inodes_per_group;/* Number of inodes in a group */ unsigned long s_itb_per_group; /* Number of inode table blocks per group */ unsigned long s_gdb_count; /* Number of group descriptor blocks */

unsigned long s_desc_per_block; /* Number of group descriptors per block */ unsigned long s_groups_count; /* Number of groups in the fs */ unsigned long s_overhead_last; /* Last calculated overhead */ unsigned long s_blocks_last; /* Last seen block count */ struct buffer_head * s_sbh; /* Buffer containing the super block */

struct ext2_super_block * s_es; /* Pointer to the super block in the buffer

struct buffer_head ** s_group_desc;

unsigned long s_mount_opt;

unsigned long s_sb_block;

uid_t s_resuid;

gid_t s_resgid;

unsigned short s_mount_state;

unsigned short s_pad;

int s_addr_per_block_bits;

int s_desc_per_block_bits;

int s_inode_size;

int s_first_ino;

spinlock_t s_next_gen_lock; u32 s_next_generation; unsigned long s_dir_count; u8 *s_debts;

struct percpu_counter s_freeblocks_counter; struct percpu_counter s_freeinodes_counter; struct percpu_counter s_dirs_counter; struct blockgroup_lock s_blockgroup_lock;

What is interesting in the structure definition is the fact that machine-specific data types can be used in place of the bit-oriented variants (u32, etc.). This is because it is not necessary to be able to swap different forms of data representation in memory between machines. Although most elements of the structure are already familiar from the on-disk superblock, some elements are found only in the RAM variant.

□ s_mount_opt holds the mount options, and the current mount state is saved in s_mount_state. The following flags are available for s_mount_opt:

Continue reading here: Info

Was this article helpful?

0 0