Skip to content

Commit 58bb3b3

Browse files
committed
ceph: support ceph_pagelist for message payload
The ceph_pagelist is a simple list of whole pages, strung together via their lru list_head. It facilitates encoding to a "buffer" of unknown size. Allow its use in place of the ceph_msg page vector. This will be used to fix the huge buffer preallocation woes of MDS reconnection. Signed-off-by: Sage Weil <sage@newdream.net>
1 parent 04a419f commit 58bb3b3

5 files changed

Lines changed: 130 additions & 5 deletions

File tree

‎fs/ceph/Makefile‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ obj-$(CONFIG_CEPH_FS) += ceph.o
88

99
ceph-objs := super.o inode.o dir.o file.o addr.o ioctl.o \
1010
export.o caps.o snap.o xattr.o \
11-
messenger.o msgpool.o buffer.o \
11+
messenger.o msgpool.o buffer.o pagelist.o \
1212
mds_client.o mdsmap.o \
1313
mon_client.o \
1414
osd_client.o osdmap.o crush/crush.o crush/mapper.o crush/hash.o \

‎fs/ceph/messenger.c‎

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "super.h"
1414
#include "messenger.h"
1515
#include "decode.h"
16+
#include "pagelist.h"
1617

1718
/*
1819
* Ceph uses the messenger to exchange ceph_msg messages with other
@@ -728,6 +729,11 @@ static int write_partial_msg_pages(struct ceph_connection *con)
728729
page = msg->pages[con->out_msg_pos.page];
729730
if (crc)
730731
kaddr = kmap(page);
732+
} else if (msg->pagelist) {
733+
page = list_first_entry(&msg->pagelist->head,
734+
struct page, lru);
735+
if (crc)
736+
kaddr = kmap(page);
731737
} else {
732738
page = con->msgr->zero_page;
733739
if (crc)
@@ -750,7 +756,7 @@ static int write_partial_msg_pages(struct ceph_connection *con)
750756
MSG_DONTWAIT | MSG_NOSIGNAL |
751757
MSG_MORE);
752758

753-
if (crc && msg->pages)
759+
if (crc && (msg->pages || msg->pagelist))
754760
kunmap(page);
755761

756762
if (ret <= 0)
@@ -762,6 +768,9 @@ static int write_partial_msg_pages(struct ceph_connection *con)
762768
con->out_msg_pos.page_pos = 0;
763769
con->out_msg_pos.page++;
764770
con->out_msg_pos.did_page_crc = 0;
771+
if (msg->pagelist)
772+
list_move_tail(&page->lru,
773+
&msg->pagelist->head);
765774
}
766775
}
767776

@@ -1051,13 +1060,13 @@ static int process_banner(struct ceph_connection *con)
10511060
&con->actual_peer_addr) &&
10521061
!(addr_is_blank(&con->actual_peer_addr.in_addr) &&
10531062
con->actual_peer_addr.nonce == con->peer_addr.nonce)) {
1054-
pr_err("wrong peer, want %s/%d, "
1055-
"got %s/%d, wtf\n",
1063+
pr_warning("wrong peer, want %s/%d, "
1064+
"got %s/%d\n",
10561065
pr_addr(&con->peer_addr.in_addr),
10571066
con->peer_addr.nonce,
10581067
pr_addr(&con->actual_peer_addr.in_addr),
10591068
con->actual_peer_addr.nonce);
1060-
con->error_msg = "protocol error, wrong peer";
1069+
con->error_msg = "wrong peer at address";
10611070
return -1;
10621071
}
10631072

@@ -2096,6 +2105,7 @@ struct ceph_msg *ceph_msg_new(int type, int front_len,
20962105
/* data */
20972106
m->nr_pages = calc_pages_for(page_off, page_len);
20982107
m->pages = pages;
2108+
m->pagelist = NULL;
20992109

21002110
dout("ceph_msg_new %p page %d~%d -> %d\n", m, page_off, page_len,
21012111
m->nr_pages);
@@ -2181,6 +2191,12 @@ void ceph_msg_last_put(struct kref *kref)
21812191
m->nr_pages = 0;
21822192
m->pages = NULL;
21832193

2194+
if (m->pagelist) {
2195+
ceph_pagelist_release(m->pagelist);
2196+
kfree(m->pagelist);
2197+
m->pagelist = NULL;
2198+
}
2199+
21842200
if (m->pool)
21852201
ceph_msgpool_put(m->pool, m);
21862202
else

