Skip to content

Commit ca79b0c

Browse files
Arun KStorvalds
authored andcommitted
mm: convert totalram_pages and totalhigh_pages variables to atomic
totalram_pages and totalhigh_pages are made static inline function. Main motivation was that managed_page_count_lock handling was complicating things. It was discussed in length here, https://lore.kernel.org/patchwork/patch/995739/#1181785 So it seemes better to remove the lock and convert variables to atomic, with preventing poteintial store-to-read tearing as a bonus. [akpm@linux-foundation.org: coding style fixes] Link: http://lkml.kernel.org/r/1542090790-21750-4-git-send-email-arunks@codeaurora.org Signed-off-by: Arun KS <arunks@codeaurora.org> Suggested-by: Michal Hocko <mhocko@suse.com> Suggested-by: Vlastimil Babka <vbabka@suse.cz> Reviewed-by: Konstantin Khlebnikov <khlebnikov@yandex-team.ru> Reviewed-by: Pavel Tatashin <pasha.tatashin@soleen.com> Acked-by: Michal Hocko <mhocko@suse.com> Acked-by: Vlastimil Babka <vbabka@suse.cz> Cc: David Hildenbrand <david@redhat.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 9705bea commit ca79b0c

53 files changed

Lines changed: 131 additions & 81 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎arch/csky/mm/init.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ void free_initrd_mem(unsigned long start, unsigned long end)
7171
ClearPageReserved(virt_to_page(start));
7272
init_page_count(virt_to_page(start));
7373
free_page(start);
74-
totalram_pages++;
74+
totalram_pages_inc();
7575
}
7676
}
7777
#endif
@@ -88,7 +88,7 @@ void free_initmem(void)
8888
ClearPageReserved(virt_to_page(addr));
8989
init_page_count(virt_to_page(addr));
9090
free_page(addr);
91-
totalram_pages++;
91+
totalram_pages_inc();
9292
addr += PAGE_SIZE;
9393
}
9494

‎arch/powerpc/platforms/pseries/cmm.c‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ static long cmm_alloc_pages(long nr)
208208

209209
pa->page[pa->index++] = addr;
210210
loaned_pages++;
211-
totalram_pages--;
211+
totalram_pages_dec();
212212
spin_unlock(&cmm_lock);
213213
nr--;
214214
}
@@ -247,7 +247,7 @@ static long cmm_free_pages(long nr)
247247
free_page(addr);
248248
loaned_pages--;
249249
nr--;
250-
totalram_pages++;
250+
totalram_pages_inc();
251251
}
252252
spin_unlock(&cmm_lock);
253253
cmm_dbg("End request with %ld pages unfulfilled\n", nr);
@@ -291,7 +291,7 @@ static void cmm_get_mpp(void)
291291
int rc;
292292
struct hvcall_mpp_data mpp_data;
293293
signed long active_pages_target, page_loan_request, target;
294-
signed long total_pages = totalram_pages + loaned_pages;
294+
signed long total_pages = totalram_pages() + loaned_pages;
295295
signed long min_mem_pages = (min_mem_mb * 1024 * 1024) / PAGE_SIZE;
296296

297297
rc = h_get_mpp(&mpp_data);
@@ -322,7 +322,7 @@ static void cmm_get_mpp(void)
322322

323323
cmm_dbg("delta = %ld, loaned = %lu, target = %lu, oom = %lu, totalram = %lu\n",
324324
page_loan_request, loaned_pages, loaned_pages_target,
325-
oom_freed_pages, totalram_pages);
325+
oom_freed_pages, totalram_pages());
326326
}
327327

