public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] replace various uses of num_physpages by totalram_pages
@ 2009-06-30 11:08 Jan Beulich
  2009-07-01  4:57 ` Rusty Russell
  2009-07-01  7:43 ` Amerigo Wang
  0 siblings, 2 replies; 7+ messages in thread
From: Jan Beulich @ 2009-06-30 11:08 UTC (permalink / raw)
  To: Rusty Russell, linux-kernel

Sizing of memory allocations shouldn't depend on the number of physical
pages found in a system, as that generally include (perhaps a huge
amount of) non-RAM pages. The amount of what actually is usable as
storage should instead be used as a basis here.

In line with that, the memory hotplug code should update num_physpages
in a way that it retains its original (post-boot) meaning; in
particular, decreasing the value should at best be done with great care
- this patch doesn't try to ever decrease this value at all as it
doesn't really seem meaningful to do so.

Signed-off-by: Jan Beulich <jbeulich@novell.com>

---
 drivers/char/agp/backend.c        |    4 ++--
 drivers/parisc/ccio-dma.c         |    4 ++--
 drivers/parisc/sba_iommu.c        |    4 ++--
 drivers/xen/balloon.c             |    4 ----
 fs/ntfs/malloc.h                  |    2 +-
 include/linux/mm.h                |    1 +
 init/main.c                       |    4 ++--
 mm/memory_hotplug.c               |    6 ++++--
 mm/slab.c                         |    2 +-
 mm/swap.c                         |    2 +-
 mm/vmalloc.c                      |    4 ++--
 net/core/sock.c                   |    4 ++--
 net/dccp/proto.c                  |    6 +++---
 net/decnet/dn_route.c             |    2 +-
 net/ipv4/route.c                  |    2 +-
 net/ipv4/tcp.c                    |    4 ++--
 net/netfilter/nf_conntrack_core.c |    4 ++--
 net/netfilter/x_tables.c          |    2 +-
 net/netfilter/xt_hashlimit.c      |    8 ++++----
 net/netlink/af_netlink.c          |    6 +++---
 net/sctp/protocol.c               |    6 +++---
 21 files changed, 40 insertions(+), 41 deletions(-)

--- linux-2.6.31-rc1/drivers/char/agp/backend.c	2009-06-26 17:49:43.000000000 +0200
+++ 2.6.31-rc1-use-totalram_pages/drivers/char/agp/backend.c	2009-06-24 16:09:34.000000000 +0200
@@ -114,9 +114,9 @@ static int agp_find_max(void)
 	long memory, index, result;
 
 #if PAGE_SHIFT < 20
-	memory = num_physpages >> (20 - PAGE_SHIFT);
+	memory = totalram_pages >> (20 - PAGE_SHIFT);
 #else
-	memory = num_physpages << (PAGE_SHIFT - 20);
+	memory = totalram_pages << (PAGE_SHIFT - 20);
 #endif
 	index = 1;
 
--- linux-2.6.31-rc1/drivers/parisc/ccio-dma.c	2009-06-10 05:05:27.000000000 +0200
+++ 2.6.31-rc1-use-totalram_pages/drivers/parisc/ccio-dma.c	2009-06-24 16:10:47.000000000 +0200
@@ -1267,7 +1267,7 @@ ccio_ioc_init(struct ioc *ioc)
 	** Hot-Plug/Removal of PCI cards. (aka PCI OLARD).
 	*/
 
-	iova_space_size = (u32) (num_physpages / count_parisc_driver(&ccio_driver));
+	iova_space_size = (u32) (totalram_pages / count_parisc_driver(&ccio_driver));
 
 	/* limit IOVA space size to 1MB-1GB */
 
@@ -1306,7 +1306,7 @@ ccio_ioc_init(struct ioc *ioc)
 
 	DBG_INIT("%s() hpa 0x%p mem %luMB IOV %dMB (%d bits)\n",
 			__func__, ioc->ioc_regs,
-			(unsigned long) num_physpages >> (20 - PAGE_SHIFT),
+			(unsigned long) totalram_pages >> (20 - PAGE_SHIFT),
 			iova_space_size>>20,
 			iov_order + PAGE_SHIFT);
 
