diff options
author | Alex Elder <elder@dreamhost.com> | 2012-01-23 16:49:27 -0500 |
---|---|---|
committer | Alex Elder <elder@dreamhost.com> | 2012-03-22 11:47:45 -0400 |
commit | 5766651971e81298732466c9aa462ff47898ba37 (patch) | |
tree | 147bfd12f3b335d6b2fdb2af162c582a58c33fe5 /net/ceph | |
parent | 80834312a4da1405a9bc788313c67643de6fcb4c (diff) |
ceph: use a shared zero page rather than one per messenger
Each messenger allocates a page to be used when writing zeroes
out in the event of error or other abnormal condition. Instead,
use the kernel ZERO_PAGE() for that purpose.
Signed-off-by: Alex Elder <elder@dreamhost.com>
Signed-off-by: Sage Weil <sage@newdream.net>
Diffstat (limited to 'net/ceph')
-rw-r--r-- | net/ceph/messenger.c | 43 |
1 files changed, 29 insertions, 14 deletions
diff --git a/net/ceph/messenger.c b/net/ceph/messenger.c index d11f91b05452..738356255e0b 100644 --- a/net/ceph/messenger.c +++ b/net/ceph/messenger.c | |||
@@ -52,6 +52,9 @@ static char addr_str[MAX_ADDR_STR][MAX_ADDR_STR_LEN]; | |||
52 | static DEFINE_SPINLOCK(addr_str_lock); | 52 | static DEFINE_SPINLOCK(addr_str_lock); |
53 | static int last_addr_str; | 53 | static int last_addr_str; |
54 | 54 | ||
55 | static struct page *zero_page; /* used in certain error cases */ | ||
56 | static void *zero_page_address; /* kernel virtual addr of zero_page */ | ||
57 | |||
55 | const char *ceph_pr_addr(const struct sockaddr_storage *ss) | 58 | const char *ceph_pr_addr(const struct sockaddr_storage *ss) |
56 | { | 59 | { |
57 | int i; | 60 | int i; |
@@ -99,18 +102,41 @@ struct workqueue_struct *ceph_msgr_wq; | |||
99 | 102 | ||
100 | int ceph_msgr_init(void) | 103 | int ceph_msgr_init(void) |
101 | { | 104 | { |
105 | BUG_ON(zero_page != NULL); | ||
106 | zero_page = ZERO_PAGE(0); | ||
107 | page_cache_get(zero_page); | ||
108 | |||
109 | BUG_ON(zero_page_address != NULL); | ||
110 | zero_page_address = kmap(zero_page); | ||
111 | |||
102 | ceph_msgr_wq = alloc_workqueue("ceph-msgr", WQ_NON_REENTRANT, 0); | 112 | ceph_msgr_wq = alloc_workqueue("ceph-msgr", WQ_NON_REENTRANT, 0); |
103 | if (!ceph_msgr_wq) { | 113 | if (!ceph_msgr_wq) { |
104 | pr_err("msgr_init failed to create workqueue\n"); | 114 | pr_err("msgr_init failed to create workqueue\n"); |
115 | |||
116 | zero_page_address = NULL; | ||
117 | kunmap(zero_page); | ||
118 | page_cache_release(zero_page); | ||
119 | zero_page = NULL; | ||
120 | |||
105 | return -ENOMEM; | 121 | return -ENOMEM; |
106 | } | 122 | } |
123 | |||
107 | return 0; | 124 | return 0; |
108 | } | 125 | } |
109 | EXPORT_SYMBOL(ceph_msgr_init); | 126 | EXPORT_SYMBOL(ceph_msgr_init); |
110 | 127 | ||
111 | void ceph_msgr_exit(void) | 128 | void ceph_msgr_exit(void) |
112 | { | 129 | { |
130 | BUG_ON(ceph_msgr_wq == NULL); | ||
113 | destroy_workqueue(ceph_msgr_wq); | 131 | destroy_workqueue(ceph_msgr_wq); |
132 | |||
133 | BUG_ON(zero_page_address == NULL); | ||
134 | zero_page_address = NULL; | ||
135 | |||
136 | BUG_ON(zero_page == NULL); | ||
137 | kunmap(zero_page); | ||
138 | page_cache_release(zero_page); | ||
139 | zero_page = NULL; | ||
114 | } | 140 | } |
115 | EXPORT_SYMBOL(ceph_msgr_exit); | 141 | EXPORT_SYMBOL(ceph_msgr_exit); |
116 | 142 | ||
@@ -841,9 +867,9 @@ static int write_partial_msg_pages(struct ceph_connection *con) | |||
841 | max_write = bv->bv_len; | 867 | max_write = bv->bv_len; |
842 | #endif | 868 | #endif |
843 | } else { | 869 | } else { |
844 | page = con->msgr->zero_page; | 870 | page = zero_page; |
845 | if (crc) | 871 | if (crc) |
846 | kaddr = page_address(con->msgr->zero_page); | 872 | kaddr = zero_page_address; |
847 | } | 873 | } |
848 | len = min_t(int, max_write - con->out_msg_pos.page_pos, | 874 | len = min_t(int, max_write - con->out_msg_pos.page_pos, |
849 | total_max_write); | 875 | total_max_write); |
@@ -914,7 +940,7 @@ static int write_partial_skip(struct ceph_connection *con) | |||
914 | 940 | ||
915 | while (con->out_skip > 0) { | 941 | while (con->out_skip > 0) { |
916 | struct kvec iov = { | 942 | struct kvec iov = { |
917 | .iov_base = page_address(con->msgr->zero_page), | 943 | .iov_base = zero_page_address, |
918 | .iov_len = min(con->out_skip, (int)PAGE_CACHE_SIZE) | 944 | .iov_len = min(con->out_skip, (int)PAGE_CACHE_SIZE) |
919 | }; | 945 | }; |
920 | 946 | ||
@@ -2222,15 +2248,6 @@ struct ceph_messenger *ceph_messenger_create(struct ceph_entity_addr *myaddr, | |||
2222 | 2248 | ||
2223 | spin_lock_init(&msgr->global_seq_lock); | 2249 | spin_lock_init(&msgr->global_seq_lock); |
2224 | 2250 | ||
2225 | /* the zero page is needed if a request is "canceled" while the message | ||
2226 | * is being written over the socket */ | ||
2227 | msgr->zero_page = __page_cache_alloc(GFP_KERNEL | __GFP_ZERO); | ||
2228 | if (!msgr->zero_page) { | ||
2229 | kfree(msgr); | ||
2230 | return ERR_PTR(-ENOMEM); | ||
2231 | } | ||
2232 | kmap(msgr->zero_page); | ||
2233 | |||
2234 | if (myaddr) | 2251 | if (myaddr) |
2235 | msgr->inst.addr = *myaddr; | 2252 | msgr->inst.addr = *myaddr; |
2236 | 2253 | ||
@@ -2247,8 +2264,6 @@ EXPORT_SYMBOL(ceph_messenger_create); | |||
2247 | void ceph_messenger_destroy(struct ceph_messenger *msgr) | 2264 | void ceph_messenger_destroy(struct ceph_messenger *msgr) |
2248 | { | 2265 | { |
2249 | dout("destroy %p\n", msgr); | 2266 | dout("destroy %p\n", msgr); |
2250 | kunmap(msgr->zero_page); | ||
2251 | __free_page(msgr->zero_page); | ||
2252 | kfree(msgr); | 2267 | kfree(msgr); |
2253 | dout("destroyed messenger %p\n", msgr); | 2268 | dout("destroyed messenger %p\n", msgr); |
2254 | } | 2269 | } |