Re: [PATCH v29 4/4] scsi: ufs: Add HPB 2.0 support

From: Can Guo
Date: Tue Mar 16 2021 - 22:46:32 EST

On 2021-03-17 09:42, Daejun Park wrote:
On 2021-03-15 15:23, Can Guo wrote:
On 2021-03-15 15:07, Daejun Park wrote:
This patch supports the HPB 2.0.

The HPB 2.0 supports read of varying sizes from 4KB to 512KB.
In the case of Read (<= 32KB) is supported as single HPB read.
In the case of Read (36KB ~ 512KB) is supported by as a combination
write buffer command and HPB read command to deliver more PPN.
The write buffer commands may not be issued immediately due to busy
To use HPB read more aggressively, the driver can requeue the write
command. The requeue threshold is implemented as timeout and can be
modified with requeue_timeout_ms entry in sysfs.

Signed-off-by: Daejun Park <daejun7.park@xxxxxxxxxxx>
+static struct attribute *hpb_dev_param_attrs[] = {
+ &dev_attr_requeue_timeout_ms.attr,
+struct attribute_group ufs_sysfs_hpb_param_group = {
+ .name = "hpb_param_sysfs",
+ .attrs = hpb_dev_param_attrs,
+static int ufshpb_pre_req_mempool_init(struct ufshpb_lu *hpb)
+ struct ufshpb_req *pre_req = NULL;
+ int qd = hpb->sdev_ufs_lu->queue_depth / 2;
+ int i, j;
+ INIT_LIST_HEAD(&hpb->lh_pre_req_free);
+ hpb->pre_req = kcalloc(qd, sizeof(struct ufshpb_req),
+ hpb->throttle_pre_req = qd;
+ hpb->num_inflight_pre_req = 0;
+ if (!hpb->pre_req)
+ goto release_mem;
+ for (i = 0; i < qd; i++) {
+ pre_req = hpb->pre_req + i;
+ INIT_LIST_HEAD(&pre_req->list_req);
+ pre_req->req = NULL;
+ pre_req->bio = NULL;

Why don't prepare bio as same as wb.m_page? Won't that save more time
for ufshpb_issue_pre_req()?

It is pre_req pool. So although we prepare bio at this time, it just
only for first pre_req.

I meant removing the bio_alloc() in ufshpb_issue_pre_req() and
in ufshpb_pre_req_compl_fn(). bios, in pre_req's case, just hold a
So, prepare 16 (if queue depth is 32) bios here, just use them along
wb.m_page and call bio_reset() in ufshpb_pre_req_compl_fn(). Shall it

If it works, you can even have the bio_add_pc_page() called here. Later
ufshpb_execute_pre_req(), you don't need to call
just call ufshpb_prep_entry() once instead - it save many repeated steps
for a
pre_req, and you don't even need to call bio_reset() in this case, since
for a
bio, nothing changes after it is binded with a specific page...

Hi, Can Guo

I tried the idea that you suggested, but it doesn't work properly.
This optimization should be done next time for enhancement.

Can you elaborate please? Any error seen?

Per my understanding, in the case for pre_reqs, a bio is no different
from a page. Here it can reserve 16 pages for later use, which can be
done the same for bios.

This is not an enhancement, but a doubt - why not? Unless it is not doable.

Can Guo.


Can Guo.

Can Guo.

After use it, it should be prepared bio at issue phase.


Can Guo.

+ pre_req->wb.m_page = alloc_page(GFP_KERNEL |
+ if (!pre_req->wb.m_page) {
+ for (j = 0; j < i; j++)
+ goto release_mem;
+ }
+ list_add_tail(&pre_req->list_req,
+ }
+ return 0;
+ kfree(hpb->pre_req);
+ return -ENOMEM;