[PATCH 2/4] mtd: rfd_ftl: add discard support

Sean Young sean at mess.org
Sat Aug 7 01:06:33 PDT 2021


On Fri, Aug 06, 2021 at 08:18:20PM +0200, Miquel Raynal wrote:
> Hi Sean,
> 
> Sean Young <sean at mess.org> wrote on Tue, 13 Jul 2021 10:44:01 +0100:
> 
> > I proposed this change 16 years ago before discard was a feature in
> > the block layer: https://lwn.net/Articles/162776/
> > 
> > Now that the block layer has discard, we can finally merge this change.
> 
> Can you explain why this is needed here?

Because discard is a huge win. This is also known as trim.

By implementing discard, both fstrim and the discard filesystem option
can be used.

Implementing discard in the ftl means that when files are removed, there
is less data in the ftl mapping. This means less stuff to move around for
erasing and also less erasing to do. This means better wear levelling.

There is also a wikipedia page on trim here:

	https://en.wikipedia.org/wiki/Trim_(computing)

Thanks,

Sean

> (also please add the maintainers in Cc: for the v2)
> 
> > Signed-off-by: Sean Young <sean at mess.org>
> > ---
> >  drivers/mtd/rfd_ftl.c | 29 +++++++++++++++++++++++++++++
> >  1 file changed, 29 insertions(+)
> > 
> > diff --git a/drivers/mtd/rfd_ftl.c b/drivers/mtd/rfd_ftl.c
> > index 7b243f2b2fa3..7f5f6d247cae 100644
> > --- a/drivers/mtd/rfd_ftl.c
> > +++ b/drivers/mtd/rfd_ftl.c
> > @@ -705,6 +705,34 @@ static int rfd_ftl_writesect(struct mtd_blktrans_dev *dev, u_long sector, char *
> >  	return rc;
> >  }
> >  
> > +static int rfd_ftl_discardsect(struct mtd_blktrans_dev *dev,
> > +			       unsigned long sector, unsigned int nr_sects)
> > +{
> > +	struct partition *part = (struct partition *)dev;
> > +	u_long addr;
> > +	int rc;
> > +
> > +	while (nr_sects) {
> > +		if (sector >= part->sector_count)
> > +			return -EIO;
> > +
> > +		addr = part->sector_map[sector];
> > +
> > +		if (addr != -1) {
> > +			rc = mark_sector_deleted(part, addr);
> > +			if (rc)
> > +				return rc;
> > +
> > +			part->sector_map[sector] = -1;
> > +		}
> > +
> > +		sector++;
> > +		nr_sects--;
> > +	}
> > +
> > +	return 0;
> > +}
> > +
> >  static int rfd_ftl_getgeo(struct mtd_blktrans_dev *dev, struct hd_geometry *geo)
> >  {
> >  	struct partition *part = (struct partition*)dev;
> > @@ -786,6 +814,7 @@ static struct mtd_blktrans_ops rfd_ftl_tr = {
> >  
> >  	.readsect	= rfd_ftl_readsect,
> >  	.writesect	= rfd_ftl_writesect,
> > +	.discard	= rfd_ftl_discardsect,
> >  	.getgeo		= rfd_ftl_getgeo,
> >  	.add_mtd	= rfd_ftl_add_mtd,
> >  	.remove_dev	= rfd_ftl_remove_dev,
> 
> 
> 
> 
> Thanks,
> Miquèl
> 
> ______________________________________________________
> Linux MTD discussion mailing list
> http://lists.infradead.org/mailman/listinfo/linux-mtd/



More information about the linux-mtd mailing list