diff options
author | Chao Yu <chao2.yu@samsung.com> | 2014-10-09 18:30:04 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2014-10-09 22:26:03 -0400 |
commit | f203c3b33f0891da98ae3dcf829851c48473ed60 (patch) | |
tree | 62ca7125431238be94db07e1448af5196fb38763 /mm | |
parent | 5538c562377580947916b3366898f1eb5f53768e (diff) |
zbud: avoid accessing last unused freelist
For now, there are NCHUNKS of 64 freelists in zbud_pool, the last
unbuddied[63] freelist linked with all zbud pages which have free chunks
of 63. Calculating according to context of num_free_chunks(), our max
chunk number of unbuddied zbud page is 62, so none of zbud pages will be
added/removed in last freelist, but still we will try to find an unbuddied
zbud page in the last unused freelist, it is unneeded.
This patch redefines NCHUNKS to 63 as free chunk number in one zbud page,
hence we can decrease size of zpool and avoid accessing the last unused
freelist whenever failing to allocate zbud from freelist in zbud_alloc.
Signed-off-by: Chao Yu <chao2.yu@samsung.com>
Cc: Seth Jennings <sjennings@variantweb.net>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'mm')
-rw-r--r-- | mm/zbud.c | 13 |
1 files changed, 7 insertions, 6 deletions
@@ -60,15 +60,17 @@ | |||
60 | * NCHUNKS_ORDER determines the internal allocation granularity, effectively | 60 | * NCHUNKS_ORDER determines the internal allocation granularity, effectively |
61 | * adjusting internal fragmentation. It also determines the number of | 61 | * adjusting internal fragmentation. It also determines the number of |
62 | * freelists maintained in each pool. NCHUNKS_ORDER of 6 means that the | 62 | * freelists maintained in each pool. NCHUNKS_ORDER of 6 means that the |
63 | * allocation granularity will be in chunks of size PAGE_SIZE/64, and there | 63 | * allocation granularity will be in chunks of size PAGE_SIZE/64. As one chunk |
64 | * will be 64 freelists per pool. | 64 | * in allocated page is occupied by zbud header, NCHUNKS will be calculated to |
65 | * 63 which shows the max number of free chunks in zbud page, also there will be | ||
66 | * 63 freelists per pool. | ||
65 | */ | 67 | */ |
66 | #define NCHUNKS_ORDER 6 | 68 | #define NCHUNKS_ORDER 6 |
67 | 69 | ||
68 | #define CHUNK_SHIFT (PAGE_SHIFT - NCHUNKS_ORDER) | 70 | #define CHUNK_SHIFT (PAGE_SHIFT - NCHUNKS_ORDER) |
69 | #define CHUNK_SIZE (1 << CHUNK_SHIFT) | 71 | #define CHUNK_SIZE (1 << CHUNK_SHIFT) |
70 | #define NCHUNKS (PAGE_SIZE >> CHUNK_SHIFT) | ||
71 | #define ZHDR_SIZE_ALIGNED CHUNK_SIZE | 72 | #define ZHDR_SIZE_ALIGNED CHUNK_SIZE |
73 | #define NCHUNKS ((PAGE_SIZE - ZHDR_SIZE_ALIGNED) >> CHUNK_SHIFT) | ||
72 | 74 | ||
73 | /** | 75 | /** |
74 | * struct zbud_pool - stores metadata for each zbud pool | 76 | * struct zbud_pool - stores metadata for each zbud pool |
@@ -268,10 +270,9 @@ static int num_free_chunks(struct zbud_header *zhdr) | |||
268 | { | 270 | { |
269 | /* | 271 | /* |
270 | * Rather than branch for different situations, just use the fact that | 272 | * Rather than branch for different situations, just use the fact that |
271 | * free buddies have a length of zero to simplify everything. -1 at the | 273 | * free buddies have a length of zero to simplify everything. |
272 | * end for the zbud header. | ||
273 | */ | 274 | */ |
274 | return NCHUNKS - zhdr->first_chunks - zhdr->last_chunks - 1; | 275 | return NCHUNKS - zhdr->first_chunks - zhdr->last_chunks; |
275 | } | 276 | } |
276 | 277 | ||
277 | /***************** | 278 | /***************** |