当前位置:   article > 正文

linux 文件擦除,linux文件系统如何使用emmc的擦除功能(Erase Trim Discard Sanitize)达到最优performance...

emmc擦除 函数

1、android init.rc中可以看到, 系统启动mount /data 目录时,mount命令添加了参数:discard

mount ext4 /emmc@usrdata /data noatime nosuid nodev wait noauto_da_alloc,discard

2、

mount的discard参数传递到ext4_mount函数的flags参数

//kernel/fs/ext4/super.c

static struct dentry *ext4_mount(struct file_system_type *fs_type, int flags,

const char *dev_name, void *data)

{return mount_bdev(fs_type, flags, dev_name, data, ext4_fill_super);

}

//kernel/fs/super.c

struct dentry *mount_bdev(struct file_system_type *fs_type,

int flags, const char *dev_name, void *data,

int (*fill_super)(struct super_block *, void *, int))

{

struct block_device *bdev;

struct super_block *s;

fmode_t mode = FMODE_READ | FMODE_EXCL;

int error = 0;

.................

s->s_flags = flags | MS_NOSEC;    //将mount flag保存在sb的s_flags成员中

s->s_mode = mode;

strlcpy(s->s_id, bdevname(bdev, b), sizeof(s->s_id));

sb_set_blocksize(s, block_size(bdev));

error = fill_super(s, data, flags & MS_SILENT ? 1 : 0);   //调用ext4的fill super :ext4_fill_super, 通过sb传递mount flag

.........................

return dget(s->s_root);

}

//kernel/fs/ext4/super.c

static int ext4_fill_super(struct super_block *sb, void *data, int silent)

{

...................

if (!parse_options((char *) data,sb, &journal_devnum,

&journal_ioprio, 0))

....................

static const struct mount_opts {

inttoken;

intmount_opt;

intflags;

} ext4_mount_opts[] = {

...........................

{Opt_discard, EXT4_MOUNT_DISCARD, MOPT_SET},

{Opt_nodiscard, EXT4_MOUNT_DISCARD, MOPT_CLEAR},

.............................................

}

2、/kernel/drivers/mmc/card/block.c

if (req && req->cmd_flags & REQ_DISCARD) {

...

ret = mmc_blk_issue_discard_rq(mq, req);

} else if (req && req->cmd_flags & REQ_FLUSH) {

/* complete ongoing async transfer before issuing flush */

if (card->host->areq)

mmc_blk_issue_rw_rq(mq, NULL);

ret = mmc_blk_issue_flush(mq, req);

} else {

ret = mmc_blk_issue_rw_rq(mq, req);

}

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/我家自动化/article/detail/217482
推荐阅读
相关标签
  

闽ICP备14008679号