From 5aac27e4891af7edd7132a8f5461ec9ddeb0acab Mon Sep 17 00:00:00 2001 From: Shaun Ruffell Date: Fri, 11 Dec 2009 23:20:35 +0000 Subject: Merged revisions 7681 via svnmerge from https://origsvn.digium.com/svn/dahdi/linux/trunk ........ r7681 | sruffell | 2009-12-11 17:20:02 -0600 (Fri, 11 Dec 2009) | 6 lines dahdi-base: Reduce the max allocation size in dahdi_reallocbufs. Lower the maximum contiguous chunk that DAHDI asks for from DAHDI_MAX_BUFFER_SIZE*2 to DAHDI_MAX_BUFFER_SIZE. With 4K pages, this can allow the kernel to try a little harder to find the memory it needs since the request goes from order 4 to order 3. ........ git-svn-id: http://svn.asterisk.org/svn/dahdi/linux/branches/2.2@7683 a0bf4364-ded3-4de4-8d8a-66a801d63aff --- drivers/dahdi/dahdi-base.c | 40 +++++++++++++++++++++++++--------------- 1 file changed, 25 insertions(+), 15 deletions(-) diff --git a/drivers/dahdi/dahdi-base.c b/drivers/dahdi/dahdi-base.c index 6ab8636..478bd64 100644 --- a/drivers/dahdi/dahdi-base.c +++ b/drivers/dahdi/dahdi-base.c @@ -897,9 +897,12 @@ static inline void calc_fcs(struct dahdi_chan *ss, int inwritebuf) data[len - 1] = (fcs >> 8) & 0xff; } -static int dahdi_reallocbufs(struct dahdi_chan *ss, int j, int numbufs) +static int dahdi_reallocbufs(struct dahdi_chan *ss, int blocksize, int numbufs) { - unsigned char *newbuf, *oldbuf; + unsigned char *newtxbuf = NULL; + unsigned char *newrxbuf = NULL; + unsigned char *oldtxbuf = NULL; + unsigned char *oldrxbuf = NULL; unsigned long flags; int x; @@ -911,25 +914,32 @@ static int dahdi_reallocbufs(struct dahdi_chan *ss, int j, int numbufs) numbufs = DAHDI_MAX_NUM_BUFS; /* We need to allocate our buffers now */ - if (j) { - if (!(newbuf = kcalloc(j * 2, numbufs, GFP_KERNEL))) + if (blocksize) { + newtxbuf = kzalloc(blocksize * numbufs, GFP_KERNEL); + if (NULL == newtxbuf) return -ENOMEM; - } else - newbuf = NULL; + newrxbuf = kzalloc(blocksize * numbufs, GFP_KERNEL); + if (NULL == newrxbuf) { + kfree(newtxbuf); + return -ENOMEM; + } + } - /* Now that we've allocated our new buffer, we can safely + /* Now that we've allocated our new buffers, we can safely move things around... */ spin_lock_irqsave(&ss->lock, flags); - ss->blocksize = j; /* set the blocksize */ - oldbuf = ss->readbuf[0]; /* Keep track of the old buffer */ + ss->blocksize = blocksize; /* set the blocksize */ + oldrxbuf = ss->readbuf[0]; /* Keep track of the old buffer */ + oldtxbuf = ss->writebuf[0]; ss->readbuf[0] = NULL; - if (newbuf) { + if (newrxbuf) { + BUG_ON(NULL == newtxbuf); for (x = 0; x < numbufs; x++) { - ss->readbuf[x] = newbuf + x * j; - ss->writebuf[x] = newbuf + (numbufs + x) * j; + ss->readbuf[x] = newrxbuf + x * blocksize; + ss->writebuf[x] = newtxbuf + x * blocksize; } } else { for (x = 0; x < numbufs; x++) { @@ -948,7 +958,7 @@ static int dahdi_reallocbufs(struct dahdi_chan *ss, int j, int numbufs) /* Keep track of where our data goes (if it goes anywhere at all) */ - if (newbuf) { + if (newrxbuf) { ss->inreadbuf = 0; ss->inwritebuf = 0; } else { @@ -972,8 +982,8 @@ static int dahdi_reallocbufs(struct dahdi_chan *ss, int j, int numbufs) spin_unlock_irqrestore(&ss->lock, flags); - if (oldbuf) - kfree(oldbuf); + kfree(oldtxbuf); + kfree(oldrxbuf); return 0; } -- cgit v1.2.3