1# SPDX-License-Identifier: GPL-2.0-only
2
3menu "Memory Management options"
4
5#
6# For some reason microblaze and nios2 hard code SWAP=n.  Hopefully we can
7# add proper SWAP support to them, in which case this can be remove.
8#
9config ARCH_NO_SWAP
10	bool
11
12config ZPOOL
13	bool
14
15menuconfig SWAP
16	bool "Support for paging of anonymous memory (swap)"
17	depends on MMU && BLOCK && !ARCH_NO_SWAP
18	default y
19	help
20	  This option allows you to choose whether you want to have support
21	  for so called swap devices or swap files in your kernel that are
22	  used to provide more virtual memory than the actual RAM present
23	  in your computer.  If unsure say Y.
24
25config ZSWAP
26	bool "Compressed cache for swap pages"
27	depends on SWAP
28	select FRONTSWAP
29	select CRYPTO
30	select ZPOOL
31	help
32	  A lightweight compressed cache for swap pages.  It takes
33	  pages that are in the process of being swapped out and attempts to
34	  compress them into a dynamically allocated RAM-based memory pool.
35	  This can result in a significant I/O reduction on swap device and,
36	  in the case where decompressing from RAM is faster than swap device
37	  reads, can also improve workload performance.
38
39config ZSWAP_DEFAULT_ON
40	bool "Enable the compressed cache for swap pages by default"
41	depends on ZSWAP
42	help
43	  If selected, the compressed cache for swap pages will be enabled
44	  at boot, otherwise it will be disabled.
45
46	  The selection made here can be overridden by using the kernel
47	  command line 'zswap.enabled=' option.
48
49choice
50	prompt "Default compressor"
51	depends on ZSWAP
52	default ZSWAP_COMPRESSOR_DEFAULT_LZO
53	help
54	  Selects the default compression algorithm for the compressed cache
55	  for swap pages.
56
57	  For an overview what kind of performance can be expected from
58	  a particular compression algorithm please refer to the benchmarks
59	  available at the following LWN page:
60	  https://lwn.net/Articles/751795/
61
62	  If in doubt, select 'LZO'.
63
64	  The selection made here can be overridden by using the kernel
65	  command line 'zswap.compressor=' option.
66
67config ZSWAP_COMPRESSOR_DEFAULT_DEFLATE
68	bool "Deflate"
69	select CRYPTO_DEFLATE
70	help
71	  Use the Deflate algorithm as the default compression algorithm.
72
73config ZSWAP_COMPRESSOR_DEFAULT_LZO
74	bool "LZO"
75	select CRYPTO_LZO
76	help
77	  Use the LZO algorithm as the default compression algorithm.
78
79config ZSWAP_COMPRESSOR_DEFAULT_842
80	bool "842"
81	select CRYPTO_842
82	help
83	  Use the 842 algorithm as the default compression algorithm.
84
85config ZSWAP_COMPRESSOR_DEFAULT_LZ4
86	bool "LZ4"
87	select CRYPTO_LZ4
88	help
89	  Use the LZ4 algorithm as the default compression algorithm.
90
91config ZSWAP_COMPRESSOR_DEFAULT_LZ4HC
92	bool "LZ4HC"
93	select CRYPTO_LZ4HC
94	help
95	  Use the LZ4HC algorithm as the default compression algorithm.
96
97config ZSWAP_COMPRESSOR_DEFAULT_ZSTD
98	bool "zstd"
99	select CRYPTO_ZSTD
100	help
101	  Use the zstd algorithm as the default compression algorithm.
102endchoice
103
104config ZSWAP_COMPRESSOR_DEFAULT
105       string
106       depends on ZSWAP
107       default "deflate" if ZSWAP_COMPRESSOR_DEFAULT_DEFLATE
108       default "lzo" if ZSWAP_COMPRESSOR_DEFAULT_LZO
109       default "842" if ZSWAP_COMPRESSOR_DEFAULT_842
110       default "lz4" if ZSWAP_COMPRESSOR_DEFAULT_LZ4
111       default "lz4hc" if ZSWAP_COMPRESSOR_DEFAULT_LZ4HC
112       default "zstd" if ZSWAP_COMPRESSOR_DEFAULT_ZSTD
113       default ""
114
115choice
116	prompt "Default allocator"
117	depends on ZSWAP
118	default ZSWAP_ZPOOL_DEFAULT_ZBUD
119	help
120	  Selects the default allocator for the compressed cache for
121	  swap pages.
122	  The default is 'zbud' for compatibility, however please do
123	  read the description of each of the allocators below before
124	  making a right choice.
125
126	  The selection made here can be overridden by using the kernel
127	  command line 'zswap.zpool=' option.
128
129config ZSWAP_ZPOOL_DEFAULT_ZBUD
130	bool "zbud"
131	select ZBUD
132	help
133	  Use the zbud allocator as the default allocator.
134
135config ZSWAP_ZPOOL_DEFAULT_Z3FOLD
136	bool "z3fold"
137	select Z3FOLD
138	help
139	  Use the z3fold allocator as the default allocator.
140
141config ZSWAP_ZPOOL_DEFAULT_ZSMALLOC
142	bool "zsmalloc"
143	select ZSMALLOC
144	help
145	  Use the zsmalloc allocator as the default allocator.
146endchoice
147
148config ZSWAP_ZPOOL_DEFAULT
149       string
150       depends on ZSWAP
151       default "zbud" if ZSWAP_ZPOOL_DEFAULT_ZBUD
152       default "z3fold" if ZSWAP_ZPOOL_DEFAULT_Z3FOLD
153       default "zsmalloc" if ZSWAP_ZPOOL_DEFAULT_ZSMALLOC
154       default ""
155
156config ZBUD
157	tristate "2:1 compression allocator (zbud)"
158	depends on ZSWAP
159	help
160	  A special purpose allocator for storing compressed pages.
161	  It is designed to store up to two compressed pages per physical
162	  page.  While this design limits storage density, it has simple and
163	  deterministic reclaim properties that make it preferable to a higher
164	  density approach when reclaim will be used.
165
166config Z3FOLD
167	tristate "3:1 compression allocator (z3fold)"
168	depends on ZSWAP
169	help
170	  A special purpose allocator for storing compressed pages.
171	  It is designed to store up to three compressed pages per physical
172	  page. It is a ZBUD derivative so the simplicity and determinism are
173	  still there.
174
175config ZSMALLOC
176	tristate
177	prompt "N:1 compression allocator (zsmalloc)" if ZSWAP
178	depends on MMU
179	help
180	  zsmalloc is a slab-based memory allocator designed to store
181	  pages of various compression levels efficiently. It achieves
182	  the highest storage density with the least amount of fragmentation.
183
184config ZSMALLOC_STAT
185	bool "Export zsmalloc statistics"
186	depends on ZSMALLOC
187	select DEBUG_FS
188	help
189	  This option enables code in the zsmalloc to collect various
190	  statistics about what's happening in zsmalloc and exports that
191	  information to userspace via debugfs.
192	  If unsure, say N.
193
194config ZSMALLOC_CHAIN_SIZE
195	int "Maximum number of physical pages per-zspage"
196	default 8
197	range 4 16
198	depends on ZSMALLOC
199	help
200	  This option sets the upper limit on the number of physical pages
201	  that a zmalloc page (zspage) can consist of. The optimal zspage
202	  chain size is calculated for each size class during the
203	  initialization of the pool.
204
205	  Changing this option can alter the characteristics of size classes,
206	  such as the number of pages per zspage and the number of objects
207	  per zspage. This can also result in different configurations of
208	  the pool, as zsmalloc merges size classes with similar
209	  characteristics.
210
211	  For more information, see zsmalloc documentation.
212
213menu "SLAB allocator options"
214
215choice
216	prompt "Choose SLAB allocator"
217	default SLUB
218	help
219	   This option allows to select a slab allocator.
220
221config SLAB
222	bool "SLAB"
223	depends on !PREEMPT_RT
224	select HAVE_HARDENED_USERCOPY_ALLOCATOR
225	help
226	  The regular slab allocator that is established and known to work
227	  well in all environments. It organizes cache hot objects in
228	  per cpu and per node queues.
229
230config SLUB
231	bool "SLUB (Unqueued Allocator)"
232	select HAVE_HARDENED_USERCOPY_ALLOCATOR
233	help
234	   SLUB is a slab allocator that minimizes cache line usage
235	   instead of managing queues of cached objects (SLAB approach).
236	   Per cpu caching is realized using slabs of objects instead
237	   of queues of objects. SLUB can use memory efficiently
238	   and has enhanced diagnostics. SLUB is the default choice for
239	   a slab allocator.
240
241config SLOB_DEPRECATED
242	depends on EXPERT
243	bool "SLOB (Simple Allocator - DEPRECATED)"
244	depends on !PREEMPT_RT
245	help
246	   Deprecated and scheduled for removal in a few cycles. SLUB
247	   recommended as replacement. CONFIG_SLUB_TINY can be considered
248	   on systems with 16MB or less RAM.
249
250	   If you need SLOB to stay, please contact linux-mm@kvack.org and
251	   people listed in the SLAB ALLOCATOR section of MAINTAINERS file,
252	   with your use case.
253
254	   SLOB replaces the stock allocator with a drastically simpler
255	   allocator. SLOB is generally more space efficient but
256	   does not perform as well on large systems.
257
258endchoice
259
260config SLOB
261	bool
262	default y
263	depends on SLOB_DEPRECATED
264
265config SLUB_TINY
266	bool "Configure SLUB for minimal memory footprint"
267	depends on SLUB && EXPERT
268	select SLAB_MERGE_DEFAULT
269	help
270	   Configures the SLUB allocator in a way to achieve minimal memory
271	   footprint, sacrificing scalability, debugging and other features.
272	   This is intended only for the smallest system that had used the
273	   SLOB allocator and is not recommended for systems with more than
274	   16MB RAM.
275
276	   If unsure, say N.
277
278config SLAB_MERGE_DEFAULT
279	bool "Allow slab caches to be merged"
280	default y
281	depends on SLAB || SLUB
282	help
283	  For reduced kernel memory fragmentation, slab caches can be
284	  merged when they share the same size and other characteristics.
285	  This carries a risk of kernel heap overflows being able to
286	  overwrite objects from merged caches (and more easily control
287	  cache layout), which makes such heap attacks easier to exploit
288	  by attackers. By keeping caches unmerged, these kinds of exploits
289	  can usually only damage objects in the same cache. To disable
290	  merging at runtime, "slab_nomerge" can be passed on the kernel
291	  command line.
292
293config SLAB_FREELIST_RANDOM
294	bool "Randomize slab freelist"
295	depends on SLAB || (SLUB && !SLUB_TINY)
296	help
297	  Randomizes the freelist order used on creating new pages. This
298	  security feature reduces the predictability of the kernel slab
299	  allocator against heap overflows.
300
301config SLAB_FREELIST_HARDENED
302	bool "Harden slab freelist metadata"
303	depends on SLAB || (SLUB && !SLUB_TINY)
304	help
305	  Many kernel heap attacks try to target slab cache metadata and
306	  other infrastructure. This options makes minor performance
307	  sacrifices to harden the kernel slab allocator against common
308	  freelist exploit methods. Some slab implementations have more
309	  sanity-checking than others. This option is most effective with
310	  CONFIG_SLUB.
311
312config SLUB_STATS
313	default n
314	bool "Enable SLUB performance statistics"
315	depends on SLUB && SYSFS && !SLUB_TINY
316	help
317	  SLUB statistics are useful to debug SLUBs allocation behavior in
318	  order find ways to optimize the allocator. This should never be
319	  enabled for production use since keeping statistics slows down
320	  the allocator by a few percentage points. The slabinfo command
321	  supports the determination of the most active slabs to figure
322	  out which slabs are relevant to a particular load.
323	  Try running: slabinfo -DA
324
325config SLUB_CPU_PARTIAL
326	default y
327	depends on SLUB && SMP && !SLUB_TINY
328	bool "SLUB per cpu partial cache"
329	help
330	  Per cpu partial caches accelerate objects allocation and freeing
331	  that is local to a processor at the price of more indeterminism
332	  in the latency of the free. On overflow these caches will be cleared
333	  which requires the taking of locks that may cause latency spikes.
334	  Typically one would choose no for a realtime system.
335
336endmenu # SLAB allocator options
337
338config SHUFFLE_PAGE_ALLOCATOR
339	bool "Page allocator randomization"
340	default SLAB_FREELIST_RANDOM && ACPI_NUMA
341	help
342	  Randomization of the page allocator improves the average
343	  utilization of a direct-mapped memory-side-cache. See section
344	  5.2.27 Heterogeneous Memory Attribute Table (HMAT) in the ACPI
345	  6.2a specification for an example of how a platform advertises
346	  the presence of a memory-side-cache. There are also incidental
347	  security benefits as it reduces the predictability of page
348	  allocations to compliment SLAB_FREELIST_RANDOM, but the
349	  default granularity of shuffling on the "MAX_ORDER - 1" i.e,
350	  10th order of pages is selected based on cache utilization
351	  benefits on x86.
352
353	  While the randomization improves cache utilization it may
354	  negatively impact workloads on platforms without a cache. For
355	  this reason, by default, the randomization is enabled only
356	  after runtime detection of a direct-mapped memory-side-cache.
357	  Otherwise, the randomization may be force enabled with the
358	  'page_alloc.shuffle' kernel command line parameter.
359
360	  Say Y if unsure.
361
362config COMPAT_BRK
363	bool "Disable heap randomization"
364	default y
365	help
366	  Randomizing heap placement makes heap exploits harder, but it
367	  also breaks ancient binaries (including anything libc5 based).
368	  This option changes the bootup default to heap randomization
369	  disabled, and can be overridden at runtime by setting
370	  /proc/sys/kernel/randomize_va_space to 2.
371
372	  On non-ancient distros (post-2000 ones) N is usually a safe choice.
373
374config MMAP_ALLOW_UNINITIALIZED
375	bool "Allow mmapped anonymous memory to be uninitialized"
376	depends on EXPERT && !MMU
377	default n
378	help
379	  Normally, and according to the Linux spec, anonymous memory obtained
380	  from mmap() has its contents cleared before it is passed to
381	  userspace.  Enabling this config option allows you to request that
382	  mmap() skip that if it is given an MAP_UNINITIALIZED flag, thus
383	  providing a huge performance boost.  If this option is not enabled,
384	  then the flag will be ignored.
385
386	  This is taken advantage of by uClibc's malloc(), and also by
387	  ELF-FDPIC binfmt's brk and stack allocator.
388
389	  Because of the obvious security issues, this option should only be
390	  enabled on embedded devices where you control what is run in
391	  userspace.  Since that isn't generally a problem on no-MMU systems,
392	  it is normally safe to say Y here.
393
394	  See Documentation/admin-guide/mm/nommu-mmap.rst for more information.
395
396config SELECT_MEMORY_MODEL
397	def_bool y
398	depends on ARCH_SELECT_MEMORY_MODEL
399
400choice
401	prompt "Memory model"
402	depends on SELECT_MEMORY_MODEL
403	default SPARSEMEM_MANUAL if ARCH_SPARSEMEM_DEFAULT
404	default FLATMEM_MANUAL
405	help
406	  This option allows you to change some of the ways that
407	  Linux manages its memory internally. Most users will
408	  only have one option here selected by the architecture
409	  configuration. This is normal.
410
411config FLATMEM_MANUAL
412	bool "Flat Memory"
413	depends on !ARCH_SPARSEMEM_ENABLE || ARCH_FLATMEM_ENABLE
414	help
415	  This option is best suited for non-NUMA systems with
416	  flat address space. The FLATMEM is the most efficient
417	  system in terms of performance and resource consumption
418	  and it is the best option for smaller systems.
419
420	  For systems that have holes in their physical address
421	  spaces and for features like NUMA and memory hotplug,
422	  choose "Sparse Memory".
423
424	  If unsure, choose this option (Flat Memory) over any other.
425
426config SPARSEMEM_MANUAL
427	bool "Sparse Memory"
428	depends on ARCH_SPARSEMEM_ENABLE
429	help
430	  This will be the only option for some systems, including
431	  memory hot-plug systems.  This is normal.
432
433	  This option provides efficient support for systems with
434	  holes is their physical address space and allows memory
435	  hot-plug and hot-remove.
436
437	  If unsure, choose "Flat Memory" over this option.
438
439endchoice
440
441config SPARSEMEM
442	def_bool y
443	depends on (!SELECT_MEMORY_MODEL && ARCH_SPARSEMEM_ENABLE) || SPARSEMEM_MANUAL
444
445config FLATMEM
446	def_bool y
447	depends on !SPARSEMEM || FLATMEM_MANUAL
448
449#
450# SPARSEMEM_EXTREME (which is the default) does some bootmem
451# allocations when sparse_init() is called.  If this cannot
452# be done on your architecture, select this option.  However,
453# statically allocating the mem_section[] array can potentially
454# consume vast quantities of .bss, so be careful.
455#
456# This option will also potentially produce smaller runtime code
457# with gcc 3.4 and later.
458#
459config SPARSEMEM_STATIC
460	bool
461
462#
463# Architecture platforms which require a two level mem_section in SPARSEMEM
464# must select this option. This is usually for architecture platforms with
465# an extremely sparse physical address space.
466#
467config SPARSEMEM_EXTREME
468	def_bool y
469	depends on SPARSEMEM && !SPARSEMEM_STATIC
470
471config SPARSEMEM_VMEMMAP_ENABLE
472	bool
473
474config SPARSEMEM_VMEMMAP
475	bool "Sparse Memory virtual memmap"
476	depends on SPARSEMEM && SPARSEMEM_VMEMMAP_ENABLE
477	default y
478	help
479	  SPARSEMEM_VMEMMAP uses a virtually mapped memmap to optimise
480	  pfn_to_page and page_to_pfn operations.  This is the most
481	  efficient option when sufficient kernel resources are available.
482
483config HAVE_MEMBLOCK_PHYS_MAP
484	bool
485
486config HAVE_FAST_GUP
487	depends on MMU
488	bool
489
490# Don't discard allocated memory used to track "memory" and "reserved" memblocks
491# after early boot, so it can still be used to test for validity of memory.
492# Also, memblocks are updated with memory hot(un)plug.
493config ARCH_KEEP_MEMBLOCK
494	bool
495
496# Keep arch NUMA mapping infrastructure post-init.
497config NUMA_KEEP_MEMINFO
498	bool
499
500config MEMORY_ISOLATION
501	bool
502
503# IORESOURCE_SYSTEM_RAM regions in the kernel resource tree that are marked
504# IORESOURCE_EXCLUSIVE cannot be mapped to user space, for example, via
505# /dev/mem.
506config EXCLUSIVE_SYSTEM_RAM
507	def_bool y
508	depends on !DEVMEM || STRICT_DEVMEM
509
510#
511# Only be set on architectures that have completely implemented memory hotplug
512# feature. If you are not sure, don't touch it.
513#
514config HAVE_BOOTMEM_INFO_NODE
515	def_bool n
516
517config ARCH_ENABLE_MEMORY_HOTPLUG
518	bool
519
520config ARCH_ENABLE_MEMORY_HOTREMOVE
521	bool
522
523# eventually, we can have this option just 'select SPARSEMEM'
524menuconfig MEMORY_HOTPLUG
525	bool "Memory hotplug"
526	select MEMORY_ISOLATION
527	depends on SPARSEMEM
528	depends on ARCH_ENABLE_MEMORY_HOTPLUG
529	depends on 64BIT
530	select NUMA_KEEP_MEMINFO if NUMA
531
532if MEMORY_HOTPLUG
533
534config MEMORY_HOTPLUG_DEFAULT_ONLINE
535	bool "Online the newly added memory blocks by default"
536	depends on MEMORY_HOTPLUG
537	help
538	  This option sets the default policy setting for memory hotplug
539	  onlining policy (/sys/devices/system/memory/auto_online_blocks) which
540	  determines what happens to newly added memory regions. Policy setting
541	  can always be changed at runtime.
542	  See Documentation/admin-guide/mm/memory-hotplug.rst for more information.
543
544	  Say Y here if you want all hot-plugged memory blocks to appear in
545	  'online' state by default.
546	  Say N here if you want the default policy to keep all hot-plugged
547	  memory blocks in 'offline' state.
548
549config MEMORY_HOTREMOVE
550	bool "Allow for memory hot remove"
551	select HAVE_BOOTMEM_INFO_NODE if (X86_64 || PPC64)
552	depends on MEMORY_HOTPLUG && ARCH_ENABLE_MEMORY_HOTREMOVE
553	depends on MIGRATION
554
555config MHP_MEMMAP_ON_MEMORY
556	def_bool y
557	depends on MEMORY_HOTPLUG && SPARSEMEM_VMEMMAP
558	depends on ARCH_MHP_MEMMAP_ON_MEMORY_ENABLE
559
560endif # MEMORY_HOTPLUG
561
562# Heavily threaded applications may benefit from splitting the mm-wide
563# page_table_lock, so that faults on different parts of the user address
564# space can be handled with less contention: split it at this NR_CPUS.
565# Default to 4 for wider testing, though 8 might be more appropriate.
566# ARM's adjust_pte (unused if VIPT) depends on mm-wide page_table_lock.
567# PA-RISC 7xxx's spinlock_t would enlarge struct page from 32 to 44 bytes.
568# SPARC32 allocates multiple pte tables within a single page, and therefore
569# a per-page lock leads to problems when multiple tables need to be locked
570# at the same time (e.g. copy_page_range()).
571# DEBUG_SPINLOCK and DEBUG_LOCK_ALLOC spinlock_t also enlarge struct page.
572#
573config SPLIT_PTLOCK_CPUS
574	int
575	default "999999" if !MMU
576	default "999999" if ARM && !CPU_CACHE_VIPT
577	default "999999" if PARISC && !PA20
578	default "999999" if SPARC32
579	default "4"
580
581config ARCH_ENABLE_SPLIT_PMD_PTLOCK
582	bool
583
584#
585# support for memory balloon
586config MEMORY_BALLOON
587	bool
588
589#
590# support for memory balloon compaction
591config BALLOON_COMPACTION
592	bool "Allow for balloon memory compaction/migration"
593	def_bool y
594	depends on COMPACTION && MEMORY_BALLOON
595	help
596	  Memory fragmentation introduced by ballooning might reduce
597	  significantly the number of 2MB contiguous memory blocks that can be
598	  used within a guest, thus imposing performance penalties associated
599	  with the reduced number of transparent huge pages that could be used
600	  by the guest workload. Allowing the compaction & migration for memory
601	  pages enlisted as being part of memory balloon devices avoids the
602	  scenario aforementioned and helps improving memory defragmentation.
603
604#
605# support for memory compaction
606config COMPACTION
607	bool "Allow for memory compaction"
608	def_bool y
609	select MIGRATION
610	depends on MMU
611	help
612	  Compaction is the only memory management component to form
613	  high order (larger physically contiguous) memory blocks
614	  reliably. The page allocator relies on compaction heavily and
615	  the lack of the feature can lead to unexpected OOM killer
616	  invocations for high order memory requests. You shouldn't
617	  disable this option unless there really is a strong reason for
618	  it and then we would be really interested to hear about that at
619	  linux-mm@kvack.org.
620
621config COMPACT_UNEVICTABLE_DEFAULT
622	int
623	depends on COMPACTION
624	default 0 if PREEMPT_RT
625	default 1
626
627#
628# support for free page reporting
629config PAGE_REPORTING
630	bool "Free page reporting"
631	def_bool n
632	help
633	  Free page reporting allows for the incremental acquisition of
634	  free pages from the buddy allocator for the purpose of reporting
635	  those pages to another entity, such as a hypervisor, so that the
636	  memory can be freed within the host for other uses.
637
638#
639# support for page migration
640#
641config MIGRATION
642	bool "Page migration"
643	def_bool y
644	depends on (NUMA || ARCH_ENABLE_MEMORY_HOTREMOVE || COMPACTION || CMA) && MMU
645	help
646	  Allows the migration of the physical location of pages of processes
647	  while the virtual addresses are not changed. This is useful in
648	  two situations. The first is on NUMA systems to put pages nearer
649	  to the processors accessing. The second is when allocating huge
650	  pages as migration can relocate pages to satisfy a huge page
651	  allocation instead of reclaiming.
652
653config DEVICE_MIGRATION
654	def_bool MIGRATION && ZONE_DEVICE
655
656config ARCH_ENABLE_HUGEPAGE_MIGRATION
657	bool
658
659config ARCH_ENABLE_THP_MIGRATION
660	bool
661
662config HUGETLB_PAGE_SIZE_VARIABLE
663	def_bool n
664	help
665	  Allows the pageblock_order value to be dynamic instead of just standard
666	  HUGETLB_PAGE_ORDER when there are multiple HugeTLB page sizes available
667	  on a platform.
668
669	  Note that the pageblock_order cannot exceed MAX_ORDER - 1 and will be
670	  clamped down to MAX_ORDER - 1.
671
672config CONTIG_ALLOC
673	def_bool (MEMORY_ISOLATION && COMPACTION) || CMA
674
675config PHYS_ADDR_T_64BIT
676	def_bool 64BIT
677
678config BOUNCE
679	bool "Enable bounce buffers"
680	default y
681	depends on BLOCK && MMU && HIGHMEM
682	help
683	  Enable bounce buffers for devices that cannot access the full range of
684	  memory available to the CPU. Enabled by default when HIGHMEM is
685	  selected, but you may say n to override this.
686
687config MMU_NOTIFIER
688	bool
689	select SRCU
690	select INTERVAL_TREE
691
692config KSM
693	bool "Enable KSM for page merging"
694	depends on MMU
695	select XXHASH
696	help
697	  Enable Kernel Samepage Merging: KSM periodically scans those areas
698	  of an application's address space that an app has advised may be
699	  mergeable.  When it finds pages of identical content, it replaces
700	  the many instances by a single page with that content, so
701	  saving memory until one or another app needs to modify the content.
702	  Recommended for use with KVM, or with other duplicative applications.
703	  See Documentation/mm/ksm.rst for more information: KSM is inactive
704	  until a program has madvised that an area is MADV_MERGEABLE, and
705	  root has set /sys/kernel/mm/ksm/run to 1 (if CONFIG_SYSFS is set).
706
707config DEFAULT_MMAP_MIN_ADDR
708	int "Low address space to protect from user allocation"
709	depends on MMU
710	default 4096
711	help
712	  This is the portion of low virtual memory which should be protected
713	  from userspace allocation.  Keeping a user from writing to low pages
714	  can help reduce the impact of kernel NULL pointer bugs.
715
716	  For most ia64, ppc64 and x86 users with lots of address space
717	  a value of 65536 is reasonable and should cause no problems.
718	  On arm and other archs it should not be higher than 32768.
719	  Programs which use vm86 functionality or have some need to map
720	  this low address space will need CAP_SYS_RAWIO or disable this
721	  protection by setting the value to 0.
722
723	  This value can be changed after boot using the
724	  /proc/sys/vm/mmap_min_addr tunable.
725
726config ARCH_SUPPORTS_MEMORY_FAILURE
727	bool
728
729config MEMORY_FAILURE
730	depends on MMU
731	depends on ARCH_SUPPORTS_MEMORY_FAILURE
732	bool "Enable recovery from hardware memory errors"
733	select MEMORY_ISOLATION
734	select RAS
735	help
736	  Enables code to recover from some memory failures on systems
737	  with MCA recovery. This allows a system to continue running
738	  even when some of its memory has uncorrected errors. This requires
739	  special hardware support and typically ECC memory.
740
741config HWPOISON_INJECT
742	tristate "HWPoison pages injector"
743	depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS
744	select PROC_PAGE_MONITOR
745
746config NOMMU_INITIAL_TRIM_EXCESS
747	int "Turn on mmap() excess space trimming before booting"
748	depends on !MMU
749	default 1
750	help
751	  The NOMMU mmap() frequently needs to allocate large contiguous chunks
752	  of memory on which to store mappings, but it can only ask the system
753	  allocator for chunks in 2^N*PAGE_SIZE amounts - which is frequently
754	  more than it requires.  To deal with this, mmap() is able to trim off
755	  the excess and return it to the allocator.
756
757	  If trimming is enabled, the excess is trimmed off and returned to the
758	  system allocator, which can cause extra fragmentation, particularly
759	  if there are a lot of transient processes.
760
761	  If trimming is disabled, the excess is kept, but not used, which for
762	  long-term mappings means that the space is wasted.
763
764	  Trimming can be dynamically controlled through a sysctl option
765	  (/proc/sys/vm/nr_trim_pages) which specifies the minimum number of
766	  excess pages there must be before trimming should occur, or zero if
767	  no trimming is to occur.
768
769	  This option specifies the initial value of this option.  The default
770	  of 1 says that all excess pages should be trimmed.
771
772	  See Documentation/admin-guide/mm/nommu-mmap.rst for more information.
773
774config ARCH_WANT_GENERAL_HUGETLB
775	bool
776
777config ARCH_WANTS_THP_SWAP
778	def_bool n
779
780menuconfig TRANSPARENT_HUGEPAGE
781	bool "Transparent Hugepage Support"
782	depends on HAVE_ARCH_TRANSPARENT_HUGEPAGE && !PREEMPT_RT
783	select COMPACTION
784	select XARRAY_MULTI
785	help
786	  Transparent Hugepages allows the kernel to use huge pages and
787	  huge tlb transparently to the applications whenever possible.
788	  This feature can improve computing performance to certain
789	  applications by speeding up page faults during memory
790	  allocation, by reducing the number of tlb misses and by speeding
791	  up the pagetable walking.
792
793	  If memory constrained on embedded, you may want to say N.
794
795if TRANSPARENT_HUGEPAGE
796
797choice
798	prompt "Transparent Hugepage Support sysfs defaults"
799	depends on TRANSPARENT_HUGEPAGE
800	default TRANSPARENT_HUGEPAGE_ALWAYS
801	help
802	  Selects the sysfs defaults for Transparent Hugepage Support.
803
804	config TRANSPARENT_HUGEPAGE_ALWAYS
805		bool "always"
806	help
807	  Enabling Transparent Hugepage always, can increase the
808	  memory footprint of applications without a guaranteed
809	  benefit but it will work automatically for all applications.
810
811	config TRANSPARENT_HUGEPAGE_MADVISE
812		bool "madvise"
813	help
814	  Enabling Transparent Hugepage madvise, will only provide a
815	  performance improvement benefit to the applications using
816	  madvise(MADV_HUGEPAGE) but it won't risk to increase the
817	  memory footprint of applications without a guaranteed
818	  benefit.
819endchoice
820
821config THP_SWAP
822	def_bool y
823	depends on TRANSPARENT_HUGEPAGE && ARCH_WANTS_THP_SWAP && SWAP && 64BIT
824	help
825	  Swap transparent huge pages in one piece, without splitting.
826	  XXX: For now, swap cluster backing transparent huge page
827	  will be split after swapout.
828
829	  For selection by architectures with reasonable THP sizes.
830
831config READ_ONLY_THP_FOR_FS
832	bool "Read-only THP for filesystems (EXPERIMENTAL)"
833	depends on TRANSPARENT_HUGEPAGE && SHMEM
834
835	help
836	  Allow khugepaged to put read-only file-backed pages in THP.
837
838	  This is marked experimental because it is a new feature. Write
839	  support of file THPs will be developed in the next few release
840	  cycles.
841
842endif # TRANSPARENT_HUGEPAGE
843
844#
845# UP and nommu archs use km based percpu allocator
846#
847config NEED_PER_CPU_KM
848	depends on !SMP || !MMU
849	bool
850	default y
851
852config NEED_PER_CPU_EMBED_FIRST_CHUNK
853	bool
854
855config NEED_PER_CPU_PAGE_FIRST_CHUNK
856	bool
857
858config USE_PERCPU_NUMA_NODE_ID
859	bool
860
861config HAVE_SETUP_PER_CPU_AREA
862	bool
863
864config FRONTSWAP
865	bool
866
867config CMA
868	bool "Contiguous Memory Allocator"
869	depends on MMU
870	select MIGRATION
871	select MEMORY_ISOLATION
872	help
873	  This enables the Contiguous Memory Allocator which allows other
874	  subsystems to allocate big physically-contiguous blocks of memory.
875	  CMA reserves a region of memory and allows only movable pages to
876	  be allocated from it. This way, the kernel can use the memory for
877	  pagecache and when a subsystem requests for contiguous area, the
878	  allocated pages are migrated away to serve the contiguous request.
879
880	  If unsure, say "n".
881
882config CMA_DEBUG
883	bool "CMA debug messages (DEVELOPMENT)"
884	depends on DEBUG_KERNEL && CMA
885	help
886	  Turns on debug messages in CMA.  This produces KERN_DEBUG
887	  messages for every CMA call as well as various messages while
888	  processing calls such as dma_alloc_from_contiguous().
889	  This option does not affect warning and error messages.
890
891config CMA_DEBUGFS
892	bool "CMA debugfs interface"
893	depends on CMA && DEBUG_FS
894	help
895	  Turns on the DebugFS interface for CMA.
896
897config CMA_SYSFS
898	bool "CMA information through sysfs interface"
899	depends on CMA && SYSFS
900	help
901	  This option exposes some sysfs attributes to get information
902	  from CMA.
903
904config CMA_AREAS
905	int "Maximum count of the CMA areas"
906	depends on CMA
907	default 19 if NUMA
908	default 7
909	help
910	  CMA allows to create CMA areas for particular purpose, mainly,
911	  used as device private area. This parameter sets the maximum
912	  number of CMA area in the system.
913
914	  If unsure, leave the default value "7" in UMA and "19" in NUMA.
915
916config MEM_SOFT_DIRTY
917	bool "Track memory changes"
918	depends on CHECKPOINT_RESTORE && HAVE_ARCH_SOFT_DIRTY && PROC_FS
919	select PROC_PAGE_MONITOR
920	help
921	  This option enables memory changes tracking by introducing a
922	  soft-dirty bit on pte-s. This bit it set when someone writes
923	  into a page just as regular dirty bit, but unlike the latter
924	  it can be cleared by hands.
925
926	  See Documentation/admin-guide/mm/soft-dirty.rst for more details.
927
928config GENERIC_EARLY_IOREMAP
929	bool
930
931config STACK_MAX_DEFAULT_SIZE_MB
932	int "Default maximum user stack size for 32-bit processes (MB)"
933	default 100
934	range 8 2048
935	depends on STACK_GROWSUP && (!64BIT || COMPAT)
936	help
937	  This is the maximum stack size in Megabytes in the VM layout of 32-bit
938	  user processes when the stack grows upwards (currently only on parisc
939	  arch) when the RLIMIT_STACK hard limit is unlimited.
940
941	  A sane initial value is 100 MB.
942
943config DEFERRED_STRUCT_PAGE_INIT
944	bool "Defer initialisation of struct pages to kthreads"
945	depends on SPARSEMEM
946	depends on !NEED_PER_CPU_KM
947	depends on 64BIT
948	select PADATA
949	help
950	  Ordinarily all struct pages are initialised during early boot in a
951	  single thread. On very large machines this can take a considerable
952	  amount of time. If this option is set, large machines will bring up
953	  a subset of memmap at boot and then initialise the rest in parallel.
954	  This has a potential performance impact on tasks running early in the
955	  lifetime of the system until these kthreads finish the
956	  initialisation.
957
958config PAGE_IDLE_FLAG
959	bool
960	select PAGE_EXTENSION if !64BIT
961	help
962	  This adds PG_idle and PG_young flags to 'struct page'.  PTE Accessed
963	  bit writers can set the state of the bit in the flags so that PTE
964	  Accessed bit readers may avoid disturbance.
965
966config IDLE_PAGE_TRACKING
967	bool "Enable idle page tracking"
968	depends on SYSFS && MMU
969	select PAGE_IDLE_FLAG
970	help
971	  This feature allows to estimate the amount of user pages that have
972	  not been touched during a given period of time. This information can
973	  be useful to tune memory cgroup limits and/or for job placement
974	  within a compute cluster.
975
976	  See Documentation/admin-guide/mm/idle_page_tracking.rst for
977	  more details.
978
979config ARCH_HAS_CACHE_LINE_SIZE
980	bool
981
982config ARCH_HAS_CURRENT_STACK_POINTER
983	bool
984	help
985	  In support of HARDENED_USERCOPY performing stack variable lifetime
986	  checking, an architecture-agnostic way to find the stack pointer
987	  is needed. Once an architecture defines an unsigned long global
988	  register alias named "current_stack_pointer", this config can be
989	  selected.
990
991config ARCH_HAS_PTE_DEVMAP
992	bool
993
994config ARCH_HAS_ZONE_DMA_SET
995	bool
996
997config ZONE_DMA
998	bool "Support DMA zone" if ARCH_HAS_ZONE_DMA_SET
999	default y if ARM64 || X86
1000
1001config ZONE_DMA32
1002	bool "Support DMA32 zone" if ARCH_HAS_ZONE_DMA_SET
1003	depends on !X86_32
1004	default y if ARM64
1005
1006config ZONE_DEVICE
1007	bool "Device memory (pmem, HMM, etc...) hotplug support"
1008	depends on MEMORY_HOTPLUG
1009	depends on MEMORY_HOTREMOVE
1010	depends on SPARSEMEM_VMEMMAP
1011	depends on ARCH_HAS_PTE_DEVMAP
1012	select XARRAY_MULTI
1013
1014	help
1015	  Device memory hotplug support allows for establishing pmem,
1016	  or other device driver discovered memory regions, in the
1017	  memmap. This allows pfn_to_page() lookups of otherwise
1018	  "device-physical" addresses which is needed for using a DAX
1019	  mapping in an O_DIRECT operation, among other things.
1020
1021	  If FS_DAX is enabled, then say Y.
1022
1023#
1024# Helpers to mirror range of the CPU page tables of a process into device page
1025# tables.
1026#
1027config HMM_MIRROR
1028	bool
1029	depends on MMU
1030
1031config GET_FREE_REGION
1032	depends on SPARSEMEM
1033	bool
1034
1035config DEVICE_PRIVATE
1036	bool "Unaddressable device memory (GPU memory, ...)"
1037	depends on ZONE_DEVICE
1038	select GET_FREE_REGION
1039
1040	help
1041	  Allows creation of struct pages to represent unaddressable device
1042	  memory; i.e., memory that is only accessible from the device (or
1043	  group of devices). You likely also want to select HMM_MIRROR.
1044
1045config VMAP_PFN
1046	bool
1047
1048config ARCH_USES_HIGH_VMA_FLAGS
1049	bool
1050config ARCH_HAS_PKEYS
1051	bool
1052
1053config ARCH_USES_PG_ARCH_X
1054	bool
1055	help
1056	  Enable the definition of PG_arch_x page flags with x > 1. Only
1057	  suitable for 64-bit architectures with CONFIG_FLATMEM or
1058	  CONFIG_SPARSEMEM_VMEMMAP enabled, otherwise there may not be
1059	  enough room for additional bits in page->flags.
1060
1061config VM_EVENT_COUNTERS
1062	default y
1063	bool "Enable VM event counters for /proc/vmstat" if EXPERT
1064	help
1065	  VM event counters are needed for event counts to be shown.
1066	  This option allows the disabling of the VM event counters
1067	  on EXPERT systems.  /proc/vmstat will only show page counts
1068	  if VM event counters are disabled.
1069
1070config PERCPU_STATS
1071	bool "Collect percpu memory statistics"
1072	help
1073	  This feature collects and exposes statistics via debugfs. The
1074	  information includes global and per chunk statistics, which can
1075	  be used to help understand percpu memory usage.
1076
1077config GUP_TEST
1078	bool "Enable infrastructure for get_user_pages()-related unit tests"
1079	depends on DEBUG_FS
1080	help
1081	  Provides /sys/kernel/debug/gup_test, which in turn provides a way
1082	  to make ioctl calls that can launch kernel-based unit tests for
1083	  the get_user_pages*() and pin_user_pages*() family of API calls.
1084
1085	  These tests include benchmark testing of the _fast variants of
1086	  get_user_pages*() and pin_user_pages*(), as well as smoke tests of
1087	  the non-_fast variants.
1088
1089	  There is also a sub-test that allows running dump_page() on any
1090	  of up to eight pages (selected by command line args) within the
1091	  range of user-space addresses. These pages are either pinned via
1092	  pin_user_pages*(), or pinned via get_user_pages*(), as specified
1093	  by other command line arguments.
1094
1095	  See tools/testing/selftests/mm/gup_test.c
1096
1097comment "GUP_TEST needs to have DEBUG_FS enabled"
1098	depends on !GUP_TEST && !DEBUG_FS
1099
1100config GUP_GET_PXX_LOW_HIGH
1101	bool
1102
1103config ARCH_HAS_PTE_SPECIAL
1104	bool
1105
1106#
1107# Some architectures require a special hugepage directory format that is
1108# required to support multiple hugepage sizes. For example a4fe3ce76
1109# "powerpc/mm: Allow more flexible layouts for hugepage pagetables"
1110# introduced it on powerpc.  This allows for a more flexible hugepage
1111# pagetable layouts.
1112#
1113config ARCH_HAS_HUGEPD
1114	bool
1115
1116config MAPPING_DIRTY_HELPERS
1117        bool
1118
1119config KMAP_LOCAL
1120	bool
1121
1122config KMAP_LOCAL_NON_LINEAR_PTE_ARRAY
1123	bool
1124
1125# struct io_mapping based helper.  Selected by drivers that need them
1126config IO_MAPPING
1127	bool
1128
1129config SECRETMEM
1130	default y
1131	bool "Enable memfd_secret() system call" if EXPERT
1132	depends on ARCH_HAS_SET_DIRECT_MAP
1133	help
1134	  Enable the memfd_secret() system call with the ability to create
1135	  memory areas visible only in the context of the owning process and
1136	  not mapped to other processes and other kernel page tables.
1137
1138config ANON_VMA_NAME
1139	bool "Anonymous VMA name support"
1140	depends on PROC_FS && ADVISE_SYSCALLS && MMU
1141
1142	help
1143	  Allow naming anonymous virtual memory areas.
1144
1145	  This feature allows assigning names to virtual memory areas. Assigned
1146	  names can be later retrieved from /proc/pid/maps and /proc/pid/smaps
1147	  and help identifying individual anonymous memory areas.
1148	  Assigning a name to anonymous virtual memory area might prevent that
1149	  area from being merged with adjacent virtual memory areas due to the
1150	  difference in their name.
1151
1152config USERFAULTFD
1153	bool "Enable userfaultfd() system call"
1154	depends on MMU
1155	help
1156	  Enable the userfaultfd() system call that allows to intercept and
1157	  handle page faults in userland.
1158
1159config HAVE_ARCH_USERFAULTFD_WP
1160	bool
1161	help
1162	  Arch has userfaultfd write protection support
1163
1164config HAVE_ARCH_USERFAULTFD_MINOR
1165	bool
1166	help
1167	  Arch has userfaultfd minor fault support
1168
1169config PTE_MARKER_UFFD_WP
1170	bool "Userfaultfd write protection support for shmem/hugetlbfs"
1171	default y
1172	depends on HAVE_ARCH_USERFAULTFD_WP
1173
1174	help
1175	  Allows to create marker PTEs for userfaultfd write protection
1176	  purposes.  It is required to enable userfaultfd write protection on
1177	  file-backed memory types like shmem and hugetlbfs.
1178
1179# multi-gen LRU {
1180config LRU_GEN
1181	bool "Multi-Gen LRU"
1182	depends on MMU
1183	# make sure folio->flags has enough spare bits
1184	depends on 64BIT || !SPARSEMEM || SPARSEMEM_VMEMMAP
1185	help
1186	  A high performance LRU implementation to overcommit memory. See
1187	  Documentation/admin-guide/mm/multigen_lru.rst for details.
1188
1189config LRU_GEN_ENABLED
1190	bool "Enable by default"
1191	depends on LRU_GEN
1192	help
1193	  This option enables the multi-gen LRU by default.
1194
1195config LRU_GEN_STATS
1196	bool "Full stats for debugging"
1197	depends on LRU_GEN
1198	help
1199	  Do not enable this option unless you plan to look at historical stats
1200	  from evicted generations for debugging purpose.
1201
1202	  This option has a per-memcg and per-node memory overhead.
1203# }
1204
1205source "mm/damon/Kconfig"
1206
1207endmenu
1208