Skip to content

Commit 3c58f73

Browse files
BStroessermartinkpetersen
authored andcommitted
scsi: target: tcmu: Optimize use of flush_dcache_page
(scatter|gather)_data_area() need to flush dcache after writing data to or before reading data from a page in uio data area. The two routines are able to handle data transfer to/from such a page in fragments and flush the cache after each fragment was copied by calling the wrapper tcmu_flush_dcache_range(). That means: 1) flush_dcache_page() can be called multiple times for the same page. 2) Calling flush_dcache_page() indirectly using the wrapper does not make sense, because each call of the wrapper is for one single page only and the calling routine already has the correct page pointer. Change (scatter|gather)_data_area() such that, instead of calling tcmu_flush_dcache_range() before/after each memcpy, it now calls flush_dcache_page() before unmapping a page (when writing is complete for that page) or after mapping a page (when starting to read the page). After this change only calls to tcmu_flush_dcache_range() for addresses in vmalloc'ed command ring are left over. The patch was tested on ARM with kernel 4.19.118 and 5.7.2 Link: https://lore.kernel.org/r/20200618131632.32748-2-bstroesser@ts.fujitsu.com Tested-by: JiangYu <lnsyyj@hotmail.com> Tested-by: Daniel Meyerholt <dxm523@gmail.com> Acked-by: Mike Christie <michael.christie@oracle.com> Signed-off-by: Bodo Stroesser <bstroesser@ts.fujitsu.com> Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
1 parent f51853f commit 3c58f73

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

drivers/target/target_core_user.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -675,8 +675,10 @@ static void scatter_data_area(struct tcmu_dev *udev,
675675
from = kmap_atomic(sg_page(sg)) + sg->offset;
676676
while (sg_remaining > 0) {
677677
if (block_remaining == 0) {
678-
if (to)
678+
if (to) {
679+
flush_dcache_page(page);
679680
kunmap_atomic(to);
681+
}
680682

681683
block_remaining = DATA_BLOCK_SIZE;
682684
dbi = tcmu_cmd_get_dbi(tcmu_cmd);
@@ -721,7 +723,6 @@ static void scatter_data_area(struct tcmu_dev *udev,
721723
memcpy(to + offset,
722724
from + sg->length - sg_remaining,
723725
copy_bytes);
724-
tcmu_flush_dcache_range(to, copy_bytes);
725726
}
726727

727728
sg_remaining -= copy_bytes;
@@ -730,8 +731,10 @@ static void scatter_data_area(struct tcmu_dev *udev,
730731
kunmap_atomic(from - sg->offset);
731732
}
732733

733-
if (to)
734+
if (to) {
735+
flush_dcache_page(page);
734736
kunmap_atomic(to);
737+
}
735738
}
736739

737740
static void gather_data_area(struct tcmu_dev *udev, struct tcmu_cmd *cmd,
@@ -777,13 +780,13 @@ static void gather_data_area(struct tcmu_dev *udev, struct tcmu_cmd *cmd,
777780
dbi = tcmu_cmd_get_dbi(cmd);
778781
page = tcmu_get_block_page(udev, dbi);
779782
from = kmap_atomic(page);
783+
flush_dcache_page(page);
780784
}
781785
copy_bytes = min_t(size_t, sg_remaining,
782786
block_remaining);
783787
if (read_len < copy_bytes)
784788
copy_bytes = read_len;
785789
offset = DATA_BLOCK_SIZE - block_remaining;
786-
tcmu_flush_dcache_range(from, copy_bytes);
787790
memcpy(to + sg->length - sg_remaining, from + offset,
788791
copy_bytes);
789792

0 commit comments

Comments
 (0)