提交 1cca8ee5 编写于 作者: L Liu Shixin 提交者: Yongqiang Liu

dhugetlb: isolate dynamic hugetlb code

hulk inclusion
category: feature
bugzilla: 46904, https://gitee.com/openeuler/kernel/issues/I6BDME
CVE: NA

--------------------------------

Add CONFIG_DYNAMIC_HUGETLB in struct mem_cgroup_extension and struct
hugetlbfs_inode_info to isolate the member.

Add CONFIG_DYNAMIC_HUGETLB for pageflag PG_pool to isolate it.
Signed-off-by: NLiu Shixin <liushixin2@huawei.com>
Reviewed-by: NKefeng Wang <wangkefeng.wang@huawei.com>
Signed-off-by: NYongqiang Liu <liuyongqiang13@huawei.com>
上级 0bc0d0d5
...@@ -1164,8 +1164,10 @@ static struct inode *hugetlbfs_alloc_inode(struct super_block *sb) ...@@ -1164,8 +1164,10 @@ static struct inode *hugetlbfs_alloc_inode(struct super_block *sb)
* private inode. This simplifies hugetlbfs_destroy_inode. * private inode. This simplifies hugetlbfs_destroy_inode.
*/ */
mpol_shared_policy_init(&p->policy, NULL); mpol_shared_policy_init(&p->policy, NULL);
#ifdef CONFIG_DYNAMIC_HUGETLB
/* Initialize hpool here in case of a quick call to destroy */ /* Initialize hpool here in case of a quick call to destroy */
p->hpool = get_dhugetlb_pool_from_task(current); p->hpool = get_dhugetlb_pool_from_task(current);
#endif
return &p->vfs_inode; return &p->vfs_inode;
} }
...@@ -1180,8 +1182,10 @@ static void hugetlbfs_destroy_inode(struct inode *inode) ...@@ -1180,8 +1182,10 @@ static void hugetlbfs_destroy_inode(struct inode *inode)
{ {
hugetlbfs_inc_free_inodes(HUGETLBFS_SB(inode->i_sb)); hugetlbfs_inc_free_inodes(HUGETLBFS_SB(inode->i_sb));
mpol_free_shared_policy(&HUGETLBFS_I(inode)->policy); mpol_free_shared_policy(&HUGETLBFS_I(inode)->policy);
#ifdef CONFIG_DYNAMIC_HUGETLB
dhugetlb_pool_put(HUGETLBFS_I(inode)->hpool); dhugetlb_pool_put(HUGETLBFS_I(inode)->hpool);
HUGETLBFS_I(inode)->hpool = NULL; HUGETLBFS_I(inode)->hpool = NULL;
#endif
call_rcu(&inode->i_rcu, hugetlbfs_i_callback); call_rcu(&inode->i_rcu, hugetlbfs_i_callback);
} }
......
...@@ -289,7 +289,9 @@ struct hugetlbfs_inode_info { ...@@ -289,7 +289,9 @@ struct hugetlbfs_inode_info {
struct shared_policy policy; struct shared_policy policy;
struct inode vfs_inode; struct inode vfs_inode;
unsigned int seals; unsigned int seals;
#ifdef CONFIG_DYNAMIC_HUGETLB
struct dhugetlb_pool *hpool; struct dhugetlb_pool *hpool;
#endif
}; };
static inline struct hugetlbfs_inode_info *HUGETLBFS_I(struct inode *inode) static inline struct hugetlbfs_inode_info *HUGETLBFS_I(struct inode *inode)
......
...@@ -326,7 +326,9 @@ struct mem_cgroup { ...@@ -326,7 +326,9 @@ struct mem_cgroup {
}; };
struct mem_cgroup_extension { struct mem_cgroup_extension {
#ifdef CONFIG_DYNAMIC_HUGETLB
struct dhugetlb_pool *hpool; struct dhugetlb_pool *hpool;
#endif
#ifdef CONFIG_MEMCG_QOS #ifdef CONFIG_MEMCG_QOS
/* Currently support 0 and -1. /* Currently support 0 and -1.
* in the future it can expand to other value. * in the future it can expand to other value.
......
...@@ -102,7 +102,9 @@ enum pageflags { ...@@ -102,7 +102,9 @@ enum pageflags {
PG_idle, PG_idle,
#endif #endif
PG_percpu_ref, PG_percpu_ref,
#ifdef CONFIG_DYNAMIC_HUGETLB
PG_pool, PG_pool,
#endif
__NR_PAGEFLAGS, __NR_PAGEFLAGS,
/* Filesystems */ /* Filesystems */
...@@ -285,7 +287,13 @@ PAGEFLAG(Active, active, PF_HEAD) __CLEARPAGEFLAG(Active, active, PF_HEAD) ...@@ -285,7 +287,13 @@ PAGEFLAG(Active, active, PF_HEAD) __CLEARPAGEFLAG(Active, active, PF_HEAD)
__PAGEFLAG(Slab, slab, PF_NO_TAIL) __PAGEFLAG(Slab, slab, PF_NO_TAIL)
__PAGEFLAG(SlobFree, slob_free, PF_NO_TAIL) __PAGEFLAG(SlobFree, slob_free, PF_NO_TAIL)
PAGEFLAG(Checked, checked, PF_NO_COMPOUND) /* Used by some filesystems */ PAGEFLAG(Checked, checked, PF_NO_COMPOUND) /* Used by some filesystems */
#ifdef CONFIG_DYNAMIC_HUGETLB
PAGEFLAG(Pool, pool, PF_NO_TAIL) PAGEFLAG(Pool, pool, PF_NO_TAIL)
#define __PG_POOL (1UL << PG_pool)
#else
PAGEFLAG_FALSE(Pool)
#define __PG_POOL 0
#endif
/* Xen */ /* Xen */
PAGEFLAG(Pinned, pinned, PF_NO_COMPOUND) PAGEFLAG(Pinned, pinned, PF_NO_COMPOUND)
...@@ -772,7 +780,7 @@ static inline void ClearPageSlabPfmemalloc(struct page *page) ...@@ -772,7 +780,7 @@ static inline void ClearPageSlabPfmemalloc(struct page *page)
1UL << PG_private | 1UL << PG_private_2 | \ 1UL << PG_private | 1UL << PG_private_2 | \
1UL << PG_writeback | 1UL << PG_reserved | \ 1UL << PG_writeback | 1UL << PG_reserved | \
1UL << PG_slab | 1UL << PG_active | \ 1UL << PG_slab | 1UL << PG_active | \
1UL << PG_pool | \ __PG_POOL | \
1UL << PG_unevictable | __PG_MLOCKED) 1UL << PG_unevictable | __PG_MLOCKED)
/* /*
......
...@@ -79,9 +79,14 @@ ...@@ -79,9 +79,14 @@
#define IF_HAVE_PG_IDLE(flag,string) #define IF_HAVE_PG_IDLE(flag,string)
#endif #endif
#ifdef CONFIG_DYNAMIC_HUGETLB
#define IF_HAVE_PG_POOL(flag,string) ,{1UL << flag, string}
#else
#define IF_HAVE_PG_POOL(flag,string)
#endif
#define __def_pageflag_names \ #define __def_pageflag_names \
{1UL << PG_locked, "locked" }, \ {1UL << PG_locked, "locked" }, \
{1UL << PG_pool, "pool" }, \
{1UL << PG_waiters, "waiters" }, \ {1UL << PG_waiters, "waiters" }, \
{1UL << PG_error, "error" }, \ {1UL << PG_error, "error" }, \
{1UL << PG_referenced, "referenced" }, \ {1UL << PG_referenced, "referenced" }, \
...@@ -102,6 +107,7 @@ ...@@ -102,6 +107,7 @@
{1UL << PG_swapbacked, "swapbacked" }, \ {1UL << PG_swapbacked, "swapbacked" }, \
{1UL << PG_unevictable, "unevictable" } \ {1UL << PG_unevictable, "unevictable" } \
IF_HAVE_PG_MLOCK(PG_mlocked, "mlocked" ) \ IF_HAVE_PG_MLOCK(PG_mlocked, "mlocked" ) \
IF_HAVE_PG_POOL(PG_pool, "pool" ) \
IF_HAVE_PG_UNCACHED(PG_uncached, "uncached" ) \ IF_HAVE_PG_UNCACHED(PG_uncached, "uncached" ) \
IF_HAVE_PG_HWPOISON(PG_hwpoison, "hwpoison" ) \ IF_HAVE_PG_HWPOISON(PG_hwpoison, "hwpoison" ) \
IF_HAVE_PG_IDLE(PG_young, "young" ) \ IF_HAVE_PG_IDLE(PG_young, "young" ) \
......
...@@ -601,6 +601,18 @@ static long region_del(struct resv_map *resv, long f, long t) ...@@ -601,6 +601,18 @@ static long region_del(struct resv_map *resv, long f, long t)
return del; return del;
} }
#ifdef CONFIG_DYNAMIC_HUGETLB
static struct dhugetlb_pool *get_hpool_from_inode(struct inode *inode)
{
return HUGETLBFS_I(inode)->hpool;
}
#else
static struct dhugetlb_pool *get_hpool_from_inode(struct inode *inode)
{
return NULL;
}
#endif
/* /*
* A rare out of memory error was encountered which prevented removal of * A rare out of memory error was encountered which prevented removal of
* the reserve map region for a page. The huge page itself was free'ed * the reserve map region for a page. The huge page itself was free'ed
...@@ -615,7 +627,7 @@ void hugetlb_fix_reserve_counts(struct inode *inode) ...@@ -615,7 +627,7 @@ void hugetlb_fix_reserve_counts(struct inode *inode)
struct hugepage_subpool *spool = subpool_inode(inode); struct hugepage_subpool *spool = subpool_inode(inode);
long rsv_adjust; long rsv_adjust;
bool reserved = false; bool reserved = false;
struct dhugetlb_pool *hpool = HUGETLBFS_I(inode)->hpool; struct dhugetlb_pool *hpool = get_hpool_from_inode(inode);
rsv_adjust = hugepage_subpool_get_pages(spool, 1, hpool); rsv_adjust = hugepage_subpool_get_pages(spool, 1, hpool);
if (rsv_adjust > 0) { if (rsv_adjust > 0) {
...@@ -2380,7 +2392,7 @@ struct page *alloc_huge_page(struct vm_area_struct *vma, ...@@ -2380,7 +2392,7 @@ struct page *alloc_huge_page(struct vm_area_struct *vma,
int ret, idx; int ret, idx;
struct hugetlb_cgroup *h_cg; struct hugetlb_cgroup *h_cg;
struct dhugetlb_pool *hpool = struct dhugetlb_pool *hpool =
HUGETLBFS_I(file_inode(vma->vm_file))->hpool; get_hpool_from_inode(file_inode(vma->vm_file));
idx = hstate_index(h); idx = hstate_index(h);
/* /*
...@@ -4673,7 +4685,7 @@ static void hugetlb_vm_op_close(struct vm_area_struct *vma) ...@@ -4673,7 +4685,7 @@ static void hugetlb_vm_op_close(struct vm_area_struct *vma)
unsigned long reserve, start, end; unsigned long reserve, start, end;
long gbl_reserve; long gbl_reserve;
struct dhugetlb_pool *hpool = struct dhugetlb_pool *hpool =
HUGETLBFS_I(file_inode(vma->vm_file))->hpool; get_hpool_from_inode(file_inode(vma->vm_file));
if (!resv || !is_vma_resv_set(vma, HPAGE_RESV_OWNER)) if (!resv || !is_vma_resv_set(vma, HPAGE_RESV_OWNER))
return; return;
...@@ -6073,7 +6085,7 @@ int hugetlb_reserve_pages(struct inode *inode, ...@@ -6073,7 +6085,7 @@ int hugetlb_reserve_pages(struct inode *inode,
struct hugepage_subpool *spool = subpool_inode(inode); struct hugepage_subpool *spool = subpool_inode(inode);
struct resv_map *resv_map; struct resv_map *resv_map;
long gbl_reserve; long gbl_reserve;
struct dhugetlb_pool *hpool = HUGETLBFS_I(inode)->hpool; struct dhugetlb_pool *hpool = get_hpool_from_inode(inode);
/* This should never happen */ /* This should never happen */
if (from > to) { if (from > to) {
...@@ -6192,7 +6204,7 @@ long hugetlb_unreserve_pages(struct inode *inode, long start, long end, ...@@ -6192,7 +6204,7 @@ long hugetlb_unreserve_pages(struct inode *inode, long start, long end,
long chg = 0; long chg = 0;
struct hugepage_subpool *spool = subpool_inode(inode); struct hugepage_subpool *spool = subpool_inode(inode);
long gbl_reserve; long gbl_reserve;
struct dhugetlb_pool *hpool = HUGETLBFS_I(inode)->hpool; struct dhugetlb_pool *hpool = get_hpool_from_inode(inode);
/* /*
* Since this routine can be called in the evict inode path for all * Since this routine can be called in the evict inode path for all
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册