Skip to content

Commit 80e4a76

Browse files
lorenzo-stoakesakpm00
authored andcommitted
mm: refactor si_mem_available()
si_mem_available() needlessly places LRU statistics into an array before retrieving only two of them, simply access those directly. In addition, refactor the code so that the blocks of code which calculate the page cache and reclaimable components each resemble one another to clearly indicate we cap both against wmark_low in the same fashion. Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Lorenzo Stoakes <[email protected]> Cc: David Hildenbrand <[email protected]> Cc: Hugh Dickins <[email protected]> Cc: Kefeng Wang <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent b72b3c9 commit 80e4a76

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

mm/show_mem.c

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,8 @@ long si_mem_available(void)
3434
long available;
3535
unsigned long pagecache;
3636
unsigned long wmark_low = 0;
37-
unsigned long pages[NR_LRU_LISTS];
3837
unsigned long reclaimable;
3938
struct zone *zone;
40-
int lru;
41-
42-
for (lru = LRU_BASE; lru < NR_LRU_LISTS; lru++)
43-
pages[lru] = global_node_page_state(NR_LRU_BASE + lru);
4439

4540
for_each_zone(zone)
4641
wmark_low += low_wmark_pages(zone);
@@ -56,7 +51,8 @@ long si_mem_available(void)
5651
* start swapping or thrashing. Assume at least half of the page
5752
* cache, or the low watermark worth of cache, needs to stay.
5853
*/
59-
pagecache = pages[LRU_ACTIVE_FILE] + pages[LRU_INACTIVE_FILE];
54+
pagecache = global_node_page_state(NR_ACTIVE_FILE) +
55+
global_node_page_state(NR_INACTIVE_FILE);
6056
pagecache -= min(pagecache / 2, wmark_low);
6157
available += pagecache;
6258

@@ -67,7 +63,8 @@ long si_mem_available(void)
6763
*/
6864
reclaimable = global_node_page_state_pages(NR_SLAB_RECLAIMABLE_B) +
6965
global_node_page_state(NR_KERNEL_MISC_RECLAIMABLE);
70-
available += reclaimable - min(reclaimable / 2, wmark_low);
66+
reclaimable -= min(reclaimable / 2, wmark_low);
67+
available += reclaimable;
7168

7269
if (available < 0)
7370
available = 0;

0 commit comments

Comments
 (0)