[ltt-dev] [PATCH 2/2] ltt-relay: cache page's address

Lai Jiangshan laijs at cn.fujitsu.com
Fri Feb 27 03:11:49 EST 2009


page_address is not fast in some systems,
we should cache it.

Signed-off-by: Lai Jiangshan <laijs at cn.fujitsu.com>
---
diff --git a/include/linux/ltt-relay.h b/include/linux/ltt-relay.h
index 8d23352..20908ec 100644
--- a/include/linux/ltt-relay.h
+++ b/include/linux/ltt-relay.h
@@ -34,6 +34,7 @@ struct rchan_buf;
 
 struct buf_page {
 	struct page *page;
+	void *virt;		/* page address of the struct page */
 	size_t offset;		/* page offset in the buffer */
 	struct list_head list;	/* buffer linked list */
 };
@@ -275,8 +276,7 @@ static inline int ltt_relay_write(struct rchan_buf *buf, size_t offset,
 
 	page = ltt_relay_cache_page(buf, &buf->wpage, page, offset);
 	pagecpy = min_t(size_t, len, PAGE_SIZE - (offset & ~PAGE_MASK));
-	ltt_relay_do_copy(page_address(page->page)
-		+ (offset & ~PAGE_MASK), src, pagecpy);
+	ltt_relay_do_copy(page->virt + (offset & ~PAGE_MASK), src, pagecpy);
 
 	if (unlikely(len != pagecpy))
 		_ltt_relay_write(buf, offset, src, len, page, pagecpy);
diff --git a/ltt/ltt-relay-alloc.c b/ltt/ltt-relay-alloc.c
index 91c12d4..a10fa4b 100644
--- a/ltt/ltt-relay-alloc.c
+++ b/ltt/ltt-relay-alloc.c
@@ -54,6 +54,7 @@ static int relay_alloc_buf(struct rchan_buf *buf, size_t *size)
 			goto depopulate;
 		}
 		list_add_tail(&buf_page->list, &buf->pages);
+		buf_page->virt = page_address(buf_page->page);
 		buf_page->offset = (size_t)i << PAGE_SHIFT;
 		set_page_private(buf_page->page, (unsigned long)buf_page);
 		if (i == 0) {
@@ -524,8 +525,8 @@ void _ltt_relay_write(struct rchan_buf *buf, size_t offset,
 
 		page = ltt_relay_cache_page(buf, &buf->wpage, page, offset);
 		pagecpy = min_t(size_t, len, PAGE_SIZE - (offset & ~PAGE_MASK));
-		ltt_relay_do_copy(page_address(page->page)
-			+ (offset & ~PAGE_MASK), src, pagecpy);
+		ltt_relay_do_copy(page->virt
+				+ (offset & ~PAGE_MASK), src, pagecpy);
 	} while (unlikely(len != pagecpy));
 }
 EXPORT_SYMBOL_GPL(_ltt_relay_write);
@@ -551,8 +552,7 @@ int ltt_relay_read(struct rchan_buf *buf, size_t offset,
 	for (;;) {
 		page = ltt_relay_cache_page(buf, &buf->rpage, page, offset);
 		pagecpy = min_t(size_t, len, PAGE_SIZE - (offset & ~PAGE_MASK));
-		memcpy(dest, page_address(page->page) + (offset & ~PAGE_MASK),
-			pagecpy);
+		memcpy(dest, page->virt + (offset & ~PAGE_MASK), pagecpy);
 		len -= pagecpy;
 		if (likely(!len))
 			break;
@@ -605,7 +605,7 @@ void *ltt_relay_offset_address(struct rchan_buf *buf, size_t offset)
 	if (offset < page->offset || offset >= page->offset + PAGE_SIZE)
 		buf->hpage[odd] = page = buf->wpage;
 	page = ltt_relay_cache_page(buf, &buf->hpage[odd], page, offset);
-	return page_address(page->page) + (offset & ~PAGE_MASK);
+	return page->virt + (offset & ~PAGE_MASK);
 }
 EXPORT_SYMBOL_GPL(ltt_relay_offset_address);
 






More information about the lttng-dev mailing list