328328
static struct notifier_block cmm_oom_nb = {
@@ -581,7 +581,7 @@ static int cmm_mem_going_offline(void *arg)
581581
free_page(pa_curr->page[idx]);
582582
freed++;
583583
loaned_pages--;
584-
totalram_pages++;
584+
totalram_pages_inc();
585585
pa_curr->page[idx] = pa_last->page[--pa_last->index];
586586
if (pa_last->index == 0) {
587587
if (pa_curr == pa_last)

‎arch/s390/mm/init.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ static void __init setup_zero_pages(void)
5959
order = 7;
6060

6161
/* Limit number of empty zero pages for small memory sizes */
62-
while (order > 2 && (totalram_pages >> 10) < (1UL << order))
62+
while (order > 2 && (totalram_pages() >> 10) < (1UL << order))
6363
order--;
6464

6565
empty_zero_page = __get_free_pages(GFP_KERNEL | __GFP_ZERO, order);

‎arch/um/kernel/mem.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ void __init mem_init(void)
5151

5252
/* this will put all low memory onto the freelists */
5353
memblock_free_all();
54-
max_low_pfn = totalram_pages;
54+
max_low_pfn = totalram_pages();
5555
max_pfn = max_low_pfn;
5656
mem_init_print_info(NULL);
5757
kmalloc_ok = 1;

‎arch/x86/kernel/cpu/microcode/core.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,7 @@ static ssize_t microcode_write(struct file *file, const char __user *buf,
434434
size_t len, loff_t *ppos)
435435
{
436436
ssize_t ret = -EINVAL;
437-
unsigned long nr_pages = totalram_pages;
437+
unsigned long nr_pages = totalram_pages();
438438

439439
if ((len >> PAGE_SHIFT) > nr_pages) {
440440
pr_err("too much data (max %ld pages)\n", nr_pages);

‎drivers/char/agp/backend.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,9 @@ static int agp_find_max(void)
115115
long memory, index, result;
116116

117117
#if PAGE_SHIFT < 20
118-
memory = totalram_pages >> (20 - PAGE_SHIFT);
118+
memory = totalram_pages() >> (20 - PAGE_SHIFT);
119119
#else
120-
memory = totalram_pages << (PAGE_SHIFT - 20);
120+
memory = totalram_pages() << (PAGE_SHIFT - 20);
121121
#endif
122122
index = 1;
123123

‎drivers/gpu/drm/i915/i915_gem.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2559,7 +2559,7 @@ static int i915_gem_object_get_pages_gtt(struct drm_i915_gem_object *obj)
25592559
* If there's no chance of allocating enough pages for the whole
25602560
* object, bail early.
25612561
*/
2562-
if (page_count > totalram_pages)
2562+
if (page_count > totalram_pages())
25632563
return -ENOMEM;
25642564

25652565
st = kmalloc(sizeof(*st), GFP_KERNEL);

‎drivers/gpu/drm/i915/selftests/i915_gem_gtt.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ static int igt_ppgtt_alloc(void *arg)
170170
* This should ensure that we do not run into the oomkiller during
171171
* the test and take down the machine wilfully.
172172
*/
173-
limit = totalram_pages << PAGE_SHIFT;
173+
limit = totalram_pages() << PAGE_SHIFT;
174174
limit = min(ppgtt->vm.total, limit);
175175

176176
/* Check we can allocate the entire range */
@@ -1244,7 +1244,7 @@ static int exercise_mock(struct drm_i915_private *i915,
12441244
u64 hole_start, u64 hole_end,
12451245
unsigned long end_time))
12461246
{
1247-
const u64 limit = totalram_pages << PAGE_SHIFT;
1247+
const u64 limit = totalram_pages() << PAGE_SHIFT;
12481248
struct i915_gem_context *ctx;
12491249
struct i915_hw_ppgtt *ppgtt;
12501250
IGT_TIMEOUT(end_time);

‎drivers/hv/hv_balloon.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1090,7 +1090,7 @@ static void process_info(struct hv_dynmem_device *dm, struct dm_info_msg *msg)
10901090
static unsigned long compute_balloon_floor(void)
10911091
{
10921092
unsigned long min_pages;
1093-
unsigned long nr_pages = totalram_pages;
1093+
unsigned long nr_pages = totalram_pages();
10941094
#define MB2PAGES(mb) ((mb) << (20 - PAGE_SHIFT))
10951095
/* Simple continuous piecewiese linear function:
10961096
* max MiB -> min MiB gradient

‎drivers/md/dm-bufio.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1887,7 +1887,7 @@ static int __init dm_bufio_init(void)
18871887
dm_bufio_allocated_vmalloc = 0;
18881888
dm_bufio_current_allocated = 0;
18891889

1890-
mem = (__u64)mult_frac(totalram_pages - totalhigh_pages,
1890+
mem = (__u64)mult_frac(totalram_pages() - totalhigh_pages(),
18911891
DM_BUFIO_MEMORY_PERCENT, 100) << PAGE_SHIFT;
18921892

18931893
if (mem > ULONG_MAX)

0 commit comments

Comments
 (0)