Commit 72772323 authored by Peter Osterlund's avatar Peter Osterlund Committed by Linus Torvalds

[PATCH] pktcdvd: Reduce stack usage

Reduce stack usage in the pkt_start_write() function.  Even though it's not
currently a real problem, the pages and offsets arrays can be eliminated,
which saves approximately 1000 bytes of stack space.
Signed-off-by: default avatarPeter Osterlund <petero2@telia.com>
Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent 948423e5
...@@ -645,7 +645,7 @@ static void pkt_copy_bio_data(struct bio *src_bio, int seg, int offs, struct pag ...@@ -645,7 +645,7 @@ static void pkt_copy_bio_data(struct bio *src_bio, int seg, int offs, struct pag
* b) The data can be used as cache to avoid read requests if we receive a * b) The data can be used as cache to avoid read requests if we receive a
* new write request for the same zone. * new write request for the same zone.
*/ */
static void pkt_make_local_copy(struct packet_data *pkt, struct page **pages, int *offsets) static void pkt_make_local_copy(struct packet_data *pkt, struct bio_vec *bvec)
{ {
int f, p, offs; int f, p, offs;
...@@ -653,15 +653,15 @@ static void pkt_make_local_copy(struct packet_data *pkt, struct page **pages, in ...@@ -653,15 +653,15 @@ static void pkt_make_local_copy(struct packet_data *pkt, struct page **pages, in
p = 0; p = 0;
offs = 0; offs = 0;
for (f = 0; f < pkt->frames; f++) { for (f = 0; f < pkt->frames; f++) {
if (pages[f] != pkt->pages[p]) { if (bvec[f].bv_page != pkt->pages[p]) {
void *vfrom = kmap_atomic(pages[f], KM_USER0) + offsets[f]; void *vfrom = kmap_atomic(bvec[f].bv_page, KM_USER0) + bvec[f].bv_offset;
void *vto = page_address(pkt->pages[p]) + offs; void *vto = page_address(pkt->pages[p]) + offs;
memcpy(vto, vfrom, CD_FRAMESIZE); memcpy(vto, vfrom, CD_FRAMESIZE);
kunmap_atomic(vfrom, KM_USER0); kunmap_atomic(vfrom, KM_USER0);
pages[f] = pkt->pages[p]; bvec[f].bv_page = pkt->pages[p];
offsets[f] = offs; bvec[f].bv_offset = offs;
} else { } else {
BUG_ON(offsets[f] != offs); BUG_ON(bvec[f].bv_offset != offs);
} }
offs += CD_FRAMESIZE; offs += CD_FRAMESIZE;
if (offs >= PAGE_SIZE) { if (offs >= PAGE_SIZE) {
...@@ -991,18 +991,17 @@ static int pkt_handle_queue(struct pktcdvd_device *pd) ...@@ -991,18 +991,17 @@ static int pkt_handle_queue(struct pktcdvd_device *pd)
static void pkt_start_write(struct pktcdvd_device *pd, struct packet_data *pkt) static void pkt_start_write(struct pktcdvd_device *pd, struct packet_data *pkt)
{ {
struct bio *bio; struct bio *bio;
struct page *pages[PACKET_MAX_SIZE];
int offsets[PACKET_MAX_SIZE];
int f; int f;
int frames_write; int frames_write;
struct bio_vec *bvec = pkt->w_bio->bi_io_vec;
for (f = 0; f < pkt->frames; f++) { for (f = 0; f < pkt->frames; f++) {
pages[f] = pkt->pages[(f * CD_FRAMESIZE) / PAGE_SIZE]; bvec[f].bv_page = pkt->pages[(f * CD_FRAMESIZE) / PAGE_SIZE];
offsets[f] = (f * CD_FRAMESIZE) % PAGE_SIZE; bvec[f].bv_offset = (f * CD_FRAMESIZE) % PAGE_SIZE;
} }
/* /*
* Fill-in pages[] and offsets[] with data from orig_bios. * Fill-in bvec with data from orig_bios.
*/ */
frames_write = 0; frames_write = 0;
spin_lock(&pkt->lock); spin_lock(&pkt->lock);
...@@ -1024,11 +1023,11 @@ static void pkt_start_write(struct pktcdvd_device *pd, struct packet_data *pkt) ...@@ -1024,11 +1023,11 @@ static void pkt_start_write(struct pktcdvd_device *pd, struct packet_data *pkt)
} }
if (src_bvl->bv_len - src_offs >= CD_FRAMESIZE) { if (src_bvl->bv_len - src_offs >= CD_FRAMESIZE) {
pages[f] = src_bvl->bv_page; bvec[f].bv_page = src_bvl->bv_page;
offsets[f] = src_bvl->bv_offset + src_offs; bvec[f].bv_offset = src_bvl->bv_offset + src_offs;
} else { } else {
pkt_copy_bio_data(bio, segment, src_offs, pkt_copy_bio_data(bio, segment, src_offs,
pages[f], offsets[f]); bvec[f].bv_page, bvec[f].bv_offset);
} }
src_offs += CD_FRAMESIZE; src_offs += CD_FRAMESIZE;
frames_write++; frames_write++;
...@@ -1042,7 +1041,7 @@ static void pkt_start_write(struct pktcdvd_device *pd, struct packet_data *pkt) ...@@ -1042,7 +1041,7 @@ static void pkt_start_write(struct pktcdvd_device *pd, struct packet_data *pkt)
BUG_ON(frames_write != pkt->write_size); BUG_ON(frames_write != pkt->write_size);
if (test_bit(PACKET_MERGE_SEGS, &pd->flags) || (pkt->write_size < pkt->frames)) { if (test_bit(PACKET_MERGE_SEGS, &pd->flags) || (pkt->write_size < pkt->frames)) {
pkt_make_local_copy(pkt, pages, offsets); pkt_make_local_copy(pkt, bvec);
pkt->cache_valid = 1; pkt->cache_valid = 1;
} else { } else {
pkt->cache_valid = 0; pkt->cache_valid = 0;
...@@ -1055,17 +1054,9 @@ static void pkt_start_write(struct pktcdvd_device *pd, struct packet_data *pkt) ...@@ -1055,17 +1054,9 @@ static void pkt_start_write(struct pktcdvd_device *pd, struct packet_data *pkt)
pkt->w_bio->bi_bdev = pd->bdev; pkt->w_bio->bi_bdev = pd->bdev;
pkt->w_bio->bi_end_io = pkt_end_io_packet_write; pkt->w_bio->bi_end_io = pkt_end_io_packet_write;
pkt->w_bio->bi_private = pkt; pkt->w_bio->bi_private = pkt;
for (f = 0; f < pkt->frames; f++) { for (f = 0; f < pkt->frames; f++)
if ((f + 1 < pkt->frames) && (pages[f + 1] == pages[f]) && if (!bio_add_page(pkt->w_bio, bvec[f].bv_page, CD_FRAMESIZE, bvec[f].bv_offset))
(offsets[f + 1] = offsets[f] + CD_FRAMESIZE)) { BUG();
if (!bio_add_page(pkt->w_bio, pages[f], CD_FRAMESIZE * 2, offsets[f]))
BUG();
f++;
} else {
if (!bio_add_page(pkt->w_bio, pages[f], CD_FRAMESIZE, offsets[f]))
BUG();
}
}
VPRINTK("pktcdvd: vcnt=%d\n", pkt->w_bio->bi_vcnt); VPRINTK("pktcdvd: vcnt=%d\n", pkt->w_bio->bi_vcnt);
atomic_set(&pkt->io_wait, 1); atomic_set(&pkt->io_wait, 1);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment