upgrade to linux 2.6.10-1.12_FC2
[linux-2.6.git] / arch / ia64 / mm / init.c
1 /*
2  * Initialize MMU support.
3  *
4  * Copyright (C) 1998-2003 Hewlett-Packard Co
5  *      David Mosberger-Tang <davidm@hpl.hp.com>
6  */
7 #include <linux/config.h>
8 #include <linux/kernel.h>
9 #include <linux/init.h>
10
11 #include <linux/bootmem.h>
12 #include <linux/efi.h>
13 #include <linux/elf.h>
14 #include <linux/mm.h>
15 #include <linux/mmzone.h>
16 #include <linux/module.h>
17 #include <linux/personality.h>
18 #include <linux/reboot.h>
19 #include <linux/slab.h>
20 #include <linux/swap.h>
21 #include <linux/proc_fs.h>
22 #include <linux/bitops.h>
23
24 #include <asm/a.out.h>
25 #include <asm/dma.h>
26 #include <asm/ia32.h>
27 #include <asm/io.h>
28 #include <asm/machvec.h>
29 #include <asm/numa.h>
30 #include <asm/patch.h>
31 #include <asm/pgalloc.h>
32 #include <asm/sal.h>
33 #include <asm/sections.h>
34 #include <asm/system.h>
35 #include <asm/tlb.h>
36 #include <asm/uaccess.h>
37 #include <asm/unistd.h>
38 #include <asm/mca.h>
39
40 DEFINE_PER_CPU(struct mmu_gather, mmu_gathers);
41
42 extern void ia64_tlb_init (void);
43
44 unsigned long MAX_DMA_ADDRESS = PAGE_OFFSET + 0x100000000UL;
45
46 #ifdef CONFIG_VIRTUAL_MEM_MAP
47 unsigned long vmalloc_end = VMALLOC_END_INIT;
48 EXPORT_SYMBOL(vmalloc_end);
49 struct page *vmem_map;
50 EXPORT_SYMBOL(vmem_map);
51 #endif
52
53 static int pgt_cache_water[2] = { 25, 50 };
54
55 struct page *zero_page_memmap_ptr;              /* map entry for zero page */
56 EXPORT_SYMBOL(zero_page_memmap_ptr);
57
58 void
59 check_pgt_cache (void)
60 {
61         int low, high;
62
63         low = pgt_cache_water[0];
64         high = pgt_cache_water[1];
65
66         preempt_disable();
67         if (pgtable_cache_size > (u64) high) {
68                 do {
69                         if (pgd_quicklist)
70                                 free_page((unsigned long)pgd_alloc_one_fast(NULL));
71                         if (pmd_quicklist)
72                                 free_page((unsigned long)pmd_alloc_one_fast(NULL, 0));
73                 } while (pgtable_cache_size > (u64) low);
74         }
75         preempt_enable();
76 }
77
78 void
79 update_mmu_cache (struct vm_area_struct *vma, unsigned long vaddr, pte_t pte)
80 {
81         unsigned long addr;
82         struct page *page;
83
84         if (!pte_exec(pte))
85                 return;                         /* not an executable page... */
86
87         page = pte_page(pte);
88         /* don't use VADDR: it may not be mapped on this CPU (or may have just been flushed): */
89         addr = (unsigned long) page_address(page);
90
91         if (test_bit(PG_arch_1, &page->flags))
92                 return;                         /* i-cache is already coherent with d-cache */
93
94         flush_icache_range(addr, addr + PAGE_SIZE);
95         set_bit(PG_arch_1, &page->flags);       /* mark page as clean */
96 }
97
98 inline void
99 ia64_set_rbs_bot (void)
100 {
101         unsigned long stack_size = current->signal->rlim[RLIMIT_STACK].rlim_max & -16;
102
103         if (stack_size > MAX_USER_STACK_SIZE)
104                 stack_size = MAX_USER_STACK_SIZE;
105         current->thread.rbs_bot = STACK_TOP - stack_size;
106 }
107
108 /*
109  * This performs some platform-dependent address space initialization.
110  * On IA-64, we want to setup the VM area for the register backing
111  * store (which grows upwards) and install the gateway page which is
112  * used for signal trampolines, etc.
113  */
114 void
115 ia64_init_addr_space (void)
116 {
117         struct vm_area_struct *vma;
118
119         ia64_set_rbs_bot();
120
121         /*
122          * If we're out of memory and kmem_cache_alloc() returns NULL, we simply ignore
123          * the problem.  When the process attempts to write to the register backing store
124          * for the first time, it will get a SEGFAULT in this case.
125          */
126         vma = kmem_cache_alloc(vm_area_cachep, SLAB_KERNEL);
127         if (vma) {
128                 memset(vma, 0, sizeof(*vma));
129                 vma->vm_mm = current->mm;
130                 vma->vm_start = current->thread.rbs_bot & PAGE_MASK;
131                 vma->vm_end = vma->vm_start + PAGE_SIZE;
132                 vma->vm_page_prot = protection_map[VM_DATA_DEFAULT_FLAGS & 0x7];
133                 vma->vm_flags = VM_DATA_DEFAULT_FLAGS | VM_GROWSUP;
134                 down_write(&current->mm->mmap_sem);
135                 if (insert_vm_struct(current->mm, vma)) {
136                         up_write(&current->mm->mmap_sem);
137                         kmem_cache_free(vm_area_cachep, vma);
138                         return;
139                 }
140                 up_write(&current->mm->mmap_sem);
141         }
142
143         /* map NaT-page at address zero to speed up speculative dereferencing of NULL: */
144         if (!(current->personality & MMAP_PAGE_ZERO)) {
145                 vma = kmem_cache_alloc(vm_area_cachep, SLAB_KERNEL);
146                 if (vma) {
147                         memset(vma, 0, sizeof(*vma));
148                         vma->vm_mm = current->mm;
149                         vma->vm_end = PAGE_SIZE;
150                         vma->vm_page_prot = __pgprot(pgprot_val(PAGE_READONLY) | _PAGE_MA_NAT);
151                         vma->vm_flags = VM_READ | VM_MAYREAD | VM_IO | VM_RESERVED;
152                         down_write(&current->mm->mmap_sem);
153                         if (insert_vm_struct(current->mm, vma)) {
154                                 up_write(&current->mm->mmap_sem);
155                                 kmem_cache_free(vm_area_cachep, vma);
156                                 return;
157                         }
158                         up_write(&current->mm->mmap_sem);
159                 }
160         }
161 }
162
163 void
164 free_initmem (void)
165 {
166         unsigned long addr, eaddr;
167
168         addr = (unsigned long) ia64_imva(__init_begin);
169         eaddr = (unsigned long) ia64_imva(__init_end);
170         while (addr < eaddr) {
171                 ClearPageReserved(virt_to_page(addr));
172                 set_page_count(virt_to_page(addr), 1);
173                 free_page(addr);
174                 ++totalram_pages;
175                 addr += PAGE_SIZE;
176         }
177         printk(KERN_INFO "Freeing unused kernel memory: %ldkB freed\n",
178                (__init_end - __init_begin) >> 10);
179 }
180
181 void
182 free_initrd_mem (unsigned long start, unsigned long end)
183 {
184         struct page *page;
185         /*
186          * EFI uses 4KB pages while the kernel can use 4KB or bigger.
187          * Thus EFI and the kernel may have different page sizes. It is
188          * therefore possible to have the initrd share the same page as
189          * the end of the kernel (given current setup).
190          *
191          * To avoid freeing/using the wrong page (kernel sized) we:
192          *      - align up the beginning of initrd
193          *      - align down the end of initrd
194          *
195          *  |             |
196          *  |=============| a000
197          *  |             |
198          *  |             |
199          *  |             | 9000
200          *  |/////////////|
201          *  |/////////////|
202          *  |=============| 8000
203          *  |///INITRD////|
204          *  |/////////////|
205          *  |/////////////| 7000
206          *  |             |
207          *  |KKKKKKKKKKKKK|
208          *  |=============| 6000
209          *  |KKKKKKKKKKKKK|
210          *  |KKKKKKKKKKKKK|
211          *  K=kernel using 8KB pages
212          *
213          * In this example, we must free page 8000 ONLY. So we must align up
214          * initrd_start and keep initrd_end as is.
215          */
216         start = PAGE_ALIGN(start);
217         end = end & PAGE_MASK;
218
219         if (start < end)
220                 printk(KERN_INFO "Freeing initrd memory: %ldkB freed\n", (end - start) >> 10);
221
222         for (; start < end; start += PAGE_SIZE) {
223                 if (!virt_addr_valid(start))
224                         continue;
225                 page = virt_to_page(start);
226                 ClearPageReserved(page);
227                 set_page_count(page, 1);
228                 free_page(start);
229                 ++totalram_pages;
230         }
231 }
232
233 struct curr_mem_request {
234         unsigned long requested;
235         unsigned long min_physaddr;
236         int found;
237 };
238
239 /*
240  *  Check whether a physical address fits within the memory descriptor
241  *  block sent from efi_mmap_walk(). If it fits, set found.
242  */
243 static int
244 verify_physaddr (unsigned long start, unsigned long end, void *arg)
245 {
246         struct curr_mem_request *cr = arg;
247
248         start = __pa(start);
249         end = __pa(end);
250
251         if ((cr->requested >= start) && (cr->requested + PAGE_SIZE) <= end) {
252                 cr->found = 1;
253                 return -1;
254         }
255
256         return 0;
257 }
258
259 /*
260  * If physical page 'nr' is valid RAM then return 1.  Otherwise return 0.
261  */
262
263 int
264 page_is_ram (unsigned long pagenr)
265 {
266         struct curr_mem_request cr;
267
268         if (!pfn_valid(pagenr))
269                 return 0;
270
271         cr.requested = pagenr << PAGE_SHIFT;
272         cr.found = 0;
273
274         efi_memmap_walk(verify_physaddr, &cr);
275
276         return cr.found;
277 }
278 EXPORT_SYMBOL_GPL(page_is_ram);
279
280 static int
281 find_next (unsigned long start, unsigned long end, void *arg)
282 {
283         struct curr_mem_request *cr = (struct curr_mem_request *)arg;
284
285         start = __pa(start);
286         end = __pa(end);
287
288         if ((cr->requested >= start) && (cr->requested + PAGE_SIZE) <= end) {
289                 cr->min_physaddr = cr->requested;
290                 cr->found = 1;
291                 return -1;
292         }
293         if ((cr->requested < start) && (start + PAGE_SIZE) <= end)
294                 if (start < cr->min_physaddr) {
295                         cr->min_physaddr = start;
296                         cr->found = 1;
297                 }
298
299         return 0;
300 }
301
302 unsigned long
303 next_ram_page (unsigned long pagenr)
304 {
305         struct curr_mem_request cr;
306
307         pagenr++;
308
309         cr.requested = pagenr << PAGE_SHIFT;
310         cr.found = 0;
311         cr.min_physaddr = ULONG_MAX;
312
313         efi_memmap_walk(find_next, &cr);
314
315         if (cr.found)
316                 return cr.min_physaddr >> PAGE_SHIFT;
317         else
318                 return ULONG_MAX;
319 }
320 EXPORT_SYMBOL_GPL(next_ram_page);
321
322 /*
323  * This installs a clean page in the kernel's page table.
324  */
325 struct page *
326 put_kernel_page (struct page *page, unsigned long address, pgprot_t pgprot)
327 {
328         pgd_t *pgd;
329         pmd_t *pmd;
330         pte_t *pte;
331
332         if (!PageReserved(page))
333                 printk(KERN_ERR "put_kernel_page: page at 0x%p not in reserved memory\n",
334                        page_address(page));
335
336         pgd = pgd_offset_k(address);            /* note: this is NOT pgd_offset()! */
337
338         spin_lock(&init_mm.page_table_lock);
339         {
340                 pmd = pmd_alloc(&init_mm, pgd, address);
341                 if (!pmd)
342                         goto out;
343                 pte = pte_alloc_map(&init_mm, pmd, address);
344                 if (!pte)
345                         goto out;
346                 if (!pte_none(*pte)) {
347                         pte_unmap(pte);
348                         goto out;
349                 }
350                 set_pte(pte, mk_pte(page, pgprot));
351                 pte_unmap(pte);
352         }
353   out:  spin_unlock(&init_mm.page_table_lock);
354         /* no need for flush_tlb */
355         return page;
356 }
357
358 static void
359 setup_gate (void)
360 {
361         struct page *page;
362
363         /*
364          * Map the gate page twice: once read-only to export the ELF headers etc. and once
365          * execute-only page to enable privilege-promotion via "epc":
366          */
367         page = virt_to_page(ia64_imva(__start_gate_section));
368         put_kernel_page(page, GATE_ADDR, PAGE_READONLY);
369 #ifdef HAVE_BUGGY_SEGREL
370         page = virt_to_page(ia64_imva(__start_gate_section + PAGE_SIZE));
371         put_kernel_page(page, GATE_ADDR + PAGE_SIZE, PAGE_GATE);
372 #else
373         put_kernel_page(page, GATE_ADDR + PERCPU_PAGE_SIZE, PAGE_GATE);
374 #endif
375         ia64_patch_gate();
376 }
377
378 void __devinit
379 ia64_mmu_init (void *my_cpu_data)
380 {
381         unsigned long psr, pta, impl_va_bits;
382         extern void __devinit tlb_init (void);
383         int cpu;
384
385 #ifdef CONFIG_DISABLE_VHPT
386 #       define VHPT_ENABLE_BIT  0
387 #else
388 #       define VHPT_ENABLE_BIT  1
389 #endif
390
391         /* Pin mapping for percpu area into TLB */
392         psr = ia64_clear_ic();
393         ia64_itr(0x2, IA64_TR_PERCPU_DATA, PERCPU_ADDR,
394                  pte_val(pfn_pte(__pa(my_cpu_data) >> PAGE_SHIFT, PAGE_KERNEL)),
395                  PERCPU_PAGE_SHIFT);
396
397         ia64_set_psr(psr);
398         ia64_srlz_i();
399
400         /*
401          * Check if the virtually mapped linear page table (VMLPT) overlaps with a mapped
402          * address space.  The IA-64 architecture guarantees that at least 50 bits of
403          * virtual address space are implemented but if we pick a large enough page size
404          * (e.g., 64KB), the mapped address space is big enough that it will overlap with
405          * VMLPT.  I assume that once we run on machines big enough to warrant 64KB pages,
406          * IMPL_VA_MSB will be significantly bigger, so this is unlikely to become a
407          * problem in practice.  Alternatively, we could truncate the top of the mapped
408          * address space to not permit mappings that would overlap with the VMLPT.
409          * --davidm 00/12/06
410          */
411 #       define pte_bits                 3
412 #       define mapped_space_bits        (3*(PAGE_SHIFT - pte_bits) + PAGE_SHIFT)
413         /*
414          * The virtual page table has to cover the entire implemented address space within
415          * a region even though not all of this space may be mappable.  The reason for
416          * this is that the Access bit and Dirty bit fault handlers perform
417          * non-speculative accesses to the virtual page table, so the address range of the
418          * virtual page table itself needs to be covered by virtual page table.
419          */
420 #       define vmlpt_bits               (impl_va_bits - PAGE_SHIFT + pte_bits)
421 #       define POW2(n)                  (1ULL << (n))
422
423         impl_va_bits = ffz(~(local_cpu_data->unimpl_va_mask | (7UL << 61)));
424
425         if (impl_va_bits < 51 || impl_va_bits > 61)
426                 panic("CPU has bogus IMPL_VA_MSB value of %lu!\n", impl_va_bits - 1);
427
428         /* place the VMLPT at the end of each page-table mapped region: */
429         pta = POW2(61) - POW2(vmlpt_bits);
430
431         if (POW2(mapped_space_bits) >= pta)
432                 panic("mm/init: overlap between virtually mapped linear page table and "
433                       "mapped kernel space!");
434         /*
435          * Set the (virtually mapped linear) page table address.  Bit
436          * 8 selects between the short and long format, bits 2-7 the
437          * size of the table, and bit 0 whether the VHPT walker is
438          * enabled.
439          */
440         ia64_set_pta(pta | (0 << 8) | (vmlpt_bits << 2) | VHPT_ENABLE_BIT);
441
442         ia64_tlb_init();
443
444 #ifdef  CONFIG_HUGETLB_PAGE
445         ia64_set_rr(HPAGE_REGION_BASE, HPAGE_SHIFT << 2);
446         ia64_srlz_d();
447 #endif
448
449         cpu = smp_processor_id();
450
451         /* mca handler uses cr.lid as key to pick the right entry */
452         ia64_mca_tlb_list[cpu].cr_lid = ia64_getreg(_IA64_REG_CR_LID);
453
454         /* insert this percpu data information into our list for MCA recovery purposes */
455         ia64_mca_tlb_list[cpu].percpu_paddr = pte_val(mk_pte_phys(__pa(my_cpu_data), PAGE_KERNEL));
456         /* Also save per-cpu tlb flush recipe for use in physical mode mca handler */
457         ia64_mca_tlb_list[cpu].ptce_base = local_cpu_data->ptce_base;
458         ia64_mca_tlb_list[cpu].ptce_count[0] = local_cpu_data->ptce_count[0];
459         ia64_mca_tlb_list[cpu].ptce_count[1] = local_cpu_data->ptce_count[1];
460         ia64_mca_tlb_list[cpu].ptce_stride[0] = local_cpu_data->ptce_stride[0];
461         ia64_mca_tlb_list[cpu].ptce_stride[1] = local_cpu_data->ptce_stride[1];
462 }
463
464 #ifdef CONFIG_VIRTUAL_MEM_MAP
465
466 int
467 create_mem_map_page_table (u64 start, u64 end, void *arg)
468 {
469         unsigned long address, start_page, end_page;
470         struct page *map_start, *map_end;
471         int node;
472         pgd_t *pgd;
473         pmd_t *pmd;
474         pte_t *pte;
475
476         map_start = vmem_map + (__pa(start) >> PAGE_SHIFT);
477         map_end   = vmem_map + (__pa(end) >> PAGE_SHIFT);
478
479         start_page = (unsigned long) map_start & PAGE_MASK;
480         end_page = PAGE_ALIGN((unsigned long) map_end);
481         node = paddr_to_nid(__pa(start));
482
483         for (address = start_page; address < end_page; address += PAGE_SIZE) {
484                 pgd = pgd_offset_k(address);
485                 if (pgd_none(*pgd))
486                         pgd_populate(&init_mm, pgd, alloc_bootmem_pages_node(NODE_DATA(node), PAGE_SIZE));
487                 pmd = pmd_offset(pgd, address);
488
489                 if (pmd_none(*pmd))
490                         pmd_populate_kernel(&init_mm, pmd, alloc_bootmem_pages_node(NODE_DATA(node), PAGE_SIZE));
491                 pte = pte_offset_kernel(pmd, address);
492
493                 if (pte_none(*pte))
494                         set_pte(pte, pfn_pte(__pa(alloc_bootmem_pages_node(NODE_DATA(node), PAGE_SIZE)) >> PAGE_SHIFT,
495                                              PAGE_KERNEL));
496         }
497         return 0;
498 }
499
500 struct memmap_init_callback_data {
501         struct page *start;
502         struct page *end;
503         int nid;
504         unsigned long zone;
505 };
506
507 static int
508 virtual_memmap_init (u64 start, u64 end, void *arg)
509 {
510         struct memmap_init_callback_data *args;
511         struct page *map_start, *map_end;
512
513         args = (struct memmap_init_callback_data *) arg;
514
515         map_start = vmem_map + (__pa(start) >> PAGE_SHIFT);
516         map_end   = vmem_map + (__pa(end) >> PAGE_SHIFT);
517
518         if (map_start < args->start)
519                 map_start = args->start;
520         if (map_end > args->end)
521                 map_end = args->end;
522
523         /*
524          * We have to initialize "out of bounds" struct page elements that fit completely
525          * on the same pages that were allocated for the "in bounds" elements because they
526          * may be referenced later (and found to be "reserved").
527          */
528         map_start -= ((unsigned long) map_start & (PAGE_SIZE - 1)) / sizeof(struct page);
529         map_end += ((PAGE_ALIGN((unsigned long) map_end) - (unsigned long) map_end)
530                     / sizeof(struct page));
531
532         if (map_start < map_end)
533                 memmap_init_zone((unsigned long)(map_end - map_start),
534                                  args->nid, args->zone, page_to_pfn(map_start));
535         return 0;
536 }
537
538 void
539 memmap_init (unsigned long size, int nid, unsigned long zone,
540              unsigned long start_pfn)
541 {
542         if (!vmem_map)
543                 memmap_init_zone(size, nid, zone, start_pfn);
544         else {
545                 struct page *start;
546                 struct memmap_init_callback_data args;
547
548                 start = pfn_to_page(start_pfn);
549                 args.start = start;
550                 args.end = start + size;
551                 args.nid = nid;
552                 args.zone = zone;
553
554                 efi_memmap_walk(virtual_memmap_init, &args);
555         }
556 }
557
558 int
559 ia64_pfn_valid (unsigned long pfn)
560 {
561         char byte;
562         struct page *pg = pfn_to_page(pfn);
563
564         return     (__get_user(byte, (char __user *) pg) == 0)
565                 && ((((u64)pg & PAGE_MASK) == (((u64)(pg + 1) - 1) & PAGE_MASK))
566                         || (__get_user(byte, (char __user *) (pg + 1) - 1) == 0));
567 }
568 EXPORT_SYMBOL(ia64_pfn_valid);
569
570 int
571 find_largest_hole (u64 start, u64 end, void *arg)
572 {
573         u64 *max_gap = arg;
574
575         static u64 last_end = PAGE_OFFSET;
576
577         /* NOTE: this algorithm assumes efi memmap table is ordered */
578
579         if (*max_gap < (start - last_end))
580                 *max_gap = start - last_end;
581         last_end = end;
582         return 0;
583 }
584 #endif /* CONFIG_VIRTUAL_MEM_MAP */
585
586 static int
587 count_reserved_pages (u64 start, u64 end, void *arg)
588 {
589         unsigned long num_reserved = 0;
590         unsigned long *count = arg;
591
592         for (; start < end; start += PAGE_SIZE)
593                 if (PageReserved(virt_to_page(start)))
594                         ++num_reserved;
595         *count += num_reserved;
596         return 0;
597 }
598
599 /*
600  * Boot command-line option "nolwsys" can be used to disable the use of any light-weight
601  * system call handler.  When this option is in effect, all fsyscalls will end up bubbling
602  * down into the kernel and calling the normal (heavy-weight) syscall handler.  This is
603  * useful for performance testing, but conceivably could also come in handy for debugging
604  * purposes.
605  */
606
607 static int nolwsys;
608
609 static int __init
610 nolwsys_setup (char *s)
611 {
612         nolwsys = 1;
613         return 1;
614 }
615
616 __setup("nolwsys", nolwsys_setup);
617
618 void
619 mem_init (void)
620 {
621         long reserved_pages, codesize, datasize, initsize;
622         unsigned long num_pgt_pages;
623         pg_data_t *pgdat;
624         int i;
625         static struct kcore_list kcore_mem, kcore_vmem, kcore_kernel;
626
627 #ifdef CONFIG_PCI
628         /*
629          * This needs to be called _after_ the command line has been parsed but _before_
630          * any drivers that may need the PCI DMA interface are initialized or bootmem has
631          * been freed.
632          */
633         platform_dma_init();
634 #endif
635
636 #ifndef CONFIG_DISCONTIGMEM
637         if (!mem_map)
638                 BUG();
639         max_mapnr = max_low_pfn;
640 #endif
641
642         high_memory = __va(max_low_pfn * PAGE_SIZE);
643
644         kclist_add(&kcore_mem, __va(0), max_low_pfn * PAGE_SIZE);
645         kclist_add(&kcore_vmem, (void *)VMALLOC_START, VMALLOC_END-VMALLOC_START);
646         kclist_add(&kcore_kernel, _stext, _end - _stext);
647
648         for_each_pgdat(pgdat)
649                 totalram_pages += free_all_bootmem_node(pgdat);
650
651         reserved_pages = 0;
652         efi_memmap_walk(count_reserved_pages, &reserved_pages);
653
654         codesize =  (unsigned long) _etext - (unsigned long) _stext;
655         datasize =  (unsigned long) _edata - (unsigned long) _etext;
656         initsize =  (unsigned long) __init_end - (unsigned long) __init_begin;
657
658         printk(KERN_INFO "Memory: %luk/%luk available (%luk code, %luk reserved, "
659                "%luk data, %luk init)\n", (unsigned long) nr_free_pages() << (PAGE_SHIFT - 10),
660                num_physpages << (PAGE_SHIFT - 10), codesize >> 10,
661                reserved_pages << (PAGE_SHIFT - 10), datasize >> 10, initsize >> 10);
662
663         /*
664          * Allow for enough (cached) page table pages so that we can map the entire memory
665          * at least once.  Each task also needs a couple of page tables pages, so add in a
666          * fudge factor for that (don't use "threads-max" here; that would be wrong!).
667          * Don't allow the cache to be more than 10% of total memory, though.
668          */
669 #       define NUM_TASKS        500     /* typical number of tasks */
670         num_pgt_pages = nr_free_pages() / PTRS_PER_PGD + NUM_TASKS;
671         if (num_pgt_pages > nr_free_pages() / 10)
672                 num_pgt_pages = nr_free_pages() / 10;
673         if (num_pgt_pages > (u64) pgt_cache_water[1])
674                 pgt_cache_water[1] = num_pgt_pages;
675
676         /*
677          * For fsyscall entrpoints with no light-weight handler, use the ordinary
678          * (heavy-weight) handler, but mark it by setting bit 0, so the fsyscall entry
679          * code can tell them apart.
680          */
681         for (i = 0; i < NR_syscalls; ++i) {
682                 extern unsigned long fsyscall_table[NR_syscalls];
683                 extern unsigned long sys_call_table[NR_syscalls];
684
685                 if (!fsyscall_table[i] || nolwsys)
686                         fsyscall_table[i] = sys_call_table[i] | 1;
687         }
688         setup_gate();
689
690 #ifdef CONFIG_IA32_SUPPORT
691         ia32_mem_init();
692 #endif
693 }