‎fs/ceph/messenger.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ struct ceph_msg {
8585
struct ceph_buffer *middle;
8686
struct page **pages; /* data payload. NOT OWNER. */
8787
unsigned nr_pages; /* size of page array */
88+
struct ceph_pagelist *pagelist; /* instead of pages */
8889
struct list_head list_head;
8990
struct kref kref;
9091
bool front_is_vmalloc;

‎fs/ceph/pagelist.c‎

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
2+
#include <linux/pagemap.h>
3+
#include <linux/highmem.h>
4+
5+
#include "pagelist.h"
6+
7+
int ceph_pagelist_release(struct ceph_pagelist *pl)
8+
{
9+
if (pl->mapped_tail)
10+
kunmap(pl->mapped_tail);
11+
while (!list_empty(&pl->head)) {
12+
struct page *page = list_first_entry(&pl->head, struct page,
13+
lru);
14+
list_del(&page->lru);
15+
__free_page(page);
16+
}
17+
return 0;
18+
}
19+
20+
static int ceph_pagelist_addpage(struct ceph_pagelist *pl)
21+
{
22+
struct page *page = alloc_page(GFP_NOFS);
23+
if (!page)
24+
return -ENOMEM;
25+
pl->room += PAGE_SIZE;
26+
list_add_tail(&page->lru, &pl->head);
27+
if (pl->mapped_tail)
28+
kunmap(pl->mapped_tail);
29+
pl->mapped_tail = kmap(page);
30+
return 0;
31+
}
32+
33+
int ceph_pagelist_append(struct ceph_pagelist *pl, void *buf, size_t len)
34+
{
35+
while (pl->room < len) {
36+
size_t bit = pl->room;
37+
int ret;
38+
39+
memcpy(pl->mapped_tail + (pl->length & ~PAGE_CACHE_MASK),
40+
buf, bit);
41+
pl->length += bit;
42+
pl->room -= bit;
43+
buf += bit;
44+
len -= bit;
45+
ret = ceph_pagelist_addpage(pl);
46+
if (ret)
47+
return ret;
48+
}
49+
50+
memcpy(pl->mapped_tail + (pl->length & ~PAGE_CACHE_MASK), buf, len);
51+
pl->length += len;
52+
pl->room -= len;
53+
return 0;
54+
}

‎fs/ceph/pagelist.h‎

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#ifndef __FS_CEPH_PAGELIST_H
2+
#define __FS_CEPH_PAGELIST_H
3+
4+
#include <linux/list.h>
5+
6+
struct ceph_pagelist {
7+
struct list_head head;
8+
void *mapped_tail;
9+
size_t length;
10+
size_t room;
11+
};
12+
13+
static inline void ceph_pagelist_init(struct ceph_pagelist *pl)
14+
{
15+
INIT_LIST_HEAD(&pl->head);
16+
pl->mapped_tail = NULL;
17+
pl->length = 0;
18+
pl->room = 0;
19+
}
20+
extern int ceph_pagelist_release(struct ceph_pagelist *pl);
21+
22+
extern int ceph_pagelist_append(struct ceph_pagelist *pl, void *d, size_t l);
23+
24+
static inline int ceph_pagelist_encode_64(struct ceph_pagelist *pl, u64 v)
25+
{
26+
__le64 ev = cpu_to_le64(v);
27+
return ceph_pagelist_append(pl, &ev, sizeof(ev));
28+
}
29+
static inline int ceph_pagelist_encode_32(struct ceph_pagelist *pl, u32 v)
30+
{
31+
__le32 ev = cpu_to_le32(v);
32+
return ceph_pagelist_append(pl, &ev, sizeof(ev));
33+
}
34+
static inline int ceph_pagelist_encode_16(struct ceph_pagelist *pl, u16 v)
35+
{
36+
__le16 ev = cpu_to_le16(v);
37+
return ceph_pagelist_append(pl, &ev, sizeof(ev));
38+
}
39+
static inline int ceph_pagelist_encode_8(struct ceph_pagelist *pl, u8 v)
40+
{
41+
return ceph_pagelist_append(pl, &v, 1);
42+
}
43+
static inline int ceph_pagelist_encode_string(struct ceph_pagelist *pl,
44+
char *s, size_t len)
45+
{
46+
int ret = ceph_pagelist_encode_32(pl, len);
47+
if (ret)
48+
return ret;
49+
if (len)
50+
return ceph_pagelist_append(pl, s, len);
51+
return 0;
52+
}
53+
54+
#endif

0 commit comments

Comments
 (0)