summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArun KS <arunks@codeaurora.org>2018-12-28 03:34:29 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2018-12-28 15:11:47 -0500
commitca79b0c211af63fa3276f0e3fd7dd9ada2439839 (patch)
treea9198e85582744619903c85349583bb453fe36cb
parent9705bea5f833f4fc21d5bef5fce7348427f76ea4 (diff)
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>
-rw-r--r--arch/csky/mm/init.c4
-rw-r--r--arch/powerpc/platforms/pseries/cmm.c10
-rw-r--r--arch/s390/mm/init.c2
-rw-r--r--arch/um/kernel/mem.c2
-rw-r--r--arch/x86/kernel/cpu/microcode/core.c2
-rw-r--r--drivers/char/agp/backend.c4
-rw-r--r--drivers/gpu/drm/i915/i915_gem.c2
-rw-r--r--drivers/gpu/drm/i915/selftests/i915_gem_gtt.c4
-rw-r--r--drivers/hv/hv_balloon.c2
-rw-r--r--drivers/md/dm-bufio.c2
-rw-r--r--drivers/md/dm-crypt.c2
-rw-r--r--drivers/md/dm-integrity.c2
-rw-r--r--drivers/md/dm-stats.c2
-rw-r--r--drivers/media/platform/mtk-vpu/mtk_vpu.c2
-rw-r--r--drivers/misc/vmw_balloon.c2
-rw-r--r--drivers/parisc/ccio-dma.c4
-rw-r--r--drivers/parisc/sba_iommu.c4
-rw-r--r--drivers/staging/android/ion/ion_system_heap.c2
-rw-r--r--drivers/xen/xen-selfballoon.c6
-rw-r--r--fs/ceph/super.h2
-rw-r--r--fs/file_table.c2
-rw-r--r--fs/fuse/inode.c2
-rw-r--r--fs/nfs/write.c2
-rw-r--r--fs/nfsd/nfscache.c2
-rw-r--r--fs/ntfs/malloc.h2
-rw-r--r--fs/proc/base.c2
-rw-r--r--include/linux/highmem.h28
-rw-r--r--include/linux/mm.h27
-rw-r--r--include/linux/swap.h1
-rw-r--r--kernel/fork.c2
-rw-r--r--kernel/kexec_core.c2
-rw-r--r--kernel/power/snapshot.c2
-rw-r--r--mm/highmem.c5
-rw-r--r--mm/huge_memory.c2
-rw-r--r--mm/kasan/quarantine.c2
-rw-r--r--mm/memblock.c4
-rw-r--r--mm/mm_init.c2
-rw-r--r--mm/oom_kill.c2
-rw-r--r--mm/page_alloc.c20
-rw-r--r--mm/shmem.c9
-rw-r--r--mm/slab.c2
-rw-r--r--mm/swap.c2
-rw-r--r--mm/util.c2
-rw-r--r--mm/vmalloc.c4
-rw-r--r--mm/workingset.c2
-rw-r--r--mm/zswap.c4
-rw-r--r--net/dccp/proto.c2
-rw-r--r--net/decnet/dn_route.c2
-rw-r--r--net/ipv4/tcp_metrics.c2
-rw-r--r--net/netfilter/nf_conntrack_core.c2
-rw-r--r--net/netfilter/xt_hashlimit.c2
-rw-r--r--net/sctp/protocol.c2
-rw-r--r--security/integrity/ima/ima_kexec.c2
53 files changed, 131 insertions, 81 deletions
diff --git a/arch/csky/mm/init.c b/arch/csky/mm/init.c
index dc07c078f9b8..66e597053488 100644
--- a/arch/csky/mm/init.c
+++ b/arch/csky/mm/init.c
@@ -71,7 +71,7 @@ void free_initrd_mem(unsigned long start, unsigned long end)
71 ClearPageReserved(virt_to_page(start)); 71 ClearPageReserved(virt_to_page(start));
72 init_page_count(virt_to_page(start)); 72 init_page_count(virt_to_page(start));
73 free_page(start); 73 free_page(start);
74 totalram_pages++; 74 totalram_pages_inc();
75 } 75 }
76} 76}
77#endif 77#endif
@@ -88,7 +88,7 @@ void free_initmem(void)
88 ClearPageReserved(virt_to_page(addr)); 88 ClearPageReserved(virt_to_page(addr));
89 init_page_count(virt_to_page(addr)); 89 init_page_count(virt_to_page(addr));
90 free_page(addr); 90 free_page(addr);
91 totalram_pages++; 91 totalram_pages_inc();
92 addr += PAGE_SIZE; 92 addr += PAGE_SIZE;
93 } 93 }
94 94
diff --git a/arch/powerpc/platforms/pseries/cmm.c b/arch/powerpc/platforms/pseries/cmm.c
index 25427a48feae..e8d63a6a9002 100644
--- a/arch/powerpc/platforms/pseries/cmm.c
+++ b/arch/powerpc/platforms/pseries/cmm.c
@@ -208,7 +208,7 @@ static long cmm_alloc_pages(long nr)
208 208
209 pa->page[pa->index++] = addr; 209 pa->page[pa->index++] = addr;
210 loaned_pages++; 210 loaned_pages++;
211 totalram_pages--; 211 totalram_pages_dec();
212 spin_unlock(&cmm_lock); 212 spin_unlock(&cmm_lock);
213 nr--; 213 nr--;
214 } 214 }
@@ -247,7 +247,7 @@ static long cmm_free_pages(long nr)
247 free_page(addr); 247 free_page(addr);
248 loaned_pages--; 248 loaned_pages--;
249 nr--; 249 nr--;
250 totalram_pages++; 250 totalram_pages_inc();
251 } 251 }
252 spin_unlock(&cmm_lock); 252 spin_unlock(&cmm_lock);
253 cmm_dbg("End request with %ld pages unfulfilled\n", nr); 253 cmm_dbg("End request with %ld pages unfulfilled\n", nr);
@@ -291,7 +291,7 @@ static void cmm_get_mpp(void)
291 int rc; 291 int rc;
292 struct hvcall_mpp_data mpp_data; 292 struct hvcall_mpp_data mpp_data;
293 signed long active_pages_target, page_loan_request, target; 293 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;
295 signed long min_mem_pages = (min_mem_mb * 1024 * 1024) / PAGE_SIZE; 295 signed long min_mem_pages = (min_mem_mb * 1024 * 1024) / PAGE_SIZE;
296 296
297 rc = h_get_mpp(&mpp_data); 297 rc = h_get_mpp(&mpp_data);
@@ -322,7 +322,7 @@ static void cmm_get_mpp(void)
322 322
323 cmm_dbg("delta = %ld, loaned = %lu, target = %lu, oom = %lu, totalram = %lu\n", 323 cmm_dbg("delta = %ld, loaned = %lu, target = %lu, oom = %lu, totalram = %lu\n",
324 page_loan_request, loaned_pages, loaned_pages_target, 324 page_loan_request, loaned_pages, loaned_pages_target,
325 oom_freed_pages, totalram_pages); 325 oom_freed_pages, totalram_pages());
326} 326}
327 327
328static struct notifier_block cmm_oom_nb = { 328static struct notifier_block cmm_oom_nb = {
@@ -581,7 +581,7 @@ static int cmm_mem_going_offline(void *arg)
581 free_page(pa_curr->page[idx]); 581 free_page(pa_curr->page[idx]);
582 freed++; 582 freed++;
583 loaned_pages--; 583 loaned_pages--;
584 totalram_pages++; 584 totalram_pages_inc();
585 pa_curr->page[idx] = pa_last->page[--pa_last->index]; 585 pa_curr->page[idx] = pa_last->page[--pa_last->index];
586 if (pa_last->index == 0) { 586 if (pa_last->index == 0) {
587 if (pa_curr == pa_last) 587 if (pa_curr == pa_last)
diff --git a/arch/s390/mm/init.c b/arch/s390/mm/init.c
index 76d0708438e9..50388190b393 100644
--- a/arch/s390/mm/init.c
+++ b/arch/s390/mm/init.c
@@ -59,7 +59,7 @@ static void __init setup_zero_pages(void)
59 order = 7; 59 order = 7;
60 60
61 /* Limit number of empty zero pages for small memory sizes */ 61 /* 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))
63 order--; 63 order--;
64 64
65 empty_zero_page = __get_free_pages(GFP_KERNEL | __GFP_ZERO, order); 65 empty_zero_page = __get_free_pages(GFP_KERNEL | __GFP_ZERO, order);
diff --git a/arch/um/kernel/mem.c b/arch/um/kernel/mem.c
index 2da209687a22..8d21a83dd289 100644
--- a/arch/um/kernel/mem.c
+++ b/arch/um/kernel/mem.c
@@ -51,7 +51,7 @@ void __init mem_init(void)
51 51
52 /* this will put all low memory onto the freelists */ 52 /* this will put all low memory onto the freelists */
53 memblock_free_all(); 53 memblock_free_all();
54 max_low_pfn = totalram_pages; 54 max_low_pfn = totalram_pages();
55 max_pfn = max_low_pfn; 55 max_pfn = max_low_pfn;
56 mem_init_print_info(NULL); 56 mem_init_print_info(NULL);
57 kmalloc_ok = 1; 57 kmalloc_ok = 1;
diff --git a/arch/x86/kernel/cpu/microcode/core.c b/arch/x86/kernel/cpu/microcode/core.c
index 168fa272cc3e..97f9ada9ceda 100644
--- a/arch/x86/kernel/cpu/microcode/core.c
+++ b/arch/x86/kernel/cpu/microcode/core.c
@@ -434,7 +434,7 @@ static ssize_t microcode_write(struct file *file, const char __user *buf,
434 size_t len, loff_t *ppos) 434 size_t len, loff_t *ppos)
435{ 435{
436 ssize_t ret = -EINVAL; 436 ssize_t ret = -EINVAL;
437 unsigned long nr_pages = totalram_pages; 437 unsigned long nr_pages = totalram_pages();
438 438
439 if ((len >> PAGE_SHIFT) > nr_pages) { 439 if ((len >> PAGE_SHIFT) > nr_pages) {
440 pr_err("too much data (max %ld pages)\n", nr_pages); 440 pr_err("too much data (max %ld pages)\n", nr_pages);
diff --git a/drivers/char/agp/backend.c b/drivers/char/agp/backend.c
index 38ffb281df97..004a3ce8ba72 100644
--- a/drivers/char/agp/backend.c
+++ b/drivers/char/agp/backend.c
@@ -115,9 +115,9 @@ static int agp_find_max(void)
115 long memory, index, result; 115 long memory, index, result;
116 116
117#if PAGE_SHIFT < 20 117#if PAGE_SHIFT < 20
118 memory = totalram_pages >> (20 - PAGE_SHIFT); 118 memory = totalram_pages() >> (20 - PAGE_SHIFT);
119#else 119#else
120 memory = totalram_pages << (PAGE_SHIFT - 20); 120 memory = totalram_pages() << (PAGE_SHIFT - 20);
121#endif 121#endif
122 index = 1; 122 index = 1;
123 123
diff --git a/drivers/gpu/drm/i915/i915_gem.c b/drivers/gpu/drm/i915/i915_gem.c
index d36a9755ad91..a9de07bb72c8 100644
--- a/drivers/gpu/drm/i915/i915_gem.c
+++ b/drivers/gpu/drm/i915/i915_gem.c
@@ -2559,7 +2559,7 @@ static int i915_gem_object_get_pages_gtt(struct drm_i915_gem_object *obj)
2559 * If there's no chance of allocating enough pages for the whole 2559 * If there's no chance of allocating enough pages for the whole
2560 * object, bail early. 2560 * object, bail early.
2561 */ 2561 */
2562 if (page_count > totalram_pages) 2562 if (page_count > totalram_pages())
2563 return -ENOMEM; 2563 return -ENOMEM;
2564 2564
2565 st = kmalloc(sizeof(*st), GFP_KERNEL); 2565 st = kmalloc(sizeof(*st), GFP_KERNEL);
diff --git a/drivers/gpu/drm/i915/selftests/i915_gem_gtt.c b/drivers/gpu/drm/i915/selftests/i915_gem_gtt.c
index 69fe86b30fbb..a9ed0ecc94e2 100644
--- a/drivers/gpu/drm/i915/selftests/i915_gem_gtt.c
+++ b/drivers/gpu/drm/i915/selftests/i915_gem_gtt.c
@@ -170,7 +170,7 @@ static int igt_ppgtt_alloc(void *arg)
170 * This should ensure that we do not run into the oomkiller during 170 * This should ensure that we do not run into the oomkiller during
171 * the test and take down the machine wilfully. 171 * the test and take down the machine wilfully.
172 */ 172 */
173 limit = totalram_pages << PAGE_SHIFT; 173 limit = totalram_pages() << PAGE_SHIFT;
174 limit = min(ppgtt->vm.total, limit); 174 limit = min(ppgtt->vm.total, limit);
175 175
176 /* Check we can allocate the entire range */ 176 /* Check we can allocate the entire range */
@@ -1244,7 +1244,7 @@ static int exercise_mock(struct drm_i915_private *i915,
1244 u64 hole_start, u64 hole_end, 1244 u64 hole_start, u64 hole_end,
1245 unsigned long end_time)) 1245 unsigned long end_time))
1246{ 1246{
1247 const u64 limit = totalram_pages << PAGE_SHIFT; 1247 const u64 limit = totalram_pages() << PAGE_SHIFT;
1248 struct i915_gem_context *ctx; 1248 struct i915_gem_context *ctx;
1249 struct i915_hw_ppgtt *ppgtt; 1249 struct i915_hw_ppgtt *ppgtt;
1250 IGT_TIMEOUT(end_time); 1250 IGT_TIMEOUT(end_time);
diff --git a/drivers/hv/hv_balloon.c b/drivers/hv/hv_balloon.c
index f3e7da981610..5301fef16c31 100644
--- a/drivers/hv/hv_balloon.c
+++ b/drivers/hv/hv_balloon.c
@@ -1090,7 +1090,7 @@ static void process_info(struct hv_dynmem_device *dm, struct dm_info_msg *msg)
1090static unsigned long compute_balloon_floor(void) 1090static unsigned long compute_balloon_floor(void)
1091{ 1091{
1092 unsigned long min_pages; 1092 unsigned long min_pages;
1093 unsigned long nr_pages = totalram_pages; 1093 unsigned long nr_pages = totalram_pages();
1094#define MB2PAGES(mb) ((mb) << (20 - PAGE_SHIFT)) 1094#define MB2PAGES(mb) ((mb) << (20 - PAGE_SHIFT))
1095 /* Simple continuous piecewiese linear function: 1095 /* Simple continuous piecewiese linear function:
1096 * max MiB -> min MiB gradient 1096 * max MiB -> min MiB gradient
diff --git a/drivers/md/dm-bufio.c b/drivers/md/dm-bufio.c
index dc385b70e4c3..8b0b628e5d1c 100644
--- a/drivers/md/dm-bufio.c
+++ b/drivers/md/dm-bufio.c
@@ -1887,7 +1887,7 @@ static int __init dm_bufio_init(void)
1887 dm_bufio_allocated_vmalloc = 0; 1887 dm_bufio_allocated_vmalloc = 0;
1888 dm_bufio_current_allocated = 0; 1888 dm_bufio_current_allocated = 0;
1889 1889
1890 mem = (__u64)mult_frac(totalram_pages - totalhigh_pages, 1890 mem = (__u64)mult_frac(totalram_pages() - totalhigh_pages(),
1891 DM_BUFIO_MEMORY_PERCENT, 100) << PAGE_SHIFT; 1891 DM_BUFIO_MEMORY_PERCENT, 100) << PAGE_SHIFT;
1892 1892
1893 if (mem > ULONG_MAX) 1893 if (mem > ULONG_MAX)
diff --git a/drivers/md/dm-crypt.c b/drivers/md/dm-crypt.c
index a7195eb5b8d8..a8c32de29e3f 100644
--- a/drivers/md/dm-crypt.c
+++ b/drivers/md/dm-crypt.c
@@ -2158,7 +2158,7 @@ static int crypt_wipe_key(struct crypt_config *cc)
2158 2158
2159static void crypt_calculate_pages_per_client(void) 2159static void crypt_calculate_pages_per_client(void)
2160{ 2160{
2161 unsigned long pages = (totalram_pages - totalhigh_pages) * DM_CRYPT_MEMORY_PERCENT / 100; 2161 unsigned long pages = (totalram_pages() - totalhigh_pages()) * DM_CRYPT_MEMORY_PERCENT / 100;
2162 2162
2163 if (!dm_crypt_clients_n) 2163 if (!dm_crypt_clients_n)
2164 return; 2164 return;
diff --git a/drivers/md/dm-integrity.c b/drivers/md/dm-integrity.c
index d4ad0bfee251..62baa3214cc7 100644
--- a/drivers/md/dm-integrity.c
+++ b/drivers/md/dm-integrity.c
@@ -2843,7 +2843,7 @@ static int create_journal(struct dm_integrity_c *ic, char **error)
2843 journal_pages = roundup((__u64)ic->journal_sections * ic->journal_section_sectors, 2843 journal_pages = roundup((__u64)ic->journal_sections * ic->journal_section_sectors,
2844 PAGE_SIZE >> SECTOR_SHIFT) >> (PAGE_SHIFT - SECTOR_SHIFT); 2844 PAGE_SIZE >> SECTOR_SHIFT) >> (PAGE_SHIFT - SECTOR_SHIFT);
2845 journal_desc_size = journal_pages * sizeof(struct page_list); 2845 journal_desc_size = journal_pages * sizeof(struct page_list);
2846 if (journal_pages >= totalram_pages - totalhigh_pages || journal_desc_size > ULONG_MAX) { 2846 if (journal_pages >= totalram_pages() - totalhigh_pages() || journal_desc_size > ULONG_MAX) {
2847 *error = "Journal doesn't fit into memory"; 2847 *error = "Journal doesn't fit into memory";
2848 r = -ENOMEM; 2848 r = -ENOMEM;
2849 goto bad; 2849 goto bad;
diff --git a/drivers/md/dm-stats.c b/drivers/md/dm-stats.c
index 21de30b4e2a1..45b92a3d9d8e 100644
--- a/drivers/md/dm-stats.c
+++ b/drivers/md/dm-stats.c
@@ -85,7 +85,7 @@ static bool __check_shared_memory(size_t alloc_size)
85 a = shared_memory_amount + alloc_size; 85 a = shared_memory_amount + alloc_size;
86 if (a < shared_memory_amount) 86 if (a < shared_memory_amount)
87 return false; 87 return false;
88 if (a >> PAGE_SHIFT > totalram_pages / DM_STATS_MEMORY_FACTOR) 88 if (a >> PAGE_SHIFT > totalram_pages() / DM_STATS_MEMORY_FACTOR)
89 return false; 89 return false;
90#ifdef CONFIG_MMU 90#ifdef CONFIG_MMU
91 if (a > (VMALLOC_END - VMALLOC_START) / DM_STATS_VMALLOC_FACTOR) 91 if (a > (VMALLOC_END - VMALLOC_START) / DM_STATS_VMALLOC_FACTOR)
diff --git a/drivers/media/platform/mtk-vpu/mtk_vpu.c b/drivers/media/platform/mtk-vpu/mtk_vpu.c
index 616f78b24a79..b6602490a247 100644
--- a/drivers/media/platform/mtk-vpu/mtk_vpu.c
+++ b/drivers/media/platform/mtk-vpu/mtk_vpu.c
@@ -855,7 +855,7 @@ static int mtk_vpu_probe(struct platform_device *pdev)
855 /* Set PTCM to 96K and DTCM to 32K */ 855 /* Set PTCM to 96K and DTCM to 32K */
856 vpu_cfg_writel(vpu, 0x2, VPU_TCM_CFG); 856 vpu_cfg_writel(vpu, 0x2, VPU_TCM_CFG);
857 857
858 vpu->enable_4GB = !!(totalram_pages > (SZ_2G >> PAGE_SHIFT)); 858 vpu->enable_4GB = !!(totalram_pages() > (SZ_2G >> PAGE_SHIFT));
859 dev_info(dev, "4GB mode %u\n", vpu->enable_4GB); 859 dev_info(dev, "4GB mode %u\n", vpu->enable_4GB);
860 860
861 if (vpu->enable_4GB) { 861 if (vpu->enable_4GB) {
diff --git a/drivers/misc/vmw_balloon.c b/drivers/misc/vmw_balloon.c
index 9b0b3fa4f836..e6126a4b95d3 100644
--- a/drivers/misc/vmw_balloon.c
+++ b/drivers/misc/vmw_balloon.c
@@ -570,7 +570,7 @@ static int vmballoon_send_get_target(struct vmballoon *b)
570 unsigned long status; 570 unsigned long status;
571 unsigned long limit; 571 unsigned long limit;
572 572
573 limit = totalram_pages; 573 limit = totalram_pages();
574 574
575 /* Ensure limit fits in 32-bits */ 575 /* Ensure limit fits in 32-bits */
576 if (limit != (u32)limit) 576 if (limit != (u32)limit)
diff --git a/drivers/parisc/ccio-dma.c b/drivers/parisc/ccio-dma.c
index 701a7d6a74d5..358e380eb7fa 100644
--- a/drivers/parisc/ccio-dma.c
+++ b/drivers/parisc/ccio-dma.c
@@ -1251,7 +1251,7 @@ ccio_ioc_init(struct ioc *ioc)
1251 ** Hot-Plug/Removal of PCI cards. (aka PCI OLARD). 1251 ** Hot-Plug/Removal of PCI cards. (aka PCI OLARD).
1252 */ 1252 */
1253 1253
1254 iova_space_size = (u32) (totalram_pages / count_parisc_driver(&ccio_driver)); 1254 iova_space_size = (u32) (totalram_pages() / count_parisc_driver(&ccio_driver));
1255 1255
1256 /* limit IOVA space size to 1MB-1GB */ 1256 /* limit IOVA space size to 1MB-1GB */
1257 1257
@@ -1290,7 +1290,7 @@ ccio_ioc_init(struct ioc *ioc)
1290 1290
1291 DBG_INIT("%s() hpa 0x%p mem %luMB IOV %dMB (%d bits)\n", 1291 DBG_INIT("%s() hpa 0x%p mem %luMB IOV %dMB (%d bits)\n",
1292 __func__, ioc->ioc_regs, 1292 __func__, ioc->ioc_regs,
1293 (unsigned long) totalram_pages >> (20 - PAGE_SHIFT), 1293 (unsigned long) totalram_pages() >> (20 - PAGE_SHIFT),
1294 iova_space_size>>20, 1294 iova_space_size>>20,
1295 iov_order + PAGE_SHIFT); 1295 iov_order + PAGE_SHIFT);
1296 1296
diff --git a/drivers/parisc/sba_iommu.c b/drivers/parisc/sba_iommu.c
index c1e599a429af..e0655949480a 100644
--- a/drivers/parisc/sba_iommu.c
+++ b/drivers/parisc/sba_iommu.c
@@ -1414,7 +1414,7 @@ sba_ioc_init(struct parisc_device *sba, struct ioc *ioc, int ioc_num)
1414 ** for DMA hints - ergo only 30 bits max. 1414 ** for DMA hints - ergo only 30 bits max.
1415 */ 1415 */
1416 1416
1417 iova_space_size = (u32) (totalram_pages/global_ioc_cnt); 1417 iova_space_size = (u32) (totalram_pages()/global_ioc_cnt);
1418 1418
1419 /* limit IOVA space size to 1MB-1GB */ 1419 /* limit IOVA space size to 1MB-1GB */
1420 if (iova_space_size < (1 << (20 - PAGE_SHIFT))) { 1420 if (iova_space_size < (1 << (20 - PAGE_SHIFT))) {
@@ -1439,7 +1439,7 @@ sba_ioc_init(struct parisc_device *sba, struct ioc *ioc, int ioc_num)
1439 DBG_INIT("%s() hpa 0x%lx mem %ldMB IOV %dMB (%d bits)\n", 1439 DBG_INIT("%s() hpa 0x%lx mem %ldMB IOV %dMB (%d bits)\n",
1440 __func__, 1440 __func__,
1441 ioc->ioc_hpa, 1441 ioc->ioc_hpa,
1442 (unsigned long) totalram_pages >> (20 - PAGE_SHIFT), 1442 (unsigned long) totalram_pages() >> (20 - PAGE_SHIFT),
1443 iova_space_size>>20, 1443 iova_space_size>>20,
1444 iov_order + PAGE_SHIFT); 1444 iov_order + PAGE_SHIFT);
1445 1445
diff --git a/drivers/staging/android/ion/ion_system_heap.c b/drivers/staging/android/ion/ion_system_heap.c
index 548bb02c0ca6..6cb0eebdff89 100644
--- a/drivers/staging/android/ion/ion_system_heap.c
+++ b/drivers/staging/android/ion/ion_system_heap.c
@@ -110,7 +110,7 @@ static int ion_system_heap_allocate(struct ion_heap *heap,
110 unsigned long size_remaining = PAGE_ALIGN(size); 110 unsigned long size_remaining = PAGE_ALIGN(size);
111 unsigned int max_order = orders[0]; 111 unsigned int max_order = orders[0];
112 112
113 if (size / PAGE_SIZE > totalram_pages / 2) 113 if (size / PAGE_SIZE > totalram_pages() / 2)
114 return -ENOMEM; 114 return -ENOMEM;
115 115
116 INIT_LIST_HEAD(&pages); 116 INIT_LIST_HEAD(&pages);
diff --git a/drivers/xen/xen-selfballoon.c b/drivers/xen/xen-selfballoon.c
index 5165aa82bf7d..246f6122c9ee 100644
--- a/drivers/xen/xen-selfballoon.c
+++ b/drivers/xen/xen-selfballoon.c
@@ -189,7 +189,7 @@ static void selfballoon_process(struct work_struct *work)
189 bool reset_timer = false; 189 bool reset_timer = false;
190 190
191 if (xen_selfballooning_enabled) { 191 if (xen_selfballooning_enabled) {
192 cur_pages = totalram_pages; 192 cur_pages = totalram_pages();
193 tgt_pages = cur_pages; /* default is no change */ 193 tgt_pages = cur_pages; /* default is no change */
194 goal_pages = vm_memory_committed() + 194 goal_pages = vm_memory_committed() +
195 totalreserve_pages + 195 totalreserve_pages +
@@ -227,7 +227,7 @@ static void selfballoon_process(struct work_struct *work)
227 if (tgt_pages < floor_pages) 227 if (tgt_pages < floor_pages)
228 tgt_pages = floor_pages; 228 tgt_pages = floor_pages;
229 balloon_set_new_target(tgt_pages + 229 balloon_set_new_target(tgt_pages +
230 balloon_stats.current_pages - totalram_pages); 230 balloon_stats.current_pages - totalram_pages());
231 reset_timer = true; 231 reset_timer = true;
232 } 232 }
233#ifdef CONFIG_FRONTSWAP 233#ifdef CONFIG_FRONTSWAP
@@ -569,7 +569,7 @@ int xen_selfballoon_init(bool use_selfballooning, bool use_frontswap_selfshrink)
569 * much more reliably and response faster in some cases. 569 * much more reliably and response faster in some cases.
570 */ 570 */
571 if (!selfballoon_reserved_mb) { 571 if (!selfballoon_reserved_mb) {
572 reserve_pages = totalram_pages / 10; 572 reserve_pages = totalram_pages() / 10;
573 selfballoon_reserved_mb = PAGES2MB(reserve_pages); 573 selfballoon_reserved_mb = PAGES2MB(reserve_pages);
574 } 574 }
575 schedule_delayed_work(&selfballoon_worker, selfballoon_interval * HZ); 575 schedule_delayed_work(&selfballoon_worker, selfballoon_interval * HZ);
diff --git a/fs/ceph/super.h b/fs/ceph/super.h
index 79a265ba9200..dfb64a5211b6 100644
--- a/fs/ceph/super.h
+++ b/fs/ceph/super.h
@@ -810,7 +810,7 @@ static inline int default_congestion_kb(void)
810 * This allows larger machines to have larger/more transfers. 810 * This allows larger machines to have larger/more transfers.
811 * Limit the default to 256M 811 * Limit the default to 256M
812 */ 812 */
813 congestion_kb = (16*int_sqrt(totalram_pages)) << (PAGE_SHIFT-10); 813 congestion_kb = (16*int_sqrt(totalram_pages())) << (PAGE_SHIFT-10);
814 if (congestion_kb > 256*1024) 814 if (congestion_kb > 256*1024)
815 congestion_kb = 256*1024; 815 congestion_kb = 256*1024;
816 816
diff --git a/fs/file_table.c b/fs/file_table.c
index b6e9587f05c7..5679e7fcb6b0 100644
--- a/fs/file_table.c
+++ b/fs/file_table.c
@@ -380,7 +380,7 @@ void __init files_init(void)
380void __init files_maxfiles_init(void) 380void __init files_maxfiles_init(void)
381{ 381{
382 unsigned long n; 382 unsigned long n;
383 unsigned long nr_pages = totalram_pages; 383 unsigned long nr_pages = totalram_pages();
384 unsigned long memreserve = (nr_pages - nr_free_pages()) * 3/2; 384 unsigned long memreserve = (nr_pages - nr_free_pages()) * 3/2;
385 385
386 memreserve = min(memreserve, nr_pages - 1); 386 memreserve = min(memreserve, nr_pages - 1);
diff --git a/fs/fuse/inode.c b/fs/fuse/inode.c
index 568abed20eb2..76baaa6be393 100644
--- a/fs/fuse/inode.c
+++ b/fs/fuse/inode.c
@@ -824,7 +824,7 @@ static const struct super_operations fuse_super_operations = {
824static void sanitize_global_limit(unsigned *limit) 824static void sanitize_global_limit(unsigned *limit)
825{ 825{
826 if (*limit == 0) 826 if (*limit == 0)
827 *limit = ((totalram_pages << PAGE_SHIFT) >> 13) / 827 *limit = ((totalram_pages() << PAGE_SHIFT) >> 13) /
828 sizeof(struct fuse_req); 828 sizeof(struct fuse_req);
829 829
830 if (*limit >= 1 << 16) 830 if (*limit >= 1 << 16)
diff --git a/fs/nfs/write.c b/fs/nfs/write.c
index 586726a590d8..4f15665f0ad1 100644
--- a/fs/nfs/write.c
+++ b/fs/nfs/write.c
@@ -2121,7 +2121,7 @@ int __init nfs_init_writepagecache(void)
2121 * This allows larger machines to have larger/more transfers. 2121 * This allows larger machines to have larger/more transfers.
2122 * Limit the default to 256M 2122 * Limit the default to 256M
2123 */ 2123 */
2124 nfs_congestion_kb = (16*int_sqrt(totalram_pages)) << (PAGE_SHIFT-10); 2124 nfs_congestion_kb = (16*int_sqrt(totalram_pages())) << (PAGE_SHIFT-10);
2125 if (nfs_congestion_kb > 256*1024) 2125 if (nfs_congestion_kb > 256*1024)
2126 nfs_congestion_kb = 256*1024; 2126 nfs_congestion_kb = 256*1024;
2127 2127
diff --git a/fs/nfsd/nfscache.c b/fs/nfsd/nfscache.c
index e2fe0e9ce0df..da52b594362a 100644
--- a/fs/nfsd/nfscache.c
+++ b/fs/nfsd/nfscache.c
@@ -99,7 +99,7 @@ static unsigned int
99nfsd_cache_size_limit(void) 99nfsd_cache_size_limit(void)
100{ 100{
101 unsigned int limit; 101 unsigned int limit;
102 unsigned long low_pages = totalram_pages - totalhigh_pages; 102 unsigned long low_pages = totalram_pages() - totalhigh_pages();
103 103
104 limit = (16 * int_sqrt(low_pages)) << (PAGE_SHIFT-10); 104 limit = (16 * int_sqrt(low_pages)) << (PAGE_SHIFT-10);
105 return min_t(unsigned int, limit, 256*1024); 105 return min_t(unsigned int, limit, 256*1024);
diff --git a/fs/ntfs/malloc.h b/fs/ntfs/malloc.h
index ab172e5f51d9..5becc8acc8f4 100644
--- a/fs/ntfs/malloc.h
+++ b/fs/ntfs/malloc.h
@@ -47,7 +47,7 @@ static inline void *__ntfs_malloc(unsigned long size, gfp_t gfp_mask)
47 return kmalloc(PAGE_SIZE, gfp_mask & ~__GFP_HIGHMEM); 47 return kmalloc(PAGE_SIZE, gfp_mask & ~__GFP_HIGHMEM);
48 /* return (void *)__get_free_page(gfp_mask); */ 48 /* return (void *)__get_free_page(gfp_mask); */
49 } 49 }
50 if (likely((size >> PAGE_SHIFT) < totalram_pages)) 50 if (likely((size >> PAGE_SHIFT) < totalram_pages()))
51 return __vmalloc(size, gfp_mask, PAGE_KERNEL); 51 return __vmalloc(size, gfp_mask, PAGE_KERNEL);
52 return NULL; 52 return NULL;
53} 53}
diff --git a/fs/proc/base.c b/fs/proc/base.c
index ce3465479447..d7fd1ca807d2 100644
--- a/fs/proc/base.c
+++ b/fs/proc/base.c
@@ -530,7 +530,7 @@ static const struct file_operations proc_lstats_operations = {
530static int proc_oom_score(struct seq_file *m, struct pid_namespace *ns, 530static int proc_oom_score(struct seq_file *m, struct pid_namespace *ns,
531 struct pid *pid, struct task_struct *task) 531 struct pid *pid, struct task_struct *task)
532{ 532{
533 unsigned long totalpages = totalram_pages + total_swap_pages; 533 unsigned long totalpages = totalram_pages() + total_swap_pages;
534 unsigned long points = 0; 534 unsigned long points = 0;
535 535
536 points = oom_badness(task, NULL, NULL, totalpages) * 536 points = oom_badness(task, NULL, NULL, totalpages) *
diff --git a/include/linux/highmem.h b/include/linux/highmem.h
index 0690679832d4..ea5cdbd8c2c3 100644
--- a/include/linux/highmem.h
+++ b/include/linux/highmem.h
@@ -36,7 +36,31 @@ static inline void invalidate_kernel_vmap_range(void *vaddr, int size)
36 36
37/* declarations for linux/mm/highmem.c */ 37/* declarations for linux/mm/highmem.c */
38unsigned int nr_free_highpages(void); 38unsigned int nr_free_highpages(void);
39extern unsigned long totalhigh_pages; 39extern atomic_long_t _totalhigh_pages;
40static inline unsigned long totalhigh_pages(void)
41{
42 return (unsigned long)atomic_long_read(&_totalhigh_pages);
43}
44
45static inline void totalhigh_pages_inc(void)
46{
47 atomic_long_inc(&_totalhigh_pages);
48}
49
50static inline void totalhigh_pages_dec(void)
51{
52 atomic_long_dec(&_totalhigh_pages);
53}
54
55static inline void totalhigh_pages_add(long count)
56{
57 atomic_long_add(count, &_totalhigh_pages);
58}
59
60static inline void totalhigh_pages_set(long val)
61{
62 atomic_long_set(&_totalhigh_pages, val);
63}
40 64
41void kmap_flush_unused(void); 65void kmap_flush_unused(void);
42 66
@@ -51,7 +75,7 @@ static inline struct page *kmap_to_page(void *addr)
51 return virt_to_page(addr); 75 return virt_to_page(addr);
52} 76}
53 77
54#define totalhigh_pages 0UL 78static inline unsigned long totalhigh_pages(void) { return 0UL; }
55 79
56#ifndef ARCH_HAS_KMAP 80#ifndef ARCH_HAS_KMAP
57static inline void *kmap(struct page *page) 81static inline void *kmap(struct page *page)
diff --git a/include/linux/mm.h b/include/linux/mm.h
index b4d01969e700..1d2be4c2d34a 100644
--- a/include/linux/mm.h
+++ b/include/linux/mm.h
@@ -48,7 +48,32 @@ static inline void set_max_mapnr(unsigned long limit)
48static inline void set_max_mapnr(unsigned long limit) { } 48static inline void set_max_mapnr(unsigned long limit) { }
49#endif 49#endif
50 50
51extern unsigned long totalram_pages; 51extern atomic_long_t _totalram_pages;
52static inline unsigned long totalram_pages(void)
53{
54 return (unsigned long)atomic_long_read(&_totalram_pages);
55}
56
57static inline void totalram_pages_inc(void)
58{
59 atomic_long_inc(&_totalram_pages);
60}
61
62static inline void totalram_pages_dec(void)
63{
64 atomic_long_dec(&_totalram_pages);
65}
66
67static inline void totalram_pages_add(long count)
68{
69 atomic_long_add(count, &_totalram_pages);
70}
71
72static inline void totalram_pages_set(long val)
73{
74 atomic_long_set(&_totalram_pages, val);
75}
76
52extern void * high_memory; 77extern void * high_memory;
53extern int page_cluster; 78extern int page_cluster;
54 79
diff --git a/include/linux/swap.h b/include/linux/swap.h
index a8f6d5d89524..77459d695010 100644
--- a/include/linux/swap.h
+++ b/include/linux/swap.h
@@ -310,7 +310,6 @@ void workingset_update_node(struct xa_node *node);
310} while (0) 310} while (0)
311 311
312/* linux/mm/page_alloc.c */ 312/* linux/mm/page_alloc.c */
313extern unsigned long totalram_pages;
314extern unsigned long totalreserve_pages; 313extern unsigned long totalreserve_pages;
315extern unsigned long nr_free_buffer_pages(void); 314extern unsigned long nr_free_buffer_pages(void);
316extern unsigned long nr_free_pagecache_pages(void); 315extern unsigned long nr_free_pagecache_pages(void);
diff --git a/kernel/fork.c b/kernel/fork.c
index 8617a326e9f5..c979605fe806 100644
--- a/kernel/fork.c
+++ b/kernel/fork.c
@@ -744,7 +744,7 @@ void __init __weak arch_task_cache_init(void) { }
744static void set_max_threads(unsigned int max_threads_suggested) 744static void set_max_threads(unsigned int max_threads_suggested)
745{ 745{
746 u64 threads; 746 u64 threads;
747 unsigned long nr_pages = totalram_pages; 747 unsigned long nr_pages = totalram_pages();
748 748
749 /* 749 /*
750 * The number of threads shall be limited such that the thread 750 * The number of threads shall be limited such that the thread
diff --git a/kernel/kexec_core.c b/kernel/kexec_core.c
index 7e967ca98d92..d7140447be75 100644
--- a/kernel/kexec_core.c
+++ b/kernel/kexec_core.c
@@ -152,7 +152,7 @@ int sanity_check_segment_list(struct kimage *image)
152 int i; 152 int i;
153 unsigned long nr_segments = image->nr_segments; 153 unsigned long nr_segments = image->nr_segments;
154 unsigned long total_pages = 0; 154 unsigned long total_pages = 0;
155 unsigned long nr_pages = totalram_pages; 155 unsigned long nr_pages = totalram_pages();
156 156
157 /* 157 /*
158 * Verify we have good destination addresses. The caller is 158 * Verify we have good destination addresses. The caller is
diff --git a/kernel/power/snapshot.c b/kernel/power/snapshot.c
index b0308a2c6000..640b2034edd6 100644
--- a/kernel/power/snapshot.c
+++ b/kernel/power/snapshot.c
@@ -105,7 +105,7 @@ unsigned long image_size;
105 105
106void __init hibernate_image_size_init(void) 106void __init hibernate_image_size_init(void)
107{ 107{
108 image_size = ((totalram_pages * 2) / 5) * PAGE_SIZE; 108 image_size = ((totalram_pages() * 2) / 5) * PAGE_SIZE;
109} 109}
110 110
111/* 111/*
diff --git a/mm/highmem.c b/mm/highmem.c
index 59db3223a5d6..107b10f9878e 100644
--- a/mm/highmem.c
+++ b/mm/highmem.c
@@ -105,9 +105,8 @@ static inline wait_queue_head_t *get_pkmap_wait_queue_head(unsigned int color)
105} 105}
106#endif 106#endif
107 107
108unsigned long totalhigh_pages __read_mostly; 108atomic_long_t _totalhigh_pages __read_mostly;
109EXPORT_SYMBOL(totalhigh_pages); 109EXPORT_SYMBOL(_totalhigh_pages);
110
111 110
112EXPORT_PER_CPU_SYMBOL(__kmap_atomic_idx); 111EXPORT_PER_CPU_SYMBOL(__kmap_atomic_idx);
113 112
diff --git a/mm/huge_memory.c b/mm/huge_memory.c
index e84a10b0d310..da6682bb69aa 100644
--- a/mm/huge_memory.c
+++ b/mm/huge_memory.c
@@ -420,7 +420,7 @@ static int __init hugepage_init(void)
420 * where the extra memory used could hurt more than TLB overhead 420 * where the extra memory used could hurt more than TLB overhead
421 * is likely to save. The admin can still enable it through /sys. 421 * is likely to save. The admin can still enable it through /sys.
422 */ 422 */
423 if (totalram_pages < (512 << (20 - PAGE_SHIFT))) { 423 if (totalram_pages() < (512 << (20 - PAGE_SHIFT))) {
424 transparent_hugepage_flags = 0; 424 transparent_hugepage_flags = 0;
425 return 0; 425 return 0;
426 } 426 }
diff --git a/mm/kasan/quarantine.c b/mm/kasan/quarantine.c
index 57334ef2d7ef..978bc4a3eb51 100644
--- a/mm/kasan/quarantine.c
+++ b/mm/kasan/quarantine.c
@@ -237,7 +237,7 @@ void quarantine_reduce(void)
237 * Update quarantine size in case of hotplug. Allocate a fraction of 237 * Update quarantine size in case of hotplug. Allocate a fraction of
238 * the installed memory to quarantine minus per-cpu queue limits. 238 * the installed memory to quarantine minus per-cpu queue limits.
239 */ 239 */
240 total_size = (READ_ONCE(totalram_pages) << PAGE_SHIFT) / 240 total_size = (totalram_pages() << PAGE_SHIFT) /
241 QUARANTINE_FRACTION; 241 QUARANTINE_FRACTION;
242 percpu_quarantines = QUARANTINE_PERCPU_SIZE * num_online_cpus(); 242 percpu_quarantines = QUARANTINE_PERCPU_SIZE * num_online_cpus();
243 new_quarantine_size = (total_size < percpu_quarantines) ? 243 new_quarantine_size = (total_size < percpu_quarantines) ?
diff --git a/mm/memblock.c b/mm/memblock.c
index 0068f87af1e8..a53d8697612c 100644
--- a/mm/memblock.c
+++ b/mm/memblock.c
@@ -1576,7 +1576,7 @@ void __init __memblock_free_late(phys_addr_t base, phys_addr_t size)
1576 1576
1577 for (; cursor < end; cursor++) { 1577 for (; cursor < end; cursor++) {
1578 memblock_free_pages(pfn_to_page(cursor), cursor, 0); 1578 memblock_free_pages(pfn_to_page(cursor), cursor, 0);
1579 totalram_pages++; 1579 totalram_pages_inc();
1580 } 1580 }
1581} 1581}
1582 1582
@@ -1978,7 +1978,7 @@ unsigned long __init memblock_free_all(void)
1978 reset_all_zones_managed_pages(); 1978 reset_all_zones_managed_pages();
1979 1979
1980 pages = free_low_memory_core_early(); 1980 pages = free_low_memory_core_early();
1981 totalram_pages += pages; 1981 totalram_pages_add(pages);
1982 1982
1983 return pages; 1983 return pages;
1984} 1984}
diff --git a/mm/mm_init.c b/mm/mm_init.c
index 6838a530789b..33917105a3a2 100644
--- a/mm/mm_init.c
+++ b/mm/mm_init.c
@@ -146,7 +146,7 @@ static void __meminit mm_compute_batch(void)
146 s32 batch = max_t(s32, nr*2, 32); 146 s32 batch = max_t(s32, nr*2, 32);
147 147
148 /* batch size set to 0.4% of (total memory/#cpus), or max int32 */ 148 /* batch size set to 0.4% of (total memory/#cpus), or max int32 */
149 memsized_batch = min_t(u64, (totalram_pages/nr)/256, 0x7fffffff); 149 memsized_batch = min_t(u64, (totalram_pages()/nr)/256, 0x7fffffff);
150 150
151 vm_committed_as_batch = max_t(s32, memsized_batch, batch); 151 vm_committed_as_batch = max_t(s32, memsized_batch, batch);
152} 152}
diff --git a/mm/oom_kill.c b/mm/oom_kill.c
index 6589f60d5018..21d487749e1d 100644
--- a/mm/oom_kill.c
+++ b/mm/oom_kill.c
@@ -269,7 +269,7 @@ static enum oom_constraint constrained_alloc(struct oom_control *oc)
269 } 269 }
270 270
271 /* Default to all available memory */ 271 /* Default to all available memory */
272 oc->totalpages = totalram_pages + total_swap_pages; 272 oc->totalpages = totalram_pages() + total_swap_pages;
273 273
274 if (!IS_ENABLED(CONFIG_NUMA)) 274 if (!IS_ENABLED(CONFIG_NUMA))
275 return CONSTRAINT_NONE; 275 return CONSTRAINT_NONE;
diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index 4b5c4ff68f18..eb2027892ef9 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -16,6 +16,7 @@
16 16
17#include <linux/stddef.h> 17#include <linux/stddef.h>
18#include <linux/mm.h> 18#include <linux/mm.h>
19#include <linux/highmem.h>
19#include <linux/swap.h> 20#include <linux/swap.h>
20#include <linux/interrupt.h> 21#include <linux/interrupt.h>
21#include <linux/pagemap.h> 22#include <linux/pagemap.h>
@@ -124,7 +125,8 @@ EXPORT_SYMBOL(node_states);
124/* Protect totalram_pages and zone->managed_pages */ 125/* Protect totalram_pages and zone->managed_pages */
125static DEFINE_SPINLOCK(managed_page_count_lock); 126static DEFINE_SPINLOCK(managed_page_count_lock);
126 127
127unsigned long totalram_pages __read_mostly; 128atomic_long_t _totalram_pages __read_mostly;
129EXPORT_SYMBOL(_totalram_pages);
128unsigned long totalreserve_pages __read_mostly; 130unsigned long totalreserve_pages __read_mostly;
129unsigned long totalcma_pages __read_mostly; 131unsigned long totalcma_pages __read_mostly;
130 132
@@ -4747,11 +4749,11 @@ EXPORT_SYMBOL_GPL(si_mem_available);
4747 4749
4748void si_meminfo(struct sysinfo *val) 4750void si_meminfo(struct sysinfo *val)
4749{ 4751{
4750 val->totalram = totalram_pages; 4752 val->totalram = totalram_pages();
4751 val->sharedram = global_node_page_state(NR_SHMEM); 4753 val->sharedram = global_node_page_state(NR_SHMEM);
4752 val->freeram = global_zone_page_state(NR_FREE_PAGES); 4754 val->freeram = global_zone_page_state(NR_FREE_PAGES);
4753 val->bufferram = nr_blockdev_pages(); 4755 val->bufferram = nr_blockdev_pages();
4754 val->totalhigh = totalhigh_pages; 4756 val->totalhigh = totalhigh_pages();
4755 val->freehigh = nr_free_highpages(); 4757 val->freehigh = nr_free_highpages();
4756 val->mem_unit = PAGE_SIZE; 4758 val->mem_unit = PAGE_SIZE;
4757} 4759}
@@ -7077,10 +7079,10 @@ void adjust_managed_page_count(struct page *page, long count)
7077{ 7079{
7078 spin_lock(&managed_page_count_lock); 7080 spin_lock(&managed_page_count_lock);
7079 atomic_long_add(count, &page_zone(page)->managed_pages); 7081 atomic_long_add(count, &page_zone(page)->managed_pages);
7080 totalram_pages += count; 7082 totalram_pages_add(count);
7081#ifdef CONFIG_HIGHMEM 7083#ifdef CONFIG_HIGHMEM
7082 if (PageHighMem(page)) 7084 if (PageHighMem(page))
7083 totalhigh_pages += count; 7085 totalhigh_pages_add(count);
7084#endif 7086#endif
7085 spin_unlock(&managed_page_count_lock); 7087 spin_unlock(&managed_page_count_lock);
7086} 7088}
@@ -7123,9 +7125,9 @@ EXPORT_SYMBOL(free_reserved_area);
7123void free_highmem_page(struct page *page) 7125void free_highmem_page(struct page *page)
7124{ 7126{
7125 __free_reserved_page(page); 7127 __free_reserved_page(page);
7126 totalram_pages++; 7128 totalram_pages_inc();
7127 atomic_long_inc(&page_zone(page)->managed_pages); 7129 atomic_long_inc(&page_zone(page)->managed_pages);
7128 totalhigh_pages++; 7130 totalhigh_pages_inc();
7129} 7131}
7130#endif 7132#endif
7131 7133
@@ -7174,10 +7176,10 @@ void __init mem_init_print_info(const char *str)
7174 physpages << (PAGE_SHIFT - 10), 7176 physpages << (PAGE_SHIFT - 10),
7175 codesize >> 10, datasize >> 10, rosize >> 10, 7177 codesize >> 10, datasize >> 10, rosize >> 10,
7176 (init_data_size + init_code_size) >> 10, bss_size >> 10, 7178 (init_data_size + init_code_size) >> 10, bss_size >> 10,
7177 (physpages - totalram_pages - totalcma_pages) << (PAGE_SHIFT - 10), 7179 (physpages - totalram_pages() - totalcma_pages) << (PAGE_SHIFT - 10),
7178 totalcma_pages << (PAGE_SHIFT - 10), 7180 totalcma_pages << (PAGE_SHIFT - 10),
7179#ifdef CONFIG_HIGHMEM 7181#ifdef CONFIG_HIGHMEM
7180 totalhigh_pages << (PAGE_SHIFT - 10), 7182 totalhigh_pages() << (PAGE_SHIFT - 10),
7181#endif 7183#endif
7182 str ? ", " : "", str ? str : ""); 7184 str ? ", " : "", str ? str : "");
7183} 7185}
diff --git a/mm/shmem.c b/mm/shmem.c
index b1f0f54470fb..6ece1e2fe76e 100644
--- a/mm/shmem.c
+++ b/mm/shmem.c
@@ -109,13 +109,14 @@ struct shmem_falloc {
109#ifdef CONFIG_TMPFS 109#ifdef CONFIG_TMPFS
110static unsigned long shmem_default_max_blocks(void) 110static unsigned long shmem_default_max_blocks(void)
111{ 111{
112 return totalram_pages / 2; 112 return totalram_pages() / 2;
113} 113}
114 114
115static unsigned long shmem_default_max_inodes(void) 115static unsigned long shmem_default_max_inodes(void)
116{ 116{
117 unsigned long nr_pages = totalram_pages; 117 unsigned long nr_pages = totalram_pages();
118 return min(nr_pages - totalhigh_pages, nr_pages / 2); 118
119 return min(nr_pages - totalhigh_pages(), nr_pages / 2);
119} 120}
120#endif 121#endif
121 122
@@ -3302,7 +3303,7 @@ static int shmem_parse_options(char *options, struct shmem_sb_info *sbinfo,
3302 size = memparse(value,&rest); 3303 size = memparse(value,&rest);
3303 if (*rest == '%') { 3304 if (*rest == '%') {
3304 size <<= PAGE_SHIFT; 3305 size <<= PAGE_SHIFT;
3305 size *= totalram_pages; 3306 size *= totalram_pages();
3306 do_div(size, 100); 3307 do_div(size, 100);
3307 rest++; 3308 rest++;
3308 } 3309 }
diff --git a/mm/slab.c b/mm/slab.c
index 01991060714c..73fe23e649c9 100644
--- a/mm/slab.c
+++ b/mm/slab.c
@@ -1235,7 +1235,7 @@ void __init kmem_cache_init(void)
1235 * page orders on machines with more than 32MB of memory if 1235 * page orders on machines with more than 32MB of memory if
1236 * not overridden on the command line. 1236 * not overridden on the command line.
1237 */ 1237 */
1238 if (!slab_max_order_set && totalram_pages > (32 << 20) >> PAGE_SHIFT) 1238 if (!slab_max_order_set && totalram_pages() > (32 << 20) >> PAGE_SHIFT)
1239 slab_max_order = SLAB_MAX_ORDER_HI; 1239 slab_max_order = SLAB_MAX_ORDER_HI;
1240 1240
1241 /* Bootstrap is tricky, because several objects are allocated 1241 /* Bootstrap is tricky, because several objects are allocated
diff --git a/mm/swap.c b/mm/swap.c
index 5d786019eab9..4d8a1f1afaab 100644
--- a/mm/swap.c
+++ b/mm/swap.c
@@ -1022,7 +1022,7 @@ EXPORT_SYMBOL(pagevec_lookup_range_nr_tag);
1022 */ 1022 */
1023void __init swap_setup(void) 1023void __init swap_setup(void)
1024{ 1024{
1025 unsigned long megs = totalram_pages >> (20 - PAGE_SHIFT); 1025 unsigned long megs = totalram_pages() >> (20 - PAGE_SHIFT);
1026 1026
1027 /* Use a smaller cluster for small-memory machines */ 1027 /* Use a smaller cluster for small-memory machines */
1028 if (megs < 16) 1028 if (megs < 16)
diff --git a/mm/util.c b/mm/util.c
index 8bf08b5b5760..4df23d64aac7 100644
--- a/mm/util.c
+++ b/mm/util.c
@@ -593,7 +593,7 @@ unsigned long vm_commit_limit(void)
593 if (sysctl_overcommit_kbytes) 593 if (sysctl_overcommit_kbytes)
594 allowed = sysctl_overcommit_kbytes >> (PAGE_SHIFT - 10); 594 allowed = sysctl_overcommit_kbytes >> (PAGE_SHIFT - 10);
595 else 595 else
596 allowed = ((totalram_pages - hugetlb_total_pages()) 596 allowed = ((totalram_pages() - hugetlb_total_pages())
597 * sysctl_overcommit_ratio / 100); 597 * sysctl_overcommit_ratio / 100);
598 allowed += total_swap_pages; 598 allowed += total_swap_pages;
599 599
diff --git a/mm/vmalloc.c b/mm/vmalloc.c
index 97d4b25d0373..871e41c55e23 100644
--- a/mm/vmalloc.c
+++ b/mm/vmalloc.c
@@ -1634,7 +1634,7 @@ void *vmap(struct page **pages, unsigned int count,
1634 1634
1635 might_sleep(); 1635 might_sleep();
1636 1636
1637 if (count > totalram_pages) 1637 if (count > totalram_pages())
1638 return NULL; 1638 return NULL;
1639 1639
1640 size = (unsigned long)count << PAGE_SHIFT; 1640 size = (unsigned long)count << PAGE_SHIFT;
@@ -1739,7 +1739,7 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align,
1739 unsigned long real_size = size; 1739 unsigned long real_size = size;
1740 1740
1741 size = PAGE_ALIGN(size); 1741 size = PAGE_ALIGN(size);
1742 if (!size || (size >> PAGE_SHIFT) > totalram_pages) 1742 if (!size || (size >> PAGE_SHIFT) > totalram_pages())
1743 goto fail; 1743 goto fail;
1744 1744
1745 area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNINITIALIZED | 1745 area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNINITIALIZED |
diff --git a/mm/workingset.c b/mm/workingset.c
index d46f8c92aa2f..dcb994f2acc2 100644
--- a/mm/workingset.c
+++ b/mm/workingset.c
@@ -549,7 +549,7 @@ static int __init workingset_init(void)
549 * double the initial memory by using totalram_pages as-is. 549 * double the initial memory by using totalram_pages as-is.
550 */ 550 */
551 timestamp_bits = BITS_PER_LONG - EVICTION_SHIFT; 551 timestamp_bits = BITS_PER_LONG - EVICTION_SHIFT;
552 max_order = fls_long(totalram_pages - 1); 552 max_order = fls_long(totalram_pages() - 1);
553 if (max_order > timestamp_bits) 553 if (max_order > timestamp_bits)
554 bucket_order = max_order - timestamp_bits; 554 bucket_order = max_order - timestamp_bits;
555 pr_info("workingset: timestamp_bits=%d max_order=%d bucket_order=%u\n", 555 pr_info("workingset: timestamp_bits=%d max_order=%d bucket_order=%u\n",
diff --git a/mm/zswap.c b/mm/zswap.c
index cd91fd9d96b8..a4e4d36ec085 100644
--- a/mm/zswap.c
+++ b/mm/zswap.c
@@ -219,8 +219,8 @@ static const struct zpool_ops zswap_zpool_ops = {
219 219
220static bool zswap_is_full(void) 220static bool zswap_is_full(void)
221{ 221{
222 return totalram_pages * zswap_max_pool_percent / 100 < 222 return totalram_pages() * zswap_max_pool_percent / 100 <
223 DIV_ROUND_UP(zswap_pool_total_size, PAGE_SIZE); 223 DIV_ROUND_UP(zswap_pool_total_size, PAGE_SIZE);
224} 224}
225 225
226static void zswap_update_total_size(void) 226static void zswap_update_total_size(void)
diff --git a/net/dccp/proto.c b/net/dccp/proto.c
index ff727ff61b5b..0e2f71ab8367 100644
--- a/net/dccp/proto.c
+++ b/net/dccp/proto.c
@@ -1131,7 +1131,7 @@ EXPORT_SYMBOL_GPL(dccp_debug);
1131static int __init dccp_init(void) 1131static int __init dccp_init(void)
1132{ 1132{
1133 unsigned long goal; 1133 unsigned long goal;
1134 unsigned long nr_pages = totalram_pages; 1134 unsigned long nr_pages = totalram_pages();
1135 int ehash_order, bhash_order, i; 1135 int ehash_order, bhash_order, i;
1136 int rc; 1136 int rc;
1137 1137
diff --git a/net/decnet/dn_route.c b/net/decnet/dn_route.c
index 1c002c0fb712..950613ee7881 100644
--- a/net/decnet/dn_route.c
+++ b/net/decnet/dn_route.c
@@ -1866,7 +1866,7 @@ void __init dn_route_init(void)
1866 dn_route_timer.expires = jiffies + decnet_dst_gc_interval * HZ; 1866 dn_route_timer.expires = jiffies + decnet_dst_gc_interval * HZ;
1867 add_timer(&dn_route_timer); 1867 add_timer(&dn_route_timer);
1868 1868
1869 goal = totalram_pages >> (26 - PAGE_SHIFT); 1869 goal = totalram_pages() >> (26 - PAGE_SHIFT);
1870 1870
1871 for(order = 0; (1UL << order) < goal; order++) 1871 for(order = 0; (1UL << order) < goal; order++)
1872 /* NOTHING */; 1872 /* NOTHING */;
diff --git a/net/ipv4/tcp_metrics.c b/net/ipv4/tcp_metrics.c
index 03b51cdcc731..b467a7cabf40 100644
--- a/net/ipv4/tcp_metrics.c
+++ b/net/ipv4/tcp_metrics.c
@@ -1000,7 +1000,7 @@ static int __net_init tcp_net_metrics_init(struct net *net)
1000 1000
1001 slots = tcpmhash_entries; 1001 slots = tcpmhash_entries;
1002 if (!slots) { 1002 if (!slots) {
1003 if (totalram_pages >= 128 * 1024) 1003 if (totalram_pages() >= 128 * 1024)
1004 slots = 16 * 1024; 1004 slots = 16 * 1024;
1005 else 1005 else
1006 slots = 8 * 1024; 1006 slots = 8 * 1024;
diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c
index 5eb990830348..741b533148ba 100644
--- a/net/netfilter/nf_conntrack_core.c
+++ b/net/netfilter/nf_conntrack_core.c
@@ -2248,7 +2248,7 @@ static __always_inline unsigned int total_extension_size(void)
2248 2248
2249int nf_conntrack_init_start(void) 2249int nf_conntrack_init_start(void)
2250{ 2250{
2251 unsigned long nr_pages = totalram_pages; 2251 unsigned long nr_pages = totalram_pages();
2252 int max_factor = 8; 2252 int max_factor = 8;
2253 int ret = -ENOMEM; 2253 int ret = -ENOMEM;
2254 int i; 2254 int i;
diff --git a/net/netfilter/xt_hashlimit.c b/net/netfilter/xt_hashlimit.c
index 88b520ba2abc..8d86e39d6280 100644
--- a/net/netfilter/xt_hashlimit.c
+++ b/net/netfilter/xt_hashlimit.c
@@ -274,7 +274,7 @@ static int htable_create(struct net *net, struct hashlimit_cfg3 *cfg,
274 struct xt_hashlimit_htable *hinfo; 274 struct xt_hashlimit_htable *hinfo;
275 const struct seq_operations *ops; 275 const struct seq_operations *ops;
276 unsigned int size, i; 276 unsigned int size, i;
277 unsigned long nr_pages = totalram_pages; 277 unsigned long nr_pages = totalram_pages();
278 int ret; 278 int ret;
279 279
280 if (cfg->size) { 280 if (cfg->size) {
diff --git a/net/sctp/protocol.c b/net/sctp/protocol.c
index a5b24182b3cc..d5878ae55840 100644
--- a/net/sctp/protocol.c
+++ b/net/sctp/protocol.c
@@ -1368,7 +1368,7 @@ static __init int sctp_init(void)
1368 int status = -EINVAL; 1368 int status = -EINVAL;
1369 unsigned long goal; 1369 unsigned long goal;
1370 unsigned long limit; 1370 unsigned long limit;
1371 unsigned long nr_pages = totalram_pages; 1371 unsigned long nr_pages = totalram_pages();
1372 int max_share; 1372 int max_share;
1373 int order; 1373 int order;
1374 int num_entries; 1374 int num_entries;
diff --git a/security/integrity/ima/ima_kexec.c b/security/integrity/ima/ima_kexec.c
index 16bd18747cfa..d6f32807b347 100644
--- a/security/integrity/ima/ima_kexec.c
+++ b/security/integrity/ima/ima_kexec.c
@@ -106,7 +106,7 @@ void ima_add_kexec_buffer(struct kimage *image)
106 kexec_segment_size = ALIGN(ima_get_binary_runtime_size() + 106 kexec_segment_size = ALIGN(ima_get_binary_runtime_size() +
107 PAGE_SIZE / 2, PAGE_SIZE); 107 PAGE_SIZE / 2, PAGE_SIZE);
108 if ((kexec_segment_size == ULONG_MAX) || 108 if ((kexec_segment_size == ULONG_MAX) ||
109 ((kexec_segment_size >> PAGE_SHIFT) > totalram_pages / 2)) { 109 ((kexec_segment_size >> PAGE_SHIFT) > totalram_pages() / 2)) {
110 pr_err("Binary measurement list too large.\n"); 110 pr_err("Binary measurement list too large.\n");
111 return; 111 return;
112 } 112 }