mm: add memory optimization. [1/1]

PD#SWPL-128561

Problem:
add memory optimization.

Solution:
add memory optimization.

Verify:
local.

Change-Id: I28b07555f88ce0c395edd384d7664217f6ddc329
Signed-off-by: Jianxiong Pan <jianxiong.pan@amlogic.com>
This commit is contained in:
Jianxiong Pan
2023-06-20 19:32:11 +08:00
committed by Dongjin Kim
parent ef7821ce7c
commit f1d84fcb1f
13 changed files with 74 additions and 2 deletions

View File

@@ -3105,8 +3105,10 @@ static int device_add_class_symlinks(struct device *dev)
if (of_node) {
error = sysfs_create_link(&dev->kobj, of_node_kobj(of_node), "of_node");
#ifndef CONFIG_AMLOGIC_DTB_NODE_OPT
if (error)
dev_warn(dev, "Error %d creating of_node link\n",error);
#endif
/* An error here doesn't warrant bringing down the device */
}

View File

@@ -166,8 +166,9 @@ void __of_phandle_cache_inv_entry(phandle handle)
void __init of_core_init(void)
{
#ifndef CONFIG_AMLOGIC_DTB_NODE_OPT
struct device_node *np;
#endif
/* Create the kset, and register existing nodes */
mutex_lock(&of_mutex);
@@ -177,11 +178,13 @@ void __init of_core_init(void)
pr_err("failed to register existing nodes\n");
return;
}
#ifndef CONFIG_AMLOGIC_DTB_NODE_OPT
for_each_of_allnodes(np) {
__of_attach_node_sysfs(np);
if (np->phandle && !phandle_cache[of_phandle_cache_hash(np->phandle)])
phandle_cache[of_phandle_cache_hash(np->phandle)] = np;
}
#endif
mutex_unlock(&of_mutex);
/* Symlink in /proc as required by userspace ABI */

View File

@@ -84,12 +84,15 @@
* number: the "number" of the padding variable in the structure. Start with
* 1 and go up.
*/
#ifdef CONFIG_AMLOGIC_MEMORY_OPT
#define ANDROID_KABI_RESERVE(number)
#else
#ifdef CONFIG_ANDROID_KABI_RESERVE
#define ANDROID_KABI_RESERVE(number) _ANDROID_KABI_RESERVE(number)
#else
#define ANDROID_KABI_RESERVE(number)
#endif
#endif /* CONFIG_AMLOGIC_OPT */
/*
* Macros to use _after_ the ABI is frozen

View File

@@ -26,6 +26,15 @@
* Same as ANDROID_VENDOR_DATA but allocates an array of u64 with
* the specified size
*/
#ifdef CONFIG_AMLOGIC_MEMORY_OPT
#define ANDROID_VENDOR_DATA(n)
#define ANDROID_VENDOR_DATA_ARRAY(n, s)
#define ANDROID_OEM_DATA(n)
#define ANDROID_OEM_DATA_ARRAY(n, s)
#define android_init_vendor_data(p, n)
#define android_init_oem_data(p, n)
#else
#ifdef CONFIG_ANDROID_VENDOR_OEM_DATA
#define ANDROID_VENDOR_DATA(n) u64 android_vendor_data##n
#define ANDROID_VENDOR_DATA_ARRAY(n, s) u64 android_vendor_data##n[s]
@@ -46,5 +55,6 @@
#define android_init_vendor_data(p, n)
#define android_init_oem_data(p, n)
#endif
#endif
#endif /* _ANDROID_VENDOR_H */

View File

@@ -336,6 +336,10 @@ extern int kptr_restrict;
* would prefix all pr_info, pr_emerg... messages in the file with the module
* name.
*/
#ifdef CONFIG_AMLOGIC_MEMORY_OPT
#undef pr_fmt
#endif
#ifndef pr_fmt
#define pr_fmt(fmt) fmt
#endif

View File

@@ -16,7 +16,11 @@
#ifdef CONFIG_SHADOW_CALL_STACK
#define SCS_ORDER 0
#ifdef CONFIG_AMLOGIC_MEMORY_OPT
#define SCS_SIZE (SZ_2K)
#else
#define SCS_SIZE (PAGE_SIZE << SCS_ORDER)
#endif
#define GFP_SCS (GFP_KERNEL | __GFP_ZERO)
/* An illegal pointer value to mark the end of the shadow stack. */

View File

@@ -214,10 +214,12 @@ struct task_struct init_task
#ifdef CONFIG_SECCOMP_FILTER
.seccomp = { .filter_count = ATOMIC_INIT(0) },
#endif
#ifndef CONFIG_AMLOGIC_MEMORY_OPT
#ifdef CONFIG_ANDROID_VENDOR_OEM_DATA
.android_vendor_data1 = {0, },
.android_oem_data1 = {0, },
#endif
#endif
};
EXPORT_SYMBOL(init_task);

View File

@@ -81,7 +81,9 @@ obj-$(CONFIG_UTS_NS) += utsname.o
obj-$(CONFIG_USER_NS) += user_namespace.o
obj-$(CONFIG_PID_NS) += pid_namespace.o
obj-$(CONFIG_IKCONFIG) += configs.o
ifndef CONFIG_AMLOGIC_KHEADERS_OPT
obj-$(CONFIG_IKHEADERS) += kheaders.o
endif
obj-$(CONFIG_SMP) += stop_machine.o
obj-$(CONFIG_KPROBES_SANITY_TEST) += test_kprobes.o
obj-$(CONFIG_AUDIT) += audit.o auditfilter.o
@@ -146,8 +148,16 @@ $(obj)/config_data.gz: $(obj)/config_data FORCE
filechk_cat = cat $<
ifdef CONFIG_AMLOGIC_CONFIG_OPT
$(obj)/cfg_less.txt: $(KCONFIG_CONFIG) FORCE
$(shell sed '/#/d' $(KCONFIG_CONFIG) > $(src)/cfg_less.txt)
$(obj)/config_data: $(obj)/cfg_less.txt FORCE
$(call filechk,cat)
else
$(obj)/config_data: $(KCONFIG_CONFIG) FORCE
$(call filechk,cat)
endif
$(obj)/kheaders.o: $(obj)/kheaders_data.tar.xz

