> -----Original Message----- > From: Eric Biggers <ebiggers@xxxxxxxxxx> > Sent: Saturday, April 16, 2022 2:50 AM > To: 常凤楠 <changfengnan@xxxxxxxx> > Cc: tytso@xxxxxxx; jaegeuk@xxxxxxxxxx; linux-fscrypt@xxxxxxxxxxxxxxx > Subject: Re: why fscrypt_mergeable_bio use logical block number? > > On Fri, Apr 15, 2022 at 08:18:11AM +0000, 常凤楠 wrote: > > Hi: > > When I dig into a problem, I found: bio merge may reduce a lot when > > enable inlinecrypt, the root cause is fscrypt_mergeable_bio use logical > > block number rather than physical block number. I had read the UFSHCI, > > but not see any description about why data unit number shoud use > logical > > block number. I want to know why, Is the anyone can explain this? > > > > Thanks. > > Fengnan Chang. > > The main reason that fscrypt generates IVs using the file logical block number > instead of the sector number is because f2fs needs to move data blocks > around without the key. That would be impossible with sector number > based encryption. So if use sector number to generate IVs, after f2fs move data blocks in gc, we can not decrypt correctly, am I right ? > > There are other reasons too. Always using the file logical block number > keeps the various fscrypt options consistent, it works well with per-file keys, it > doesn't break filesystem resizing, and it avoids having the interpretation of > the filesystem depend on its on-disk location which would be a layering > violation. But the need to support f2fs is the main one. > > Note that by default, fscrypt uses a different key for every file, and in that case > the only way that using the file logical block number instead of the sector > number would prevent merging is if data was being read/written from a file > that is physically but not logically contiguous. That's not a very common > case. This is exactly the problem I have faced. We read/write a file in physically contiguous but not logically. So I'm wander if we can keep physically contiguous always, can we skip check wheatear logical block number is contiguous when bio merge? > > - Eric