Patchwork [08/11] resource: only return range with needed align

login
register
mail settings
Submitter Yinghai Lu
Date May 23, 2012, 6:34 a.m.
Message ID <1337754877-19759-9-git-send-email-yinghai@kernel.org>
Download mbox | patch
Permalink /patch/160872/
State Rejected
Headers show

Comments

Yinghai Lu - May 23, 2012, 6:34 a.m.
Compare align between put range in head and tail, pick small one
to leave big one for future user.

Signed-off-by: Yinghai Lu <yinghai@kernel.org>
---
 kernel/resource.c |   14 +++++++++++++-
 1 files changed, 13 insertions(+), 1 deletions(-)

Patch

diff --git a/kernel/resource.c b/kernel/resource.c
index b4dae55..8277090 100644
--- a/kernel/resource.c
+++ b/kernel/resource.c
@@ -506,8 +506,20 @@  out:
 	}
 
 	if (!ret) {
-		new->start = avail_start;
+		/* compare which one have max order */
+		new->start = round_down(avail_start + avail_size - size,
+					 constraint->align);
+		new->end = avail_start + avail_size - 1;
+		new->start = constraint->alignf(constraint->alignf_data, new,
+					size, constraint->align);
 		new->end = new->start + size - 1;
+
+		if (new->start < avail_start ||
+		    new->end > (avail_start + avail_size - 1) ||
+		    __ffs64(new->start) >= __ffs64(avail_start)) {
+			new->start = avail_start;
+			new->end = new->start + size - 1;
+		}
 	}
 	return ret;
 }