View File

@@ -1045,9 +1045,11 @@ static struct task_struct *dup_task_struct(struct task_struct *orig, int node)
#ifdef CONFIG_MEMCG
tsk->active_memcg = NULL;
#endif
#ifndef CONFIG_AMLOGIC_MEMORY_OPT
#ifdef CONFIG_ANDROID_VENDOR_OEM_DATA
memset(&tsk->android_vendor_data1, 0, sizeof(tsk->android_vendor_data1));
memset(&tsk->android_oem_data1, 0, sizeof(tsk->android_oem_data1));
#endif
#endif
trace_android_vh_dup_task_struct(tsk, orig);
return tsk;

View File

@@ -2743,15 +2743,21 @@ static bool is_core_symbol(const Elf_Sym *src, const Elf_Shdr *sechdrs,
|| !src->st_name)
return false;
#ifndef CONFIG_AMLOGIC_KALLSYM_OPT
#ifdef CONFIG_KALLSYMS_ALL
if (src->st_shndx == pcpundx)
return true;
#endif
#endif
sec = sechdrs + src->st_shndx;
if (!(sec->sh_flags & SHF_ALLOC)
#ifdef CONFIG_AMLOGIC_KALLSYM_OPT
|| !(sec->sh_flags & SHF_EXECINSTR)
#else
#ifndef CONFIG_KALLSYMS_ALL
|| !(sec->sh_flags & SHF_EXECINSTR)
#endif
#endif
|| (sec->sh_entsize & INIT_OFFSET_MASK))
return false;

View File

@@ -421,8 +421,13 @@ static u32 log_buf_len = __LOG_BUF_LEN;
#if CONFIG_LOG_BUF_SHIFT <= PRB_AVGBITS
#error CONFIG_LOG_BUF_SHIFT value too small.
#endif
#ifdef CONFIG_AMLOGIC_PRINTK_OPT
_DEFINE_PRINTKRB(printk_rb_static, CONFIG_LOG_BUF_SHIFT - PRB_AVGBITS - 2,
PRB_AVGBITS, &__log_buf[0]);
#else
_DEFINE_PRINTKRB(printk_rb_static, CONFIG_LOG_BUF_SHIFT - PRB_AVGBITS,
PRB_AVGBITS, &__log_buf[0]);
#endif
static struct printk_ringbuffer printk_rb_dynamic;

View File

@@ -11,6 +11,9 @@
#include <linux/scs.h>
#include <linux/vmalloc.h>
#include <linux/vmstat.h>
#ifdef CONFIG_AMLOGIC_MEMORY_OPT
#include <linux/slab.h>
#endif
#ifdef CONFIG_DYNAMIC_SCS
DEFINE_STATIC_KEY_FALSE(dynamic_scs_enabled);
@@ -36,16 +39,22 @@ static void *__scs_alloc(int node)
for (i = 0; i < NR_CACHED_SCS; i++) {
s = this_cpu_xchg(scs_cache[i], NULL);
if (s) {
#ifndef CONFIG_AMLOGIC_MEMORY_OPT
s = kasan_unpoison_vmalloc(s, SCS_SIZE,
KASAN_VMALLOC_PROT_NORMAL);
#endif
memset(s, 0, SCS_SIZE);
goto out;
}
}
#ifdef CONFIG_AMLOGIC_MEMORY_OPT
s = kmalloc(SCS_SIZE, GFP_SCS);
#else
s = __vmalloc_node_range(SCS_SIZE, 1, VMALLOC_START, VMALLOC_END,
GFP_SCS, PAGE_KERNEL, 0, node,
__builtin_return_address(0));
#endif
out:
return kasan_reset_tag(s);
@@ -86,8 +95,12 @@ void scs_free(void *s)
if (this_cpu_cmpxchg(scs_cache[i], 0, s) == NULL)
return;
#ifdef CONFIG_AMLOGIC_MEMORY_OPT
kfree(s);
#else
kasan_unpoison_vmalloc(s, SCS_SIZE, KASAN_VMALLOC_PROT_NORMAL);
vfree_atomic(s);
#endif
}
static int scs_cleanup(unsigned int cpu)
@@ -96,7 +109,11 @@ static int scs_cleanup(unsigned int cpu)
void **cache = per_cpu_ptr(scs_cache, cpu);
for (i = 0; i < NR_CACHED_SCS; i++) {
#ifdef CONFIG_AMLOGIC_MEMORY_OPT
kfree(cache[i]);
#else
vfree(cache[i]);
#endif
cache[i] = NULL;
}

View File

@@ -67,7 +67,11 @@ static DECLARE_WORK(slab_caches_to_rcu_destroy_work,
/*
* Merge control. If this is set then no merging of slab caches will occur.
*/
#ifdef CONFIG_AMLOGIC_MEMORY_OPT
static bool slab_nomerge = true;
#else
static bool slab_nomerge = !IS_ENABLED(CONFIG_SLAB_MERGE_DEFAULT);
#endif
static int __init setup_slab_nomerge(char *str)
{