--- linux-2.6.31-rc1/drivers/parisc/sba_iommu.c	2009-06-26 17:49:47.000000000 +0200
+++ 2.6.31-rc1-use-totalram_pages/drivers/parisc/sba_iommu.c	2009-06-24 16:10:58.000000000 +0200
@@ -1390,7 +1390,7 @@ sba_ioc_init(struct parisc_device *sba, 
 	** for DMA hints - ergo only 30 bits max.
 	*/
 
-	iova_space_size = (u32) (num_physpages/global_ioc_cnt);
+	iova_space_size = (u32) (totalram_pages/global_ioc_cnt);
 
 	/* limit IOVA space size to 1MB-1GB */
 	if (iova_space_size < (1 << (20 - PAGE_SHIFT))) {
@@ -1415,7 +1415,7 @@ sba_ioc_init(struct parisc_device *sba, 
 	DBG_INIT("%s() hpa 0x%lx mem %ldMB IOV %dMB (%d bits)\n",
 			__func__,
 			ioc->ioc_hpa,
-			(unsigned long) num_physpages >> (20 - PAGE_SHIFT),
+			(unsigned long) totalram_pages >> (20 - PAGE_SHIFT),
 			iova_space_size>>20,
 			iov_order + PAGE_SHIFT);
 
--- linux-2.6.31-rc1/drivers/xen/balloon.c	2009-06-10 05:05:27.000000000 +0200
+++ 2.6.31-rc1-use-totalram_pages/drivers/xen/balloon.c	2009-06-24 16:02:01.000000000 +0200
@@ -96,11 +96,7 @@ static struct balloon_stats balloon_stat
 /* We increase/decrease in batches which fit in a page */
 static unsigned long frame_list[PAGE_SIZE / sizeof(unsigned long)];
 
-/* VM /proc information for memory */
-extern unsigned long totalram_pages;
-
 #ifdef CONFIG_HIGHMEM
-extern unsigned long totalhigh_pages;
 #define inc_totalhigh_pages() (totalhigh_pages++)
 #define dec_totalhigh_pages() (totalhigh_pages--)
 #else
--- linux-2.6.31-rc1/fs/ntfs/malloc.h	2008-04-17 04:49:44.000000000 +0200
+++ 2.6.31-rc1-use-totalram_pages/fs/ntfs/malloc.h	2009-06-24 16:11:49.000000000 +0200
@@ -47,7 +47,7 @@ static inline void *__ntfs_malloc(unsign
 		return kmalloc(PAGE_SIZE, gfp_mask & ~__GFP_HIGHMEM);
 		/* return (void *)__get_free_page(gfp_mask); */
 	}
-	if (likely(size >> PAGE_SHIFT < num_physpages))
+	if (likely((size >> PAGE_SHIFT) < totalram_pages))
 		return __vmalloc(size, gfp_mask, PAGE_KERNEL);
 	return NULL;
 }
--- linux-2.6.31-rc1/include/linux/mm.h	2009-06-26 17:50:00.000000000 +0200
+++ 2.6.31-rc1-use-totalram_pages/include/linux/mm.h	2009-06-24 16:00:50.000000000 +0200
@@ -25,6 +25,7 @@ extern unsigned long max_mapnr;
 #endif
 
 extern unsigned long num_physpages;
+extern unsigned long totalram_pages;
 extern void * high_memory;
 extern int page_cluster;
 
--- linux-2.6.31-rc1/init/main.c	2009-06-26 17:50:00.000000000 +0200
+++ 2.6.31-rc1-use-totalram_pages/init/main.c	2009-06-24 16:12:30.000000000 +0200
@@ -691,12 +691,12 @@ asmlinkage void __init start_kernel(void
 #endif
 	thread_info_cache_init();
 	cred_init();
-	fork_init(num_physpages);
+	fork_init(totalram_pages);
 	proc_caches_init();
 	buffer_init();
 	key_init();
 	security_init();
-	vfs_caches_init(num_physpages);
+	vfs_caches_init(totalram_pages);
 	radix_tree_init();
 	signals_init();
 	/* rootfs populating might need page-writeback */
--- linux-2.6.31-rc1/mm/memory_hotplug.c	2009-06-26 17:50:00.000000000 +0200
+++ 2.6.31-rc1-use-totalram_pages/mm/memory_hotplug.c	2009-06-24 16:04:44.000000000 +0200
@@ -339,8 +339,11 @@ EXPORT_SYMBOL_GPL(__remove_pages);
 
 void online_page(struct page *page)
 {
+	unsigned long pfn = page_to_pfn(page);
+
 	totalram_pages++;
-	num_physpages++;
+	if (pfn >= num_physpages)
+		num_physpages = pfn + 1;
 
 #ifdef CONFIG_HIGHMEM
 	if (PageHighMem(page))
@@ -831,7 +834,6 @@ repeat:
 	zone->present_pages -= offlined_pages;
 	zone->zone_pgdat->node_present_pages -= offlined_pages;
 	totalram_pages -= offlined_pages;
-	num_physpages -= offlined_pages;
 
 	setup_per_zone_wmarks();
 	calculate_zone_inactive_ratio(zone);
--- linux-2.6.31-rc1/mm/slab.c	2009-06-26 17:50:00.000000000 +0200
+++ 2.6.31-rc1-use-totalram_pages/mm/slab.c	2009-06-24 16:06:21.000000000 +0200
@@ -1384,7 +1384,7 @@ void __init kmem_cache_init(void)
 	 * Fragmentation resistance on low memory - only use bigger
 	 * page orders on machines with more than 32MB of memory.
 	 */
-	if (num_physpages > (32 << 20) >> PAGE_SHIFT)
+	if (totalram_pages > (32 << 20) >> PAGE_SHIFT)
 		slab_break_gfp_order = BREAK_GFP_ORDER_HI;
 
 	/* Bootstrap is tricky, because several objects are allocated
--- linux-2.6.31-rc1/mm/swap.c	2009-06-10 05:05:27.000000000 +0200
+++ 2.6.31-rc1-use-totalram_pages/mm/swap.c	2009-06-24 16:06:40.000000000 +0200
@@ -496,7 +496,7 @@ EXPORT_SYMBOL(pagevec_lookup_tag);
  */
 void __init swap_setup(void)
 {
-	unsigned long megs = num_physpages >> (20 - PAGE_SHIFT);
+	unsigned long megs = totalram_pages >> (20 - PAGE_SHIFT);
 
 #ifdef CONFIG_SWAP
 	bdi_init(swapper_space.backing_dev_info);
--- linux-2.6.31-rc1/mm/vmalloc.c	2009-06-26 17:50:00.000000000 +0200
+++ 2.6.31-rc1-use-totalram_pages/mm/vmalloc.c	2009-06-24 16:05:47.000000000 +0200
@@ -1368,7 +1368,7 @@ void *vmap(struct page **pages, unsigned
 
 	might_sleep();
 
-	if (count > num_physpages)
+	if (count > totalram_pages)
 		return NULL;
 
 	area = get_vm_area_caller((count << PAGE_SHIFT), flags,
@@ -1475,7 +1475,7 @@ static void *__vmalloc_node(unsigned lon
 	unsigned long real_size = size;
 
 	size = PAGE_ALIGN(size);
-	if (!size || (size >> PAGE_SHIFT) > num_physpages)
+	if (!size || (size >> PAGE_SHIFT) > totalram_pages)
 		return NULL;
 
 	area = __get_vm_area_node(size, VM_ALLOC, VMALLOC_START, VMALLOC_END,
--- linux-2.6.31-rc1/net/core/sock.c	2009-06-26 17:50:00.000000000 +0200
+++ 2.6.31-rc1-use-totalram_pages/net/core/sock.c	2009-06-24 16:14:00.000000000 +0200
@@ -1169,12 +1169,12 @@ EXPORT_SYMBOL_GPL(sk_setup_caps);
 
 void __init sk_init(void)
 {
-	if (num_physpages <= 4096) {
+	if (totalram_pages <= 4096) {
 		sysctl_wmem_max = 32767;
 		sysctl_rmem_max = 32767;
 		sysctl_wmem_default = 32767;
 		sysctl_rmem_default = 32767;
-	} else if (num_physpages >= 131072) {
+	} else if (totalram_pages >= 131072) {
 		sysctl_wmem_max = 131071;
 		sysctl_rmem_max = 131071;
 	}
--- linux-2.6.31-rc1/net/dccp/proto.c	2009-06-10 05:05:27.000000000 +0200
+++ 2.6.31-rc1-use-totalram_pages/net/dccp/proto.c	2009-06-24 16:13:35.000000000 +0200
@@ -1049,10 +1049,10 @@ static int __init dccp_init(void)
 	 *
 	 * The methodology is similar to that of the buffer cache.
 	 */
-	if (num_physpages >= (128 * 1024))
-		goal = num_physpages >> (21 - PAGE_SHIFT);
+	if (totalram_pages >= (128 * 1024))
+		goal = totalram_pages >> (21 - PAGE_SHIFT);
 	else
-		goal = num_physpages >> (23 - PAGE_SHIFT);
+		goal = totalram_pages >> (23 - PAGE_SHIFT);
 
 	if (thash_entries)
 		goal = (thash_entries *
--- linux-2.6.31-rc1/net/decnet/dn_route.c	2009-06-26 17:50:00.000000000 +0200
+++ 2.6.31-rc1-use-totalram_pages/net/decnet/dn_route.c	2009-06-24 16:17:11.000000000 +0200
@@ -1750,7 +1750,7 @@ void __init dn_route_init(void)
 	dn_route_timer.expires = jiffies + decnet_dst_gc_interval * HZ;
 	add_timer(&dn_route_timer);
 
-	goal = num_physpages >> (26 - PAGE_SHIFT);
+	goal = totalram_pages >> (26 - PAGE_SHIFT);
 
 	for(order = 0; (1UL << order) < goal; order++)
 		/* NOTHING */;
--- linux-2.6.31-rc1/net/ipv4/route.c	2009-06-26 17:50:00.000000000 +0200
+++ 2.6.31-rc1-use-totalram_pages/net/ipv4/route.c	2009-06-24 16:14:48.000000000 +0200
@@ -3412,7 +3412,7 @@ int __init ip_rt_init(void)
 		alloc_large_system_hash("IP route cache",
 					sizeof(struct rt_hash_bucket),
 					rhash_entries,
-					(num_physpages >= 128 * 1024) ?
+					(totalram_pages >= 128 * 1024) ?
 					15 : 17,
 					0,
 					&rt_hash_log,
--- linux-2.6.31-rc1/net/ipv4/tcp.c	2009-06-26 17:50:00.000000000 +0200
+++ 2.6.31-rc1-use-totalram_pages/net/ipv4/tcp.c	2009-06-24 16:14:24.000000000 +0200
@@ -2857,7 +2857,7 @@ void __init tcp_init(void)
 		alloc_large_system_hash("TCP established",
 					sizeof(struct inet_ehash_bucket),
 					thash_entries,
-					(num_physpages >= 128 * 1024) ?
+					(totalram_pages >= 128 * 1024) ?
 					13 : 15,
 					0,
 					&tcp_hashinfo.ehash_size,
@@ -2874,7 +2874,7 @@ void __init tcp_init(void)
 		alloc_large_system_hash("TCP bind",
 					sizeof(struct inet_bind_hashbucket),
 					tcp_hashinfo.ehash_size,
-					(num_physpages >= 128 * 1024) ?
+					(totalram_pages >= 128 * 1024) ?
 					13 : 15,
 					0,
 					&tcp_hashinfo.bhash_size,
--- linux-2.6.31-rc1/net/netfilter/nf_conntrack_core.c	2009-06-26 17:50:00.000000000 +0200
+++ 2.6.31-rc1-use-totalram_pages/net/netfilter/nf_conntrack_core.c	2009-06-24 16:16:47.000000000 +0200
@@ -1230,9 +1230,9 @@ static int nf_conntrack_init_init_net(vo
 	 * machine has 512 buckets. >= 1GB machines have 16384 buckets. */
 	if (!nf_conntrack_htable_size) {
 		nf_conntrack_htable_size
-			= (((num_physpages << PAGE_SHIFT) / 16384)
+			= (((totalram_pages << PAGE_SHIFT) / 16384)
 			   / sizeof(struct hlist_head));
-		if (num_physpages > (1024 * 1024 * 1024 / PAGE_SIZE))
+		if (totalram_pages > (1024 * 1024 * 1024 / PAGE_SIZE))
 			nf_conntrack_htable_size = 16384;
 		if (nf_conntrack_htable_size < 32)
 			nf_conntrack_htable_size = 32;
--- linux-2.6.31-rc1/net/netfilter/x_tables.c	2009-06-26 17:50:00.000000000 +0200
+++ 2.6.31-rc1-use-totalram_pages/net/netfilter/x_tables.c	2009-06-24 16:16:28.000000000 +0200
@@ -617,7 +617,7 @@ struct xt_table_info *xt_alloc_table_inf
 	int cpu;
 
 	/* Pedantry: prevent them from hitting BUG() in vmalloc.c --RR */
-	if ((SMP_ALIGN(size) >> PAGE_SHIFT) + 2 > num_physpages)
+	if ((SMP_ALIGN(size) >> PAGE_SHIFT) + 2 > totalram_pages)
 		return NULL;
 
 	newinfo = kzalloc(XT_TABLE_INFO_SZ, GFP_KERNEL);
--- linux-2.6.31-rc1/net/netfilter/xt_hashlimit.c	2009-06-10 05:05:27.000000000 +0200
+++ 2.6.31-rc1-use-totalram_pages/net/netfilter/xt_hashlimit.c	2009-06-24 16:16:07.000000000 +0200
@@ -194,9 +194,9 @@ static int htable_create_v0(struct xt_ha
 	if (minfo->cfg.size)
 		size = minfo->cfg.size;
 	else {
-		size = ((num_physpages << PAGE_SHIFT) / 16384) /
+		size = ((totalram_pages << PAGE_SHIFT) / 16384) /
 		       sizeof(struct list_head);
-		if (num_physpages > (1024 * 1024 * 1024 / PAGE_SIZE))
+		if (totalram_pages > (1024 * 1024 * 1024 / PAGE_SIZE))
 			size = 8192;
 		if (size < 16)
 			size = 16;
@@ -266,9 +266,9 @@ static int htable_create(struct xt_hashl
 	if (minfo->cfg.size) {
 		size = minfo->cfg.size;
 	} else {
-		size = (num_physpages << PAGE_SHIFT) / 16384 /
+		size = (totalram_pages << PAGE_SHIFT) / 16384 /
 		       sizeof(struct list_head);
-		if (num_physpages > 1024 * 1024 * 1024 / PAGE_SIZE)
+		if (totalram_pages > 1024 * 1024 * 1024 / PAGE_SIZE)
 			size = 8192;
 		if (size < 16)
 			size = 16;
--- linux-2.6.31-rc1/net/netlink/af_netlink.c	2009-06-26 17:50:00.000000000 +0200
+++ 2.6.31-rc1-use-totalram_pages/net/netlink/af_netlink.c	2009-06-24 16:17:28.000000000 +0200
@@ -2026,10 +2026,10 @@ static int __init netlink_proto_init(voi
 	if (!nl_table)
 		goto panic;
 
-	if (num_physpages >= (128 * 1024))
-		limit = num_physpages >> (21 - PAGE_SHIFT);
+	if (totalram_pages >= (128 * 1024))
+		limit = totalram_pages >> (21 - PAGE_SHIFT);
 	else
-		limit = num_physpages >> (23 - PAGE_SHIFT);
+		limit = totalram_pages >> (23 - PAGE_SHIFT);
 
 	order = get_bitmask_order(limit) - 1 + PAGE_SHIFT;
 	limit = (1UL << order) / sizeof(struct hlist_head);
--- linux-2.6.31-rc1/net/sctp/protocol.c	2009-06-26 17:50:00.000000000 +0200
+++ 2.6.31-rc1-use-totalram_pages/net/sctp/protocol.c	2009-06-24 16:15:36.000000000 +0200
@@ -1185,10 +1185,10 @@ SCTP_STATIC __init int sctp_init(void)
 	/* Size and allocate the association hash table.
 	 * The methodology is similar to that of the tcp hash tables.
 	 */
-	if (num_physpages >= (128 * 1024))
-		goal = num_physpages >> (22 - PAGE_SHIFT);
+	if (totalram_pages >= (128 * 1024))
+		goal = totalram_pages >> (22 - PAGE_SHIFT);
 	else
-		goal = num_physpages >> (24 - PAGE_SHIFT);
+		goal = totalram_pages >> (24 - PAGE_SHIFT);
 
 	for (order = 0; (1UL << order) < goal; order++)
 		;



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] replace various uses of num_physpages by totalram_pages
  2009-06-30 11:08 Jan Beulich
@ 2009-07-01  4:57 ` Rusty Russell
  2009-07-01  6:54   ` Jan Beulich
  2009-07-01  7:43 ` Amerigo Wang
  1 sibling, 1 reply; 7+ messages in thread
From: Rusty Russell @ 2009-07-01  4:57 UTC (permalink / raw)
  To: Jan Beulich; +Cc: linux-kernel

On Tue, 30 Jun 2009 08:38:32 pm Jan Beulich wrote:
> Sizing of memory allocations shouldn't depend on the number of physical
> pages found in a system, as that generally include (perhaps a huge
> amount of) non-RAM pages. The amount of what actually is usable as
> storage should instead be used as a basis here.

I like this patch.  Where's num_physpages used after this: should it be an 
arch-specific or even a static?

FWIW: Acked-by: Rusty Russell <rusty@rustcorp.com.au>

Thanks,
Rusty.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] replace various uses of num_physpages by totalram_pages
  2009-07-01  4:57 ` Rusty Russell
@ 2009-07-01  6:54   ` Jan Beulich
  0 siblings, 0 replies; 7+ messages in thread
From: Jan Beulich @ 2009-07-01  6:54 UTC (permalink / raw)
  To: Rusty Russell; +Cc: linux-kernel

>>> Rusty Russell <rusty@rustcorp.com.au> 01.07.09 06:57 >>>
>On Tue, 30 Jun 2009 08:38:32 pm Jan Beulich wrote:
>> Sizing of memory allocations shouldn't depend on the number of physical
>> pages found in a system, as that generally include (perhaps a huge
>> amount of) non-RAM pages. The amount of what actually is usable as
>> storage should instead be used as a basis here.
>
>I like this patch.  Where's num_physpages used after this: should it be an 
>arch-specific or even a static?

It's still being used for some hash value initialization in under net/, and in
the generic power management code (kernel/power/). While the earlier
part certainly looks replaceable, I'm not certain about the latter.

In any case it would seem like a first step might now be to no longer export
the symbol (or, for a transitional period, make it an unused export).

Once all uses are gone, making it arch specific (reducing its scope as much
as possible, up to complete elimination) would certainly seem desirable
(not the least to perhaps finally address comments like "How many end-
of-memory variables you have, grandma!").

Jan


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] replace various uses of num_physpages by totalram_pages
  2009-06-30 11:08 Jan Beulich
  2009-07-01  4:57 ` Rusty Russell
@ 2009-07-01  7:43 ` Amerigo Wang
  1 sibling, 0 replies; 7+ messages in thread
From: Amerigo Wang @ 2009-07-01  7:43 UTC (permalink / raw)
  To: Jan Beulich; +Cc: Rusty Russell, linux-kernel

On Tue, Jun 30, 2009 at 12:08:32PM +0100, Jan Beulich wrote:
>Sizing of memory allocations shouldn't depend on the number of physical
>pages found in a system, as that generally include (perhaps a huge
>amount of) non-RAM pages. The amount of what actually is usable as
>storage should instead be used as a basis here.


For this part, ACK.

>
>In line with that, the memory hotplug code should update num_physpages
>in a way that it retains its original (post-boot) meaning; in
>particular, decreasing the value should at best be done with great care
>- this patch doesn't try to ever decrease this value at all as it
>doesn't really seem meaningful to do so.


Could you please split this part out and send it with Cc: to linux-mm
mailing list?

Thanks.

>
>Signed-off-by: Jan Beulich <jbeulich@novell.com>
>
>---
> drivers/char/agp/backend.c        |    4 ++--
> drivers/parisc/ccio-dma.c         |    4 ++--
> drivers/parisc/sba_iommu.c        |    4 ++--
> drivers/xen/balloon.c             |    4 ----
> fs/ntfs/malloc.h                  |    2 +-
> include/linux/mm.h                |    1 +
> init/main.c                       |    4 ++--
> mm/memory_hotplug.c               |    6 ++++--
> mm/slab.c                         |    2 +-
> mm/swap.c                         |    2 +-
> mm/vmalloc.c                      |    4 ++--
> net/core/sock.c                   |    4 ++--
> net/dccp/proto.c                  |    6 +++---
> net/decnet/dn_route.c             |    2 +-
> net/ipv4/route.c                  |    2 +-
> net/ipv4/tcp.c                    |    4 ++--
> net/netfilter/nf_conntrack_core.c |    4 ++--
> net/netfilter/x_tables.c          |    2 +-
> net/netfilter/xt_hashlimit.c      |    8 ++++----
> net/netlink/af_netlink.c          |    6 +++---
> net/sctp/protocol.c               |    6 +++---
> 21 files changed, 40 insertions(+), 41 deletions(-)
>
>--- linux-2.6.31-rc1/drivers/char/agp/backend.c	2009-06-26 17:49:43.000000000 +0200
>+++ 2.6.31-rc1-use-totalram_pages/drivers/char/agp/backend.c	2009-06-24 16:09:34.000000000 +0200
>@@ -114,9 +114,9 @@ static int agp_find_max(void)
> 	long memory, index, result;
> 
> #if PAGE_SHIFT < 20
>-	memory = num_physpages >> (20 - PAGE_SHIFT);
>+	memory = totalram_pages >> (20 - PAGE_SHIFT);
> #else
>-	memory = num_physpages << (PAGE_SHIFT - 20);
>+	memory = totalram_pages << (PAGE_SHIFT - 20);
> #endif
> 	index = 1;
> 
>--- linux-2.6.31-rc1/drivers/parisc/ccio-dma.c	2009-06-10 05:05:27.000000000 +0200
>+++ 2.6.31-rc1-use-totalram_pages/drivers/parisc/ccio-dma.c	2009-06-24 16:10:47.000000000 +0200
>@@ -1267,7 +1267,7 @@ ccio_ioc_init(struct ioc *ioc)
> 	** Hot-Plug/Removal of PCI cards. (aka PCI OLARD).
> 	*/
> 
>-	iova_space_size = (u32) (num_physpages / count_parisc_driver(&ccio_driver));
>+	iova_space_size = (u32) (totalram_pages / count_parisc_driver(&ccio_driver));
> 
> 	/* limit IOVA space size to 1MB-1GB */
> 
>@@ -1306,7 +1306,7 @@ ccio_ioc_init(struct ioc *ioc)
> 
> 	DBG_INIT("%s() hpa 0x%p mem %luMB IOV %dMB (%d bits)\n",
> 			__func__, ioc->ioc_regs,
>-			(unsigned long) num_physpages >> (20 - PAGE_SHIFT),
>+			(unsigned long) totalram_pages >> (20 - PAGE_SHIFT),
> 			iova_space_size>>20,
> 			iov_order + PAGE_SHIFT);
> 
>--- linux-2.6.31-rc1/drivers/parisc/sba_iommu.c	2009-06-26 17:49:47.000000000 +0200
>+++ 2.6.31-rc1-use-totalram_pages/drivers/parisc/sba_iommu.c	2009-06-24 16:10:58.000000000 +0200
>@@ -1390,7 +1390,7 @@ sba_ioc_init(struct parisc_device *sba, 
> 	** for DMA hints - ergo only 30 bits max.
> 	*/
> 
>-	iova_space_size = (u32) (num_physpages/global_ioc_cnt);
>+	iova_space_size = (u32) (totalram_pages/global_ioc_cnt);
> 
> 	/* limit IOVA space size to 1MB-1GB */
> 	if (iova_space_size < (1 << (20 - PAGE_SHIFT))) {
>@@ -1415,7 +1415,7 @@ sba_ioc_init(struct parisc_device *sba, 
> 	DBG_INIT("%s() hpa 0x%lx mem %ldMB IOV %dMB (%d bits)\n",
> 			__func__,
> 			ioc->ioc_hpa,
>-			(unsigned long) num_physpages >> (20 - PAGE_SHIFT),
>+			(unsigned long) totalram_pages >> (20 - PAGE_SHIFT),
> 			iova_space_size>>20,
> 			iov_order + PAGE_SHIFT);
> 
>--- linux-2.6.31-rc1/drivers/xen/balloon.c	2009-06-10 05:05:27.000000000 +0200
>+++ 2.6.31-rc1-use-totalram_pages/drivers/xen/balloon.c	2009-06-24 16:02:01.000000000 +0200
>@@ -96,11 +96,7 @@ static struct balloon_stats balloon_stat
> /* We increase/decrease in batches which fit in a page */
> static unsigned long frame_list[PAGE_SIZE / sizeof(unsigned long)];
> 
>-/* VM /proc information for memory */
>-extern unsigned long totalram_pages;
>-
> #ifdef CONFIG_HIGHMEM
>-extern unsigned long totalhigh_pages;
> #define inc_totalhigh_pages() (totalhigh_pages++)
> #define dec_totalhigh_pages() (totalhigh_pages--)
> #else
>--- linux-2.6.31-rc1/fs/ntfs/malloc.h	2008-04-17 04:49:44.000000000 +0200
>+++ 2.6.31-rc1-use-totalram_pages/fs/ntfs/malloc.h	2009-06-24 16:11:49.000000000 +0200
>@@ -47,7 +47,7 @@ static inline void *__ntfs_malloc(unsign
> 		return kmalloc(PAGE_SIZE, gfp_mask & ~__GFP_HIGHMEM);
> 		/* return (void *)__get_free_page(gfp_mask); */
> 	}
>-	if (likely(size >> PAGE_SHIFT < num_physpages))
>+	if (likely((size >> PAGE_SHIFT) < totalram_pages))
> 		return __vmalloc(size, gfp_mask, PAGE_KERNEL);
> 	return NULL;
> }
>--- linux-2.6.31-rc1/include/linux/mm.h	2009-06-26 17:50:00.000000000 +0200
>+++ 2.6.31-rc1-use-totalram_pages/include/linux/mm.h	2009-06-24 16:00:50.000000000 +0200
>@@ -25,6 +25,7 @@ extern unsigned long max_mapnr;
> #endif
> 
> extern unsigned long num_physpages;
>+extern unsigned long totalram_pages;
> extern void * high_memory;
> extern int page_cluster;
> 
>--- linux-2.6.31-rc1/init/main.c	2009-06-26 17:50:00.000000000 +0200
>+++ 2.6.31-rc1-use-totalram_pages/init/main.c	2009-06-24 16:12:30.000000000 +0200
>@@ -691,12 +691,12 @@ asmlinkage void __init start_kernel(void
> #endif
> 	thread_info_cache_init();
> 	cred_init();
>-	fork_init(num_physpages);
>+	fork_init(totalram_pages);
> 	proc_caches_init();
> 	buffer_init();
> 	key_init();
> 	security_init();
>-	vfs_caches_init(num_physpages);
>+	vfs_caches_init(totalram_pages);
> 	radix_tree_init();
> 	signals_init();
> 	/* rootfs populating might need page-writeback */
>--- linux-2.6.31-rc1/mm/memory_hotplug.c	2009-06-26 17:50:00.000000000 +0200
>+++ 2.6.31-rc1-use-totalram_pages/mm/memory_hotplug.c	2009-06-24 16:04:44.000000000 +0200
>@@ -339,8 +339,11 @@ EXPORT_SYMBOL_GPL(__remove_pages);
> 
> void online_page(struct page *page)
> {
>+	unsigned long pfn = page_to_pfn(page);
>+
> 	totalram_pages++;
>-	num_physpages++;
>+	if (pfn >= num_physpages)
>+		num_physpages = pfn + 1;
> 
> #ifdef CONFIG_HIGHMEM
> 	if (PageHighMem(page))
>@@ -831,7 +834,6 @@ repeat:
> 	zone->present_pages -= offlined_pages;
> 	zone->zone_pgdat->node_present_pages -= offlined_pages;
> 	totalram_pages -= offlined_pages;
>-	num_physpages -= offlined_pages;
> 
> 	setup_per_zone_wmarks();
> 	calculate_zone_inactive_ratio(zone);
>--- linux-2.6.31-rc1/mm/slab.c	2009-06-26 17:50:00.000000000 +0200
>+++ 2.6.31-rc1-use-totalram_pages/mm/slab.c	2009-06-24 16:06:21.000000000 +0200
>@@ -1384,7 +1384,7 @@ void __init kmem_cache_init(void)
> 	 * Fragmentation resistance on low memory - only use bigger
> 	 * page orders on machines with more than 32MB of memory.
> 	 */
>-	if (num_physpages > (32 << 20) >> PAGE_SHIFT)
>+	if (totalram_pages > (32 << 20) >> PAGE_SHIFT)
> 		slab_break_gfp_order = BREAK_GFP_ORDER_HI;
> 
> 	/* Bootstrap is tricky, because several objects are allocated
>--- linux-2.6.31-rc1/mm/swap.c	2009-06-10 05:05:27.000000000 +0200
>+++ 2.6.31-rc1-use-totalram_pages/mm/swap.c	2009-06-24 16:06:40.000000000 +0200
>@@ -496,7 +496,7 @@ EXPORT_SYMBOL(pagevec_lookup_tag);
>  */
> void __init swap_setup(void)
> {
>-	unsigned long megs = num_physpages >> (20 - PAGE_SHIFT);
>+	unsigned long megs = totalram_pages >> (20 - PAGE_SHIFT);
> 
> #ifdef CONFIG_SWAP
> 	bdi_init(swapper_space.backing_dev_info);
>--- linux-2.6.31-rc1/mm/vmalloc.c	2009-06-26 17:50:00.000000000 +0200
>+++ 2.6.31-rc1-use-totalram_pages/mm/vmalloc.c	2009-06-24 16:05:47.000000000 +0200
>@@ -1368,7 +1368,7 @@ void *vmap(struct page **pages, unsigned
> 
> 	might_sleep();
> 
>-	if (count > num_physpages)
>+	if (count > totalram_pages)
> 		return NULL;
> 
> 	area = get_vm_area_caller((count << PAGE_SHIFT), flags,
>@@ -1475,7 +1475,7 @@ static void *__vmalloc_node(unsigned lon
> 	unsigned long real_size = size;
> 
> 	size = PAGE_ALIGN(size);
>-	if (!size || (size >> PAGE_SHIFT) > num_physpages)
>+	if (!size || (size >> PAGE_SHIFT) > totalram_pages)
> 		return NULL;
> 
> 	area = __get_vm_area_node(size, VM_ALLOC, VMALLOC_START, VMALLOC_END,
>--- linux-2.6.31-rc1/net/core/sock.c	2009-06-26 17:50:00.000000000 +0200
>+++ 2.6.31-rc1-use-totalram_pages/net/core/sock.c	2009-06-24 16:14:00.000000000 +0200
>@@ -1169,12 +1169,12 @@ EXPORT_SYMBOL_GPL(sk_setup_caps);
> 
> void __init sk_init(void)
> {
>-	if (num_physpages <= 4096) {
>+	if (totalram_pages <= 4096) {
> 		sysctl_wmem_max = 32767;
> 		sysctl_rmem_max = 32767;
> 		sysctl_wmem_default = 32767;
> 		sysctl_rmem_default = 32767;
>-	} else if (num_physpages >= 131072) {
>+	} else if (totalram_pages >= 131072) {
> 		sysctl_wmem_max = 131071;
> 		sysctl_rmem_max = 131071;
> 	}
>--- linux-2.6.31-rc1/net/dccp/proto.c	2009-06-10 05:05:27.000000000 +0200
>+++ 2.6.31-rc1-use-totalram_pages/net/dccp/proto.c	2009-06-24 16:13:35.000000000 +0200
>@@ -1049,10 +1049,10 @@ static int __init dccp_init(void)
> 	 *
> 	 * The methodology is similar to that of the buffer cache.
> 	 */
>-	if (num_physpages >= (128 * 1024))
>-		goal = num_physpages >> (21 - PAGE_SHIFT);
>+	if (totalram_pages >= (128 * 1024))
>+		goal = totalram_pages >> (21 - PAGE_SHIFT);
> 	else
>-		goal = num_physpages >> (23 - PAGE_SHIFT);
>+		goal = totalram_pages >> (23 - PAGE_SHIFT);
> 
> 	if (thash_entries)
> 		goal = (thash_entries *
>--- linux-2.6.31-rc1/net/decnet/dn_route.c	2009-06-26 17:50:00.000000000 +0200
>+++ 2.6.31-rc1-use-totalram_pages/net/decnet/dn_route.c	2009-06-24 16:17:11.000000000 +0200
>@@ -1750,7 +1750,7 @@ void __init dn_route_init(void)
> 	dn_route_timer.expires = jiffies + decnet_dst_gc_interval * HZ;
> 	add_timer(&dn_route_timer);
> 
>-	goal = num_physpages >> (26 - PAGE_SHIFT);
>+	goal = totalram_pages >> (26 - PAGE_SHIFT);
> 
> 	for(order = 0; (1UL << order) < goal; order++)
> 		/* NOTHING */;
>--- linux-2.6.31-rc1/net/ipv4/route.c	2009-06-26 17:50:00.000000000 +0200
>+++ 2.6.31-rc1-use-totalram_pages/net/ipv4/route.c	2009-06-24 16:14:48.000000000 +0200
>@@ -3412,7 +3412,7 @@ int __init ip_rt_init(void)
> 		alloc_large_system_hash("IP route cache",
> 					sizeof(struct rt_hash_bucket),
> 					rhash_entries,
>-					(num_physpages >= 128 * 1024) ?
>+					(totalram_pages >= 128 * 1024) ?
> 					15 : 17,
> 					0,
> 					&rt_hash_log,
>--- linux-2.6.31-rc1/net/ipv4/tcp.c	2009-06-26 17:50:00.000000000 +0200
>+++ 2.6.31-rc1-use-totalram_pages/net/ipv4/tcp.c	2009-06-24 16:14:24.000000000 +0200
>@@ -2857,7 +2857,7 @@ void __init tcp_init(void)
> 		alloc_large_system_hash("TCP established",
> 					sizeof(struct inet_ehash_bucket),
> 					thash_entries,
>-					(num_physpages >= 128 * 1024) ?
>+					(totalram_pages >= 128 * 1024) ?
> 					13 : 15,
> 					0,
> 					&tcp_hashinfo.ehash_size,
>@@ -2874,7 +2874,7 @@ void __init tcp_init(void)
> 		alloc_large_system_hash("TCP bind",
> 					sizeof(struct inet_bind_hashbucket),
> 					tcp_hashinfo.ehash_size,
>-					(num_physpages >= 128 * 1024) ?
>+					(totalram_pages >= 128 * 1024) ?
> 					13 : 15,
> 					0,
> 					&tcp_hashinfo.bhash_size,
>--- linux-2.6.31-rc1/net/netfilter/nf_conntrack_core.c	2009-06-26 17:50:00.000000000 +0200
>+++ 2.6.31-rc1-use-totalram_pages/net/netfilter/nf_conntrack_core.c	2009-06-24 16:16:47.000000000 +0200
>@@ -1230,9 +1230,9 @@ static int nf_conntrack_init_init_net(vo
> 	 * machine has 512 buckets. >= 1GB machines have 16384 buckets. */
> 	if (!nf_conntrack_htable_size) {
> 		nf_conntrack_htable_size
>-			= (((num_physpages << PAGE_SHIFT) / 16384)
>+			= (((totalram_pages << PAGE_SHIFT) / 16384)
> 			   / sizeof(struct hlist_head));
>-		if (num_physpages > (1024 * 1024 * 1024 / PAGE_SIZE))
>+		if (totalram_pages > (1024 * 1024 * 1024 / PAGE_SIZE))
> 			nf_conntrack_htable_size = 16384;
> 		if (nf_conntrack_htable_size < 32)
> 			nf_conntrack_htable_size = 32;
>--- linux-2.6.31-rc1/net/netfilter/x_tables.c	2009-06-26 17:50:00.000000000 +0200
>+++ 2.6.31-rc1-use-totalram_pages/net/netfilter/x_tables.c	2009-06-24 16:16:28.000000000 +0200
>@@ -617,7 +617,7 @@ struct xt_table_info *xt_alloc_table_inf
> 	int cpu;
> 
> 	/* Pedantry: prevent them from hitting BUG() in vmalloc.c --RR */
>-	if ((SMP_ALIGN(size) >> PAGE_SHIFT) + 2 > num_physpages)
>+	if ((SMP_ALIGN(size) >> PAGE_SHIFT) + 2 > totalram_pages)
> 		return NULL;
> 
> 	newinfo = kzalloc(XT_TABLE_INFO_SZ, GFP_KERNEL);
>--- linux-2.6.31-rc1/net/netfilter/xt_hashlimit.c	2009-06-10 05:05:27.000000000 +0200
>+++ 2.6.31-rc1-use-totalram_pages/net/netfilter/xt_hashlimit.c	2009-06-24 16:16:07.000000000 +0200
>@@ -194,9 +194,9 @@ static int htable_create_v0(struct xt_ha
> 	if (minfo->cfg.size)
> 		size = minfo->cfg.size;
> 	else {
>-		size = ((num_physpages << PAGE_SHIFT) / 16384) /
>+		size = ((totalram_pages << PAGE_SHIFT) / 16384) /
> 		       sizeof(struct list_head);
>-		if (num_physpages > (1024 * 1024 * 1024 / PAGE_SIZE))
>+		if (totalram_pages > (1024 * 1024 * 1024 / PAGE_SIZE))
> 			size = 8192;
> 		if (size < 16)
> 			size = 16;
>@@ -266,9 +266,9 @@ static int htable_create(struct xt_hashl
> 	if (minfo->cfg.size) {
> 		size = minfo->cfg.size;
> 	} else {
>-		size = (num_physpages << PAGE_SHIFT) / 16384 /
>+		size = (totalram_pages << PAGE_SHIFT) / 16384 /
> 		       sizeof(struct list_head);
>-		if (num_physpages > 1024 * 1024 * 1024 / PAGE_SIZE)
>+		if (totalram_pages > 1024 * 1024 * 1024 / PAGE_SIZE)
> 			size = 8192;
> 		if (size < 16)
> 			size = 16;
>--- linux-2.6.31-rc1/net/netlink/af_netlink.c	2009-06-26 17:50:00.000000000 +0200
>+++ 2.6.31-rc1-use-totalram_pages/net/netlink/af_netlink.c	2009-06-24 16:17:28.000000000 +0200
>@@ -2026,10 +2026,10 @@ static int __init netlink_proto_init(voi
> 	if (!nl_table)
> 		goto panic;
> 
>-	if (num_physpages >= (128 * 1024))
>-		limit = num_physpages >> (21 - PAGE_SHIFT);
>+	if (totalram_pages >= (128 * 1024))
>+		limit = totalram_pages >> (21 - PAGE_SHIFT);
> 	else
>-		limit = num_physpages >> (23 - PAGE_SHIFT);
>+		limit = totalram_pages >> (23 - PAGE_SHIFT);
> 
> 	order = get_bitmask_order(limit) - 1 + PAGE_SHIFT;
> 	limit = (1UL << order) / sizeof(struct hlist_head);
>--- linux-2.6.31-rc1/net/sctp/protocol.c	2009-06-26 17:50:00.000000000 +0200
>+++ 2.6.31-rc1-use-totalram_pages/net/sctp/protocol.c	2009-06-24 16:15:36.000000000 +0200
>@@ -1185,10 +1185,10 @@ SCTP_STATIC __init int sctp_init(void)
> 	/* Size and allocate the association hash table.
> 	 * The methodology is similar to that of the tcp hash tables.
> 	 */
>-	if (num_physpages >= (128 * 1024))
>-		goal = num_physpages >> (22 - PAGE_SHIFT);
>+	if (totalram_pages >= (128 * 1024))
>+		goal = totalram_pages >> (22 - PAGE_SHIFT);
> 	else
>-		goal = num_physpages >> (24 - PAGE_SHIFT);
>+		goal = totalram_pages >> (24 - PAGE_SHIFT);
> 
> 	for (order = 0; (1UL << order) < goal; order++)
> 		;
>
>
>--
>To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
>the body of a message to majordomo@vger.kernel.org
>More majordomo info at  http://vger.kernel.org/majordomo-info.html
>Please read the FAQ at  http://www.tux.org/lkml/

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH] replace various uses of num_physpages by totalram_pages
@ 2009-08-18 15:34 Jan Beulich
  2009-08-18 15:38 ` Ingo Molnar
  0 siblings, 1 reply; 7+ messages in thread
From: Jan Beulich @ 2009-08-18 15:34 UTC (permalink / raw)
  To: linux-mm, linux-kernel; +Cc: Rusty Russell

Sizing of memory allocations shouldn't depend on the number of physical
pages found in a system, as that generally includes (perhaps a huge
amount of) non-RAM pages. The amount of what actually is usable as
storage should instead be used as a basis here.

Some of the calculations (i.e. those not intending to use high memory)
should likely even use (totalram_pages - totalhigh_pages).

Signed-off-by: Jan Beulich <jbeulich@novell.com>
Acked-by: Rusty Russell <rusty@rustcorp.com.au>

---
 arch/x86/kernel/microcode_core.c  |    4 ++--
 drivers/char/agp/backend.c        |    4 ++--
 drivers/parisc/ccio-dma.c         |    4 ++--
 drivers/parisc/sba_iommu.c        |    4 ++--
 drivers/xen/balloon.c             |    4 ----
 fs/ntfs/malloc.h                  |    2 +-
 include/linux/mm.h                |    1 +
 init/main.c                       |    4 ++--
 mm/slab.c                         |    2 +-
 mm/swap.c                         |    2 +-
 mm/vmalloc.c                      |    4 ++--
 net/core/sock.c                   |    4 ++--
 net/dccp/proto.c                  |    6 +++---
 net/decnet/dn_route.c             |    2 +-
 net/ipv4/route.c                  |    2 +-
 net/ipv4/tcp.c                    |    4 ++--
 net/netfilter/nf_conntrack_core.c |    4 ++--
 net/netfilter/x_tables.c          |    2 +-
 net/netfilter/xt_hashlimit.c      |    8 ++++----
 net/netlink/af_netlink.c          |    6 +++---
 net/sctp/protocol.c               |    6 +++---
 21 files changed, 38 insertions(+), 41 deletions(-)

--- linux-2.6.31-rc6/arch/x86/kernel/microcode_core.c	2009-08-18 15:31:16.000000000 +0200
+++ 2.6.31-rc6-use-totalram_pages/arch/x86/kernel/microcode_core.c	2009-08-17 15:21:19.000000000 +0200
@@ -210,8 +210,8 @@ static ssize_t microcode_write(struct fi
 {
 	ssize_t ret = -EINVAL;
 
-	if ((len >> PAGE_SHIFT) > num_physpages) {
-		pr_err("microcode: too much data (max %ld pages)\n", num_physpages);
+	if ((len >> PAGE_SHIFT) > totalram_pages) {
+		pr_err("microcode: too much data (max %ld pages)\n", totalram_pages);
 		return ret;
 	}
 
--- linux-2.6.31-rc6/drivers/char/agp/backend.c	2009-08-18 15:31:17.000000000 +0200
+++ 2.6.31-rc6-use-totalram_pages/drivers/char/agp/backend.c	2009-08-17 15:21:19.000000000 +0200
@@ -114,9 +114,9 @@ static int agp_find_max(void)
 	long memory, index, result;
 
 #if PAGE_SHIFT < 20
-	memory = num_physpages >> (20 - PAGE_SHIFT);
+	memory = totalram_pages >> (20 - PAGE_SHIFT);
 #else
-	memory = num_physpages << (PAGE_SHIFT - 20);
+	memory = totalram_pages << (PAGE_SHIFT - 20);
 #endif
 	index = 1;
 
--- linux-2.6.31-rc6/drivers/parisc/ccio-dma.c	2009-08-18 15:31:36.000000000 +0200
+++ 2.6.31-rc6-use-totalram_pages/drivers/parisc/ccio-dma.c	2009-08-17 15:21:19.000000000 +0200
@@ -1266,7 +1266,7 @@ ccio_ioc_init(struct ioc *ioc)
 	** Hot-Plug/Removal of PCI cards. (aka PCI OLARD).
 	*/
 
-	iova_space_size = (u32) (num_physpages / count_parisc_driver(&ccio_driver));
+	iova_space_size = (u32) (totalram_pages / count_parisc_driver(&ccio_driver));
 
 	/* limit IOVA space size to 1MB-1GB */
 
@@ -1305,7 +1305,7 @@ ccio_ioc_init(struct ioc *ioc)
 
 	DBG_INIT("%s() hpa 0x%p mem %luMB IOV %dMB (%d bits)\n",
 			__func__, ioc->ioc_regs,
-			(unsigned long) num_physpages >> (20 - PAGE_SHIFT),
+			(unsigned long) totalram_pages >> (20 - PAGE_SHIFT),
 			iova_space_size>>20,
 			iov_order + PAGE_SHIFT);
 
--- linux-2.6.31-rc6/drivers/parisc/sba_iommu.c	2009-08-18 15:31:36.000000000 +0200
+++ 2.6.31-rc6-use-totalram_pages/drivers/parisc/sba_iommu.c	2009-08-17 15:21:19.000000000 +0200
@@ -1390,7 +1390,7 @@ sba_ioc_init(struct parisc_device *sba, 
 	** for DMA hints - ergo only 30 bits max.
 	*/
 
-	iova_space_size = (u32) (num_physpages/global_ioc_cnt);
+	iova_space_size = (u32) (totalram_pages/global_ioc_cnt);
 
 	/* limit IOVA space size to 1MB-1GB */
 	if (iova_space_size < (1 << (20 - PAGE_SHIFT))) {
@@ -1415,7 +1415,7 @@ sba_ioc_init(struct parisc_device *sba, 
 	DBG_INIT("%s() hpa 0x%lx mem %ldMB IOV %dMB (%d bits)\n",
 			__func__,
 			ioc->ioc_hpa,
-			(unsigned long) num_physpages >> (20 - PAGE_SHIFT),
+			(unsigned long) totalram_pages >> (20 - PAGE_SHIFT),
 			iova_space_size>>20,
 			iov_order + PAGE_SHIFT);
 
--- linux-2.6.31-rc6/drivers/xen/balloon.c	2009-06-10 05:05:27.000000000 +0200
+++ 2.6.31-rc6-use-totalram_pages/drivers/xen/balloon.c	2009-08-17 15:21:19.000000000 +0200
@@ -96,11 +96,7 @@ static struct balloon_stats balloon_stat
 /* We increase/decrease in batches which fit in a page */
 static unsigned long frame_list[PAGE_SIZE / sizeof(unsigned long)];
 
-/* VM /proc information for memory */
-extern unsigned long totalram_pages;
-
 #ifdef CONFIG_HIGHMEM
-extern unsigned long totalhigh_pages;
 #define inc_totalhigh_pages() (totalhigh_pages++)
 #define dec_totalhigh_pages() (totalhigh_pages--)
 #else
--- linux-2.6.31-rc6/fs/ntfs/malloc.h	2008-04-17 04:49:44.000000000 +0200
+++ 2.6.31-rc6-use-totalram_pages/fs/ntfs/malloc.h	2009-08-17 15:21:19.000000000 +0200
@@ -47,7 +47,7 @@ static inline void *__ntfs_malloc(unsign
 		return kmalloc(PAGE_SIZE, gfp_mask & ~__GFP_HIGHMEM);
 		/* return (void *)__get_free_page(gfp_mask); */
 	}
-	if (likely(size >> PAGE_SHIFT < num_physpages))
+	if (likely((size >> PAGE_SHIFT) < totalram_pages))
 		return __vmalloc(size, gfp_mask, PAGE_KERNEL);
 	return NULL;
 }
--- linux-2.6.31-rc6/include/linux/mm.h	2009-08-18 15:31:55.000000000 +0200
+++ 2.6.31-rc6-use-totalram_pages/include/linux/mm.h	2009-08-17 15:21:19.000000000 +0200
@@ -25,6 +25,7 @@ extern unsigned long max_mapnr;
 #endif
 
 extern unsigned long num_physpages;
+extern unsigned long totalram_pages;
 extern void * high_memory;
 extern int page_cluster;
 
--- linux-2.6.31-rc6/init/main.c	2009-08-18 15:31:56.000000000 +0200
+++ 2.6.31-rc6-use-totalram_pages/init/main.c	2009-08-17 15:21:19.000000000 +0200
@@ -691,12 +691,12 @@ asmlinkage void __init start_kernel(void
 #endif
 	thread_info_cache_init();
 	cred_init();
-	fork_init(num_physpages);
+	fork_init(totalram_pages);
 	proc_caches_init();
 	buffer_init();
 	key_init();
 	security_init();
-	vfs_caches_init(num_physpages);
+	vfs_caches_init(totalram_pages);
 	radix_tree_init();
 	signals_init();
 	/* rootfs populating might need page-writeback */
--- linux-2.6.31-rc6/mm/slab.c	2009-08-18 15:31:56.000000000 +0200
+++ 2.6.31-rc6-use-totalram_pages/mm/slab.c	2009-08-17 15:21:19.000000000 +0200
@@ -1384,7 +1384,7 @@ void __init kmem_cache_init(void)
 	 * Fragmentation resistance on low memory - only use bigger
 	 * page orders on machines with more than 32MB of memory.
 	 */
-	if (num_physpages > (32 << 20) >> PAGE_SHIFT)
+	if (totalram_pages > (32 << 20) >> PAGE_SHIFT)
 		slab_break_gfp_order = BREAK_GFP_ORDER_HI;
 
 	/* Bootstrap is tricky, because several objects are allocated
--- linux-2.6.31-rc6/mm/swap.c	2009-06-10 05:05:27.000000000 +0200
+++ 2.6.31-rc6-use-totalram_pages/mm/swap.c	2009-08-17 15:21:19.000000000 +0200
@@ -496,7 +496,7 @@ EXPORT_SYMBOL(pagevec_lookup_tag);
  */
 void __init swap_setup(void)
 {
-	unsigned long megs = num_physpages >> (20 - PAGE_SHIFT);
+	unsigned long megs = totalram_pages >> (20 - PAGE_SHIFT);
 
 #ifdef CONFIG_SWAP
 	bdi_init(swapper_space.backing_dev_info);
--- linux-2.6.31-rc6/mm/vmalloc.c	2009-08-18 15:31:56.000000000 +0200
+++ 2.6.31-rc6-use-totalram_pages/mm/vmalloc.c	2009-08-17 15:21:19.000000000 +0200
@@ -1368,7 +1368,7 @@ void *vmap(struct page **pages, unsigned
 
 	might_sleep();
 
-	if (count > num_physpages)
+	if (count > totalram_pages)
 		return NULL;
 
 	area = get_vm_area_caller((count << PAGE_SHIFT), flags,
@@ -1475,7 +1475,7 @@ static void *__vmalloc_node(unsigned lon
 	unsigned long real_size = size;
 
 	size = PAGE_ALIGN(size);
-	if (!size || (size >> PAGE_SHIFT) > num_physpages)
+	if (!size || (size >> PAGE_SHIFT) > totalram_pages)
 		return NULL;
 
 	area = __get_vm_area_node(size, VM_ALLOC, VMALLOC_START, VMALLOC_END,
--- linux-2.6.31-rc6/net/core/sock.c	2009-08-18 15:31:57.000000000 +0200
+++ 2.6.31-rc6-use-totalram_pages/net/core/sock.c	2009-08-17 15:21:19.000000000 +0200
@@ -1195,12 +1195,12 @@ EXPORT_SYMBOL_GPL(sk_setup_caps);
 
 void __init sk_init(void)
 {
-	if (num_physpages <= 4096) {
+	if (totalram_pages <= 4096) {
 		sysctl_wmem_max = 32767;
 		sysctl_rmem_max = 32767;
 		sysctl_wmem_default = 32767;
 		sysctl_rmem_default = 32767;
-	} else if (num_physpages >= 131072) {
+	} else if (totalram_pages >= 131072) {
 		sysctl_wmem_max = 131071;
 		sysctl_rmem_max = 131071;
 	}
--- linux-2.6.31-rc6/net/dccp/proto.c	2009-08-18 15:31:57.000000000 +0200
+++ 2.6.31-rc6-use-totalram_pages/net/dccp/proto.c	2009-08-17 15:21:19.000000000 +0200
@@ -1049,10 +1049,10 @@ static int __init dccp_init(void)
 	 *
 	 * The methodology is similar to that of the buffer cache.
 	 */
-	if (num_physpages >= (128 * 1024))
-		goal = num_physpages >> (21 - PAGE_SHIFT);
+	if (totalram_pages >= (128 * 1024))
+		goal = totalram_pages >> (21 - PAGE_SHIFT);
 	else
-		goal = num_physpages >> (23 - PAGE_SHIFT);
+		goal = totalram_pages >> (23 - PAGE_SHIFT);
 
 	if (thash_entries)
 		goal = (thash_entries *
--- linux-2.6.31-rc6/net/decnet/dn_route.c	2009-08-18 15:31:57.000000000 +0200
+++ 2.6.31-rc6-use-totalram_pages/net/decnet/dn_route.c	2009-08-17 15:21:19.000000000 +0200
@@ -1750,7 +1750,7 @@ void __init dn_route_init(void)
 	dn_route_timer.expires = jiffies + decnet_dst_gc_interval * HZ;
 	add_timer(&dn_route_timer);
 
-	goal = num_physpages >> (26 - PAGE_SHIFT);
+	goal = totalram_pages >> (26 - PAGE_SHIFT);
 
 	for(order = 0; (1UL << order) < goal; order++)
 		/* NOTHING */;
--- linux-2.6.31-rc6/net/ipv4/route.c	2009-08-18 15:31:59.000000000 +0200
+++ 2.6.31-rc6-use-totalram_pages/net/ipv4/route.c	2009-08-17 15:21:19.000000000 +0200
@@ -3412,7 +3412,7 @@ int __init ip_rt_init(void)
 		alloc_large_system_hash("IP route cache",
 					sizeof(struct rt_hash_bucket),
 					rhash_entries,
-					(num_physpages >= 128 * 1024) ?
+					(totalram_pages >= 128 * 1024) ?
 					15 : 17,
 					0,
 					&rt_hash_log,
--- linux-2.6.31-rc6/net/ipv4/tcp.c	2009-08-18 15:31:59.000000000 +0200
+++ 2.6.31-rc6-use-totalram_pages/net/ipv4/tcp.c	2009-08-17 15:21:19.000000000 +0200
@@ -2862,7 +2862,7 @@ void __init tcp_init(void)
 		alloc_large_system_hash("TCP established",
 					sizeof(struct inet_ehash_bucket),
 					thash_entries,
-					(num_physpages >= 128 * 1024) ?
+					(totalram_pages >= 128 * 1024) ?
 					13 : 15,
 					0,
 					&tcp_hashinfo.ehash_size,
@@ -2879,7 +2879,7 @@ void __init tcp_init(void)
 		alloc_large_system_hash("TCP bind",
 					sizeof(struct inet_bind_hashbucket),
 					tcp_hashinfo.ehash_size,
-					(num_physpages >= 128 * 1024) ?
+					(totalram_pages >= 128 * 1024) ?
 					13 : 15,
 					0,
 					&tcp_hashinfo.bhash_size,
--- linux-2.6.31-rc6/net/netfilter/nf_conntrack_core.c	2009-08-18 15:32:01.000000000 +0200
+++ 2.6.31-rc6-use-totalram_pages/net/netfilter/nf_conntrack_core.c	2009-08-17 15:21:19.000000000 +0200
@@ -1245,9 +1245,9 @@ static int nf_conntrack_init_init_net(vo
 	 * machine has 512 buckets. >= 1GB machines have 16384 buckets. */
 	if (!nf_conntrack_htable_size) {
 		nf_conntrack_htable_size
-			= (((num_physpages << PAGE_SHIFT) / 16384)
+			= (((totalram_pages << PAGE_SHIFT) / 16384)
 			   / sizeof(struct hlist_head));
-		if (num_physpages > (1024 * 1024 * 1024 / PAGE_SIZE))
+		if (totalram_pages > (1024 * 1024 * 1024 / PAGE_SIZE))
 			nf_conntrack_htable_size = 16384;
 		if (nf_conntrack_htable_size < 32)
 			nf_conntrack_htable_size = 32;
--- linux-2.6.31-rc6/net/netfilter/x_tables.c	2009-08-18 15:32:01.000000000 +0200
+++ 2.6.31-rc6-use-totalram_pages/net/netfilter/x_tables.c	2009-08-17 15:21:19.000000000 +0200
@@ -617,7 +617,7 @@ struct xt_table_info *xt_alloc_table_inf
 	int cpu;
 
 	/* Pedantry: prevent them from hitting BUG() in vmalloc.c --RR */
-	if ((SMP_ALIGN(size) >> PAGE_SHIFT) + 2 > num_physpages)
+	if ((SMP_ALIGN(size) >> PAGE_SHIFT) + 2 > totalram_pages)
 		return NULL;
 
 	newinfo = kzalloc(XT_TABLE_INFO_SZ, GFP_KERNEL);
--- linux-2.6.31-rc6/net/netfilter/xt_hashlimit.c	2009-06-10 05:05:27.000000000 +0200
+++ 2.6.31-rc6-use-totalram_pages/net/netfilter/xt_hashlimit.c	2009-08-17 15:21:19.000000000 +0200
@@ -194,9 +194,9 @@ static int htable_create_v0(struct xt_ha
 	if (minfo->cfg.size)
 		size = minfo->cfg.size;
 	else {
-		size = ((num_physpages << PAGE_SHIFT) / 16384) /
+		size = ((totalram_pages << PAGE_SHIFT) / 16384) /
 		       sizeof(struct list_head);
-		if (num_physpages > (1024 * 1024 * 1024 / PAGE_SIZE))
+		if (totalram_pages > (1024 * 1024 * 1024 / PAGE_SIZE))
 			size = 8192;
 		if (size < 16)
 			size = 16;
@@ -266,9 +266,9 @@ static int htable_create(struct xt_hashl
 	if (minfo->cfg.size) {
 		size = minfo->cfg.size;
 	} else {
-		size = (num_physpages << PAGE_SHIFT) / 16384 /
+		size = (totalram_pages << PAGE_SHIFT) / 16384 /
 		       sizeof(struct list_head);
-		if (num_physpages > 1024 * 1024 * 1024 / PAGE_SIZE)
+		if (totalram_pages > 1024 * 1024 * 1024 / PAGE_SIZE)
 			size = 8192;
 		if (size < 16)
 			size = 16;
--- linux-2.6.31-rc6/net/netlink/af_netlink.c	2009-08-18 15:32:01.000000000 +0200
+++ 2.6.31-rc6-use-totalram_pages/net/netlink/af_netlink.c	2009-08-17 15:21:19.000000000 +0200
@@ -2026,10 +2026,10 @@ static int __init netlink_proto_init(voi
 	if (!nl_table)
 		goto panic;
 
-	if (num_physpages >= (128 * 1024))
-		limit = num_physpages >> (21 - PAGE_SHIFT);
+	if (totalram_pages >= (128 * 1024))
+		limit = totalram_pages >> (21 - PAGE_SHIFT);
 	else
-		limit = num_physpages >> (23 - PAGE_SHIFT);
+		limit = totalram_pages >> (23 - PAGE_SHIFT);
 
 	order = get_bitmask_order(limit) - 1 + PAGE_SHIFT;
 	limit = (1UL << order) / sizeof(struct hlist_head);
--- linux-2.6.31-rc6/net/sctp/protocol.c	2009-08-18 15:32:01.000000000 +0200
+++ 2.6.31-rc6-use-totalram_pages/net/sctp/protocol.c	2009-08-17 15:21:19.000000000 +0200
@@ -1185,10 +1185,10 @@ SCTP_STATIC __init int sctp_init(void)
 	/* Size and allocate the association hash table.
 	 * The methodology is similar to that of the tcp hash tables.
 	 */
-	if (num_physpages >= (128 * 1024))
-		goal = num_physpages >> (22 - PAGE_SHIFT);
+	if (totalram_pages >= (128 * 1024))
+		goal = totalram_pages >> (22 - PAGE_SHIFT);
 	else
-		goal = num_physpages >> (24 - PAGE_SHIFT);
+		goal = totalram_pages >> (24 - PAGE_SHIFT);
 
 	for (order = 0; (1UL << order) < goal; order++)
 		;



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] replace various uses of num_physpages by totalram_pages
  2009-08-18 15:34 [PATCH] replace various uses of num_physpages by totalram_pages Jan Beulich
@ 2009-08-18 15:38 ` Ingo Molnar
  2009-08-18 15:48   ` Jan Beulich
  0 siblings, 1 reply; 7+ messages in thread
From: Ingo Molnar @ 2009-08-18 15:38 UTC (permalink / raw)
  To: Jan Beulich; +Cc: linux-mm, linux-kernel, Rusty Russell


* Jan Beulich <JBeulich@novell.com> wrote:

> Sizing of memory allocations shouldn't depend on the number of 
> physical pages found in a system, as that generally includes 
> (perhaps a huge amount of) non-RAM pages. The amount of what 
> actually is usable as storage should instead be used as a basis 
> here.
> 
> Some of the calculations (i.e. those not intending to use high 
> memory) should likely even use (totalram_pages - 
> totalhigh_pages).
> 
> Signed-off-by: Jan Beulich <jbeulich@novell.com>
> Acked-by: Rusty Russell <rusty@rustcorp.com.au>
> 
> ---
>  arch/x86/kernel/microcode_core.c  |    4 ++--

Acked-by: Ingo Molnar <mingo@elte.hu>

Just curious: how did you find this bug? Did you find this by 
experiencing problems on a system with a lot of declared non-RAM 
memory?

	Ingo

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] replace various uses of num_physpages by totalram_pages
  2009-08-18 15:38 ` Ingo Molnar
@ 2009-08-18 15:48   ` Jan Beulich
  0 siblings, 0 replies; 7+ messages in thread
From: Jan Beulich @ 2009-08-18 15:48 UTC (permalink / raw)
  To: Ingo Molnar; +Cc: linux-mm, Rusty Russell, linux-kernel

>>> Ingo Molnar <mingo@elte.hu> 18.08.09 17:38 >>>
>
>* Jan Beulich <JBeulich@novell.com> wrote:
>
>> Sizing of memory allocations shouldn't depend on the number of 
>> physical pages found in a system, as that generally includes 
>> (perhaps a huge amount of) non-RAM pages. The amount of what 
>> actually is usable as storage should instead be used as a basis 
>> here.
>> 
>> Some of the calculations (i.e. those not intending to use high 
>> memory) should likely even use (totalram_pages - 
>> totalhigh_pages).
>> 
>> Signed-off-by: Jan Beulich <jbeulich@novell.com>
>> Acked-by: Rusty Russell <rusty@rustcorp.com.au>
>> 
>> ---
>>  arch/x86/kernel/microcode_core.c  |    4 ++--
>
>Acked-by: Ingo Molnar <mingo@elte.hu>
>
>Just curious: how did you find this bug? Did you find this by 
>experiencing problems on a system with a lot of declared non-RAM 
>memory?

Actually, I noticed this on Xen (non-pv-ops) when booting a domain with
a sufficiently large initial balloon. Under that condition, booting would
frequently fail due to various table sizes being calculated way too large.

Jan


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2009-08-18 15:48 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-08-18 15:34 [PATCH] replace various uses of num_physpages by totalram_pages Jan Beulich
2009-08-18 15:38 ` Ingo Molnar
2009-08-18 15:48   ` Jan Beulich
  -- strict thread matches above, loose matches on Subject: below --
2009-06-30 11:08 Jan Beulich
2009-07-01  4:57 ` Rusty Russell
2009-07-01  6:54   ` Jan Beulich
2009-07-01  7:43 ` Amerigo Wang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox