svn commit: r313910 - head/sys/cam/ctl

Alexander Motin mav at FreeBSD.org
Sat Feb 18 06:03:18 UTC 2017


Author: mav
Date: Sat Feb 18 06:03:16 2017
New Revision: 313910
URL: https://svnweb.freebsd.org/changeset/base/313910

Log:
  Change XCOPY memory allocations.
  
  Before this change XCOPY code could allocate memory in chunks up to 16-32MB
  (VMware does XCOPY in 4MB chunks by default), that could be difficult for
  VM subsystem to do due to KVA fragmentation, that sometimes created huge
  allocation delays, blocking any I/O for respective LU for that time.
  
  This change limits allocations down to TPC_MAX_IO_SIZE, which is 1MB now.
  1MB is also not a cookie, but ZFS also can do that for large blocks, so
  it should be less dramatic.  As drawback this increases CPU overhead, but
  it still look acceptable comparing to time consumed by ZFS read/write.
  
  MFC after:	1 week

Modified:
  head/sys/cam/ctl/ctl_tpc.c

Modified: head/sys/cam/ctl/ctl_tpc.c
==============================================================================
--- head/sys/cam/ctl/ctl_tpc.c	Sat Feb 18 05:07:53 2017	(r313909)
+++ head/sys/cam/ctl/ctl_tpc.c	Sat Feb 18 06:03:16 2017	(r313910)
@@ -85,6 +85,7 @@ struct tpc_io {
 	uint8_t			 target;
 	uint32_t		 cscd;
 	uint64_t		 lun;
+	uint8_t			*buf;
 	struct tpc_list		*list;
 	struct runl		 run;
 	TAILQ_ENTRY(tpc_io)	 rlinks;
@@ -127,7 +128,6 @@ struct tpc_list {
 	off_t			 curbytes;
 	int			 curops;
 	int			 stage;
-	uint8_t			*buf;
 	off_t			 segsectors;
 	off_t			 segbytes;
 	int			 tbdio;
@@ -813,9 +813,9 @@ tpc_process_b2b(struct tpc_list *list)
 		while ((tior = TAILQ_FIRST(&list->allio)) != NULL) {
 			TAILQ_REMOVE(&list->allio, tior, links);
 			ctl_free_io(tior->io);
+			free(tior->buf, M_CTL);
 			free(tior, M_CTL);
 		}
-		free(list->buf, M_CTL);
 		if (list->abort) {
 			ctl_set_task_aborted(list->ctsio);
 			return (CTL_RETVAL_ERROR);
@@ -874,7 +874,6 @@ tpc_process_b2b(struct tpc_list *list)
 		return (CTL_RETVAL_ERROR);
 	}
 
-	list->buf = malloc(numbytes, M_CTL, M_WAITOK);
 	list->segbytes = numbytes;
 	list->segsectors = numbytes / dstblock;
 	donebytes = 0;
@@ -894,11 +893,12 @@ tpc_process_b2b(struct tpc_list *list)
 
 		tior = malloc(sizeof(*tior), M_CTL, M_WAITOK | M_ZERO);
 		TAILQ_INIT(&tior->run);
+		tior->buf = malloc(roundbytes, M_CTL, M_WAITOK);
 		tior->list = list;
 		TAILQ_INSERT_TAIL(&list->allio, tior, links);
 		tior->io = tpcl_alloc_io();
 		ctl_scsi_read_write(tior->io,
-				    /*data_ptr*/ &list->buf[donebytes],
+				    /*data_ptr*/ tior->buf,
 				    /*data_len*/ roundbytes,
 				    /*read_op*/ 1,
 				    /*byte2*/ 0,
@@ -919,7 +919,7 @@ tpc_process_b2b(struct tpc_list *list)
 		TAILQ_INSERT_TAIL(&list->allio, tiow, links);
 		tiow->io = tpcl_alloc_io();
 		ctl_scsi_read_write(tiow->io,
-				    /*data_ptr*/ &list->buf[donebytes],
+				    /*data_ptr*/ tior->buf,
 				    /*data_len*/ roundbytes,
 				    /*read_op*/ 0,
 				    /*byte2*/ 0,
@@ -1029,9 +1029,9 @@ tpc_process_register_key(struct tpc_list
 		while ((tio = TAILQ_FIRST(&list->allio)) != NULL) {
 			TAILQ_REMOVE(&list->allio, tio, links);
 			ctl_free_io(tio->io);
+			free(tio->buf, M_CTL);
 			free(tio, M_CTL);
 		}
-		free(list->buf, M_CTL);
 		if (list->abort) {
 			ctl_set_task_aborted(list->ctsio);
 			return (CTL_RETVAL_ERROR);
@@ -1064,9 +1064,9 @@ tpc_process_register_key(struct tpc_list
 	TAILQ_INSERT_TAIL(&list->allio, tio, links);
 	tio->io = tpcl_alloc_io();
 	datalen = sizeof(struct scsi_per_res_out_parms);
-	list->buf = malloc(datalen, M_CTL, M_WAITOK);
+	tio->buf = malloc(datalen, M_CTL, M_WAITOK);
 	ctl_scsi_persistent_res_out(tio->io,
-	    list->buf, datalen, SPRO_REGISTER, -1,
+	    tio->buf, datalen, SPRO_REGISTER, -1,
 	    scsi_8btou64(seg->res_key), scsi_8btou64(seg->sa_res_key),
 	    /*tag_type*/ CTL_TAG_SIMPLE, /*control*/ 0);
 	tio->io->io_hdr.retries = 3;
@@ -1166,9 +1166,9 @@ tpc_process_wut(struct tpc_list *list)
 		while ((tio = TAILQ_FIRST(&list->allio)) != NULL) {
 			TAILQ_REMOVE(&list->allio, tio, links);
 			ctl_free_io(tio->io);
+			free(tio->buf, M_CTL);
 			free(tio, M_CTL);
 		}
-		free(list->buf, M_CTL);
 		if (list->abort) {
 			ctl_set_task_aborted(list->ctsio);
 			return (CTL_RETVAL_ERROR);
@@ -1233,8 +1233,6 @@ tpc_process_wut(struct tpc_list *list)
 		return (CTL_RETVAL_ERROR);
 	}
 
-	list->buf = malloc(numbytes, M_CTL, M_WAITOK |
-	    (list->token == NULL ? M_ZERO : 0));
 	list->segbytes = numbytes;
 	list->segsectors = numbytes / dstblock;
 //printf("Copy chunk of %ju sectors from %ju to %ju\n", list->segsectors,
@@ -1257,11 +1255,12 @@ tpc_process_wut(struct tpc_list *list)
 
 		tior = malloc(sizeof(*tior), M_CTL, M_WAITOK | M_ZERO);
 		TAILQ_INIT(&tior->run);
+		tior->buf = malloc(roundbytes, M_CTL, M_WAITOK);
 		tior->list = list;
 		TAILQ_INSERT_TAIL(&list->allio, tior, links);
 		tior->io = tpcl_alloc_io();
 		ctl_scsi_read_write(tior->io,
-				    /*data_ptr*/ &list->buf[donebytes],
+				    /*data_ptr*/ tior->buf,
 				    /*data_len*/ roundbytes,
 				    /*read_op*/ 1,
 				    /*byte2*/ 0,
@@ -1280,7 +1279,7 @@ tpc_process_wut(struct tpc_list *list)
 		TAILQ_INSERT_TAIL(&list->allio, tiow, links);
 		tiow->io = tpcl_alloc_io();
 		ctl_scsi_read_write(tiow->io,
-				    /*data_ptr*/ &list->buf[donebytes],
+				    /*data_ptr*/ tior->buf,
 				    /*data_len*/ roundbytes,
 				    /*read_op*/ 0,
 				    /*byte2*/ 0,


More information about the svn-src-head mailing list